47template <std::
integral S>
54 requires(std::default_initializable<S> && !std::constructible_from<S, int>)
55struct default_stride<S> {
56 static constexpr S value{};
66template <
class T,
class I = ptrdiff_t,
class S = std::
integral_constant<I, 1>,
67 StorageOrder O = StorageOrder::ColMajor>
115 [[gnu::always_inline]]
118 assert(0 <= r && r <
rows);
119 assert(0 <= c && c <
cols);
122#if __cpp_multidimensional_subscript >= 202110L
124 [[gnu::always_inline]]
133 assert(0 <= n && n <=
rows);
143 assert(0 <= n && n <=
cols);
153 assert(0 <= n && n <=
rows);
163 assert(0 <= n && n <=
cols);
274 default: assert(!
"Unexpected value for guanaqo::Triangular");
303 default: assert(!
"Unexpected value for guanaqo::Triangular");
337 template <
class Other>
340 assert(other.rows == this->rows);
341 assert(other.cols == this->cols);
342 const auto *src = other.data;
343 auto *dst = this->data;
345 if (other.inner_stride == 1 && this->inner_stride == 1)
348 const auto *src_ = src;
352 src_ += other.inner_stride;
353 dst_ += this->inner_stride;
356 src += other.outer_stride;
357 dst += this->outer_stride;
366 template <
class U,
class J,
class R>
367 requires(!std::is_const_v<T> &&
368 std::convertible_to<U, std::remove_cv_t<T>> &&
369 std::equality_comparable_with<I, J>)
375 template <
class U,
class J,
class R>
376 requires(!std::is_const_v<T> &&
377 std::convertible_to<U, std::remove_cv_t<T>> &&
378 std::equality_comparable_with<I, J>)
380 assert(other.
rows == this->rows);
381 assert(other.
cols == this->cols);
382 const auto *src = other.
data;
383 auto *dst = this->data;
385 const auto *src_ = src;
390 dst_ += this->inner_stride;
393 dst += this->outer_stride;
400 auto *dst = this->data;
405 dst_ += this->inner_stride;
407 dst += this->outer_stride;
411 template <
class Generator>
415 (*
this)(r, c) = gen();
418 this->data = other.
data;
419 this->rows = other.
rows;
420 this->cols = other.
cols;
428template <
class T,
class I = ptrdiff_t,
class S = std::
integral_constant<I, 1>>
MatrixView< T, I, S, StorageOrder::RowMajor > MatrixViewRM
Convenience alias for a row-major MatrixView.
StorageOrder
Storage order of matrices.
constexpr StorageOrder transpose(StorageOrder o)
Transpose the storage order (swaps row and column major).
Triangular
Triangular matrix structure.
@ ColMajor
Column-major storage order (Fortran-style, layout left, unit row stride).
@ RowMajor
Row-major storage order (C-style, layout right, unit column stride).
@ StrictlyLower
Strictly lower triangular (excluding diagonal).
@ Upper
Upper triangular (including diagonal).
@ StrictlyUpper
Strictly upper triangular (excluding diagonal).
@ Lower
Lower triangular (including diagonal).
Get the default stride value for a given integer type (primary template).
A lightweight view of a 2D matrix.
static MatrixView as_row(std::span< T > v)
MatrixView(PlainMatrixView p)
MatrixView middle_cols(index_type c, index_type n) const
MatrixView right_cols(index_type n) const
MatrixView< T, I, I, O > diagonal()
void set_constant(const value_type &t)
constexpr index_type col_stride() const
MatrixView< T, I, S, transpose(O)> transposed() const
static constexpr StorageOrder storage_order
MatrixView bottom_right(index_type nr, index_type nc) const
MatrixView top_right(index_type nr, index_type nc) const
MatrixView top_rows(index_type n) const
void iter_diagonal(const auto f)
MatrixView block(index_type r, index_type c, index_type nr, index_type nc) const
MatrixView middle_rows(index_type r, index_type n) const
inner_stride_type inner_stride
MatrixView bottom_left(index_type nr, index_type nc) const
void copy_values(const Other &other)
MatrixView bottom_rows(index_type n) const
constexpr auto row_stride() const
value_type & operator()(index_type r, index_type c) const
MatrixView & operator+=(const U &u)
void generate(Generator gen)
inner_stride_type inner_stride
MatrixView top_left(index_type nr, index_type nc) const
constexpr index_type outer_size() const
void set_diagonal(const value_type &t)
static constexpr bool is_column_major
void add_to_diagonal(const value_type &t)
MatrixView & reassign(MatrixView other)
static MatrixView as_column(std::span< T > v)
MatrixView & operator=(const MatrixView &other)
void iter_diagonal(const auto f) const
static constexpr bool is_row_major
MatrixView left_cols(index_type n) const
MatrixView(const MatrixView &)=default
void set_constant(const value_type &t, Triangular tr)
constexpr index_type inner_size() const
void set_constant(const value_type &t, Triangular tr)
POD type for designated initializers.