|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Dynamic matrix with sparse storage. More...
#include <tpl_dynMat.H>
Classes | |
| class | Iterator |
| Iterator for traversing matrix elements. More... | |
Public Types | |
| using | Set_Type = DynMatrix< T > |
| The container type (self-reference for generic programming). | |
| using | Item_Type = T |
| The type of elements stored in the matrix. | |
| using | Key_Type = T |
| Alias for Item_Type, required by functional mixins. | |
Public Member Functions | |
| void | set_default_initial_value (const T &value) |
| Set the default value for unwritten entries. | |
| const T & | get_default_value () const noexcept |
| Get the default value for unwritten entries. | |
| void | swap (DynMatrix &mat) noexcept(std::is_nothrow_swappable_v< T >) |
| Swap the contents of this matrix with another. | |
| void | set_dimension (const size_t num_rows, const size_t num_cols) |
| Change the matrix dimensions. | |
| void | allocate () |
| Pre-allocate memory for the entire matrix. | |
| DynMatrix (const size_t num_rows, const size_t num_cols, const T &zero=T()) | |
| Construct a matrix with specified dimensions. | |
| DynMatrix () noexcept(std::is_nothrow_default_constructible_v< T >)=default | |
| Default constructor - creates an invalid matrix. | |
| ~DynMatrix () | |
| Destructor - releases all allocated memory. | |
| DynMatrix (const DynMatrix< T > &mat) | |
| Copy constructor. | |
| DynMatrix (DynMatrix< T > &&mat) noexcept(std::is_nothrow_default_constructible_v< T > and std::is_nothrow_swappable_v< T >) | |
| Move constructor. | |
| DynMatrix< T > & | operator= (const DynMatrix< T > &mat) |
| Copy assignment operator. | |
| DynMatrix< T > & | operator= (DynMatrix< T > &&mat) noexcept(std::is_nothrow_default_constructible_v< T > and std::is_nothrow_swappable_v< T >) |
| Move assignment operator. | |
| bool | operator== (const DynMatrix< T > &mat) const |
| Equality comparison. | |
| bool | operator!= (const DynMatrix< T > &mat) const |
| Inequality comparison. | |
| constexpr size_t | rows () const noexcept |
| Get the number of rows. | |
| constexpr size_t | cols () const noexcept |
| Get the number of columns. | |
| constexpr size_t | size () const noexcept |
| Get the total number of entries. | |
| constexpr bool | is_square () const noexcept |
| Check if the matrix is square. | |
| constexpr bool | is_empty () const noexcept |
| Check if the matrix is empty (uninitialized). | |
| const T & | read (const size_t i, const size_t j) const |
| Read the entry at position (i, j). | |
| const T & | read_ne (const size_t i, const size_t j) const noexcept |
| Read entry without bounds checking. | |
| T & | write (const size_t i, const size_t j, const T &data) |
| Write a value to position (i, j). | |
| T & | write (const size_t i, const size_t j, T &&data) |
See write(const size_t i, const size_t j, const T & data). | |
| T & | access (const size_t i, const size_t j) |
| Direct access to an allocated entry. | |
| const T & | access (const size_t i, const size_t j) const |
| Direct const access to an allocated entry. | |
| T & | operator() (const size_t i, const size_t j) |
| Subscript operator for allocated entries. | |
| const T & | operator() (const size_t i, const size_t j) const |
| Const subscript operator for allocated entries. | |
| void | fill (const T &value) |
| Fill all entries with a value. | |
| DynMatrix< T > | transpose () const |
| Create a transposed copy of the matrix. | |
| Iterator | get_it () const |
| Get an iterator positioned at the first element. | |
| template<class Operation > requires Aleph::PredicateWith<Operation &, const T &> | |
| bool | traverse (Operation &operation) const |
| Traverse all elements in row-major order. | |
| template<class Operation > requires Aleph::PredicateWith<Operation &, const T &> | |
| bool | traverse (Operation &operation) |
| template<class Operation > requires Aleph::PredicateWith<Operation &, const T &> | |
| bool | traverse (Operation &&operation) const |
See traverse(Operation & operation). | |
| template<class Operation > requires Aleph::PredicateWith<Operation &, const T &> | |
| bool | traverse (Operation &&operation) |
See traverse(Operation & operation). | |
| template<class Operation > | |
| bool | traverse_allocated (Operation &&operation) |
| Traverse entries in allocated memory blocks. | |
| template<class Operation > | |
| bool | traverse_allocated (Operation &&operation) const |
See traverse_allocated(Operation && operation). | |
Public Member Functions inherited from LocateFunctions< DynMatrix< T >, T > | |
| auto | get_it () |
| Return a properly initialized iterator positioned at the first item on the container. | |
| auto | get_it () const |
| Read-only iterator positioned at the first item. | |
| auto | get_it (const size_t pos) |
Return a properly initialized iterator positioned at the pos item on the container. | |
| auto | get_it (const size_t pos) const |
Read-only iterator positioned at the pos item. | |
| auto | get_itor () |
Alias of get_it(). | |
| auto | get_itor () const |
See get_itor(). | |
| T & | nth_ne (const size_t n) noexcept(Aleph::dry_detail::mutable_traversal_is_noexcept< C, T >) |
| Return the n‑th element without bounds checking. | |
| const T & | nth_ne (const size_t n) const noexcept(Aleph::dry_detail::const_traversal_is_noexcept< DynMatrix< T >, T >) |
Constant overload of nth_ne(size_t). | |
| T & | nth (const size_t n) |
| Return the n-th item of the container. | |
| const T & | nth (const size_t n) const |
Const overload of nth(size_t). | |
| and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< DynMatrix< T >, Operation >::type, T > T * | find_ptr (Operation &operation) noexcept(mutable_search_is_noexcept< Operation >()) |
| Find a pointer to an item in the container according to a searching criterion. | |
| const T * | find_ptr (Operation &operation) const noexcept(const_search_is_noexcept< Operation >()) |
Const overload of find_ptr(Operation&). | |
| const T * | find_ptr (Operation &&operation) const noexcept(const_search_is_noexcept< Operation >()) |
| Overload of find_ptr() const that accepts rvalues. | |
| and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< DynMatrix< T >, Operation >::type, T > T * | find_ptr (Operation &&operation) noexcept(mutable_search_is_noexcept< Operation >()) |
| Overload of find_ptr() that accepts rvalues. | |
| size_t | find_index (Operation &operation) const noexcept(const_search_is_noexcept< Operation >()) |
| Find the position of an item in the container according to a searching criterion. | |
| size_t | find_index (Operation &&operation) const noexcept(const_search_is_noexcept< Operation >()) |
| Overload of find_index() that accepts rvalues. | |
| and std::default_initializable< T > and std::copy_constructible< T > std::tuple< bool, T > | find_item (Operation &operation) const noexcept(find_item_is_noexcept< Operation >()) |
| Safe sequential searching of an item matching a criterion. | |
| and std::default_initializable< T > and std::copy_constructible< T > std::tuple< bool, T > | find_item (Operation &&operation) const noexcept(find_item_is_noexcept< Operation >()) |
| Overload of find_item() that accepts rvalues. | |
| and std::copy_constructible< T > std::optional< T > | find_opt (Operation &operation) const |
| Copy of the first item satisfying a criterion, if any. | |
| and std::copy_constructible< T > std::optional< T > | find_opt (Operation &&operation) const |
| Overload of find_opt() that accepts rvalues. | |
| bool | contains_if (Operation &&operation) const noexcept(const_search_is_noexcept< Operation >()) |
| Test if an item satisfying a criterion is present in the container. | |
| bool | contains (const T &item) const |
| Test if an item is present in the container using equality. | |
Public Member Functions inherited from FunctionalMethods< DynMatrix< T >, T > | |
| void | emplace (Args &&... args) |
| Appends a new element into the container by constructing it from the given args. | |
| void | emplace_end (Args &&... args) |
See emplace(Args && ... args). | |
| void | emplace_ins (Args &&... args) |
| size_t | ninsert (Args &&... args) |
| Insert n variadic items. | |
| size_t | nappend (Args &&... args) |
| Append n variadic items. | |
| void | for_each (Operation &operation) const |
| Traverse all the container and performs an operation on each element. | |
| void | for_each (Operation &&operation) const |
| Overload of for_each() that accepts rvalues. | |
| void | each (Operation &operation) const |
| Alias of for_each(). | |
| void | each (Operation &&operation) const |
| Alias of for_each() that accepts rvalues. | |
| void | each (const size_t pos, const size_t slice, Operation &operation) const |
Traverse the container starting at pos taking one item every slice, performing an operation on each visited element. | |
| void | each (const size_t pos, const size_t slice, Operation &&operation) const |
See each(size_t pos, size_t slice, Operation & operation) const. | |
| and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< DynMatrix< T >, Operation >::type, T > void | each (const size_t pos, const size_t slice, Operation &operation) |
Traverse the container starting at pos taking one item every slice, performing an operation that may modify each visited item. | |
| and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< DynMatrix< T >, Operation >::type, T > void | each (const size_t pos, const size_t slice, Operation &&operation) |
See each(size_t pos, size_t slice, Operation & operation). | |
| and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< DynMatrix< T >, Operation >::type, T > void | mutable_for_each (Operation &operation) |
| Apply a mutable operation to each element of the container. | |
| and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< DynMatrix< T >, Operation >::type, T > void | mutable_for_each (Operation &&operation) |
See mutable_for_each(Operation & operation). | |
| bool | all (Operation &operation) const |
| Check if all the elements of the container satisfy a condition. | |
| bool | all (Operation &&operation) const |
| Overload of all() that accepts rvalues. | |
| bool | exists (Operation &op) const |
| Test for existence in the container of an element satisfying a criterion. | |
| bool | exists (Operation &&op) const |
| Overload of exists() that accepts rvalues. | |
| bool | none (Operation &op) const |
| Test that no element satisfies a criterion. | |
| bool | none (Operation &&op) const |
| Overload of none() that accepts rvalues. | |
| size_t | count_if (Operation &op) const |
| Count the elements that satisfy a criterion. | |
| size_t | count_if (Operation &&op) const |
| Overload of count_if() that accepts rvalues. | |
| Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > | maps (Operation &op) const |
| Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > | maps (Operation &&op) const |
| Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > | maps_if (Prop prop, Operation &op) const |
| Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > | maps_if (Prop prop, Operation &&op) const |
| Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > | map (Operation &op) const |
| Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > | map (Operation &&op) const |
| Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > | map_if (Prop prop, Operation &op) const |
| Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > | map_if (Prop prop, Operation &&op) const |
| auto | flat_map (Operation &op) const |
| Map each element to a container and concatenate the results. | |
| auto | flat_map (Operation &&op) const |
| Overload of flat_map() that accepts rvalues. | |
| Aleph::DynList< T > | to_dynlist () const |
| Convert container to DynList. | |
| std::vector< T > | to_vector () const |
| Convert container to std::vector. | |
| Acc | foldl (const Acc &init, Op &op) const |
| Fold the elements of the container to a specific result. | |
| Acc | foldl (const Acc &init, Op &&op) const |
| Overload of foldl() that accepts rvalues. | |
| Acc | fold_left (const Acc &init, Op &op) const |
| Alias for foldl(). | |
| Acc | fold_left (const Acc &init, Op &&op) const |
| Overload of fold_left() that accepts rvalues. | |
| T | fold (const T &init, Operation &operation) const |
| Simplified version of foldl() where the folded type is the same type of elements stored in the container. | |
| T | fold (const T &init, Operation &&operation) const |
| Overload of fold() that accepts rvalues. | |
| Acc | foldr (const Acc &init, Op &op) const |
| Fold the elements from the last to the first. | |
| Acc | foldr (const Acc &init, Op &&op) const |
| Overload of foldr() that accepts rvalues. | |
| and std::copy_constructible< U > std::optional< T > | reduce (Op &op) const |
| Fold the elements with no initial value. | |
| and std::copy_constructible< U > std::optional< T > | reduce (Op &&op) const |
| Overload of reduce() that accepts rvalues. | |
| Aleph::DynList< T > | filter (Operation &operation) const |
| Filter the elements of a container according to a matching criterion. | |
| Aleph::DynList< T > | filter (Operation &&operation) const |
| Overload of filter() that accepts rvalues. | |
| Aleph::DynList< const T * > | ptr_filter (Operation &operation) const |
| Filter the elements of a container according to a matching criterion and return a pointer to the matched items in the container. | |
| Aleph::DynList< const T * > | ptr_filter (Operation &&operation) const |
| Overload of ptr_filter() that accepts rvalues. | |
| Aleph::DynList< std::tuple< T, size_t > > | pfilter (Operation &operation) const |
| Filter the elements of a container according to a matching criterion and determine its positions respect to the traversal of container. | |
| Aleph::DynList< std::tuple< T, size_t > > | pfilter (Operation &&operation) const |
| Overload of pfilter() that accepts rvalues. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | partition (Operation &op) const |
| Exclusive partition of container according to a filter criterion. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | partition (Operation &&op) const |
| Overload of partition() that accepts rvalues. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | partition (size_t n) const |
| Exclusive partition of container in the nth item. | |
| std::pair< Aleph::DynList< T >, Aleph::DynList< T > > | split_half () const |
| Split the container into two halves by alternating elements. | |
| std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > | tpartition (Operation &op) const |
| Exclusive partition of container according to a filter criterion. | |
| std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > | tpartition (Operation &&op) const |
| Overload of tpartition() that accepts rvalues. | |
| size_t | length () const noexcept(Aleph::dry_detail::const_traversal_is_noexcept< DynMatrix< T >, T >) |
| Count the number of elements of a container. | |
| Aleph::DynList< T > | rev () const |
| Return a list with the elements of container in reverse order respect to its traversal order. | |
| Aleph::DynList< T > | take (const size_t n) const |
| Return a list with the first n elements seen in the container during its traversal. | |
| Aleph::DynList< T > | take (size_t i, const size_t j, const size_t step=1) const |
Return a list with the elements at positions i, i + step, i + 2 step, ... that are not greater than j, respect to the traversal order. | |
| Aleph::DynList< T > | drop (const size_t n) const |
| Drop the first n elements seen in the container during its traversal. | |
| Aleph::DynList< T > | take_while (Operation &op) const |
| The longest prefix of elements that satisfy a criterion. | |
| Aleph::DynList< T > | take_while (Operation &&op) const |
| Overload of take_while() that accepts rvalues. | |
| Aleph::DynList< T > | drop_while (Operation &op) const |
| The elements after the longest prefix that satisfies a criterion. | |
| Aleph::DynList< T > | drop_while (Operation &&op) const |
| Overload of drop_while() that accepts rvalues. | |
| void | mutable_drop (const size_t n) |
| Drop the first n elements seen from container. | |
Private Member Functions | |
| const T & | read_array_entry (const size_t i) const noexcept |
| T & | write_array_entry (const size_t i, const T &data) |
| T & | write_array_entry (const size_t i, T &&data) |
| constexpr size_t | get_index (const size_t i, const size_t j) const noexcept |
| void | check_indices (const size_t i, const size_t j) const |
Private Attributes | |
| size_t | n = 0 |
| Number of rows. | |
| size_t | m = 0 |
| Number of columns. | |
| DynArray< T > * | array_ptr = nullptr |
| T | default_value = T() |
Additional Inherited Members | |
Static Public Member Functions inherited from FunctionalMethods< DynMatrix< T >, T > | |
| static DynMatrix< T > | build (Items &&... items) |
| Build a container that holds the given items. | |
| static D | build_as (Items &&... items) |
Build a D, a class derived from the container, holding the given items. | |
Public Attributes inherited from FunctionalMethods< DynMatrix< T >, T > | |
| and | |
| Insert a new element into the container by constructing it from the given args. | |
| and Aleph::InvocableWith< Operation &, const T & > | and |
| Conditional mapping of the elements of the container. | |
Dynamic matrix with sparse storage.
DynMatrix<T> implements a two-dimensional matrix of generic type T with dynamic, sparse storage. Only entries that are explicitly written consume memory; unwritten entries return the default "zero" value.
The matrix uses a DynArray<T> internally, which provides:
This class is not thread-safe. External synchronization is required for concurrent access from multiple threads.
| T | Type of elements stored in the matrix. Must be default-constructible. |
Definition at line 119 of file tpl_dynMat.H.
| using Aleph::DynMatrix< T >::Item_Type = T |
The type of elements stored in the matrix.
Definition at line 168 of file tpl_dynMat.H.
| using Aleph::DynMatrix< T >::Key_Type = T |
Alias for Item_Type, required by functional mixins.
Definition at line 171 of file tpl_dynMat.H.
| using Aleph::DynMatrix< T >::Set_Type = DynMatrix<T> |
The container type (self-reference for generic programming).
Definition at line 165 of file tpl_dynMat.H.
|
inline |
Construct a matrix with specified dimensions.
Creates a matrix with num_rows rows and num_cols columns. All entries are initialized to zero (default: T()).
| [in] | num_rows | Number of rows (must be > 0). |
| [in] | num_cols | Number of columns (must be > 0). |
| [in] | zero | Default value for unwritten entries. |
| std::bad_alloc | If memory allocation fails. |
| std::invalid_argument | If num_rows or num_cols is zero. |
Definition at line 288 of file tpl_dynMat.H.
References ah_invalid_argument_if, Aleph::DynMatrix< T >::m, Aleph::DynMatrix< T >::n, and Aleph::DynMatrix< T >::set_dimension().
|
defaultnoexcept |
Default constructor - creates an invalid matrix.
Creates a matrix with zero dimensions. The matrix must be initialized with set_dimension() before use.
| What | the default construction of T throws, for the default value of the matrix; nothing when it is noexcept. |
|
inline |
Destructor - releases all allocated memory.
Definition at line 311 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr.
|
inline |
Copy constructor.
Creates a deep copy of mat.
| [in] | mat | The matrix to copy. |
| std::bad_alloc | If memory allocation fails. |
Definition at line 324 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::m, Aleph::DynMatrix< T >::n, and Aleph::DynMatrix< T >::set_dimension().
|
inlinenoexcept |
Move constructor.
Takes the dimensions, the entries and the default value of mat, which is left as a matrix built by default: without dimensions, and with a T built by default as its default value.
| [in,out] | mat | The matrix to move from. |
| What | the default construction of T throws, for the default value that mat is left with, and then mat is as it was; or what the swap of the default values throws. Nothing when both are noexcept. |
Definition at line 347 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::swap().
|
inline |
Direct access to an allocated entry.
Returns a reference to the entry at position (i, j). The entry must have been previously written, or the matrix must have been allocated with allocate().
Time complexity: O(1).
| [in] | i | Row index (0-based). |
| [in] | j | Column index (0-based). |
Definition at line 542 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr, and Aleph::DynMatrix< T >::get_index().
Referenced by Aleph::DynMatrix< T >::operator()(), Aleph::DynMatrix< T >::operator()(), and Aleph::Floyd_All_Shortest_Paths< GT, Distance, SA >::print().
|
inline |
Direct const access to an allocated entry.
| [in] | i | Row index. |
| [in] | j | Column index. |
Definition at line 553 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr, and Aleph::DynMatrix< T >::get_index().
|
inline |
Pre-allocate memory for the entire matrix.
Allocates memory for all n*m entries, allowing O(1) access via operator() without triggering additional allocations.
| std::bad_alloc | If there is not enough memory. |
Definition at line 271 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.
Referenced by Aleph::Floyd_All_Shortest_Paths< GT, Distance, SA >::Floyd_All_Shortest_Paths(), Aleph::Hungarian_Assignment< Cost_Type >::Hungarian_Assignment(), Aleph::Hungarian_Assignment< Cost_Type >::Hungarian_Assignment(), Aleph::DynMatrix< T >::fill(), Aleph::hungarian_max_assignment(), make_matrix(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TYPED_TEST().
|
inlineprivate |
Definition at line 154 of file tpl_dynMat.H.
References ah_out_of_range_error_if, Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.
Referenced by Aleph::DynMatrix< T >::read(), Aleph::DynMatrix< T >::write(), and Aleph::DynMatrix< T >::write().
|
inlineconstexprnoexcept |
Get the number of columns.
Definition at line 447 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::m.
Referenced by Aleph::Hungarian_Assignment< Cost_Type >::Hungarian_Assignment(), Aleph::hungarian_max_assignment(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), and TEST_F().
|
inline |
Fill all entries with a value.
Sets all entries to value. This allocates memory for all entries.
| [in] | value | The value to fill with. |
| std::bad_alloc | If memory allocation fails. |
Definition at line 590 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::allocate(), Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::m, Aleph::DynMatrix< T >::n, and value.
Referenced by TEST().
|
inlinenoexcept |
Get the default value for unwritten entries.
Definition at line 194 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::default_value.
|
inlineconstexprprivatenoexcept |
Definition at line 148 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::m.
Referenced by Aleph::DynMatrix< T >::access(), Aleph::DynMatrix< T >::access(), Aleph::DynMatrix< T >::read(), Aleph::DynMatrix< T >::read_ne(), Aleph::DynMatrix< T >::transpose(), Aleph::DynMatrix< T >::write(), and Aleph::DynMatrix< T >::write().
|
inline |
Get an iterator positioned at the first element.
Definition at line 715 of file tpl_dynMat.H.
|
inlineconstexprnoexcept |
Check if the matrix is empty (uninitialized).
Definition at line 465 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.
|
inlineconstexprnoexcept |
Check if the matrix is square.
Definition at line 459 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.
|
inline |
Inequality comparison.
| [in] | mat | The matrix to compare with. |
Definition at line 432 of file tpl_dynMat.H.
|
inline |
Subscript operator for allocated entries.
Equivalent to access(i, j).
| [in] | i | Row index. |
| [in] | j | Column index. |
Definition at line 566 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::access().
|
inline |
Const subscript operator for allocated entries.
| [in] | i | Row index. |
| [in] | j | Column index. |
Definition at line 577 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::access().
|
inline |
Copy assignment operator.
Replaces the contents of this matrix with a copy of mat.
| [in] | mat | The matrix to copy. |
| std::bad_alloc | If memory allocation fails. |
Definition at line 364 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::default_value, Aleph::DynMatrix< T >::m, Aleph::DynMatrix< T >::n, and Aleph::DynMatrix< T >::set_dimension().
|
inlinenoexcept |
Move assignment operator.
Transfers ownership of resources from mat to this matrix.
| [in,out] | mat | The matrix to move from. |
| What | the default construction of T throws, for the default value that mat is left with, and then both matrices are as they were; or what the swap of the default values throws. Nothing when both are noexcept. |
Definition at line 392 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::swap().
|
inline |
Equality comparison.
Returns true if this matrix has the same dimensions as mat and all corresponding entries are equal (using T::operator==).
| [in] | mat | The matrix to compare with. |
Definition at line 414 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::m, N, Aleph::DynMatrix< T >::n, and Aleph::DynMatrix< T >::read_array_entry().
|
inline |
Read the entry at position (i, j).
Returns the value at row i and column j. If the entry has not been written, returns the default value.
Time complexity: O(1) amortized.
| [in] | i | Row index (0-based). |
| [in] | j | Column index (0-based). |
Definition at line 480 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::check_indices(), Aleph::DynMatrix< T >::get_index(), and Aleph::DynMatrix< T >::read_array_entry().
Referenced by Aleph::Hungarian_Assignment< Cost_Type >::Hungarian_Assignment(), compute_assignment_cost(), Aleph::hungarian_max_assignment(), main(), Aleph::Hungarian_Assignment< Cost_Type >::solve(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), and TEST_F().
|
inlineprivatenoexcept |
Definition at line 130 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr, and Aleph::DynMatrix< T >::default_value.
Referenced by Aleph::DynMatrix< T >::Iterator::get_curr_ne(), Aleph::DynMatrix< T >::operator==(), Aleph::DynMatrix< T >::read(), Aleph::DynMatrix< T >::read_ne(), Aleph::DynMatrix< T >::transpose(), and Aleph::DynMatrix< T >::traverse().
|
inlinenoexcept |
Read entry without bounds checking.
| [in] | i | Row index. |
| [in] | j | Column index. |
Definition at line 494 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::get_index(), and Aleph::DynMatrix< T >::read_array_entry().
|
inlineconstexprnoexcept |
Get the number of rows.
Definition at line 441 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::n.
Referenced by Aleph::Hungarian_Assignment< Cost_Type >::Hungarian_Assignment(), Aleph::hungarian_max_assignment(), Moved_From_Case< Floyd_All_Shortest_Paths< Dgraph > >::is_empty(), Aleph::Floyd_All_Shortest_Paths< GT, Distance, SA >::print(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), and TEST_F().
|
inline |
Set the default value for unwritten entries.
Changes the value returned for entries that have not been explicitly written. This also affects new entries created by touch().
| [in] | value | The new default value. |
Definition at line 183 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::default_value, and value.
Referenced by TEST().
|
inline |
Change the matrix dimensions.
Resizes the matrix to have num_rows rows and num_cols columns. All existing data is discarded.
| [in] | num_rows | The new number of rows. |
| [in] | num_cols | The new number of columns. |
| std::overflow_error | If num_rows * num_cols does not fit in size_t. |
| std::length_error | If the number of entries exceeds what a DynArray can hold. |
| std::bad_alloc | If memory allocation fails. |
Definition at line 243 of file tpl_dynMat.H.
References ah_overflow_error_if, FunctionalMethods< DynMatrix< T >, T >::and, Aleph::DynMatrix< T >::array_ptr, Aleph::DynArray< T >::compute_sizes(), Aleph::DynMatrix< T >::default_value, Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.
Referenced by Aleph::DynMatrix< T >::DynMatrix(), Aleph::DynMatrix< T >::DynMatrix(), and Aleph::DynMatrix< T >::operator=().
|
inlineconstexprnoexcept |
Get the total number of entries.
Definition at line 453 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.
Referenced by Aleph::DynMatrix< T >::Iterator::has_curr(), TEST(), TEST(), and TEST().
|
inlinenoexcept |
Swap the contents of this matrix with another.
Exchanges the contents of this matrix with those of mat in constant time O(1). No elements are copied or moved individually.
| [in,out] | mat | The matrix to swap with. |
| What | the swap of the default values throws; nothing when it is noexcept. It goes first, so that if it throws, the dimensions and the entries stay where they were. It is the swap of T found by its arguments, if it has one, and std::swap() otherwise. |
Definition at line 212 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::default_value, Aleph::DynMatrix< T >::m, Aleph::DynMatrix< T >::n, and Aleph::DynMatrix< T >::swap().
Referenced by Aleph::DynMatrix< T >::DynMatrix(), Aleph::DynMatrix< T >::operator=(), Aleph::DynMatrix< T >::swap(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inline |
Create a transposed copy of the matrix.
Returns a new matrix where entry (i,j) contains this->read(j,i).
| std::bad_alloc | If memory allocation fails. |
Definition at line 605 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::default_value, Aleph::DynMatrix< T >::get_index(), Aleph::DynMatrix< T >::m, Aleph::DynMatrix< T >::n, Aleph::DynMatrix< T >::read_array_entry(), and Aleph::DynMatrix< T >::write().
Referenced by TEST().
|
inline |
See traverse(Operation & operation).
Definition at line 755 of file tpl_dynMat.H.
|
inline |
See traverse(Operation & operation).
Definition at line 747 of file tpl_dynMat.H.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 739 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::traverse().
|
inline |
Traverse all elements in row-major order.
Executes operation on each element. The traversal stops early if operation returns false.
| Operation | A callable with signature bool(const T&). |
| [in] | operation | The operation to perform. |
Definition at line 728 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::m, Aleph::DynMatrix< T >::n, and Aleph::DynMatrix< T >::read_array_entry().
Referenced by Aleph::DynMatrix< T >::traverse().
|
inline |
Traverse entries in allocated memory blocks.
Visits all entries within allocated memory blocks. This is more efficient than traverse() when the matrix is very sparse, but note that it visits all entries in each allocated block, not just those that were explicitly written.
| Operation | A callable with signature bool(T&). |
| [in] | operation | The operation to perform. |
Definition at line 776 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.
|
inline |
See traverse_allocated(Operation && operation).
Definition at line 794 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.
|
inline |
Write a value to position (i, j).
Sets the value at row i and column j. Allocates memory for the entry if not already allocated.
Time complexity: O(1) amortized.
| [in] | i | Row index (0-based). |
| [in] | j | Column index (0-based). |
| [in] | data | The value to write. |
| std::out_of_range | If i >= rows() or j >= cols(). |
| std::bad_alloc | If memory allocation fails. |
Definition at line 514 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::check_indices(), Aleph::DynMatrix< T >::get_index(), and Aleph::DynMatrix< T >::write_array_entry().
Referenced by FilledMatrix::FilledMatrix(), SquareMatrix::SquareMatrix(), demo_modular_linalg(), main(), Moved_From_Case< Hungarian_Assignment< long > >::make(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), and Aleph::DynMatrix< T >::transpose().
|
inline |
See write(const size_t i, const size_t j, const T & data).
Definition at line 521 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::check_indices(), Aleph::DynMatrix< T >::get_index(), and Aleph::DynMatrix< T >::write_array_entry().
|
inlineprivate |
Definition at line 136 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr.
Referenced by Aleph::DynMatrix< T >::write(), and Aleph::DynMatrix< T >::write().
|
inlineprivate |
Definition at line 142 of file tpl_dynMat.H.
References Aleph::DynMatrix< T >::array_ptr.
|
private |
Definition at line 126 of file tpl_dynMat.H.
Referenced by Aleph::DynMatrix< T >::DynMatrix(), Aleph::DynMatrix< T >::~DynMatrix(), Aleph::DynMatrix< T >::access(), Aleph::DynMatrix< T >::access(), Aleph::DynMatrix< T >::allocate(), Aleph::DynMatrix< T >::fill(), Aleph::DynMatrix< T >::operator=(), Aleph::DynMatrix< T >::read_array_entry(), Aleph::DynMatrix< T >::set_default_initial_value(), Aleph::DynMatrix< T >::set_dimension(), Aleph::DynMatrix< T >::swap(), Aleph::DynMatrix< T >::traverse_allocated(), Aleph::DynMatrix< T >::traverse_allocated(), Aleph::DynMatrix< T >::write_array_entry(), and Aleph::DynMatrix< T >::write_array_entry().
|
private |
Definition at line 128 of file tpl_dynMat.H.
Referenced by Aleph::DynMatrix< T >::get_default_value(), Aleph::DynMatrix< T >::operator=(), Aleph::DynMatrix< T >::read_array_entry(), Aleph::DynMatrix< T >::set_default_initial_value(), Aleph::DynMatrix< T >::set_dimension(), Aleph::DynMatrix< T >::swap(), and Aleph::DynMatrix< T >::transpose().
|
private |
Number of columns.
Definition at line 124 of file tpl_dynMat.H.
Referenced by Aleph::DynMatrix< T >::DynMatrix(), Aleph::DynMatrix< T >::DynMatrix(), Aleph::DynMatrix< T >::allocate(), Aleph::DynMatrix< T >::check_indices(), Aleph::DynMatrix< T >::cols(), Aleph::DynMatrix< T >::fill(), Aleph::DynMatrix< T >::Iterator::get_col(), Aleph::DynMatrix< T >::get_index(), Aleph::DynMatrix< T >::Iterator::get_row(), Aleph::DynMatrix< T >::is_empty(), Aleph::DynMatrix< T >::is_square(), Aleph::DynMatrix< T >::operator=(), Aleph::DynMatrix< T >::operator==(), Aleph::DynMatrix< T >::set_dimension(), Aleph::DynMatrix< T >::size(), Aleph::DynMatrix< T >::swap(), Aleph::DynMatrix< T >::transpose(), Aleph::DynMatrix< T >::traverse(), Aleph::DynMatrix< T >::traverse_allocated(), and Aleph::DynMatrix< T >::traverse_allocated().
|
private |
Number of rows.
Definition at line 123 of file tpl_dynMat.H.
Referenced by Aleph::DynMatrix< T >::DynMatrix(), Aleph::DynMatrix< T >::DynMatrix(), Aleph::DynMatrix< T >::allocate(), Aleph::DynMatrix< T >::check_indices(), Aleph::DynMatrix< T >::fill(), Aleph::DynMatrix< T >::is_empty(), Aleph::DynMatrix< T >::is_square(), Aleph::DynMatrix< T >::operator=(), Aleph::DynMatrix< T >::operator==(), Aleph::DynMatrix< T >::rows(), Aleph::DynMatrix< T >::set_dimension(), Aleph::DynMatrix< T >::size(), Aleph::DynMatrix< T >::swap(), Aleph::DynMatrix< T >::transpose(), Aleph::DynMatrix< T >::traverse(), Aleph::DynMatrix< T >::traverse_allocated(), and Aleph::DynMatrix< T >::traverse_allocated().