|
MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
|
Dense vector with configurable orientation, storage, and dimensions. More...
#include <dense_vector.hpp>
Public Types | |
| using | param_type = Parameters |
| using | orientation = typename Parameters::orientation |
| using | dim_type = typename Parameters::dimensions_type |
| using | size_type = typename Parameters::size_type |
| using | actual_storage = typename Parameters::storage |
| using | memory_space = ::mtl::detail::memory_space_of_t<Parameters> |
| Where the elements live (#223). | |
| using | memory_type = detail::contiguous_memory_block<Value, actual_storage, static_size, memory_space> |
| using | value_type = Value |
| using | reference = std::conditional_t<read_only, const Value&, Value&> |
| using | const_reference = const Value& |
| using | pointer = std::conditional_t<read_only, const Value*, Value*> |
| using | const_pointer = const Value* |
| using | handle_type = typename memory_type::handle_type |
| What data() returns: how the memory space names the storage (#1017). | |
| using | const_handle_type = typename memory_type::const_handle_type |
Public Member Functions | |
| dense_vector () | |
| dense_vector (size_type n) | |
| dense_vector (size_type n, const Value &val) | |
| template<typename Ptr> requires (!read_only && std::same_as<Ptr, handle_type>) | |
| dense_vector (size_type n, Ptr ptr) | |
| template<typename Ptr> requires (read_only && (std::same_as<Ptr, const Value*> || std::same_as<Ptr, Value*> || std::same_as<Ptr, handle_type>)) | |
| dense_vector (size_type n, Ptr ptr) | |
| dense_vector (std::initializer_list< Value > il) | |
| dense_vector (const std::vector< Value > &v) | |
| dense_vector (const dense_vector &)=default | |
| template<typename P2> requires (!read_only && host_access && !std::same_as<P2, Parameters> && dense_vector<Value, P2>::read_only && dense_vector<Value, P2>::host_access) | |
| dense_vector (const dense_vector< Value, P2 > &view) | |
| An owning (or external) vector from a read-only view: copies the elements, so the copy can be changed. | |
| template<typename P2> requires (!read_only && host_access && AllocatingMemorySpace<memory_space, Value> && dense_vector<Value, P2>::host_access && detail::vec_params_differ_only_in_space_v<Parameters, P2>) | |
| dense_vector (const dense_vector< Value, P2 > &src) | |
| A copy of a vector in another memory space (#1012): the bundles agree in every axis but the space, and both spaces are host-accessible, so the copy is a host loop. | |
| dense_vector (const dense_vector &other) | |
| Copying a read-only view gives another view of the same buffer, not a copy of its elements: like the view itself, the copy is valid only while the caller's buffer is (#855). | |
| dense_vector (dense_vector &&other) noexcept(std::is_nothrow_move_constructible_v< memory_type >) | |
| template<typename Expr> requires (!read_only && host_access && Vector<Expr> && traits::is_expression_v<Expr> && std::convertible_to<typename Expr::value_type, Value>) | |
| dense_vector (const Expr &expr) | |
| dense_vector & | operator= (const dense_vector &)=default |
| template<typename P2> requires (!read_only && host_access && dense_vector<Value, P2>::host_access && detail::vec_params_differ_only_in_space_v<Parameters, P2>) | |
| dense_vector & | operator= (const dense_vector< Value, P2 > &src) |
| Assignment from a vector in another host-accessible memory space (#1012), with the rules of expression assignment: a vector over an external buffer keeps it and receives the elements, and a source of another size throws. | |
| dense_vector & | operator= (const dense_vector &)=delete |
| dense_vector & | operator= (dense_vector &&)=delete |
| A vector over an external buffer of the same size keeps its buffer and receives the elements; the source keeps its size (#829). | |
| dense_vector & | operator= (dense_vector &&other) noexcept |
| template<typename Expr> requires (!read_only && host_access && Vector<Expr> && traits::is_expression_v<Expr> && std::convertible_to<typename Expr::value_type, Value>) | |
| dense_vector & | operator= (const Expr &expr) |
| ~dense_vector ()=default | |
| template<typename Expr> requires (!read_only && host_access && Vector<Expr> && traits::is_expression_v<Expr> && std::convertible_to<typename Expr::value_type, Value>) | |
| dense_vector & | operator+= (const Expr &expr) |
| dense_vector & | operator+= (const dense_vector &other) |
| template<typename Expr> requires (!read_only && host_access && Vector<Expr> && traits::is_expression_v<Expr> && std::convertible_to<typename Expr::value_type, Value>) | |
| dense_vector & | operator-= (const Expr &expr) |
| dense_vector & | operator-= (const dense_vector &other) |
| Value & | operator() (size_type i) |
| const_reference | operator() (size_type i) const |
| Value & | operator[] (size_type i) |
| const_reference | operator[] (size_type i) const |
| size_type | size () const |
| bool | empty () const |
| size_type | num_rows () const |
| Orientation-aware row/column dimensions. | |
| size_type | num_cols () const |
| bool | owns_memory () const noexcept |
| Whether this vector owns its elements: false for one made over an external pointer, whose elements belong to the caller. | |
| handle_type | data () |
| const_handle_type | data () const |
| Value * | begin () |
| const_pointer | begin () const |
| Value * | end () |
| const_pointer | end () const |
| void | change_dim (size_type n) |
| void | checked_change_dim (size_type n) |
| template<typename S> requires (!read_only && host_access && Scalar<S>) | |
| dense_vector & | operator*= (const S &alpha) |
| template<typename S> requires (!read_only && host_access && Field<S>) | |
| dense_vector & | operator/= (const S &alpha) |
| void | swap (dense_vector &other) noexcept |
Static Public Member Functions | |
| static constexpr size_type | stride () |
| Stride is always 1 for dense vectors. | |
Static Public Attributes | |
| static constexpr std::size_t | static_size = dim_type::value |
| static constexpr bool | host_access = memory_space::host_accessible |
| static constexpr bool | read_only = std::is_same_v<actual_storage, tag::read_only> |
| A read-only view (tag::read_only storage) over a caller's const Value*: only const access, so writing through it does not compile. | |
Friends | |
| void | swap (dense_vector &a, dense_vector &b) noexcept |
| Found by ADL (using std::swap; swap(v, w);): exchanges the storage, so a vector over an external buffer and an owning one trade places. | |
Dense vector with configurable orientation, storage, and dimensions.
| using mtl::vec::dense_vector< Value, Parameters >::actual_storage = typename Parameters::storage |
| using mtl::vec::dense_vector< Value, Parameters >::const_handle_type = typename memory_type::const_handle_type |
| using mtl::vec::dense_vector< Value, Parameters >::const_pointer = const Value* |
| using mtl::vec::dense_vector< Value, Parameters >::const_reference = const Value& |
| using mtl::vec::dense_vector< Value, Parameters >::dim_type = typename Parameters::dimensions_type |
| using mtl::vec::dense_vector< Value, Parameters >::handle_type = typename memory_type::handle_type |
What data() returns: how the memory space names the storage (#1017).
Value* and const Value* in every space whose handle is a pointer, host memory included; an object with an offset in a space whose storage is not addressed by a pointer, whose host address begin() gives where the space is host-accessible.
| using mtl::vec::dense_vector< Value, Parameters >::memory_space = ::mtl::detail::memory_space_of_t<Parameters> |
Where the elements live (#223).
Element access needs host access. A parameter bundle without a memory_space (one written before #223) is host.
| using mtl::vec::dense_vector< Value, Parameters >::memory_type = detail::contiguous_memory_block<Value, actual_storage, static_size, memory_space> |
| using mtl::vec::dense_vector< Value, Parameters >::orientation = typename Parameters::orientation |
| using mtl::vec::dense_vector< Value, Parameters >::param_type = Parameters |
| using mtl::vec::dense_vector< Value, Parameters >::pointer = std::conditional_t<read_only, const Value*, Value*> |
| using mtl::vec::dense_vector< Value, Parameters >::reference = std::conditional_t<read_only, const Value&, Value&> |
| using mtl::vec::dense_vector< Value, Parameters >::size_type = typename Parameters::size_type |
| using mtl::vec::dense_vector< Value, Parameters >::value_type = Value |
|
inline |
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineexplicit |
|
default |
|
inlineexplicit |
An owning (or external) vector from a read-only view: copies the elements, so the copy can be changed.
Explicit (#855): implicit, it let a view passed to a by-value dense_vector parameter deep-copy without a word at the call site. Write dense_vector<double>(view).
|
inlineexplicit |
A copy of a vector in another memory space (#1012): the bundles agree in every axis but the space, and both spaces are host-accessible, so the copy is a host loop.
This vector owns its copy, so its space must allocate. Explicit, as the view copy above (#855): a vector passed to a by-value parameter of another space does not deep-copy without a word at the call site.
|
inline |
Copying a read-only view gives another view of the same buffer, not a copy of its elements: like the view itself, the copy is valid only while the caller's buffer is (#855).
For an owning copy, construct a dense_vector<Value> from it.
|
inlinenoexcept |
|
inline |
|
default |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Orientation-aware row/column dimensions.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
default |
|
delete |
|
inline |
Assignment from a vector in another host-accessible memory space (#1012), with the rules of expression assignment: a vector over an external buffer keeps it and receives the elements, and a source of another size throws.
So y = A * x works for y in shared memory, where A * x is a host vector. Two views of one buffer copy nothing. A source that overlaps this vector's storage otherwise (a view of part of it, or of the buffer a resize would free) is copied out first.
|
inline |
|
delete |
A vector over an external buffer of the same size keeps its buffer and receives the elements; the source keeps its size (#829).
An owning vector stays owning: a source over an external buffer is copied, not taken over, and keeps its buffer (#856).
|
inlinenoexcept |
|
inline |
|
inline |
|
inlinenoexcept |
Whether this vector owns its elements: false for one made over an external pointer, whose elements belong to the caller.
|
inline |
|
inlinestaticconstexpr |
Stride is always 1 for dense vectors.
|
inlinenoexcept |
|
friend |
Found by ADL (using std::swap; swap(v, w);): exchanges the storage, so a vector over an external buffer and an owning one trade places.
std::swap goes through the moves instead, and a move into an external vector of another size aborts (#856).
|
staticconstexpr |
|
staticconstexpr |
A read-only view (tag::read_only storage) over a caller's const Value*: only const access, so writing through it does not compile.
It is still a dense_vector<Value, Parameters>, so every operation that takes const dense_vector<V, P>& accepts it. Copying it gives another view of the same buffer; it cannot be assigned to or resized.
|
staticconstexpr |