23 #ifndef SELDON_FILE_MATRIX_SPARSE_HXX
25 #include "../share/Common.hxx"
26 #include "../share/Properties.hxx"
27 #include "../share/Storage.hxx"
28 #include "../share/Errors.hxx"
29 #include "../share/Allocator.hxx"
43 template <
class T,
class Prop,
class Storage,
class Allocator
44 =
typename SeldonDefaultAllocator<Storage, T>::allocator>
49 typedef typename Allocator::value_type value_type;
50 typedef typename Allocator::pointer pointer;
51 typedef typename Allocator::const_pointer const_pointer;
52 typedef typename Allocator::reference reference;
53 typedef typename Allocator::const_reference const_reference;
54 typedef typename SeldonDefaultAllocator<VectFull, int>::allocator AllocatorInt;
55 typedef typename SeldonDefaultAllocator<VectFull, long>::allocator AllocatorLong;
56 typedef value_type entry_type;
57 typedef value_type access_type;
58 typedef value_type const_access_type;
75 template <
class Storage0,
class Allocator0,
76 class Storage1,
class Allocator1,
77 class Storage2,
class Allocator2>
88 template <
class Storage0,
class Allocator0,
89 class Storage1,
class Allocator1,
90 class Storage2,
class Allocator2>
95 void SetData(
int i,
int j,
long nz, pointer values,
long* ptr,
int* ind);
100 void Resize(
int i,
int j,
long nz);
114 const value_type
operator() (
int i,
int j)
const;
115 value_type&
Val(
int i,
int j);
116 value_type&
Get(
int i,
int j);
118 const value_type&
Val(
int i,
int j)
const;
119 const value_type&
Get(
int i,
int j)
const;
124 const Vector<T>& val,
bool sorted =
false);
126 void Set(
int i,
int j,
const T& x);
127 void SetEntry(
int i,
int j,
const T& x);
139 void Fill(
const T0& x);
142 void FillRand(
long Nelement,
const T& x);
145 void Write(
string FileName)
const;
146 void Write(ostream& FileStream)
const;
147 void WriteText(
string FileName,
bool cplx =
false)
const;
148 void WriteText(ostream& FileStream,
bool cplx =
false)
const;
149 void Read(
string FileName);
150 void Read(istream& FileStream);
151 void ReadText(
string FileName,
bool cplx =
false);
152 void ReadText(istream& FileStream,
bool cplx =
false);
154 #ifdef SELDON_WITH_VIRTUAL
155 typedef typename ClassComplexType<T>::Treal Treal;
156 typedef typename ClassComplexType<T>::Tcplx Tcplx;
159 const typename ClassComplexType<T>::Treal& omega,
160 int nb_iter,
int stage_ssor)
const;
163 const typename ClassComplexType<T>::Treal& omega,
164 int nb_iter,
int stage_ssor)
const;
166 virtual void MltAddVector(
const Treal& alpha,
const Vector<Treal>& x,
169 virtual void MltAddVector(
const Tcplx& alpha,
const Vector<Tcplx>& x,
189 virtual bool IsSymmetric()
const;
196 template <
class T,
class Prop,
class Allocator>
202 typedef typename Allocator::value_type value_type;
203 typedef Prop property;
205 typedef Allocator allocator;
209 explicit Matrix(
int i,
int j);
210 explicit Matrix(
int i,
int j,
long nz);
211 template <
class Storage0,
class Allocator0,
212 class Storage1,
class Allocator1,
213 class Storage2,
class Allocator2>
222 template <
class T,
class Prop,
class Allocator>
228 typedef typename Allocator::value_type value_type;
229 typedef Prop property;
231 typedef Allocator allocator;
235 explicit Matrix(
int i,
int j);
236 explicit Matrix(
int i,
int j,
long nz);
237 template <
class Storage0,
class Allocator0,
238 class Storage1,
class Allocator1,
239 class Storage2,
class Allocator2>
250 #define SELDON_FILE_MATRIX_SPARSE_HXX
Matrix_Sparse< T, Prop, Storage, Allocator > & operator=(const Matrix_Sparse< T, Prop, Storage, Allocator > &A)
Duplicates a matrix (assignment operator).
void Fill()
Fills the non-zero entries with 0, 1, 2, ...
void Read(string FileName)
Reads the matrix from a file.
void Write(string FileName) const
Writes the matrix in a file.
Base class for all matrices.
void FillPtrInt(Vector< int > &) const
Fills vector ptr with integers instead of longs.
Matrix_Sparse()
Default constructor.
int GetPtrSize() const
Returns the length of the array of start indices.
long GetDataSize() const
Returns the number of elements stored in memory.
long GetIndSize() const
Returns the length of the array of (column or row) indices.
~Matrix_Sparse()
Destructor.
void SetIdentity()
Sets the matrix to identity.
value_type & Val(int i, int j)
Access method.
void Copy(const Matrix_Sparse< T, Prop, Storage, Allocator > &A)
Copies a matrix.
void SetData(int i, int j, Vector< T, Storage0, Allocator0 > &values, Vector< long, Storage1, Allocator1 > &ptr, Vector< int, Storage2, Allocator2 > &ind)
Redefines the matrix.
long GetNonZeros() const
Returns the number of non-zero elements.
long * GetPtr() const
Returns (row or column) start indices.
void Zero()
Resets all non-zero entries to 0-value.
void Print() const
Displays the matrix on the standard output.
void FillRand()
Fills the non-zero entries randomly.
void ReadText(string FileName, bool cplx=false)
Reads the matrix from a file.
void Nullify()
Clears the matrix without releasing memory.
void Reallocate(int i, int j)
Initialization of an empty sparse matrix with i rows and j columns.
void AddInteraction(int i, int j, const T &val)
Add a value to a non-zero entry.
void SetEntry(int i, int j, const T &x)
Sets an element (i, j) to a value.
void AddInteractionRow(int i, int nb, const Vector< int > &col, const Vector< T > &val, bool sorted=false)
Adds values to several non-zero entries on a given row.
void Clear()
Clears the matrix.
void WriteText(string FileName, bool cplx=false) const
Writes the matrix in a file.
void Set(int i, int j, const T &x)
Sets an element (i, j) to a value.
size_t GetMemorySize() const
returns size of A in bytes used to store the matrix
const value_type operator()(int i, int j) const
Access operator.
int * GetInd() const
Returns (row or column) indices of non-zero entries.
void Resize(int i, int j)
Reallocates memory to resize the matrix and keeps previous entries.
value_type & Get(int i, int j)
Access method.