54 template <Scalar S, std::
integral Int =
long>
69 template <ArrayOfRank<2> M>
71 static_assert(
get_rank<M> == 2,
"Error in nda::trace: Array/View must have rank 2");
72 EXPECTS(m.shape()[0] == m.shape()[1]);
74 auto d = m.shape()[0];
75 for (
int i = 0; i < d; ++i) r += m(i, i);
90 template <ArrayOfRank<2> M>
105 template <MemoryArrayOfRank<2> M>
107 long dim = std::min(m.shape()[0], m.shape()[1]);
109 using vector_view_t =
121 template <
typename V>
122 requires(std::ranges::contiguous_range<V> or ArrayOfRank<V, 1>)
124 if constexpr (std::ranges::contiguous_range<V>) {
147 template <ArrayOfRank<2> A, ArrayOfRank<2> B>
150 static_assert(
get_rank<A> == 2,
"Error in nda::vstack: Only rank 2 arrays/views are allowed");
151 static_assert(
get_rank<A> == 2,
"Error in nda::vstack: Only rank 2 arrays/views are allowed");
152 EXPECTS_WITH_MESSAGE(a.shape()[1] == b.shape()[1],
"Error in nda::vstack: The second dimension of the two matrices must be equal");
154 auto [n, q] = a.shape();
155 auto p = b.shape()[0];
157 res(range(0, n), range::all) = a;
158 res(range(n, n + p), range::all) = b;
Defines accessors for nda::array objects (cf. std::default_accessor).
Provides utility functions for std::array.
A generic view of a multi-dimensional array.
A generic multi-dimensional array.
Layout that specifies how to map multi-dimensional indices to a linear/flat index.
Check if a given type is an nda::Array of a certain rank.
Provides concepts for the nda library.
Provides various convenient aliases and helper functions for nda::basic_array and nda::basic_array_vi...
auto eye(Int dim)
Create an identity nda::matrix with ones on the diagonal.
ArrayOfRank< 1 > auto diagonal(M &m)
Get a view of the diagonal of a 2-dimensional array/view.
ArrayOfRank< 2 > auto diag(V const &v)
Get a new nda::matrix with the given values on the diagonal.
auto zeros(std::array< Int, Rank > const &shape)
Make an array of the given shape on the given address space and zero-initialize it.
auto transpose(A &&a)
Transpose the memory layout of an nda::MemoryArray or an nda::expr_call.
matrix< get_value_t< A > > vstack(A const &a, B const &b)
Stack two 2-dimensional arrays/views vertically.
auto trace(M const &m)
Get the trace of a 2-dimensional square array/view.
auto conj(T t)
Get the complex conjugate of a scalar.
ArrayOfRank< 2 > auto dagger(M const &m)
Get the conjugate transpose of 2-dimensional array/view.
basic_array< ValueType, 2, Layout, 'M', ContainerPolicy > matrix
Alias template of an nda::basic_array with rank 2 and an 'M' algebra.
constexpr int get_rank
Constexpr variable that specifies the rank of an nda::Array or of a contiguous 1-dimensional range.
std::decay_t< decltype(get_first_element(std::declval< A const >()))> get_value_t
Get the value type of an array/view or a scalar type.
constexpr auto sum(std::array< T, R > const &a)
Calculate the sum of all elements in a std::array.
constexpr bool is_complex_v
Constexpr variable that is true if type T is a std::complex type.
Provides definitions of various layout policies.
Macros used in the nda library.
Provides some custom implementations of standard mathematical functions used for lazy,...
Defines various memory handling policies.
Strided (non-contiguous) layout policy with C-order (row-major order).
Memory policy using an nda::mem::handle_borrowed.
Default accessor for various array and view types.