17template <
class,
class I,
class Str
ide>
19 using type = std::integral_constant<I, 0>;
21template <
class T,
class I,
class Str
ide>
23 { Stride::value } -> std::convertible_to<I>;
26 using type = std::integral_constant<I,
alignof(T) * Stride::value>;
28template <
class T,
class I,
class Str
ide>
57template <
class T,
class I = index_t,
class S = std::
integral_constant<I, 1>,
class D = I,
58 StorageOrder O = StorageOrder::ColMajor,
class A = detail::default_alignment_t<T, I, S>>
60 static_assert(!std::is_const_v<T>);
83 if constexpr (std::is_integral_v<alignment_type>)
84 return alignof(T) *
static_cast<size_t>(
layout.batch_size);
85 if constexpr (alignment_type::value == 0)
86 return alignof(T) *
static_cast<size_t>(
layout.batch_size);
100 if (
auto d = std::exchange(
view_.data_ptr,
nullptr))
102 view_.layout.rows = 0;
105 template <
class U,
class J,
class R,
class E,
class M>
106 requires(std::convertible_to<U, T> && std::equality_comparable_with<index_type, J>)
109 .rows = other.
rows(),
110 .cols = other.
cols(),
138 swap(o.view_.data_ptr, this->view_.data_ptr);
139 swap(o.view_.layout, this->view_.layout);
151 view_.layout = new_layout;
161 return view()(l, r, c);
165 return view()(l, r, c);
416 template <
class U,
class J,
class R,
class E,
class M>
417 requires(std::convertible_to<U, T> && std::equality_comparable_with<index_type, J>)
430 template <
class Other>
435 template <
class U,
class J,
class R,
class E,
class M>
436 requires(std::convertible_to<U, T> && std::equality_comparable_with<index_type, J>)
482template <
class T,
class I,
class S,
class D,
class A, StorageOrder O>
486template <
class T,
class I,
class S,
class D,
class A, StorageOrder O>
488template <
class T,
class I,
class S,
class D,
class A, StorageOrder O>
492template <
class T,
class I,
class S,
class D,
class A, StorageOrder O>
496template <
class T,
class I,
class S,
class D,
class A, StorageOrder O>
500template <
class T,
class I,
class S,
class D,
class A, StorageOrder O>
504template <
class T,
class I,
class S,
class D,
class A, StorageOrder O>
auto make_aligned_unique_ptr(size_t size, A align)
Returns a smart pointer to an array of T that satisfies the given alignment requirements.
std::integral_constant< I, 0 > type
typename default_alignment< T, I, Stride >::type default_alignment_t
std::integral_constant< I, alignof(T) *Stride::value > type
constexpr auto cols(const Matrix< T, I, S, D, O, A > &v)
typename integral_value_type< T >::type integral_value_type_t
constexpr auto data(Matrix< T, I, S, D, O, A > &v)
constexpr auto outer_stride(const Matrix< T, I, S, D, O, A > &v)
constexpr auto rows(const Matrix< T, I, S, D, O, A > &v)
constexpr auto depth(const Matrix< T, I, S, D, O, A > &v)
Aligned allocation for matrix storage.
Owning array of matrices, stored in an efficient batched format.
auto top_right(index_type nr, index_type nc) const
Get a view of the top-right nr by nc block of the matrices.
bool has_full_inner_stride() const
Whether the inner_stride() == 1. Always true.
void add_to_diagonal(const value_type &t)
static constexpr bool has_single_layer_at_compile_time
Matrix(const Matrix &o)
Copy the values from another matrix.
auto bottom_rows(index_type n) const
Get a view of the last n rows.
auto bottom_left(index_type nr, index_type nc) const
Get a view of the bottom-left nr by nc block of the matrices.
auto middle_layers(index_type l, N n)
Get a view of n layers starting at layer l.
auto batch_dyn(index_type b)
Same as batch(), but returns a view with a dynamic batch size.
void assign_from_view(View< U, J, R, E, M, O > other)
View< S, index_t, simd_stride_t, index_t, DefaultStride, O > view_type
auto first_layers(N n) const
Get a view of the first n layers. Note that n can be a compile-time constant.
auto middle_batches(index_type b, index_type n, index_type stride=1)
Get a view of n batches starting at batch b, with a stride of stride layers.
Matrix(plain_layout_type p)
Matrix(plain_layout_type p, uninitialized_t init)
typename layout_type::PlainLayout plain_layout_type
static constexpr bool has_single_batch_at_compile_time
auto middle_batches(index_type b, index_type n, index_type stride=1) const
Get a view of n batches starting at batch b, with a stride of stride layers.
Matrix & operator=(Matrix &&o) noexcept
Cheap move assignment. No data is copied.
typename layout_type::batch_size_type batch_size_type
auto reshaped(index_type rows, index_type cols) const
Reshape the view to the given dimensions. The total size should not change.
auto middle_layers(index_type l, N n) const
Get a view of n layers starting at layer l.
typename layout_type::standard_stride_type standard_stride_type
static auto allocate(layout_type layout)
index_type padded_size() const
Total number of elements in the view (including all padding).
void resize(layout_type new_layout)
Resize the matrix to a new layout, reallocating if the padded size changes.
batch_size_type batch_size() const
The batch size, i.e. the number of layers in each batch. Equals the inner stride.
value_type * data()
Get a pointer to the first element of the first layer.
index_type size() const
Total number of elements in the view (excluding padding).
Matrix & operator=(const Matrix &o)
Copy the values of another matrix, resizing if necessary.
static constexpr StorageOrder storage_order
auto block(index_type r, index_type c, index_type nr, index_type nc)
Get a view of the nr by nc block of the matrices starting at row r and column c.
auto top_rows(index_type n) const
Get a view of the first n rows.
auto transposed() const
Get a transposed view of the matrices.
index_type rows() const
Number of rows of the matrices.
Matrix(layout_type layout)
auto reshaped(index_type rows, index_type cols)
Reshape the view to the given dimensions. The total size should not change.
void set_constant(value_type t)
auto top_left(index_type nr, index_type nc) const
Get a view of the top-left nr by nc block of the matrices.
auto bottom_rows(index_type n)
Get a view of the last n rows.
auto left_cols(index_type n)
Get a view of the first n columns.
constexpr auto inner_stride() const
The inner stride of the matrices.
auto left_cols(index_type n) const
Get a view of the first n columns.
static constexpr bool is_row_major
auto middle_cols(index_type c, index_type n)
Get a view of n columns starting at column c.
auto top_rows(index_type n)
Get a view of the first n rows.
auto batch(index_type b)
Access a batch of batch_size() layers, starting at batch index b (i.e.
auto middle_cols(index_type c, index_type n) const
Get a view of n columns starting at column c.
static constexpr bool is_column_major
auto right_cols(index_type n)
Get a view of the last n columns.
auto bottom_right(index_type nr, index_type nc) const
Get a view of the bottom-right nr by nc block of the matrices.
void copy_values(const Other &other)
view_type view()
Returns the same view. For consistency with Matrix.
auto top_right(index_type nr, index_type nc)
Get a view of the top-right nr by nc block of the matrices.
auto end()
Sentinel for begin().
auto first_layers(N n)
Get a view of the first n layers. Note that n can be a compile-time constant.
auto bottom_left(index_type nr, index_type nc)
Get a view of the bottom-left nr by nc block of the matrices.
bool has_full_outer_stride() const
Whether the outer_stride() == inner_stride() * inner_size().
index_type layer_stride() const
The layer stride, i.e.
bool has_full_layer_stride() const
Whether the layer_stride() == outer_stride() * outer_size().
auto right_cols(index_type n) const
Get a view of the last n columns.
Matrix(layout_type layout, uninitialized_t init)
typename view_type::layout_type layout_type
index_type inner_size() const
The size of the inner dimension, i.e.
guanaqo::MatrixView< const T, I, standard_stride_type, O > operator()(index_type l) const
Access a single layer l as a non-batched view.
static constexpr auto default_alignment(layout_type layout)
auto top_left(index_type nr, index_type nc)
Get a view of the top-left nr by nc block of the matrices.
auto batch_dyn(index_type b) const
Same as batch(), but returns a view with a dynamic batch size.
simd_align_t alignment_type
auto middle_rows(index_type r, index_type n, index_type stride)
Get a view of n rows starting at row r.
value_type & operator()(index_type l, index_type r, index_type c)
Access a single element at layer l, row r and column c.
index_type outer_stride() const
Outer stride of the matrices (leading dimension in BLAS parlance).
Matrix(Matrix &&o) noexcept
const_view_type view() const
Returns the same view. For consistency with Matrix.
index_type outer_size() const
The size of the outer dimension, i.e.
typename view_type::const_view_type const_view_type
auto batch(index_type b) const
Access a batch of batch_size() layers, starting at batch index b (i.e.
constexpr auto row_stride() const
The row stride of the matrices, i.e.
layout_type layout() const
auto begin() const
Iterate linearly (in storage order) over all elements of the view.
constexpr auto col_stride() const
The column stride of the matrices, i.e.
auto end() const
Sentinel for begin().
auto block(index_type r, index_type c, index_type nr, index_type nc) const
Get a view of the nr by nc block of the matrices starting at row r and column c.
static auto allocate(layout_type layout, uninitialized_t init)
typename layout_type::depth_type depth_type
const value_type & operator()(index_type l, index_type r, index_type c) const
Access a single element at layer l, row r and column c.
index_type ceil_depth() const
The depth rounded up to a multiple of the batch size.
auto middle_rows(index_type r, index_type n) const
Get a view of n rows starting at row r.
typename layout_type::index_type index_type
auto begin()
Iterate linearly (in storage order) over all elements of the view.
auto bottom_right(index_type nr, index_type nc)
Get a view of the bottom-right nr by nc block of the matrices.
auto transposed()
Get a transposed view of the matrices.
auto as_const() const
Explicit conversion to a const view.
auto middle_cols(index_type c, index_type n, index_type stride) const
Get a view of n columns starting at column c.
guanaqo::MatrixView< T, I, standard_stride_type, O > operator()(index_type l)
Access a single layer l as a non-batched view.
auto middle_cols(index_type c, index_type n, index_type stride)
Get a view of n columns starting at column c.
auto middle_rows(index_type r, index_type n, index_type stride) const
Get a view of n rows starting at row r.
auto middle_rows(index_type r, index_type n)
Get a view of n rows starting at row r.
index_type cols() const
Number of columns of the matrices.
const value_type * data() const
Get a pointer to the first element of the first layer.
depth_type depth() const
Number of layers in the view (i.e. depth).
index_type num_batches() const
Number of batches in the view, i.e. ceil_depth() / batch_size().
Non-owning view of an array of matrices, stored in an efficient batched format.
Layout< I, S, D, L, O > layout_type
static constexpr bool is_column_major
View< T, I, S, N, L, O > first_layers(N n) const
Get a view of the first n layers. Note that n can be a compile-time constant.
general_slice_view_type bottom_right(index_type nr, index_type nc) const
Get a view of the bottom-right nr by nc block of the matrices.
constexpr bool has_full_outer_stride() const
Whether the outer_stride() == inner_stride() * inner_size().
general_slice_view_type block(index_type r, index_type c, index_type nr, index_type nc) const
Get a view of the nr by nc block of the matrices starting at row r and column c.
void set_constant(value_type t)
auto transposed() const
Get a transposed view of the matrices.
constexpr auto inner_stride() const
The inner stride of the matrices.
constexpr index_type num_batches() const
Number of batches in the view, i.e. ceil_depth() / batch_size().
col_slice_view_type middle_cols(index_type c, index_type n) const
Get a view of n columns starting at column c.
constexpr index_type padded_size() const
Total number of elements in the view (including all padding).
void add_to_diagonal(const value_type &t)
linear_iterator begin() const
Iterate linearly (in storage order) over all elements of the view.
row_slice_view_type bottom_rows(index_type n) const
Get a view of the last n rows.
general_slice_view_type reshaped(index_type rows, index_type cols) const
Reshape the view to the given dimensions. The total size should not change.
View< T, I, S, N, L, O > middle_layers(index_type l, N n) const
Get a view of n layers starting at layer l.
static constexpr bool has_single_batch_at_compile_time
True if batch_size() and depth() are compile-time constants and are equal.
constexpr auto col_stride() const
The column stride of the matrices, i.e.
general_slice_view_type bottom_left(index_type nr, index_type nc) const
Get a view of the bottom-left nr by nc block of the matrices.
View< const T, I, S, D, L, O > const_view_type
row_slice_view_type middle_rows(index_type r, index_type n) const
Get a view of n rows starting at row r.
constexpr batch_size_type batch_size() const
The batch size, i.e. the number of layers in each batch. Equals the inner stride.
constexpr index_type cols() const
Number of columns of the matrices.
std::default_sentinel_t end() const
Sentinel for begin().
col_slice_view_type right_cols(index_type n) const
Get a view of the last n columns.
View< T, I, S, I, L, O > batch_dyn(index_type b) const
Same as batch(), but returns a view with a dynamic batch size.
constexpr bool has_full_inner_stride() const
Whether the inner_stride() == 1. Always true.
col_slice_view_type left_cols(index_type n) const
Get a view of the first n columns.
constexpr bool has_full_layer_stride() const
Whether the layer_stride() == outer_stride() * outer_size().
static constexpr bool has_single_layer_at_compile_time
True if depth() is a compile-time constant and is equal to one.
row_slice_view_type top_rows(index_type n) const
Get a view of the first n rows.
constexpr index_type rows() const
Number of rows of the matrices.
constexpr index_type inner_size() const
The size of the inner dimension, i.e.
constexpr index_type ceil_depth() const
The depth rounded up to a multiple of the batch size.
constexpr index_type size() const
Total number of elements in the view (excluding padding).
constexpr auto row_stride() const
The row stride of the matrices, i.e.
T * data() const
Get a pointer to the first element of the first layer.
general_slice_view_type top_left(index_type nr, index_type nc) const
Get a view of the top-left nr by nc block of the matrices.
constexpr index_type outer_size() const
The size of the outer dimension, i.e.
constexpr index_type layer_stride() const
The layer stride, i.e.
static constexpr bool is_row_major
View< T, I, S, I, I, O > middle_batches(index_type b, index_type n, index_type stride=1) const
Get a view of n batches starting at batch b, with a stride of stride layers.
general_slice_view_type top_right(index_type nr, index_type nc) const
Get a view of the top-right nr by nc block of the matrices.
constexpr depth_type depth() const
Number of layers in the view (i.e. depth).
void copy_values(const Other &other) const
static constexpr StorageOrder storage_order
constexpr index_type outer_stride() const
Outer stride of the matrices (leading dimension in BLAS parlance).
batch_view_type batch(index_type b) const
Access a batch of batch_size() layers, starting at batch index b (i.e.
Deleter for aligned memory allocated with operator new(size, align_val).
Non-owning view of a batch of matrices.