Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Vector< T, NumType > Class Template Reference

Sparse vector implementation with domain-based indexing. More...

#include <al-vector.H>

Inheritance diagram for Aleph::Vector< T, NumType >:
[legend]
Collaboration diagram for Aleph::Vector< T, NumType >:
[legend]

Classes

struct  Iterator
 
class  Proxy
 The entry of a key, as v[k] gives it: reads and assigns it. More...
 

Public Types

using Domain = AlDomain< T >
 
using DomainPtr = std::shared_ptr< Domain >
 
using Map = Aleph::HashMap< T, NumType, MapODhash >
 
using Item_Type = std::pair< T, NumType >
 
using Pair = std::pair< T, NumType >
 
typedef std::pair< std::string, std::string > Pair
 
using Const_Iterator = Aleph::Const_Iterator< Iterator >
 Read-only iterator: the iterator of a constant vector.
 

Public Member Functions

const NumType & get_epsilon () const noexcept
 Get the epsilon value used for zero comparisons.
 
void set_epsilon (const NumType &e) noexcept
 Set the epsilon value for zero comparisons.
 
const Domain & get_domain () const noexcept
 Get the domain over which this vector is defined.
 
const DomainPtr & get_domain_ptr () const noexcept
 Return the shared pointer to the domain.
 
 Vector (DomainPtr d, const NumType &zero=default_epsilon)
 Construct a vector over a given domain (shared_ptr version)
 
 Vector (const Domain &d, const NumType &zero=default_epsilon)
 Construct a vector over a given domain (reference version)
 
 Vector (Domain &&d, const NumType &zero=default_epsilon)
 Construct a vector over a temporary domain, which it keeps.
 
template<typename I >
requires std::is_integral_v<I>
 Vector (I, const NumType &=default_epsilon)=delete
 A vector needs a domain: Vector(IntRange(n)), not Vector(n), which would turn n into an empty domain.
 
 Vector (const Vector &v)
 Copy constructor.
 
 Vector (Vector &&v) noexcept
 Move constructor.
 
 Vector (DomainPtr d, const DynList< NumType > &l, const NumType &zero=default_epsilon)
 Construct vector from domain and list of values (shared_ptr version)
 
 Vector (const Domain &d, const DynList< NumType > &l, const NumType &zero=default_epsilon)
 Construct vector from domain and list of values (reference version)
 
 Vector (Domain &&d, const DynList< NumType > &l, const NumType &zero=default_epsilon)
 Construct vector from a temporary domain, which it keeps, and a list of values.
 
template<typename I >
requires std::is_integral_v<I>
 Vector (I, const DynList< NumType > &, const NumType &=default_epsilon)=delete
 A vector needs a domain: Vector(IntRange(n), l), not Vector(n, l), which would turn n into an empty domain.
 
Vector & operator= (const Vector &v)
 Copy assignment operator.
 
Vector & operator= (Vector &&v)
 Move assignment operator.
 
void set_entry (const T &i, const NumType &value)
 Set a vector entry at given index.
 
void set_entries (std::initializer_list< T > ld, std::initializer_list< NumType > lr)
 Set multiple entries using initializer lists.
 
template<template< typename > class Container = DynList>
void set_entries (const Container< T > &c, std::initializer_list< NumType > lr)
 Set multiple entries using container and initializer list.
 
NumType get_entry (const T &i)
 Get vector entry at given index (non-const version)
 
NumType get_entry (const T &i) const noexcept
 Get vector entry at given index (const version)
 
NumType * search_entry (const T &i) noexcept
 Search for an entry and return pointer to its value.
 
const NumType * search_entry (const T &i) const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A pointer to const.
 
bool are_equal (const NumType &n1, const NumType &n2) const noexcept
 Check if two numeric values are equal within epsilon.
 
bool equal_to (const Vector &other) const noexcept
 Check if this vector equals another within epsilon tolerance.
 
bool operator== (const Vector &v) const noexcept
 Whether the entries of v are equal to these, within epsilon.
 
bool operator!= (const Vector &v) const noexcept
 Whether some entry of v differs from this one, beyond epsilon.
 
Vector & operator+= (const Vector &v)
 Add v, over the same domain, to this vector.
 
Vector & operator-= (const Vector &v)
 Subtract v, over the same domain, from this vector.
 
Vector operator+ (const Vector &r) const
 The sum of this vector and r, over the same domain.
 
Vector operator- (const Vector &r) const
 The difference of this vector and r, over the same domain.
 
Vector & product_by_scalar (const NumType &scalar) noexcept
 Multiply every entry by scalar.
 
Vector operator* (const NumType &scalar) const
 This vector multiplied by scalar.
 
Vector & divide_by_scalar (const NumType &scalar)
 Divide every entry by scalar, which must not be zero.
 
Vector operator/ (const NumType &scalar) const
 This vector divided by scalar, which must not be zero.
 
Vector operator- () const
 The negation of this vector.
 
NumType scalar_product (const Vector &v) const and AlMultiplicativeNumber< NumType >
 The scalar product of this vector and v, over the same domain.
 
NumType operator* (const Vector &v) const and AlMultiplicativeNumber< NumType >
 The scalar product of this vector and v, over the same domain.
 
