Ravelin
SparseVectorN.h
1 #ifndef SPARSEVECTORN
2 #error This class is not to be included by the user directly. Use SparseVectorNf.h or SparseVectorNd.h instead.
3 #endif
4 
7 {
8  public:
9  SPARSEVECTORN() { _size = _nelm = 0; }
10  SPARSEVECTORN(unsigned n, const std::map<unsigned, REAL>& values);
11  SPARSEVECTORN(unsigned n, unsigned nnz, boost::shared_array<unsigned> indices, boost::shared_array<REAL> data);
12  SPARSEVECTORN(const VECTORN& v);
13  REAL dot(const VECTORN& x) const;
14  REAL square() const;
15  unsigned size() const { return _size; }
16  unsigned num_elements() const { return _nelm; }
17  unsigned* get_indices() { return _indices.get(); }
18  REAL* get_data() { return _data.get(); }
19  const unsigned* get_indices() const { return _indices.get(); }
20  const REAL* get_data() const { return _data.get(); }
21  VECTORN& to_dense(VECTORN& result) const;
23  SPARSEVECTORN& operator*=(REAL scalar);
24  SPARSEVECTORN& mult(REAL scalar, SPARSEVECTORN& result) const;
25 
26  protected:
27  boost::shared_array<unsigned> _indices; // indices of the data
28  boost::shared_array<REAL> _data; //
29  unsigned _size;
30  unsigned _nelm;
31 }; // end class
32 
33 std::ostream& operator<<(std::ostream& out, const SPARSEVECTORN& s);
34 
SPARSEVECTORN & mult(REAL scalar, SPARSEVECTORN &result) const
Multiplies this sparse vector by a scalar and returns the result in a new vector. ...
Definition: SparseVectorN.cpp:110
VECTORN & to_dense(VECTORN &result) const
Gets the dense version of the vector.
Definition: SparseVectorN.cpp:92
SPARSEVECTORN & negate()
Negates this sparse vector in place.
Definition: SparseVectorN.cpp:126
REAL dot(const VECTORN &x) const
Computes the dot product between a sparse vector and a dense vector.
Definition: SparseVectorN.cpp:76
A sparse vector represented in 'CSR' format.
Definition: SparseVectorN.h:6
A generic N-dimensional floating point vector.
Definition: VectorN.h:16
REAL square() const
Computes the dot product between a sparse vector and itself.
Definition: SparseVectorN.cpp:65
SPARSEVECTORN & operator*=(REAL scalar)
Multiplies this sparse vector by a scalar (in place)
Definition: SparseVectorN.cpp:102