144 T & ref =
array_ptr->touch(i) = std::move(data);
148 [[nodiscard]]
constexpr size_t get_index(
const size_t i,
149 const size_t j)
const noexcept
157 <<
"DynMatrix: row index " << i <<
" out of range [0, " <<
n <<
")";
159 <<
"DynMatrix: column index " << j <<
" out of range [0, " <<
m <<
")";
246 <<
"DynMatrix::set_dimension(" << num_rows <<
", " << num_cols
247 <<
"): the number of entries overflows size_t";
251 auto fresh = std::make_unique<DynArray<T>>(d, s, b);
288 DynMatrix(
const size_t num_rows,
const size_t num_cols,
const T & zero =
T())
292 <<
"DynMatrix dimensions must be > 0";
348 noexcept(std::is_nothrow_default_constructible_v<T>
and
349 std::is_nothrow_swappable_v<T>)
371 if (
n != mat.
n ||
m != mat.
m)
393 noexcept(std::is_nothrow_default_constructible_v<T>
and
394 std::is_nothrow_swappable_v<T>)
416 if (
n != mat.
n ||
m != mat.
m)
419 const size_t N =
n *
m;
420 for (
size_t i = 0; i <
N; ++i)
434 return !(*
this == mat);
441 [[nodiscard]]
constexpr size_t rows() const noexcept {
return n; }
447 [[nodiscard]]
constexpr size_t cols() const noexcept {
return m; }
453 [[nodiscard]]
constexpr size_t size() const noexcept {
return n *
m; }
459 [[nodiscard]]
constexpr bool is_square() const noexcept {
return n ==
m; }
465 [[nodiscard]]
constexpr bool is_empty() const noexcept {
return n == 0 ||
m == 0; }
480 [[nodiscard]]
const T &
read(
const size_t i,
const size_t j)
const
494 [[nodiscard]]
const T &
read_ne(
const size_t i,
const size_t j)
const noexcept
514 T &
write(
const size_t i,
const size_t j,
const T & data)
521 T &
write(
const size_t i,
const size_t j,
T && data)
542 [[nodiscard]]
T &
access(
const size_t i,
const size_t j)
553 [[nodiscard]]
const T &
access(
const size_t i,
const size_t j)
const
577 [[nodiscard]]
const T &
operator () (
const size_t i,
const size_t j)
const
593 for (
size_t idx = 0; idx <
n *
m; ++idx)
608 for (
size_t i = 0; i <
n; ++i)
609 for (
size_t j = 0; j <
m; ++j)
613 result.
write(j, i, val);
669 <<
"DynMatrix::Iterator: no current element";
684 <<
"DynMatrix::Iterator: no more elements";
726 template <
class Operation>
730 for (
size_t i = 0; i <
n *
m; ++i)
737 template <
class Operation>
745 template <
class Operation>
749 return traverse<Operation>(operation);
753 template <
class Operation>
757 return traverse<Operation>(operation);
775 template <
class Operation>
781 const size_t total =
n *
m;
782 for (
size_t idx = 0; idx < total; ++idx)
785 if (!operation(*entry))
793 template <
class Operation>
799 const size_t total =
n *
m;
800 for (
size_t idx = 0; idx < total; ++idx)
803 if (!operation(*entry))
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_unless(C)
Throws std::overflow_error if condition does NOT hold.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
DRY (Don't Repeat Yourself) utilities and macros.
size_t size_t int32_t value
static void compute_sizes(const size_t n, size_t &d, size_t &s, size_t &b)
Given a dimension n, it proposes values for the directory, segment and block sizes.
Iterator for traversing matrix elements.
Iterator(const DynMatrix< T > &mat) noexcept
Construct an iterator for a matrix.
size_t get_row() const noexcept
Get the current row index.
const T & get_curr() const
Get the current element.
const T & get_curr_ne() const noexcept
Get the current element without bounds checking.
const DynMatrix * mat_ptr
void next_ne() noexcept
Advance to the next element without bounds checking.
bool has_curr() const noexcept
Check if iterator has a current element.
size_t get_col() const noexcept
Get the current column index.
void next()
Advance to the next element.
void reset() noexcept
Reset iterator to the beginning.
Dynamic matrix with sparse storage.
bool traverse(Operation &operation) const
Traverse all elements in row-major order.
T & write(const size_t i, const size_t j, T &&data)
See write(const size_t i, const size_t j, const T & data).
void set_dimension(const size_t num_rows, const size_t num_cols)
Change the matrix dimensions.
T & write(const size_t i, const size_t j, const T &data)
Write a value to position (i, j).
bool operator==(const DynMatrix< T > &mat) const
Equality comparison.
bool traverse(Operation &&operation) const
See traverse(Operation & operation).
T & write_array_entry(const size_t i, const T &data)
DynArray< T > * array_ptr
T & operator()(const size_t i, const size_t j)
Subscript operator for allocated entries.
bool traverse(Operation &&operation)
See traverse(Operation & operation).
bool operator!=(const DynMatrix< T > &mat) const
Inequality comparison.
const T & read(const size_t i, const size_t j) const
Read the entry at position (i, j).
DynMatrix() noexcept(std::is_nothrow_default_constructible_v< T >)=default
Default constructor - creates an invalid matrix.
constexpr bool is_empty() const noexcept
Check if the matrix is empty (uninitialized).
constexpr size_t cols() const noexcept
Get the number of columns.
bool traverse_allocated(Operation &&operation)
Traverse entries in allocated memory blocks.
Iterator get_it() const
Get an iterator positioned at the first element.
DynMatrix(const DynMatrix< T > &mat)
Copy constructor.
void check_indices(const size_t i, const size_t j) const
void allocate()
Pre-allocate memory for the entire matrix.
DynMatrix(DynMatrix< T > &&mat) noexcept(std::is_nothrow_default_constructible_v< T > and std::is_nothrow_swappable_v< T >)
Move constructor.
bool traverse_allocated(Operation &&operation) const
See traverse_allocated(Operation && operation).
const T & get_default_value() const noexcept
Get the default value for unwritten entries.
bool traverse(Operation &operation)
constexpr size_t rows() const noexcept
Get the number of rows.
void swap(DynMatrix &mat) noexcept(std::is_nothrow_swappable_v< T >)
Swap the contents of this matrix with another.
void set_default_initial_value(const T &value)
Set the default value for unwritten entries.
const T & read_ne(const size_t i, const size_t j) const noexcept
Read entry without bounds checking.
constexpr size_t size() const noexcept
Get the total number of entries.
T Key_Type
Alias for Item_Type, required by functional mixins.
constexpr bool is_square() const noexcept
Check if the matrix is square.
T & access(const size_t i, const size_t j)
Direct access to an allocated entry.
DynMatrix(const size_t num_rows, const size_t num_cols, const T &zero=T())
Construct a matrix with specified dimensions.
DynMatrix< T > transpose() const
Create a transposed copy of the matrix.
DynMatrix< T > & operator=(const DynMatrix< T > &mat)
Copy assignment operator.
T Item_Type
The type of elements stored in the matrix.
void fill(const T &value)
Fill all entries with a value.
const T & read_array_entry(const size_t i) const noexcept
size_t m
Number of columns.
T & write_array_entry(const size_t i, T &&data)
constexpr size_t get_index(const size_t i, const size_t j) const noexcept
const T & access(const size_t i, const size_t j) const
Direct const access to an allocated entry.
Number Theoretic Transform over Z / MOD Z.
Common methods to the Aleph-w ( ) containers.
and
Insert a new element into the container by constructing it from the given args.
Common sequential searching methods on containers.
f(args...) is a valid call whose result is usable as a condition.
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
Lazy and scalable dynamic array implementation.