DynList< NumType > to_list () const
 The values of the vector, in the order of the sorted keys of its domain.
 
void print () const and AlStreamable< T > and AlStreamable< NumType >
 Print the nonzero entries, in the order of the sorted keys.
 
std::string to_str () const and AlStreamable< T > and
 The keys over their values, in the order of the keys.
 
return dstr n std::string (dstr.size(), '-')+"\n"+estr
 
NumType operator[] (const T &k) const noexcept
 The value of the entry of k, read-only: 0 if it has none.
 
Proxy operator[] (const T &k)
 The entry of k, which a Proxy reads and assigns.
 
NumType operator() (const T &k) const noexcept
 The value of the entry of k, read-only: 0 if it has none.
 
Proxy operator() (const T &k)
 The entry of k, which a Proxy reads and assigns.
 
Iterator get_itor () noexcept
 
Iterator get_it () noexcept
 
Const_Iterator get_itor () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Read-only.
 
Const_Iterator get_it () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Read-only.
 
- Public Member Functions inherited from Aleph::TraverseMixin< Vector< T, NumType >, std::pair< T, NumType > >
bool traverse (Operation &operation) const
 Traverse all elements, applying an operation to each.
 
bool traverse (Operation &operation)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool traverse (Operation and operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool traverse (Operation and operation=Operation())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
- Public Member Functions inherited from Aleph::LocateMixin< Vector< T, NumType >, std::pair< T, NumType > >
std::pair< T, NumType > & nth (const size_t n)
 Access the n-th element (bounds-checked).
 
const std::pair< T, NumType > & nth (const size_t n) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const.
 
std::pair< T, NumType > & nth_ne (const size_t n) noexcept
 Access the n-th element (unchecked).
 
const std::pair< T, NumType > & nth_ne (const size_t n) const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const.
 
std::pair< T, NumType > * find_ptr (Operation &operation)
 Find the first element satisfying a predicate.
 
const std::pair< T, NumType > * find_ptr (Operation &operation) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const std::pair< T, NumType > * find_ptr (Operation and operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
std::pair< T, NumType > * find_ptr (Operation and operation=Operation())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
std::tuple< bool, std::pair< T, NumType > > find_item (Operation &operation)
 Find element with success flag.
 
std::tuple< bool, std::pair< T, NumType > > find_item (Operation &operation) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
std::tuple< bool, std::pair< T, NumType > > find_item (Operation &&operation=Operation())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
std::tuple< bool, std::pair< T, NumType > > find_item (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
- Public Member Functions inherited from Aleph::FunctionalMixin< Vector< T, NumType >, std::pair< T, NumType > >
auto for_each (Operation &operation) const -> decltype(self())
 Apply an operation to each element (read-only).
 
auto for_each (Operation &operation) -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
auto for_each (Operation &&operation=Operation()) const -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
auto for_each (Operation &&operation=Operation()) -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
auto mutable_for_each (Operation &operation) -> decltype(self())
 Apply an operation to each element (mutable).
 
auto mutable_for_each (Operation &&operation=Operation()) -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool all (Operation &operation) const
 Test if all elements satisfy a predicate.
 
bool all (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool forall (Operation &operation) const
 Alias for all().
 
bool forall (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool exists (Operation &operation) const
 Test if any element satisfies a predicate.
 
bool exists (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
Container< concepts_detail::map_result_t< R, Operation &, std::pair< T, NumType > > > maps (Operation &operation) const
 
Container< concepts_detail::map_result_t< R, Operation &, std::pair< T, NumType > > > maps (Operation &&operation=Operation()) const
 
Acc foldl (const Acc &init, std::function< Acc(const Acc &, const std::pair< T, NumType > &)> operation) const
 Left fold (reduce) with initial value.
 
Acc fold_left (std::function< Acc(const Acc &, const std::pair< T, NumType > &)> operation, const Acc &init) const
 Left fold with operation first (alternative signature).
 
std::pair< T, NumType > fold (const std::pair< T, NumType > &init, Operation &operation) const
 Simple fold with same type for accumulator and elements.
 
std::pair< T, NumType > fold (const std::pair< T, NumType > &init, Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
DynList< std::pair< T, NumType > > filter (Operation &operation) const
 Filter elements by a predicate.
 
DynList< std::pair< T, NumType > > filter (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
DynList< std::tuple< std::pair< T, NumType >, size_t > > pfilter (Operation &operation) const
 Filter with position information.
 
DynList< std::tuple< std::pair< T, NumType >, size_t > > pfilter (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
std::pair< DynList< std::pair< T, NumType > >, DynList< std::pair< T, NumType > > > partition (Operation &op) const
 Partition elements by a predicate.
 
std::pair< DynList< std::pair< T, NumType > >, DynList< std::pair< T, NumType > > > partition (Operation &&op=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
std::tuple< DynList< std::pair< T, NumType > >, DynList< std::pair< T, NumType > > > tpartition (Operation &op) const
 Partition returning tuple instead of pair.
 
std::tuple< DynList< std::pair< T, NumType > >, DynList< std::pair< T, NumType > > > tpartition (Operation &&op=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
size_t length () const noexcept
 Count the number of elements.
 
Container< std::pair< T, NumType > > rev () const
 Create a reversed copy.
 
Container< std::pair< T, NumType > > take (const size_t n) const
 Take the first n elements.
 
Container< std::pair< T, NumType > > drop (const size_t n) const
 Skip the first n elements.
 
std::pair< T, NumType > sum (const std::pair< T, NumType > &init=std::pair< T, NumType > {}) const
 Compute the sum of all elements.
 
std::pair< T, NumType > product (const std::pair< T, NumType > &init) const
 Compute the product of all elements.
 
const std::pair< T, NumType > * min () const
 Find the minimum element.
 
const std::pair< T, NumType > * max () const
 Find the maximum element.
 
const std::pair< T, NumType > * min_by (Compare cmp) const
 Find the minimum element using a custom comparator.
 
const std::pair< T, NumType > * max_by (Compare cmp) const
 Find the maximum element using a custom comparator.
 
bool has_value (const std::pair< T, NumType > &val) const
 Check if container has a value.
 
bool none (Predicate &pred) const
 Check if no element satisfies a predicate.
 
bool none (Predicate &&pred) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
size_t count_if (Predicate pred) const
 Count elements satisfying a predicate.
 
const std::pair< T, NumType > * first () const
 Get the first element.
 
std::pair< T, NumType > first_or (const std::pair< T, NumType > &default_val) const
 Get the first element or a default value.
 
const std::pair< T, NumType > * last () const
 Get the last element.
 
std::pair< T, NumType > last_or (const std::pair< T, NumType > &default_val) const
 Get the last element or a default value.
 
Container< std::pair< size_t, std::pair< T, NumType > > > enumerate () const
 Enumerate elements with their indices.
 
size_t find_index (Predicate pred) const
 Find the index of the first element satisfying a predicate.
 
size_t index_of (const std::pair< T, NumType > &val) const
 Find the index of a specific value.
 
Container< std::pair< T, NumType > > unique () const
 Remove consecutive duplicate elements.
 
Container< std::pair< T, NumType > > unique_by (EqPred eq) const
 Remove consecutive duplicates using a custom equality predicate.
 
Container< std::pair< T, NumType > > intersperse (const std::pair< T, NumType > &sep) const
 Intersperse a separator between elements.
 
Container< Container< std::pair< T, NumType > > > chunk (size_t n) const
 Split into chunks of fixed size.
 
Container< Container< std::pair< T, NumType > > > sliding (size_t size, size_t step=1) const
 Create sliding windows of fixed size.
 
std::vector< std::pair< T, NumType > > to_vector () const
 Convert to std::vector.
 
DynListType to_dynlist () const
 Convert container to DynList.
 
StringType join (const StringType &sep=StringType{", "}) const
 Join elements into a string with separator.
 
std::string join_str (const std::string &sep=", ") const
 Join string elements with separator.
 
Container< std::pair< std::pair< T, NumType >, typename Other::Item_Type > > zip_with (const Other &other) const
 Zip with another container.
 

Public Attributes

const DynList< std::string > entries_str
 
DynList< Pair > pairs = zip(keys_str, entries_str)
 
const DynList< Pair > format
 
std::pair< DynList< std::string >, DynList< std::string > > ret = unzip(format)
 
auto concatenate
 
const std::string dstr = ret.first.template foldl<std::string>("", concatenate)
 
const std::string estr = ret.second.template foldl<std::string>("", concatenate)
 
- Public Attributes inherited from Aleph::FunctionalMixin< Vector< T, NumType >, std::pair< T, NumType > >
 and
 Transform elements using a mapping function.
 

Private Member Functions

bool is_zero (const NumType &val) const noexcept
 
void insert_or_remove_entry (const T &i, const NumType &value, Pair *ptr)
 

Static Private Member Functions

static NumType abs (const NumType &val) noexcept
 
static bool test_epsilon (const NumType &e) noexcept
 

Private Attributes

DomainPtr domain_ptr = nullptr
 
NumType epsilon = default_epsilon
 
Map entries
 

Static Private Attributes

static const NumType default_epsilon = 1e-7
 

Additional Inherited Members

- Protected Member Functions inherited from Aleph::TraverseMixin< Vector< T, NumType >, std::pair< T, NumType > >
const Vector< T, NumType > & self () const noexcept
 Access the derived class (const version).
 
Vector< T, NumType > & self () noexcept
 Access the derived class (mutable version).
 
- Protected Member Functions inherited from Aleph::LocateMixin< Vector< T, NumType >, std::pair< T, NumType > >
const Vector< T, NumType > & self () const noexcept
 
Vector< T, NumType > & self () noexcept
 
- Protected Member Functions inherited from Aleph::FunctionalMixin< Vector< T, NumType >, std::pair< T, NumType > >
const Vector< T, NumType > & self () const noexcept
 
Vector< T, NumType > & self () noexcept
 

Detailed Description

template<typename T, typename NumType>
requires AlDomainKey<T>
class Aleph::Vector< T, NumType >

Sparse vector implementation with domain-based indexing.

This class implements a mathematical vector with sparse storage, where only non-zero entries are stored. The vector is defined over a domain of type T, and entries have values of type NumType.

The vector uses epsilon-based comparison for numerical tolerance, automatically removing entries that become close to zero.

Template Parameters
TType of domain elements (default: int)
NumTypeNumeric type for vector entries (default: double)
Author
Leandro Rabindranath Leon

Definition at line 152 of file al-vector.H.

Member Typedef Documentation

◆ Const_Iterator

template<typename T , typename NumType >
using Aleph::Vector< T, NumType >::Const_Iterator = Aleph::Const_Iterator<Iterator>

Read-only iterator: the iterator of a constant vector.

Definition at line 875 of file al-vector.H.

◆ Domain

template<typename T , typename NumType >
using Aleph::Vector< T, NumType >::Domain = AlDomain<T>

Definition at line 157 of file al-vector.H.

◆ DomainPtr

template<typename T , typename NumType >
using Aleph::Vector< T, NumType >::DomainPtr = std::shared_ptr<Domain>

Definition at line 158 of file al-vector.H.

◆ Item_Type

template<typename T , typename NumType >
using Aleph::Vector< T, NumType >::Item_Type = std::pair<T, NumType>

Definition at line 160 of file al-vector.H.

◆ Map

template<typename T , typename NumType >
using Aleph::Vector< T, NumType >::Map = Aleph::HashMap<T, NumType, MapODhash>

Definition at line 159 of file al-vector.H.

◆ Pair [1/2]

template<typename T , typename NumType >
using Aleph::Vector< T, NumType >::Pair = std::pair<T, NumType>

Definition at line 199 of file al-vector.H.

◆ Pair [2/2]

template<typename T , typename NumType >
typedef std::pair<std::string, std::string> Aleph::Vector< T, NumType >::Pair

Definition at line 760 of file al-vector.H.

Constructor & Destructor Documentation

◆ Vector() [1/10]

template<typename T , typename NumType >
Aleph::Vector< T, NumType >::Vector ( DomainPtr  d,
const NumType &  zero = default_epsilon 
)
inline

Construct a vector over a given domain (shared_ptr version)

Parameters
dShared pointer to domain for the vector indices
zeroEpsilon value for zero comparisons (default: 1e-7)

Definition at line 215 of file al-vector.H.

◆ Vector() [2/10]

template<typename T , typename NumType >
Aleph::Vector< T, NumType >::Vector ( const Domain &  d,
const NumType &  zero = default_epsilon 
)
inline

Construct a vector over a given domain (reference version)

Parameters
dDomain for the vector indices (will be wrapped in shared_ptr)
zeroEpsilon value for zero comparisons (default: 1e-7)
Note
Creates a non-owning shared_ptr; caller must ensure domain outlives vector

Definition at line 227 of file al-vector.H.

◆ Vector() [3/10]

template<typename T , typename NumType >
Aleph::Vector< T, NumType >::Vector ( Domain &&  d,
const NumType &  zero = default_epsilon 
)
inline

Construct a vector over a temporary domain, which it keeps.

The vector takes d, as Vector(IntRange(10)) gives it, so that the domain lives as long as the vector and those that share it. Another vector over an equal domain has another one: operations between them need the same domain, as get_domain_ptr() gives it.

Parameters
dTemporary domain for the vector indices
zeroEpsilon value for zero comparisons (default: 1e-7)

Definition at line 244 of file al-vector.H.

◆ Vector() [4/10]

template<typename T , typename NumType >
template<typename I >
requires std::is_integral_v<I>
Aleph::Vector< T, NumType >::Vector ( I  ,
const NumType &  = default_epsilon 
)
delete

A vector needs a domain: Vector(IntRange(n)), not Vector(n), which would turn n into an empty domain.

◆ Vector() [5/10]

template<typename T , typename NumType >
Aleph::Vector< T, NumType >::Vector ( const Vector< T, NumType > &  v)
inline

Copy constructor.

Parameters
vVector to copy from

Definition at line 260 of file al-vector.H.

◆ Vector() [6/10]

template<typename T , typename NumType >
Aleph::Vector< T, NumType >::Vector ( Vector< T, NumType > &&  v)
inlinenoexcept

Move constructor.

Parameters
vVector to move from

Definition at line 270 of file al-vector.H.

◆ Vector() [7/10]

template<typename T , typename NumType >
Aleph::Vector< T, NumType >::Vector ( DomainPtr  d,
const DynList< NumType > &  l,
const NumType &  zero = default_epsilon 
)
inline

Construct vector from domain and list of values (shared_ptr version)

Parameters
dShared pointer to domain for the vector indices
lList of values (must match domain size)
zeroEpsilon value for zero comparisons (default: 1e-7)
Exceptions
ah_length_errorif list size doesn't match domain size

Definition at line 284 of file al-vector.H.

References ah_length_error_if, Aleph::Vector< T, NumType >::domain_ptr, l, Aleph::Vector< T, NumType >::set_entry(), Aleph::DynList< T >::size(), and Aleph::zip_it().

◆ Vector() [8/10]

template<typename T , typename NumType >
Aleph::Vector< T, NumType >::Vector ( const Domain &  d,
const DynList< NumType > &  l,
const NumType &  zero = default_epsilon 
)
inline

Construct vector from domain and list of values (reference version)

Parameters
dDomain for the vector indices (will be wrapped in shared_ptr)
lList of values (must match domain size)
zeroEpsilon value for zero comparisons (default: 1e-7)
Exceptions
ah_length_errorif list size doesn't match domain size
Note
Creates a non-owning shared_ptr; caller must ensure domain outlives vector

Definition at line 307 of file al-vector.H.

◆ Vector() [9/10]

template<typename T , typename NumType >
Aleph::Vector< T, NumType >::Vector ( Domain &&  d,
const DynList< NumType > &  l,
const NumType &  zero = default_epsilon 
)
inline

Construct vector from a temporary domain, which it keeps, and a list of values.

Parameters
dTemporary domain for the vector indices
lList of values (must match domain size)
zeroEpsilon value for zero comparisons (default: 1e-7)
Exceptions
ah_length_errorif list size doesn't match domain size

Definition at line 321 of file al-vector.H.

◆ Vector() [10/10]

template<typename T , typename NumType >
template<typename I >
requires std::is_integral_v<I>
Aleph::Vector< T, NumType >::Vector ( I  ,
const DynList< NumType > &  ,
const NumType &  = default_epsilon 
)
delete

A vector needs a domain: Vector(IntRange(n), l), not Vector(n, l), which would turn n into an empty domain.

Member Function Documentation

◆ abs()

template<typename T , typename NumType >
static NumType Aleph::Vector< T, NumType >::abs ( const NumType &  val)
inlinestaticprivatenoexcept

Definition at line 169 of file al-vector.H.

Referenced by Aleph::Vector< T, NumType >::is_zero().

◆ are_equal()

template<typename T , typename NumType >
bool Aleph::Vector< T, NumType >::are_equal ( const NumType &  n1,
const NumType &  n2 
) const
inlinenoexcept

Check if two numeric values are equal within epsilon.

Parameters
n1First value
n2Second value
Returns
true if |n1 - n2| <= epsilon

Definition at line 542 of file al-vector.H.

References Aleph::Vector< T, NumType >::is_zero().

Referenced by Aleph::Vector< T, NumType >::equal_to(), and TEST_F().

◆ divide_by_scalar()

template<typename T , typename NumType >
Vector & Aleph::Vector< T, NumType >::divide_by_scalar ( const NumType &  scalar)
inline

Divide every entry by scalar, which must not be zero.

Definition at line 651 of file al-vector.H.

References ah_domain_error_if, Aleph::Vector< T, NumType >::entries, and Aleph::Vector< T, NumType >::is_zero().

Referenced by Aleph::Vector< T, NumType >::operator/().

◆ equal_to()

template<typename T , typename NumType >
bool Aleph::Vector< T, NumType >::equal_to ( const Vector< T, NumType > &  other) const
inlinenoexcept

Check if this vector equals another within epsilon tolerance.

Parameters
otherVector to compare with (must have same domain)
Returns
true if all corresponding entries are within epsilon

Definition at line 553 of file al-vector.H.

References Aleph::FunctionalMixin< Vector< T, NumType >, std::pair< T, NumType > >::and, Aleph::Vector< T, NumType >::are_equal(), Aleph::Vector< T, NumType >::domain_ptr, Aleph::Vector< T, NumType >::entries, and Aleph::Vector< T, NumType >::get_entry().

◆ get_domain()

template<typename T , typename NumType >
const Domain & Aleph::Vector< T, NumType >::get_domain ( ) const
inlinenoexcept

Get the domain over which this vector is defined.

Returns
Reference to the domain

Definition at line 205 of file al-vector.H.

References Aleph::Vector< T, NumType >::domain_ptr.

Referenced by Aleph::Matrix< Trow, Tcol, NumType >::set_vector_as_col(), Aleph::Matrix< Trow, Tcol, NumType >::set_vector_as_row(), TEST(), TEST_F(), and TEST_F().

◆ get_domain_ptr()

template<typename T , typename NumType >
const DomainPtr & Aleph::Vector< T, NumType >::get_domain_ptr ( ) const
inlinenoexcept

Return the shared pointer to the domain.

Definition at line 208 of file al-vector.H.

References Aleph::Vector< T, NumType >::domain_ptr.

Referenced by Aleph::outer_product(), and TEST().

◆ get_entry() [1/2]

◆ get_entry() [2/2]

template<typename T , typename NumType >
NumType Aleph::Vector< T, NumType >::get_entry ( const T &  i) const
inlinenoexcept

Get vector entry at given index (const version)

Parameters
iIndex (must be in domain)
Returns
Value at index (0 if not set)

Definition at line 496 of file al-vector.H.

References Aleph::Vector< T, NumType >::domain_ptr, and Aleph::Vector< T, NumType >::entries.

◆ get_epsilon()

template<typename T , typename NumType >
const NumType & Aleph::Vector< T, NumType >::get_epsilon ( ) const
inlinenoexcept

Get the epsilon value used for zero comparisons.

Returns
Current epsilon value

Definition at line 187 of file al-vector.H.

References Aleph::Vector< T, NumType >::epsilon.

Referenced by demo_epsilon(), TEST_F(), TEST_F(), and TEST_F().

◆ get_it() [1/2]

template<typename T , typename NumType >
Const_Iterator Aleph::Vector< T, NumType >::get_it ( ) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Read-only.

Definition at line 886 of file al-vector.H.

◆ get_it() [2/2]

template<typename T , typename NumType >
Iterator Aleph::Vector< T, NumType >::get_it ( )
inlinenoexcept

◆ get_itor() [1/2]

template<typename T , typename NumType >
Const_Iterator Aleph::Vector< T, NumType >::get_itor ( ) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Read-only.

Definition at line 882 of file al-vector.H.

◆ get_itor() [2/2]

template<typename T , typename NumType >
Iterator Aleph::Vector< T, NumType >::get_itor ( )
inlinenoexcept

Definition at line 877 of file al-vector.H.

◆ insert_or_remove_entry()

template<typename T , typename NumType >
void Aleph::Vector< T, NumType >::insert_or_remove_entry ( const T &  i,
const NumType &  value,
Pair *  ptr 
)
inlineprivate

◆ is_zero()

◆ operator!=()

template<typename T , typename NumType >
bool Aleph::Vector< T, NumType >::operator!= ( const Vector< T, NumType > &  v) const
inlinenoexcept

Whether some entry of v differs from this one, beyond epsilon.

Definition at line 576 of file al-vector.H.

◆ operator()() [1/2]

template<typename T , typename NumType >
Proxy Aleph::Vector< T, NumType >::operator() ( const T &  k)
inline

The entry of k, which a Proxy reads and assigns.

Definition at line 860 of file al-vector.H.

References k.

◆ operator()() [2/2]

template<typename T , typename NumType >
NumType Aleph::Vector< T, NumType >::operator() ( const T &  k) const
inlinenoexcept

The value of the entry of k, read-only: 0 if it has none.

Definition at line 854 of file al-vector.H.

References Aleph::Vector< T, NumType >::get_entry(), and k.

◆ operator*() [1/2]

template<typename T , typename NumType >
Vector Aleph::Vector< T, NumType >::operator* ( const NumType &  scalar) const
inline

This vector multiplied by scalar.

Definition at line 643 of file al-vector.H.

References Aleph::Vector< T, NumType >::product_by_scalar().

◆ operator*() [2/2]

template<typename T , typename NumType >
NumType Aleph::Vector< T, NumType >::operator* ( const Vector< T, NumType > &  v) const
inline

The scalar product of this vector and v, over the same domain.

Definition at line 707 of file al-vector.H.

References Aleph::Vector< T, NumType >::scalar_product().

◆ operator+()

template<typename T , typename NumType >
Vector Aleph::Vector< T, NumType >::operator+ ( const Vector< T, NumType > &  r) const
inline

The sum of this vector and r, over the same domain.

Definition at line 607 of file al-vector.H.

References r.

◆ operator+=()

template<typename T , typename NumType >
Vector & Aleph::Vector< T, NumType >::operator+= ( const Vector< T, NumType > &  v)
inline

Add v, over the same domain, to this vector.

Definition at line 583 of file al-vector.H.

References Aleph::Vector< T, NumType >::domain_ptr, Aleph::Vector< T, NumType >::get_entry(), and Aleph::Vector< T, NumType >::set_entry().

◆ operator-() [1/2]

template<typename T , typename NumType >
Vector Aleph::Vector< T, NumType >::operator- ( ) const
inline

The negation of this vector.

Definition at line 676 of file al-vector.H.

References Aleph::Vector< T, NumType >::product_by_scalar().

◆ operator-() [2/2]

template<typename T , typename NumType >
Vector Aleph::Vector< T, NumType >::operator- ( const Vector< T, NumType > &  r) const
inline

The difference of this vector and r, over the same domain.

Definition at line 615 of file al-vector.H.

References r.

◆ operator-=()

template<typename T , typename NumType >
Vector & Aleph::Vector< T, NumType >::operator-= ( const Vector< T, NumType > &  v)
inline

Subtract v, over the same domain, from this vector.

Definition at line 595 of file al-vector.H.

References Aleph::Vector< T, NumType >::domain_ptr, Aleph::Vector< T, NumType >::get_entry(), and Aleph::Vector< T, NumType >::set_entry().

◆ operator/()

template<typename T , typename NumType >
Vector Aleph::Vector< T, NumType >::operator/ ( const NumType &  scalar) const
inline

This vector divided by scalar, which must not be zero.

Definition at line 668 of file al-vector.H.

References Aleph::Vector< T, NumType >::divide_by_scalar().

◆ operator=() [1/2]

template<typename T , typename NumType >
Vector & Aleph::Vector< T, NumType >::operator= ( const Vector< T, NumType > &  v)
inline

Copy assignment operator.

Parameters
vVector to copy from
Returns
Reference to this vector
Exceptions
std::domain_errorif domains are different (not the same object)
Note
Vectors must share the same domain (pointer equality) for assignment

Definition at line 340 of file al-vector.H.

References ah_domain_error_if, Aleph::Vector< T, NumType >::domain_ptr, Aleph::Vector< T, NumType >::entries, and Aleph::Vector< T, NumType >::epsilon.

◆ operator=() [2/2]

template<typename T , typename NumType >
Vector & Aleph::Vector< T, NumType >::operator= ( Vector< T, NumType > &&  v)
inline

Move assignment operator.

Parameters
vVector to move from
Returns
Reference to this vector
Exceptions
std::domain_errorif domains are different (not the same object)
Note
Vectors must share the same domain (pointer equality) for assignment

Definition at line 361 of file al-vector.H.

References ah_domain_error_if, Aleph::Vector< T, NumType >::domain_ptr, Aleph::Vector< T, NumType >::entries, and Aleph::Vector< T, NumType >::epsilon.

◆ operator==()

template<typename T , typename NumType >
bool Aleph::Vector< T, NumType >::operator== ( const Vector< T, NumType > &  v) const
inlinenoexcept

Whether the entries of v are equal to these, within epsilon.

Definition at line 569 of file al-vector.H.

◆ operator[]() [1/2]

template<typename T , typename NumType >
Proxy Aleph::Vector< T, NumType >::operator[] ( const T &  k)
inline

The entry of k, which a Proxy reads and assigns.

Definition at line 848 of file al-vector.H.

References k.

◆ operator[]() [2/2]

template<typename T , typename NumType >
NumType Aleph::Vector< T, NumType >::operator[] ( const T &  k) const
inlinenoexcept

The value of the entry of k, read-only: 0 if it has none.

Definition at line 842 of file al-vector.H.

References Aleph::Vector< T, NumType >::get_entry(), and k.

◆ print()

template<typename T , typename NumType >
void Aleph::Vector< T, NumType >::print ( ) const
inline

Print the nonzero entries, in the order of the sorted keys.

Definition at line 728 of file al-vector.H.

References Aleph::Vector< T, NumType >::domain_ptr, Aleph::Vector< T, NumType >::entries, and k.

◆ product_by_scalar()

template<typename T , typename NumType >
Vector & Aleph::Vector< T, NumType >::product_by_scalar ( const NumType &  scalar)
inlinenoexcept

◆ scalar_product()

template<typename T , typename NumType >
NumType Aleph::Vector< T, NumType >::scalar_product ( const Vector< T, NumType > &  v) const
inline

The scalar product of this vector and v, over the same domain.

Definition at line 683 of file al-vector.H.

References ah_domain_error_if, Aleph::Vector< T, NumType >::domain_ptr, Aleph::Vector< T, NumType >::entries, and Aleph::Vector< T, NumType >::get_entry().

Referenced by Aleph::Vector< T, NumType >::operator*(), and TEST_F().

◆ search_entry() [1/2]

template<typename T , typename NumType >
const NumType * Aleph::Vector< T, NumType >::search_entry ( const T &  i) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A pointer to const.

Definition at line 525 of file al-vector.H.

References Aleph::Vector< T, NumType >::domain_ptr, and Aleph::Vector< T, NumType >::entries.

◆ search_entry() [2/2]

template<typename T , typename NumType >
NumType * Aleph::Vector< T, NumType >::search_entry ( const T &  i)
inlinenoexcept

Search for an entry and return pointer to its value.

Parameters
iIndex (must be in domain)
Returns
Pointer to value if exists, nullptr otherwise

Definition at line 512 of file al-vector.H.

References Aleph::Vector< T, NumType >::domain_ptr, and Aleph::Vector< T, NumType >::entries.

Referenced by TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ set_entries() [1/2]

template<typename T , typename NumType >
template<template< typename > class Container = DynList>
void Aleph::Vector< T, NumType >::set_entries ( const Container< T > &  c,
std::initializer_list< NumType >  lr 
)
inline

Set multiple entries using container and initializer list.

Template Parameters
ContainerContainer type (default: DynList)
Parameters
cContainer of domain indices
lrList of corresponding values
Exceptions
ah_range_errorif container and list have different sizes
ah_domain_errorif any index not in domain

Definition at line 452 of file al-vector.H.

References ah_domain_error_if, ah_range_error_if, Aleph::Vector< T, NumType >::domain_ptr, and Aleph::Vector< T, NumType >::set_entry().

◆ set_entries() [2/2]

template<typename T , typename NumType >
void Aleph::Vector< T, NumType >::set_entries ( std::initializer_list< T >  ld,
std::initializer_list< NumType >  lr 
)
inline

Set multiple entries using initializer lists.

Parameters
ldList of domain indices
lrList of corresponding values
Exceptions
ah_range_errorif lists have different sizes
ah_domain_errorif any index not in domain

Definition at line 427 of file al-vector.H.

References ah_domain_error_if, ah_range_error_if, Aleph::Vector< T, NumType >::domain_ptr, and Aleph::Vector< T, NumType >::set_entry().

Referenced by TEST_F(), TEST_F(), and TEST_F().

◆ set_entry()

template<typename T , typename NumType >
void Aleph::Vector< T, NumType >::set_entry ( const T &  i,
const NumType &  value 
)
inline

Set a vector entry at given index.

Parameters
iIndex (must be in domain)
valueValue to set (automatically removed if within epsilon of zero)
Note
If value is zero (within epsilon), the entry is removed from storage

Definition at line 381 of file al-vector.H.

References Aleph::Vector< T, NumType >::domain_ptr, Aleph::Vector< T, NumType >::entries, Aleph::Vector< T, NumType >::is_zero(), and value.

Referenced by Aleph::Vector< T, NumType >::Vector(), demo_epsilon(), demo_linear_system(), demo_matrix_vector_mult(), demo_outer_product(), demo_row_col_operations(), demo_sparse_vector(), demo_string_indexed_vector(), demo_vector_arithmetic(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_vector(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_vector(), Aleph::Matrix< Trow, Tcol, NumType >::mult_matrix_vector_dot_product(), Aleph::Matrix< Trow, Tcol, NumType >::mult_matrix_vector_sparse(), Aleph::Matrix< Trow, Tcol, NumType >::mult_vector_matrix_dot_product(), Aleph::Vector< T, NumType >::operator+=(), Aleph::Vector< T, NumType >::operator-=(), Aleph::Vector< T, NumType >::Proxy::operator=(), Aleph::Vector< T, NumType >::set_entries(), Aleph::Vector< T, NumType >::set_entries(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), Aleph::Matrix< Trow, Tcol, NumType >::to_collist(), and Aleph::Matrix< Trow, Tcol, NumType >::to_rowlist().

◆ set_epsilon()

template<typename T , typename NumType >
void Aleph::Vector< T, NumType >::set_epsilon ( const NumType &  e)
inlinenoexcept

Set the epsilon value for zero comparisons.

Parameters
eNew epsilon value (must be >= 0)
Note
Values with absolute value <= epsilon are considered zero

Definition at line 194 of file al-vector.H.

References Aleph::Vector< T, NumType >::epsilon.

Referenced by demo_epsilon(), and TEST_F().

◆ std::string()

template<typename T , typename NumType >
return dstr n Aleph::Vector< T, NumType >::std::string ( dstr.  size(),
'-'   
)

◆ test_epsilon()

template<typename T , typename NumType >
static bool Aleph::Vector< T, NumType >::test_epsilon ( const NumType &  e)
inlinestaticprivatenoexcept

Definition at line 180 of file al-vector.H.

◆ to_list()

template<typename T , typename NumType >
DynList< NumType > Aleph::Vector< T, NumType >::to_list ( ) const
inline

The values of the vector, in the order of the sorted keys of its domain.

It is the list that the constructor from a domain and a list takes: Vector(d, l).to_list() gives l.

Definition at line 719 of file al-vector.H.

References Aleph::Vector< T, NumType >::domain_ptr, and Aleph::Vector< T, NumType >::get_entry().

Referenced by TEST_F(), and Aleph::Matrix< Trow, Tcol, NumType >::to_str().

◆ to_str()

template<typename T , typename NumType >
std::string Aleph::Vector< T, NumType >::to_str ( ) const
inline

The keys over their values, in the order of the keys.

Definition at line 740 of file al-vector.H.

References Aleph::Vector< T, NumType >::std::string().

Referenced by Aleph::operator<<(), and TEST_F().

Member Data Documentation

◆ concatenate

template<typename T , typename NumType >
auto Aleph::Vector< T, NumType >::concatenate
Initial value:
= [](const std::string & s1, const std::string & s2)
{
return s1 + s2;
}
return dstr n std::string(dstr.size(), '-')+"\n"+estr

Definition at line 775 of file al-vector.H.

◆ default_epsilon

template<typename T , typename NumType >
requires AlDomainKey<T>
and AlNumber< NumType > const NumType Aleph::Vector< T, NumType >::default_epsilon = 1e-7
staticprivate

Definition at line 163 of file al-vector.H.

◆ domain_ptr

◆ dstr

template<typename T , typename NumType >
const std::string Aleph::Vector< T, NumType >::dstr = ret.first.template foldl<std::string>("", concatenate)

Definition at line 780 of file al-vector.H.

◆ entries

◆ entries_str

template<typename T , typename NumType >
const DynList<std::string> Aleph::Vector< T, NumType >::entries_str
Initial value:
=
domain_ptr->keys().template maps<std::string>([this](const T & d)
{
return std::to_string(get_entry(d));
})
NumType get_entry(const T &i)
Get vector entry at given index (non-const version)
Definition al-vector.H:474
DomainPtr domain_ptr
Definition al-vector.H:165
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152

Definition at line 754 of file al-vector.H.

◆ epsilon

◆ estr

template<typename T , typename NumType >
const std::string Aleph::Vector< T, NumType >::estr = ret.second.template foldl<std::string>("", concatenate)

Definition at line 782 of file al-vector.H.

◆ format

template<typename T , typename NumType >
const DynList<Pair> Aleph::Vector< T, NumType >::format
Initial value:
template maps<Pair>([](const Pair & p)
{
const size_t fsz = p.first.size();
const size_t ssz = p.second.size();
if (fsz > ssz)
return Pair(" " + p.first, std::string(fsz - ssz + 1, ' ') + p.second);
return Pair(std::string(ssz - fsz + 1, ' ') + p.first, " " + p.second);
})
std::pair< T, NumType > Pair
Definition al-vector.H:199
DynList< Pair > pairs
Definition al-vector.H:761

Definition at line 763 of file al-vector.H.

◆ pairs

template<typename T , typename NumType >
DynList<Pair> Aleph::Vector< T, NumType >::pairs = zip(keys_str, entries_str)

Definition at line 761 of file al-vector.H.

◆ ret

template<typename T , typename NumType >
std::pair<DynList<std::string>, DynList<std::string> > Aleph::Vector< T, NumType >::ret = unzip(format)

Definition at line 773 of file al-vector.H.


The documentation for this class was generated from the following file: