G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsSparseVector.h
Go to the documentation of this file.
1
15# pragma once
16
17// Assumes that Eigen library has been already included
18
19
20namespace gismo
21{
22
33template<typename T, int _Options, typename _Index>
34class gsSparseVector : public gsEigen::SparseVector<T,_Options,_Index>
35{
36public:
37
38 typedef gsEigen::SparseVector<T,_Options,_Index> Base;
39
40 // Type pointing to a block of the sparse vector
41 typedef typename gsEigen::Block<Base> Block;
42
43 // Type pointing to a block view of the sparse vector
45
47 typedef memory::shared_ptr< gsSparseVector > Ptr;
48
49public:
50 gsSparseVector() : Base() { }
51 gsSparseVector(_Index rows) : Base(rows) { }
52
55 template<typename OtherDerived>
56 gsSparseVector(const gsEigen::EigenBase<OtherDerived>& other) : Base(other) { }
57
60 template<typename OtherDerived>
61 gsSparseVector(const gsEigen::MatrixBase<OtherDerived>& other) : Base(other) { }
62
65 template<typename OtherDerived>
66 gsSparseVector(const gsEigen::SparseMatrixBase<OtherDerived>& other) : Base(other) { }
67
70 template<typename OtherDerived>
71 gsSparseVector(const gsEigen::ReturnByValue<OtherDerived>& other) : Base(other) { }
72
73 ~gsSparseVector() { }
74
75#if !EIGEN_HAS_RVALUE_REFERENCES
76 // Using the assignment operators of Eigen
77 // Note: using Base::operator=; is ambiguous in MSVC
78#ifdef _MSC_VER
79 template <class EigenExpr>
80 gsSparseVector& operator= (const EigenExpr & other)
81 {
82 this->Base::operator=(other);
83 return *this;
84 }
85#else
86 using Base::operator=;
87#endif
88
89#else
90
91 // Avoid default keyword for MSVC<2013
92 // https://msdn.microsoft.com/en-us/library/hh567368.aspx
93 gsSparseVector(const gsSparseVector& other) : Base(other)
94 { Base::operator=(other); }
95
96 gsSparseVector& operator= (const gsSparseVector & other)
97 { Base::operator=(other); return *this; }
98
99 gsSparseVector(gsSparseVector&& other)
100 { operator=(std::forward<gsSparseVector>(other)); }
101
102 gsSparseVector & operator=(gsSparseVector&& other)
103 {
104 this->swap(other);
105 other.clear();
106 return *this;
107 }
108
109#endif
110
111 void clear()
112 {
113 this->resize(0);
114 this->data().squeeze();
115 }
116
117 inline T at (_Index i ) const { return this->coeff(i); }
118 inline T & at (_Index i ) { return this->coeffRef(i); }
119
120 inline T operator () (_Index i) const { return this->coeff(i); }
121 inline T & operator () (_Index i) { return this->coeffRef(i); }
122
123 inline T operator [] (_Index i) const { return this->coeff(i); }
124 inline T & operator [] (_Index i) { return this->coeffRef(i); }
125
128 { return new gsSparseVector(*this); }
129
130}; // class gsSparseVector
131
132
133
134
135} // namespace gismo
Represents a block-view of the given matrix.
Definition gsMatrixBlockView.h:32
Sparse vector class, based on gsEigen::SparseVector.
Definition gsSparseVector.h:35
gsSparseVector * clone() const
Clone function. Used to make a copy of the matrix.
Definition gsSparseVector.h:127
gsSparseVector(const gsEigen::ReturnByValue< OtherDerived > &other)
Definition gsSparseVector.h:71
memory::shared_ptr< gsSparseVector > Ptr
Shared pointer for gsSparseVector.
Definition gsSparseVector.h:47
gsSparseVector(const gsEigen::EigenBase< OtherDerived > &other)
Definition gsSparseVector.h:56
gsSparseVector(const gsEigen::SparseMatrixBase< OtherDerived > &other)
Definition gsSparseVector.h:66
gsSparseVector(const gsEigen::MatrixBase< OtherDerived > &other)
Definition gsSparseVector.h:61
The G+Smo namespace, containing all definitions for the library.