Go to the documentation of this file.
41 #ifndef SPARSE_VECTOR_INCLUDE
42 #define SPARSE_VECTOR_INCLUDE
163 const unsigned int kb,
const unsigned int ke);
250 const unsigned int M = 0);
257 const unsigned int M = 0);
277 friend std::ostream& operator<<<T>(std::ostream& os,
286 const unsigned int kb,
const unsigned int ke);
327 T *ptrSmall, T *ptrBig);
337 const unsigned int M);
363 const unsigned int&
len);
371 inline unsigned int size()
const {
return len; }
385 return (
double(
vecMap.size()) /
double(
len));
400 typename std::map<unsigned int, T>::iterator it;
402 it =
vecMap.lower_bound(n);
408 inline void resize(
const unsigned int newlen)
458 std::string
dump(
const int p = 3,
bool dosci =
false)
const
460 std::ostringstream oss;
462 oss <<
"len=" <<
len <<
", N=" <<
vecMap.size();
463 oss << (dosci ? std::scientific : std::fixed) << std::setprecision(p);
464 typename std::map<unsigned int, T>::const_iterator it =
vecMap.begin();
465 for (; it !=
vecMap.end(); ++it)
466 oss <<
" " << it->first <<
"," << it->second;
475 typename std::map<unsigned int, T>::iterator it =
vecMap.begin();
476 for (; it !=
vecMap.end(); ++it)
496 typename std::map<unsigned int, T>::iterator it;
497 for (it = toRet.
vecMap.begin(); it != toRet.
vecMap.end(); ++it)
520 std::vector<unsigned int> vecind;
521 typename std::map<unsigned int, T>::const_iterator it;
523 vecind.push_back(it->first);
543 typename std::map<unsigned int, T>::iterator it = mySV.vecMap.find(index);
544 if (it != mySV.vecMap.end())
558 typename std::map<unsigned int, T>::iterator it =
559 mySV.vecMap.find(index);
560 if (it != mySV.vecMap.end())
562 mySV.vecMap.erase(it);
569 (
static_cast<std::map<unsigned int, T> &
>(mySV.vecMap))[index] = rhs;
577 typename std::map<unsigned int, T>::iterator it = mySV.vecMap.find(index);
578 if (it != mySV.vecMap.end())
595 for (
unsigned int i = 0; i < len; i++)
612 const unsigned int& ind,
const unsigned int& n)
614 if (ind + n > SV.
len)
624 typename std::map<unsigned int, T>::const_iterator it;
625 for (it = SV.
vecMap.begin(); it != SV.
vecMap.end(); ++it)
631 if (it->first > ind + n)
635 vecMap[it->first - ind] = it->second;
643 typename std::map<unsigned int, T>::const_iterator it;
644 for (it = vecMap.begin(); it != vecMap.end(); ++it)
646 toRet(it->first) = it->second;
658 std::vector<unsigned int> toDelete;
659 typename std::map<unsigned int, T>::iterator it;
661 for (it = vecMap.begin(); it != vecMap.end(); ++it)
663 if (
ABS(it->second) <= tol)
665 toDelete.push_back(it->first);
669 for (
unsigned int i = 0; i < toDelete.size(); i++)
670 vecMap.erase(toDelete[i]);
677 std::ofstream savefmt;
681 typename std::map<unsigned int, T>::const_iterator it = SV.
vecMap.begin();
682 for (i = 0; i < SV.
len; i++)
686 os << std::setw(1) <<
' ';
689 if (it != SV.
vecMap.end() && i == it->first)
707 typename std::map<unsigned int, T>::const_iterator it = SV.
vecMap.begin();
708 if (it == SV.
vecMap.end())
713 T tn(
ABS(it->second));
714 for (; it != SV.
vecMap.end(); ++it)
716 if (tn >
ABS(it->second))
718 tn *=
SQRT(T(1) + (it->second / tn) * (it->second / tn));
720 else if (tn <
ABS(it->second))
722 tn =
ABS(it->second) *
723 SQRT(T(1) + (tn / it->second) * (tn / it->second));
750 if (norm1 == T(0) || norm2 == T(0))
755 return ((cv / norm1) / norm2);
772 if (norm1 == T(0) || norm2 == T(0))
777 return ((cv / norm1) / norm2);
796 typename std::map<unsigned int, T>::const_iterator it = SL.
vecMap.begin();
797 typename std::map<unsigned int, T>::const_iterator jt = SR.
vecMap.begin();
800 if (it->first > jt->first)
804 else if (jt->first > it->first)
810 value += it->second * jt->second;
821 const unsigned int kb,
const unsigned int ke)
828 typename std::map<unsigned int, T>::const_iterator it = SL.
vecMap.begin();
829 typename std::map<unsigned int, T>::const_iterator jt = SR.
vecMap.begin();
832 if (it->first >= ke || jt->first >= ke)
836 if (it->first > jt->first || jt->first < kb)
840 else if (jt->first > it->first || it->first < kb)
848 value += it->second * jt->second;
865 typename std::map<unsigned int, T>::const_iterator it;
866 for (it = SL.
vecMap.begin(); it != SL.
vecMap.end(); ++it)
868 value += it->second * R[it->first];
881 typename std::map<unsigned int, T>::const_iterator it = SV.
vecMap.begin();
882 if (it == SV.
vecMap.end())
887 for (++it; it != SV.
vecMap.end(); ++it)
888 if (it->second < value)
897 typename std::map<unsigned int, T>::const_iterator it = SV.
vecMap.begin();
898 if (it == SV.
vecMap.end())
903 for (++it; it != SV.
vecMap.end(); ++it)
904 if (it->second > value)
913 typename std::map<unsigned int, T>::const_iterator it = SV.
vecMap.begin();
914 if (it == SV.
vecMap.end())
918 T value(
ABS(it->second));
919 for (++it; it != SV.
vecMap.end(); ++it)
920 if (
ABS(it->second) < value)
922 value =
ABS(it->second);
929 typename std::map<unsigned int, T>::const_iterator it = SV.
vecMap.begin();
930 if (it == SV.
vecMap.end())
934 T value(
ABS(it->second));
935 for (++it; it != SV.
vecMap.end(); ++it)
936 if (
ABS(it->second) > value)
938 value =
ABS(it->second);
955 typename std::map<unsigned int, T>::const_iterator Rit;
956 for (Rit = R.
vecMap.begin(); Rit != R.
vecMap.end(); ++Rit)
958 if (vecMap.find(Rit->first) == vecMap.end())
960 vecMap[Rit->first] = -Rit->second;
964 vecMap[Rit->first] -= Rit->second;
981 for (
unsigned int i = 0; i < R.
size(); i++)
988 if (vecMap.find(i) == vecMap.end())
1006 if (len != R.
size())
1011 typename std::map<unsigned int, T>::const_iterator Rit;
1012 for (Rit = R.
vecMap.begin(); Rit != R.
vecMap.end(); ++Rit)
1014 if (vecMap.find(Rit->first) == vecMap.end())
1016 vecMap[Rit->first] = Rit->second;
1020 vecMap[Rit->first] += Rit->second;
1032 if (len != R.
size())
1038 for (
unsigned int i = 0; i < R.
size(); i++)
1045 if (vecMap.find(i) == vecMap.end())
1068 if (len != R.
size())
1071 Exception(
"Incompatible dimensions addScaledSparseVector()"));
1074 for (
unsigned int i = 0; i < R.
size(); i++)
1081 if (vecMap.find(i) == vecMap.end())
1083 vecMap[i] = a * R[i];
1087 vecMap[i] += a * R[i];
1103 typename std::map<unsigned int, T>::iterator it;
1104 for (it = vecMap.begin(); it != vecMap.end(); ++it)
1106 it->second *= value;
1122 typename std::map<unsigned int, T>::iterator it;
1123 for (it = vecMap.begin(); it != vecMap.end(); ++it)
1125 it->second /= value;
1230 #endif // define SPARSE_VECTOR_INCLUDE
SVecProxy & operator-=(const SVecProxy< T > &rhs)
operator-= for non-const (lvalue)
SparseVector(const unsigned int N)
constructor with length
T value() const
get the value of the SparseVector at index
SparseMatrix< T > lowerCholesky(const SparseMatrix< T > &A)
double density() const
density - ratio of number of non-zero element to size()
void addScaledSparseVector(const T &a, const SparseVector< T > &SV)
unsigned int datasize() const
datasize - number of non-zero data
friend class SVecProxy< T >
Proxy needs access to vecMap.
T dot(const SparseVector< T > &SL, const SparseVector< T > &SR)
dot (SparseVector, SparseVector)
SparseMatrix< T > operator+(const SparseMatrix< T > &L, const SparseMatrix< T > &R)
Matrix addition: SparseMatrix = SparseMatrix + SparseMatrix : copy, += SM.
void zeroize(const T tol=static_cast< T >(zeroTolerance))
friend T dot(const SparseVector< T > &SL, const SparseVector< T > &SR)
dot (SparseVector, SparseVector)
T max(const SparseMatrix< T > &SM)
Maximum element - return 0 if empty.
SparseVector< T > & operator/=(const T &value)
SVecProxy & operator=(T rhs)
operator = for const (rvalue)
SVecProxy & operator-=(T rhs)
operator-= for const (rvalue)
SparseMatrix< T > identSparse(const unsigned int dim)
SparseVector< T > & operator*=(const T &value)
T dot_lim(const SparseVector< T > &SL, const SparseVector< T > &SR, const unsigned int kb, const unsigned int ke)
dot (SparseVector, SparseVector) but only use indexes k=kb, k<ke
static const double zeroTolerance
SVecProxy & operator=(const SVecProxy< T > &rhs)
operator = for non-const (lvalue)
T maxabs(const SparseMatrix< T > &SM)
Maximum absolute value - return 0 if empty.
unsigned int index
index in mySV for this data
SVecProxy(SparseVector< T > &SV, unsigned int index)
constructor
void resize(const unsigned int newlen)
resize - remove elements (truncate) and change nominal length len
SparseMatrix< T > transform(const SparseMatrix< T > &M, const SparseMatrix< T > &C)
void SrifMU(Matrix< T > &R, Vector< T > &Z, SparseMatrix< T > &A, const unsigned int M)
void assign(T rhs)
assign the SparseVector element, used by operator=,+=,etc
void truncate(const unsigned int n)
bool isEmpty() const
is this SV empty? NB may have to call zeroize() to get a yes.
T minabs(const SparseMatrix< T > &SM)
Minimum absolute value - return 0 if empty.
std::map< unsigned int, T > vecMap
map of index,value pairs; vecMap[index in real vector] = data element
SparseMatrix< T > transpose(const SparseMatrix< T > &M)
transpose
SVecProxy & operator*=(const SVecProxy< T > &rhs)
operator*= for non-const (lvalue)
SparseMatrix< T > operator*(const SparseMatrix< T > &L, const SparseMatrix< T > &R)
Matrix multiply: SparseMatrix = SparseMatrix * SparseMatrix.
std::string dump(const int p=3, bool dosci=false) const
Dump only non-zero values, with indexes (i,value)
SparseVector< T > & mySV
reference to the vector to which this data belongs
SVecProxy & operator+=(T rhs)
operator+= for const (rvalue)
SparseMatrix< T > inverseLT(const SparseMatrix< T > <, T *ptrSmall, T *ptrBig)
Compute inverse of lower-triangular SparseMatrix.
std::ostream & operator<<(std::ostream &s, const ObsEpoch &oe) noexcept
T min(const SparseMatrix< T > &SM)
Maximum element - return 0 if empty.
T cosVec(const SparseVector< T > &S1, const SparseVector< T > &S2)
#define GNSSTK_RETHROW(exc)
SparseVector< T > & operator+=(const SparseVector< T > &SV)
Vector< T > transformDiag(const SparseMatrix< T > &P, const Matrix< T > &C)
Compute diagonal of P*C*P^T, ie diagonal of transform of square Matrix C.
unsigned int size() const
size - of the real Vector, not the data array
SparseVector< T > & operator-=(const SparseVector< T > &SV)
SVecProxy & operator+=(const SVecProxy< T > &rhs)
operator+= for non-const (lvalue)
SparseMatrix< T > operator||(const SparseMatrix< T > &L, const Vector< T > &V)
Concatenation SparseMatrix || Vector TD the rest of them...
size_t size() const
STL size.
SparseMatrix< T > SparseHouseholder(const SparseMatrix< T > &A)
Householder transformation of a matrix.
SparseVector< T > operator-() const
T sum(const SparseVector< T > &SV) const
Sum of elements.
std::vector< unsigned int > getIndexes() const
bool isFilled(const unsigned int i) const
true if the element is non-zero
#define GNSSTK_THROW(exc)
SparseMatrix< T > operator-(const SparseMatrix< T > &L, const SparseMatrix< T > &R)
Matrix subtraction: SparseMatrix = SparseMatrix - SparseMatrix.
T norm(const SparseVector< T > &SV)
SparseMatrix< T > inverse(const SparseMatrix< T > &A)
SVecProxy & operator*=(T rhs)
operator*= for const (rvalue)
const SVecProxy< T > operator[](unsigned int in) const
operator[] for const, but SVecProxy does all the work
SVecProxy< T > operator[](unsigned int in)
operator[] for non-const, but SVecProxy does all the work
SparseVector()
empty constructor
void clear()
clear - set all data to 0 (i.e. remove all data); leave length alone
gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:41