FlexELA
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
svec::SVector Class Reference

A container for sparse vectors. More...

#include <svector.h>

Public Member Functions

 SVector ()=default
 Construct a new SVector object with no non-zero elements.
 
 SVector (const Element &elm)
 Construct a new SVector object with a single non-zero element.
 
 SVector (const Element *const buff)
 Construct a new SVector object with non-zero elements given in buff.
 
Value sum () const
 Get the sum of values.
 
std::size_t NNZ () const noexcept
 Get the number of non-zero elements.
 
bool isEmpty () const noexcept
 Check if any non-zero elements.
 
Value getMinValue () const
 Get the minimum non-zero entry.
 
Value getMaxValue () const
 Get the maximum non-zero entry.
 
Label getMaxLabel () const
 Get the maximum label.
 
const Elementdata () const noexcept
 Directly access the non-zero elements.
 
bool containsNaN () const
 Check if any elements have a NaN value.
 
std::vector< Element >::const_iterator begin () const noexcept
 Start of the non-zero elements.
 
std::vector< Element >::const_iterator end () const noexcept
 End of the non-zero elements.
 
void add (const SVector &a, const Value &C=1.0)
 Inplace Addition (and Multiplication), s=s+a*C.
 
void add (const NormalizedSVector &a, const Value &C=1.0)
 Inplace Addition (and Multiplication), s=s+a*C.
 
void normalize (const Value &total=1.0)
 s=s/sum(s) * total
 
void chop (const Value &ref=0.0)
 Remove small elements in s.
 
void zeroEntry (const Label &l)
 Set the entry at label l to zero.
 
void clear () noexcept
 Clear out all non-zero entries.
 

Friends

SVector fma (const SVector &a, const Value &C, const SVector &b)
 Fused Multiply and Add, C*a+b.
 
SVector operator/ (const SVector &a, const Value &C)
 Division, a/C.
 
SVector operator* (const SVector &a, const Value &C)
 Multiplication, a*C.
 

Detailed Description

A container for sparse vectors.

The SVector class is used to store a vector \(\mathbf{s}\) in terms of its non-zero elements \(s_\ell\). The underlying storage structure is a std::vector<Element>, which allows the storage to grow dynamically as the number of non-zero elements changes.

Note
While elements \(s_\ell\) are refereed to in documentation as ''non-zero elements'', it is not guaranteed that \(s_\ell\ne 0\) until chop() is called, after which it is guaranteed \(s_\ell\gt 0\).

Constructor & Destructor Documentation

◆ SVector() [1/2]

svec::SVector::SVector ( const Element elm)
inline

Construct a new SVector object with a single non-zero element.

Parameters
elmThe non-zero element

◆ SVector() [2/2]

svec::SVector::SVector ( const Element *const  buff)

Construct a new SVector object with non-zero elements given in buff.

Note
The elements in buff must be sorted in ascending order by label, with no repeated labels.
Parameters
buffA sequence of elements, ending in END_ELEMENT

Member Function Documentation

◆ add() [1/2]

void svec::SVector::add ( const NormalizedSVector a,
const Value C = 1.0 
)

Inplace Addition (and Multiplication), s=s+a*C.

For an NormalizedSVector \(\tilde{\mathbf{a}}\) and a Value \(C\), changes this \(\mathbf{s}\) by

\[ \mathbf{s} \gets \mathbf{s} + \left(C \times \tilde{\mathbf{a}}\right) \]

Parameters
aNormalizedSVector, \(\tilde{\mathbf{a}}\)
CValue, \(C\)

◆ add() [2/2]

void svec::SVector::add ( const SVector a,
const Value C = 1.0 
)

Inplace Addition (and Multiplication), s=s+a*C.

For an SVector \(\mathbf{a}\) and a Value \(C\), changes this \(\mathbf{s}\) by

\[ \mathbf{s} \gets \mathbf{s} + \left(C \times \mathbf{a}\right) \]

