|
MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
|
Namespaces | |
| namespace | detail_bcast |
| namespace | ops |
| namespace | detail_interop |
| namespace | detail_nd |
| namespace | detail_ops |
| namespace | detail_shape |
| namespace | detail_slice |
Classes | |
| class | broadcast_expr |
| Lazy expression for element-wise binary operations with broadcasting. More... | |
| class | ndarray |
| N-dimensional array with static rank and runtime shape. More... | |
| class | shape |
| Static-rank shape: an array of N extents. More... | |
| struct | all_t |
| Select all elements along a dimension. More... | |
| struct | range |
| Select a contiguous range [start, stop) with optional step. More... | |
Typedefs | |
| using | c_order = tag::row_major |
| Layout order for multi-dimensional arrays. | |
| using | f_order = tag::col_major |
Functions | |
| template<detail_bcast::Array A, detail_bcast::Array B> | |
| auto | operator+ (A &&a, B &&b) |
| template<detail_bcast::Array A, detail_bcast::Array B> | |
| auto | operator- (A &&a, B &&b) |
| template<detail_bcast::Array A, detail_bcast::Array B> | |
| auto | operator* (A &&a, B &&b) |
| template<detail_bcast::Array A, detail_bcast::Array B> | |
| auto | operator/ (A &&a, B &&b) |
| template<typename Value, typename Params> | |
| ndarray< Value, 1, c_order > | as_ndarray (vec::dense_vector< Value, Params > &v) |
| Create a 1D ndarray view over a dense_vector (zero-copy). | |
| template<typename Value, typename Params> | |
| ndarray< const Value, 1, c_order > | as_ndarray (const vec::dense_vector< Value, Params > &v) |
| template<typename Value, typename Params> | |
| auto | as_ndarray (mat::dense2D< Value, Params > &m) |
| Create a 2D ndarray view over a dense2D matrix (zero-copy). | |
| template<typename Value, typename Params> | |
| auto | as_ndarray (const mat::dense2D< Value, Params > &m) |
| template<typename Value, typename Order> | |
| vec::dense_vector< Value > | as_vector (ndarray< Value, 1, Order > &a) |
| Create a dense_vector view over a 1D ndarray (zero-copy). | |
| template<typename Value, typename Order> | |
| vec::dense_vector< const Value > | as_vector (const ndarray< Value, 1, Order > &a) |
| template<typename Value, typename Order> requires std::is_same_v<Order, c_order> | |
| mat::dense2D< Value > | as_matrix (ndarray< Value, 2, Order > &a) |
| Create a dense2D view over a 2D ndarray (zero-copy). | |
| template<typename Value, typename Order> requires std::is_same_v<Order, c_order> | |
| mat::dense2D< const Value > | as_matrix (const ndarray< Value, 2, Order > &a) |
| template<typename V, std::size_t N, typename O, typename F> | |
| ndarray< std::remove_cv_t< V >, N, O > | transform (const ndarray< V, N, O > &a, F &&f) |
| Element-wise transform: apply f to every element of a, writing to out. | |
| template<typename V, std::size_t N, typename O, typename F> | |
| void | transform_inplace (ndarray< V, N, O > &a, F &&f) |
| In-place transform: apply f to every element. | |
| template<typename V, std::size_t N, typename O, typename T, typename BinOp> | |
| T | reduce (const ndarray< V, N, O > &a, T init, BinOp op) |
| Reduce all elements with a binary operation and initial value. | |
| template<typename V, std::size_t N, typename O> | |
| ndarray< std::remove_cv_t< V >, 1, c_order > | flatten (const ndarray< V, N, O > &a) |
| Flatten any ndarray to a contiguous 1D ndarray (always copies for safety), in the array's own order: the same elements, in the same order, as a.reshape({a.size()}) views when a is contiguous in that order. | |
| template<typename Value, std::size_t N> | |
| ndarray (Value *, shape< N >) -> ndarray< Value, N, c_order > | |
| template<typename Value, std::size_t N> | |
| ndarray (Value *, shape< N >, std::array< std::size_t, N >) -> ndarray< Value, N, c_order > | |
| template<typename V, std::size_t N, typename O> | |
| std::remove_cv_t< V > | sum (const ndarray< V, N, O > &a) |
| Sum all elements; zero for an empty array. | |
| template<typename V, std::size_t N, typename O> | |
| std::remove_cv_t< V > | prod (const ndarray< V, N, O > &a) |
| Product of all elements; one for an empty array. | |
| template<typename V, std::size_t N, typename O> requires std::totally_ordered<std::remove_cv_t<V>> | |
| std::remove_cv_t< V > | min (const ndarray< V, N, O > &a) |
| Minimum element, seeded from the first one. Throws on an empty array. | |
| template<typename V, std::size_t N, typename O> requires std::totally_ordered<std::remove_cv_t<V>> | |
| std::remove_cv_t< V > | max (const ndarray< V, N, O > &a) |
| Maximum element, seeded from the first one. Throws on an empty array. | |
| template<typename V, std::size_t N, typename O> | |
| std::remove_cv_t< V > | mean (const ndarray< V, N, O > &a) |
| Mean of all elements. Throws on an empty array. | |
| template<typename V, std::size_t N, typename O> requires (N > 1) | |
| ndarray< std::remove_cv_t< V >, N - 1, O > | sum_axis (const ndarray< V, N, O > &a, std::size_t axis) |
| Sum along a specified axis, producing an ndarray of rank N-1. | |
| template<typename V, std::size_t N, typename O> requires (N > 1) | |
| ndarray< std::remove_cv_t< V >, N - 1, O > | mean_axis (const ndarray< V, N, O > &a, std::size_t axis) |
| Mean along a specified axis. | |
| template<std::size_t N> | |
| constexpr std::array< std::size_t, N > | c_order_strides (const shape< N > &sh) |
| Compute C-order (row-major) strides: last dimension has stride 1. | |
| template<std::size_t N> | |
| constexpr std::array< std::size_t, N > | f_order_strides (const shape< N > &sh) |
| Compute F-order (column-major) strides: first dimension has stride 1. | |
| template<typename Order, std::size_t N> | |
| constexpr std::array< std::size_t, N > | compute_strides (const shape< N > &sh) |
| Compute strides for a given layout order. | |
| template<std::size_t N> | |
| constexpr std::size_t | compute_offset (const std::array< std::size_t, N > &indices, const std::array< std::size_t, N > &strides) |
| Compute flat offset from multi-index and strides. | |
| template<std::size_t N, typename... Indices> | |
| constexpr std::size_t | offset_from (const std::array< std::size_t, N > &strides, Indices... indices) |
| Variadic offset computation - converts (i, j, k, ...) to flat index. | |
| template<std::size_t N> | |
| constexpr bool | broadcast_shape (const shape< N > &a, const shape< N > &b, shape< N > &result) |
| Compute the broadcast shape of two shapes. | |
| template<std::size_t N> | |
| constexpr std::array< std::size_t, N > | broadcast_strides (const shape< N > &original, const std::array< std::size_t, N > &strides, const shape< N > &target) |
| Compute broadcast strides: dimension with extent 1 gets stride 0 (repeat). | |
| template<std::size_t N> | |
| constexpr bool | is_contiguous_c (const shape< N > &sh, const std::array< std::size_t, N > &strides) |
| Check if strides correspond to a contiguous C-order layout. | |
| template<std::size_t N> | |
| constexpr bool | is_contiguous_f (const shape< N > &sh, const std::array< std::size_t, N > &strides) |
| Check if strides correspond to a contiguous F-order layout. | |
| template<std::size_t N> | |
| constexpr bool | is_contiguous (const shape< N > &sh, const std::array< std::size_t, N > &strides) |
| Check if the array is contiguous in any order. | |
| template<typename Value, std::size_t N, typename Order, typename... Args> requires (sizeof...(Args) == N) | |
| auto | slice (ndarray< Value, N, Order > &arr, Args... args) |
| Slice an ndarray, returning a view with potentially reduced rank. | |
| template<typename Value, std::size_t N, typename Order, typename... Args> requires (sizeof...(Args) == N) | |
| auto | slice (const ndarray< Value, N, Order > &arr, Args... args) |
| Const overload: returns a view over const data. | |
Variables | |
| constexpr all_t | all {} |
| using mtl::array::c_order = tag::row_major |
Layout order for multi-dimensional arrays.
| using mtl::array::f_order = tag::col_major |
| mat::dense2D< const Value > mtl::array::as_matrix | ( | const ndarray< Value, 2, Order > & | a | ) |
| mat::dense2D< Value > mtl::array::as_matrix | ( | ndarray< Value, 2, Order > & | a | ) |
Create a dense2D view over a 2D ndarray (zero-copy).
Requires contiguous C-order (row-major) storage, and now CHECKS for it. The precondition used to be spelled is_contiguous(), which is true for an F-contiguous array too – so any transpose of a C-order array passed here aliased its memory as row-major and silently produced the TRANSPOSE (#359). dense2D is row-major, so C-contiguity is the only layout that can be aliased without a copy; pass flattened or explicitly copied data otherwise.
| auto mtl::array::as_ndarray | ( | const mat::dense2D< Value, Params > & | m | ) |
| ndarray< const Value, 1, c_order > mtl::array::as_ndarray | ( | const vec::dense_vector< Value, Params > & | v | ) |
| auto mtl::array::as_ndarray | ( | mat::dense2D< Value, Params > & | m | ) |
Create a 2D ndarray view over a dense2D matrix (zero-copy).
Works for row-major matrices; column-major uses F-order strides.
| ndarray< Value, 1, c_order > mtl::array::as_ndarray | ( | vec::dense_vector< Value, Params > & | v | ) |
Create a 1D ndarray view over a dense_vector (zero-copy).
| vec::dense_vector< const Value > mtl::array::as_vector | ( | const ndarray< Value, 1, Order > & | a | ) |
| vec::dense_vector< Value > mtl::array::as_vector | ( | ndarray< Value, 1, Order > & | a | ) |
Create a dense_vector view over a 1D ndarray (zero-copy).
Requires contiguous storage, and throws std::invalid_argument otherwise (#856). The either-order predicate is correct here: for N == 1 the C and F strides are both {1}, so the distinction that broke as_matrix and reshape (#359) does not exist at rank 1.
|
constexpr |
Compute the broadcast shape of two shapes.
Follows NumPy rules: trailing dimensions aligned, size-1 axes stretch. Returns false if shapes are incompatible.
|
constexpr |
Compute broadcast strides: dimension with extent 1 gets stride 0 (repeat).
|
constexpr |
Compute C-order (row-major) strides: last dimension has stride 1.
|
constexpr |
Compute flat offset from multi-index and strides.
|
constexpr |
Compute strides for a given layout order.
|
constexpr |
Compute F-order (column-major) strides: first dimension has stride 1.
| ndarray< std::remove_cv_t< V >, 1, c_order > mtl::array::flatten | ( | const ndarray< V, N, O > & | a | ) |
Flatten any ndarray to a contiguous 1D ndarray (always copies for safety), in the array's own order: the same elements, in the same order, as a.reshape({a.size()}) views when a is contiguous in that order.
|
constexpr |
Check if the array is contiguous in any order.
|
constexpr |
Check if strides correspond to a contiguous C-order layout.
|
constexpr |
Check if strides correspond to a contiguous F-order layout.
| std::remove_cv_t< V > mtl::array::max | ( | const ndarray< V, N, O > & | a | ) |
Maximum element, seeded from the first one. Throws on an empty array.
| std::remove_cv_t< V > mtl::array::mean | ( | const ndarray< V, N, O > & | a | ) |
Mean of all elements. Throws on an empty array.
| ndarray< std::remove_cv_t< V >, N - 1, O > mtl::array::mean_axis | ( | const ndarray< V, N, O > & | a, |
| std::size_t | axis ) |
Mean along a specified axis.
Throws std::invalid_argument when the axis has extent 0 (there is nothing to average).
| std::remove_cv_t< V > mtl::array::min | ( | const ndarray< V, N, O > & | a | ) |
Minimum element, seeded from the first one. Throws on an empty array.
| mtl::array::ndarray | ( | Value * | , |
| shape< N > | )->ndarray< Value, N, c_order > |
| mtl::array::ndarray | ( | Value * | , |
| shape< N > | , | ||
| std::array< std::size_t, N > | )->ndarray< Value, N, c_order > |
|
constexpr |
Variadic offset computation - converts (i, j, k, ...) to flat index.
| auto mtl::array::operator* | ( | A && | a, |
| B && | b ) |
| auto mtl::array::operator+ | ( | A && | a, |
| B && | b ) |
| auto mtl::array::operator- | ( | A && | a, |
| B && | b ) |
| auto mtl::array::operator/ | ( | A && | a, |
| B && | b ) |
| std::remove_cv_t< V > mtl::array::prod | ( | const ndarray< V, N, O > & | a | ) |
Product of all elements; one for an empty array.
| T mtl::array::reduce | ( | const ndarray< V, N, O > & | a, |
| T | init, | ||
| BinOp | op ) |
Reduce all elements with a binary operation and initial value.
| auto mtl::array::slice | ( | const ndarray< Value, N, Order > & | arr, |
| Args... | args ) |
Const overload: returns a view over const data.
| auto mtl::array::slice | ( | ndarray< Value, N, Order > & | arr, |
| Args... | args ) |
Slice an ndarray, returning a view with potentially reduced rank.
Each argument is one of:
Returns an ndarray view with rank = N - (number of integer args). A rank-0 array takes no arguments and gives a view of itself.
| std::remove_cv_t< V > mtl::array::sum | ( | const ndarray< V, N, O > & | a | ) |
Sum all elements; zero for an empty array.
| ndarray< std::remove_cv_t< V >, N - 1, O > mtl::array::sum_axis | ( | const ndarray< V, N, O > & | a, |
| std::size_t | axis ) |
Sum along a specified axis, producing an ndarray of rank N-1.
An axis of extent 0 gives zeros. Throws std::out_of_range for an axis >= N.
| ndarray< std::remove_cv_t< V >, N, O > mtl::array::transform | ( | const ndarray< V, N, O > & | a, |
| F && | f ) |
Element-wise transform: apply f to every element of a, writing to out.
Works on any NdArray (ndarray, or adapted vector/matrix views).
| void mtl::array::transform_inplace | ( | ndarray< V, N, O > & | a, |
| F && | f ) |
In-place transform: apply f to every element.
|
inlineconstexpr |