|
FlexELA
|
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 Element * | data () 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. | |
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.
chop() is called, after which it is guaranteed \(s_\ell\gt 0\).
|
inline |
Construct a new SVector object with a single non-zero element.
| elm | The non-zero element |
| svec::SVector::SVector | ( | const Element *const | buff | ) |
Construct a new SVector object with non-zero elements given in buff.
buff must be sorted in ascending order by label, with no repeated labels.| buff | A sequence of elements, ending in END_ELEMENT |
| 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) \]
| a | NormalizedSVector, \(\tilde{\mathbf{a}}\) |
| C | Value, \(C\) |
|
inlinenoexcept |
Start of the non-zero elements.
Returns the (constant) beginning iterator for the underlying std::vector<Element>
| 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.
| ref | \( R \) |
|
inlinenoexcept |
Clear out all non-zero entries.
This has the effect of \(\mathbf{s}\gets\mathbf{0}\).
| bool svec::SVector::containsNaN | ( | ) | const |
Check if any elements have a NaN value.
|
inlinenoexcept |
Directly access the non-zero elements.
Returns a direct pointer to the memory array used by the underlying std::vector<Element>
|
inlinenoexcept |
End of the non-zero elements.
Returns the (constant) end iterator for the underlying std::vector<Element>
| Label svec::SVector::getMaxLabel | ( | ) | const |
| Value svec::SVector::getMaxValue | ( | ) | const |
Get the maximum non-zero entry.
| Value svec::SVector::getMinValue | ( | ) | const |
Get the minimum non-zero entry.
|
inlinenoexcept |
|
inlinenoexcept |
Get the number of non-zero elements.
Returns the number of non-zero elements in this \(\mathbf{s}\)
| 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}\).
| total |
| Value svec::SVector::sum | ( | ) | const |
Get the sum of values.
| void svec::SVector::zeroEntry | ( | const Label & | l | ) |
Set the entry at label l to zero.
\[ s_l \gets 0 \]
| l | the label to set to zero |