1 #ifndef MATH_SPARSE_VECTOR_TEMPLATE_H 2 #define MATH_SPARSE_VECTOR_TEMPLATE_H 5 #include "VectorTemplate.h" 6 #include <KrisLibrary/structs/SparseArray.h> 19 typedef typename BaseT::iterator iterator;
20 typedef typename BaseT::const_iterator const_iterator;
27 void print(std::ostream&)
const;
31 T operator() (
int i)
const {
return get(i); }
32 T operator[] (
int i)
const {
return get(i); }
34 inline void set(
int i,
const T& t) { BaseT::insert(i,t); }
36 inline void setZero() { BaseT::entries.clear(); }
37 inline void set(
const BaseT& v) { BaseT::operator = (v); }
38 void set(
const VectorT&,T zeroTol=Zero);
39 void set(
const T*,
int n,T zeroTol=Zero);
41 void get(VectorT&)
const;
42 void inplaceNegative();
46 void copy(
const MyT&);
47 void copySubVector(
int i,
const MyT&);
48 void copySubVector(
int i,
const VectorT&,T zeroTol=0);
50 void add(
const MyT&,
const MyT&);
51 void sub(
const MyT&,
const MyT&);
52 void mul(
const MyT&, T s);
53 void div(
const MyT&, T s);
55 T dot(
const VectorT&)
const;
56 T dot(
const MyT&)
const;
58 T normSquared()
const;
59 T distance(
const MyT&)
const;
60 T distanceSquared(
const MyT&)
const;
62 inline bool isEmpty()
const {
return BaseT::empty(); }
63 inline bool hasDims(
size_t _n)
const {
return BaseT::n==_n; }
65 T minElement(
int* index=NULL)
const;
66 T maxElement(
int* index=NULL)
const;
67 T minAbsElement(
int* index=NULL)
const;
68 T maxAbsElement(
int* index=NULL)
const;
82 void init(
int n,
int num_entries);
83 void resize(
int n,
int num_entries);
84 void makeSimilar(
const MyT&);
88 bool Write(
File&)
const;
89 void print(std::ostream&)
const;
91 const MyT& operator =(
const MyT&);
92 T operator() (
int i)
const;
96 void set(
const VectorT&,T zeroTol=Zero);
97 void set(
const T*,
int n,T zeroTol=Zero);
99 void get(VectorT&)
const;
100 void inplaceNegative();
101 void inplaceMul(T s);
102 void inplaceDiv(T s);
104 void add(
const MyT&,
const MyT&);
105 void sub(
const MyT&,
const MyT&);
106 void mul(
const MyT&, T s);
107 void div(
const MyT&, T s);
109 T dot(
const VectorT&)
const;
110 T dot(
const MyT&)
const;
112 T normSquared()
const;
113 T distance(
const MyT&)
const;
114 T distanceSquared(
const MyT&)
const;
116 bool isValid()
const;
117 inline bool isEmpty()
const {
return n == 0; }
118 inline bool hasDims(
int _n)
const {
return n==_n; }
119 inline bool isValidIndex(
int i)
const {
return 0<=i&&i<n; }
121 T minElement(
int* index=NULL)
const;
122 T maxElement(
int* index=NULL)
const;
123 T minAbsElement(
int* index=NULL)
const;
124 T maxAbsElement(
int* index=NULL)
const;
142 :vec(_vec),index(_index)
145 :vec(rhs.vec),index(rhs.index)
149 return vec->get(index);
164 for(
typename SparseVectorTemplate<T>::const_iterator i=x.begin();i!=x.end();i++)
165 if(!
IsFinite(i->second))
return false;
173 for(
typename SparseVectorTemplate<T>::const_iterator i=x.begin();i!=x.end();i++)
174 if(
IsNaN(i->second))
return false;
182 for(
typename SparseVectorTemplate<T>::const_iterator i=x.begin();i!=x.end();i++)
A sparse 1D array class.
Definition: SparseArray.h:13
int IsInf(double x)
Returns +1 if x is +inf, -1 if x is -inf, and 0 otherwise.
Definition: infnan.cpp:40
int HasInf(const MatrixTemplate< T > &A)
returns nonzero if any element of A is infinite
Definition: MatrixTemplate.h:262
Definition: SparseVectorTemplate.h:72
Definition: SparseVectorTemplate.h:14
Complex number class (x + iy).
Definition: complex.h:17
bool HasNaN(const MatrixTemplate< T > &A)
returns true if any element of A is NaN
Definition: MatrixTemplate.h:252
int IsNaN(double x)
Returns nonzero if x is not-a-number (NaN)
Definition: infnan.cpp:9
Definition: SparseVectorTemplate.h:11
The logging system used in KrisLibrary.
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12
A vector over the field T.
Definition: function.h:9
A cross-platform class for reading/writing binary data.
Definition: File.h:47
int IsFinite(double x)
Returns nonzero unless x is infinite or a NaN.
Definition: infnan.cpp:23