Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API changes to constructing DenseSkOps and populating their buffers, set next_state on construction, add web documentation, more stat tests #104

Merged
merged 38 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
81931a9
explicitly remove support for CBRNGs based on AES or ARS. Refactor of…
rileyjmurray Jul 26, 2024
f209a07
some renaming, tweak comments, clean up CMakeLists.txt
rileyjmurray Jul 26, 2024
1d210a0
inline non-templated functions in rng_common.hh. Add a test for incre…
rileyjmurray Jul 27, 2024
d92eb50
Add safe_signed_int_product function (to check for overflows when ind…
rileyjmurray Jul 27, 2024
1946a1c
cleanup of fill_dense_submat_impl
rileyjmurray Jul 27, 2024
4dae5a0
clean up fill_dense_submat_impl
rileyjmurray Jul 27, 2024
421197c
heavily revise fill_dense_submat_impl
rileyjmurray Jul 27, 2024
ae624fc
implemented compute_next_state for DenseSkOp and SparseSkOp
rileyjmurray Jul 27, 2024
d731290
left out
rileyjmurray Jul 27, 2024
d7b9970
Resolve issue #105. Remove unused "convenience" constructors for Dens…
rileyjmurray Aug 2, 2024
60613d3
remove another unnecessary DenseSkOp constructor
rileyjmurray Aug 2, 2024
bf6df16
fix example to account for change in RandBLAS::fill_dense API
rileyjmurray Aug 2, 2024
e2954db
change default compiler optimization level in examples
rileyjmurray Aug 2, 2024
9801761
docstring changes
rileyjmurray Aug 2, 2024
e8e5751
refactor tests for populating DenseSkOp buffers. Add a new page to we…
rileyjmurray Aug 2, 2024
69cdf6f
copyright statement in web docs
rileyjmurray Aug 2, 2024
8d992a4
add Kolmogorov-Smirnov tests for uniform distribution over [-1, 1]. F…
rileyjmurray Aug 3, 2024
3820e3e
KS tests for the Gaussian distribution
rileyjmurray Aug 3, 2024
d7f6c3f
rename test class;
rileyjmurray Aug 3, 2024
b688e53
add isometry_scale_factor functions
rileyjmurray Aug 5, 2024
bd042c0
start of infrastructure for distortion tests
rileyjmurray Aug 5, 2024
2a00447
basic QR by blocked Gram-Schmidt
rileyjmurray Aug 5, 2024
2d89a1f
implement QR via block classical Gram-Schmidt
rileyjmurray Aug 5, 2024
ea1b0b6
rename functions
rileyjmurray Aug 5, 2024
b726e7e
function to compute eigenvalues by QR iteration
rileyjmurray Aug 5, 2024
a0557d1
cholqr2, block_cgs2, cholesky iteration for eigenvalues of positive d…
rileyjmurray Aug 9, 2024
3378c9d
power method is FINE
rileyjmurray Aug 9, 2024
7648683
remove awful lanczos implementaiton. Power method suffices in our con…
rileyjmurray Aug 9, 2024
c39d27d
Make a convenient function for computing extremal eigenvalues of a po…
rileyjmurray Aug 9, 2024
cec1678
passing tests for distortion of Gaussian operators
rileyjmurray Aug 10, 2024
de57a9d
scale uniform to have variance 1. Need to change distributional tests…
rileyjmurray Aug 20, 2024
ede4aa2
Merge branch 'main' into more-stat-tests-local
rileyjmurray Aug 21, 2024
c5c80b2
implementation cleaned up and all tests pass
rileyjmurray Aug 21, 2024
08486e3
change default scalar distribution to Gaussian, since describing the …
rileyjmurray Aug 21, 2024
d5abae5
fix segfault arising from calling the KS test critical value mutator …
rileyjmurray Aug 21, 2024
bbfa43c
remove rouge character
rileyjmurray Aug 21, 2024
0718d2b
Introduce (mostly empty) SketchingDistribution and SketchingOperator …
rileyjmurray Aug 22, 2024
973e327
create an easier-to-understand overload of repeated_fisher_yates. Mak…
rileyjmurray Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 90 additions & 18 deletions RandBLAS/base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,35 @@ template<typename T>
concept SignedInteger = (std::numeric_limits<T>::is_signed && std::numeric_limits<T>::is_integer);


template <SignedInteger TI, SignedInteger TO = int64_t>
inline TO safe_int_product(TI a, TI b) {
if (a == 0 || b == 0) {
return 0;
}
TO c = a * b;
TO b_check = c / a;
TO a_check = c / b;
if ((a_check != a) || (b_check != b)) {
std::stringstream s;
s << "Overflow when multiplying a (=" << a << ") and b(=" << b << "), which resulted in " << c << ".\n";
throw std::overflow_error(s.str());
}
return c;
}


enum class MajorAxis : char {
// ---------------------------------------------------------------------------
/// short-axis vectors (cols of a wide matrix, rows of a tall matrix)
Short = 'S',

// ---------------------------------------------------------------------------
/// long-axis vectors (rows of a wide matrix, cols of a tall matrix)
Long = 'L'
Long = 'L',

// ---------------------------------------------------------------------------
/// Undefined (used when row-major vs column-major must be explicit)
Undefined = 'U'
};


Expand All @@ -134,28 +155,38 @@ enum class MajorAxis : char {
* the counter and the key. The arrays' types are statically sized, small
* (typically of length 2 or 4), and can be distinct from one another.
*
* @tparam RNG A CBRNG type in defined in Random123. We've found that Philox-based
* CBRNGs work best for our purposes. Strictly speaking, we allow all Random123 CBRNGs
* besides those based on AES.
* The template parameter RNG is a CBRNG type in defined in Random123. We've found
* that Philox-based CBRNGs work best for our purposes, but we also support Threefry-based CBRNGS.
*/
template <typename RNG = r123::Philox4x32>
struct RNGState
{
using generator = RNG;
// The unsigned integer type used in this RNGState's counter array.
using ctr_uint_type = typename RNG::ctr_type::value_type;
/// @brief The unsigned integer type used in this RNGState's key array.
/// This is typically std::uint32_t, but it can be std::uint64_t.
using key_uint_type = typename RNG::key_type::value_type;
// An array type defined in Random123.

using ctr_type = typename RNG::ctr_type;
// An array type defined in Random123.
// ^ An array type defined in Random123.
using key_type = typename RNG::key_type;
// ^ An array type defined in Random123.
using ctr_uint = typename RNG::ctr_type::value_type;
// ^ The unsigned integer type used in this RNGState's counter array.

/// -------------------------------------------------------------------
/// @brief The unsigned integer type used in this RNGState's key array.
/// This is typically std::uint32_t, but it can be std::uint64_t.
using key_uint = typename RNG::key_type::value_type;


const static int len_c = RNG::ctr_type::static_size;
const static int len_k = RNG::key_type::static_size;
typename RNG::ctr_type counter; ///< This RNGState's counter array.
typename RNG::key_type key; ///< This RNGState's key array.
typename RNG::ctr_type counter;
// ^ This RNGState's counter array.

/// ------------------------------------------------------------------
/// This RNGState's key array. If you want to manually advance the key
/// by an integer increment of size "step," then you do so by calling
/// this->key.incr(step).
typename RNG::key_type key;


/// Initialize the counter and key arrays to all zeros.
RNGState() : counter{{0}}, key(key_type{{}}) {}
Expand All @@ -171,7 +202,7 @@ struct RNGState

/// Initialize the counter array to all zeros. Initialize the key array to have first
/// element equal to k and all other elements equal to zero.
RNGState(key_uint_type k) : counter{{0}}, key{{k}} {}
RNGState(key_uint k) : counter{{0}}, key{{k}} {}

~RNGState() {};

Expand All @@ -187,16 +218,16 @@ template <typename RNG>
RNGState<RNG>::RNGState(
const RNGState<RNG> &s
) {
std::memcpy(this->counter.v, s.counter.v, this->len_c * sizeof(ctr_uint_type));
std::memcpy(this->key.v, s.key.v, this->len_k * sizeof(key_uint_type));
std::memcpy(this->counter.v, s.counter.v, this->len_c * sizeof(ctr_uint));
std::memcpy(this->key.v, s.key.v, this->len_k * sizeof(key_uint));
}

template <typename RNG>
RNGState<RNG> &RNGState<RNG>::operator=(
const RNGState &s
) {
std::memcpy(this->counter.v, s.counter.v, this->len_c * sizeof(ctr_uint_type));
std::memcpy(this->key.v, s.key.v, this->len_k * sizeof(key_uint_type));
std::memcpy(this->counter.v, s.counter.v, this->len_c * sizeof(ctr_uint));
std::memcpy(this->key.v, s.key.v, this->len_k * sizeof(key_uint));
return *this;
}

Expand All @@ -219,4 +250,45 @@ std::ostream &operator<<(
return out;
}

// =============================================================================
/// @verbatim embed:rst:leading-slashes
///
/// .. NOTE: \ttt expands to \texttt (its definition is given in an rst file)
///
/// Words. Hello!
///
/// @endverbatim
template<typename SkDist>
concept SketchingDistribution = requires(SkDist D) {
{ D.n_rows } -> std::convertible_to<const int64_t>;
{ D.n_cols } -> std::convertible_to<const int64_t>;
{ D.major_axis } -> std::convertible_to<const MajorAxis>;
};

// =============================================================================
/// \fn isometry_scale_factor(SkDist D)
/// @verbatim embed:rst:leading-slashes
/// Words here ...
/// @endverbatim
template <typename T, SketchingDistribution SkDist>
inline T isometry_scale_factor(SkDist D);


// =============================================================================
/// @verbatim embed:rst:leading-slashes
///
/// .. NOTE: \ttt expands to \texttt (its definition is given in an rst file)
///
/// Words. Hello!
///
/// @endverbatim
template<typename SkOp>
concept SketchingOperator = requires(SkOp S) {
{ S.n_rows } -> std::convertible_to<const int64_t>;
{ S.n_cols } -> std::convertible_to<const int64_t>;
{ S.seed_state } -> std::convertible_to<const typename SkOp::state_t>;
{ S.seed_state } -> std::convertible_to<const typename SkOp::state_t>;
};


} // end namespace RandBLAS::base
Loading
Loading