Parameters
aSVector, \(\mathbf{a}\)
CValue, \(C\)

◆ begin()

std::vector< Element >::const_iterator svec::SVector::begin ( ) const
inlinenoexcept

Start of the non-zero elements.

Returns the (constant) beginning iterator for the underlying std::vector<Element>

Returns
std::vector<Element>::const_iterator

◆ chop()

void svec::SVector::chop ( const Value ref = 0.0)

Remove small elements in s.

For any \(s_l\le \varepsilon R \), \( s_l \gets 0 \). Where \( \varepsilon \) is machine precision.

Parameters
ref\( R \)

◆ clear()

void svec::SVector::clear ( )
inlinenoexcept

Clear out all non-zero entries.

This has the effect of \(\mathbf{s}\gets\mathbf{0}\).

Note
Does not change the allocated memory

◆ containsNaN()

bool svec::SVector::containsNaN ( ) const

Check if any elements have a NaN value.

Returns
true if any non-zero elements has a value of NaN
false otherwise

◆ data()

const Element * svec::SVector::data ( ) const
inlinenoexcept

Directly access the non-zero elements.

Returns a direct pointer to the memory array used by the underlying std::vector<Element>

◆ end()

std::vector< Element >::const_iterator svec::SVector::end ( ) const
inlinenoexcept

End of the non-zero elements.

Returns the (constant) end iterator for the underlying std::vector<Element>

Returns
std::vector<Element>::const_iterator

◆ getMaxLabel()

Label svec::SVector::getMaxLabel ( ) const

Get the maximum label.

Returns zero if NNZ()==0

Returns
Label

◆ getMaxValue()

Value svec::SVector::getMaxValue ( ) const

Get the maximum non-zero entry.

Returns
Value

◆ getMinValue()

Value svec::SVector::getMinValue ( ) const

Get the minimum non-zero entry.

Returns
Value

◆ isEmpty()

bool svec::SVector::isEmpty ( ) const
inlinenoexcept

Check if any non-zero elements.

Returns
true if NNZ()==0
false if NNZ()!=0

◆ NNZ()

std::size_t svec::SVector::NNZ ( ) const
inlinenoexcept

Get the number of non-zero elements.

Returns the number of non-zero elements in this \(\mathbf{s}\)

◆ normalize()

void svec::SVector::normalize ( const Value total = 1.0)

s=s/sum(s) * total

If sum(s) is zero or sum(s)/total is subnormal, \(\mathbf{s}\gets\mathbf{0}\).

Parameters
total

◆ sum()

Value svec::SVector::sum ( ) const

Get the sum of values.

Returns
Value

◆ zeroEntry()

void svec::SVector::zeroEntry ( const Label l)

Set the entry at label l to zero.

\[ s_l \gets 0 \]

Parameters
lthe label to set to zero

Friends And Related Symbol Documentation

◆ fma

SVector fma ( const SVector a,
const Value C,
const SVector b 
)
friend

Fused Multiply and Add, C*a+b.

For two SVector \(\mathbf{a}\) and \(\mathbf{b}\) and a Value \(C\), returns

\[ \left(C \times \mathbf{a}\right) + \mathbf{b} \]

Parameters
aSVector, \(\mathbf{a}\)
CValue, \(C\)
bSVector, \(\mathbf{b}\)
Returns
SVector

◆ operator*

SVector operator* ( const SVector a,
const Value C 
)
friend

Multiplication, a*C.

For a SVector \(\mathbf{a}\) and a Value \(C\), returns

\[ \mathbf{a} * C \]

Parameters
aSVector, \(\mathbf{a}\)
CValue, \(C\)
Returns
SVector

◆ operator/

SVector operator/ ( const SVector a,
const Value C 
)
friend

Division, a/C.

For a SVector \(\mathbf{a}\) and a Value \(C\), returns

\[ \mathbf{a} / C \]

Parameters
aSVector, \(\mathbf{a}\)
CValue, \(C\)
Returns
SVector

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