23 #ifndef SELDON_FILE_MATRIX_ARRAY_SPARSE_HXX
36 template <
class T,
class Prop,
class Storage,
class Allocator
37 =
typename SeldonDefaultAllocator<Storage, T>::allocator>
42 typedef typename Allocator::value_type value_type;
43 typedef typename Allocator::pointer pointer;
44 typedef typename Allocator::const_pointer const_pointer;
45 typedef typename Allocator::reference reference;
46 typedef typename Allocator::const_reference const_reference;
48 typedef T& access_type;
49 typedef T const_access_type;
82 #ifdef SELDON_WITH_MODIFIABLE_PARENTHESIS_OPERATOR
87 const T&
Get(
int i,
int j)
const;
89 const T&
Val(
int i,
int j)
const;
90 void Set(
int i,
int j,
const T& x);
91 void SetEntry(
int i,
int j,
const T& x);
93 const T&
Value(
int num_row,
int i)
const;
94 T&
Value(
int num_row,
int i);
95 int Index(
int num_row,
int i)
const;
96 int&
Index(
int num_row,
int i);
99 void SetData(
int,
int, T*,
int*);
113 void Fill(
const T0& x);
119 void Write(
string FileName)
const;
120 void Write(ostream& FileStream)
const;
121 void WriteText(
string FileName,
bool cplx =
false)
const;
122 void WriteText(ostream& FileStream,
bool cplx =
false)
const;
123 void Read(
string FileName);
124 void Read(istream& FileStream);
125 void ReadText(
string FileName,
bool cplx =
false);
126 void ReadText(istream& FileStream,
bool cplx =
false);
128 #ifdef SELDON_WITH_VIRTUAL
130 typedef typename ClassComplexType<T>::Treal Treal;
131 typedef typename ClassComplexType<T>::Tcplx Tcplx;
134 const typename ClassComplexType<T>::Treal& omega,
135 int nb_iter,
int stage_ssor)
const;
138 const typename ClassComplexType<T>::Treal& omega,
139 int nb_iter,
int stage_ssor)
const;
141 virtual void MltAddVector(
const Treal& alpha,
const Vector<Treal>& x,
144 virtual void MltAddVector(
const Tcplx& alpha,
const Vector<Tcplx>& x,
164 virtual bool IsSymmetric()
const;
171 template <
class T,
class Prop,
class Allocator>
177 typedef typename Allocator::value_type value_type;
178 typedef Prop property;
180 typedef Allocator allocator;
184 explicit Matrix(
int i,
int j);
187 void ClearColumn(
int i);
188 void ReallocateColumn(
int i,
int j);
189 void ResizeColumn(
int i,
int j);
190 void SwapColumn(
int i,
int i_);
191 void ReplaceIndexColumn(
int i,
IVect& new_index);
193 int GetColumnSize(
int i)
const;
194 void PrintColumn(
int i)
const;
195 void AssembleColumn(
int i);
197 void AddInteraction(
int i,
int j,
const T& val);
199 void AddInteractionRow(
int,
int,
int*, T*,
bool already_sorted =
false);
200 void AddInteractionColumn(
int,
int,
int*, T*,
bool already_sorted =
false);
202 void AddInteractionRow(
int i,
int nb,
const Vector<int>& col,
203 const Vector<T>& val,
bool already_sorted =
false);
205 void AddInteractionColumn(
int i,
int nb,
const Vector<int>& row,
207 bool already_sorted =
false);
213 template <
class T,
class Prop,
class Allocator>
219 typedef typename Allocator::value_type value_type;
220 typedef Prop property;
222 typedef Allocator allocator;
226 explicit Matrix(
int i,
int j);
229 void ClearRow(
int i);
230 void ReallocateRow(
int i,
int j);
231 void ResizeRow(
int i,
int j);
232 void SwapRow(
int i,
int i_);
233 void ReplaceIndexRow(
int i,
IVect& new_index);
235 int GetRowSize(
int i)
const;
236 void PrintRow(
int i)
const;
237 void AssembleRow(
int i);
239 void AddInteraction(
int i,
int j,
const T& val);
241 void AddInteractionRow(
int,
int,
int*, T*,
bool already_sorted =
false);
242 void AddInteractionColumn(
int,
int,
int*, T*,
bool already_sorted =
false);
244 void AddInteractionRow(
int i,
int nb,
const Vector<int>& col,
245 const Vector<T>& val,
bool already_sorted =
false);
247 void AddInteractionColumn(
int i,
int nb,
const Vector<int>& row,
248 const Vector<T>& val,
bool already_sorted =
false);
253 template <
class T,
class Prop,
class Allocator>
259 typedef typename Allocator::value_type value_type;
260 typedef Prop property;
262 typedef Allocator allocator;
266 explicit Matrix(
int i,
int j);
269 #ifdef SELDON_WITH_MODIFIABLE_PARENTHESIS_OPERATOR
270 T& operator() (
int i,
int j);
272 const T operator() (
int i,
int j)
const;
274 T& Get(
int i,
int j);
275 const T& Get(
int i,
int j)
const;
276 T& Val(
int i,
int j);
277 const T& Val(
int i,
int j)
const;
278 void Set(
int i,
int j,
const T& x);
279 void SetEntry(
int i,
int j,
const T& x);
282 void ClearColumn(
int i);
283 void ReallocateColumn(
int i,
int j);
284 void ResizeColumn(
int i,
int j);
285 void SwapColumn(
int i,
int i_);
286 void ReplaceIndexColumn(
int i,
IVect& new_index);
288 int GetColumnSize(
int i)
const;
289 void PrintColumn(
int i)
const;
290 void AssembleColumn(
int i);
292 void AddInteraction(
int i,
int j,
const T& val);
294 void AddInteractionRow(
int,
int,
int*, T*,
bool already_sorted =
false);
295 void AddInteractionColumn(
int,
int,
int*, T*,
296 bool already_sorted =
false);
298 void AddInteractionRow(
int i,
int nb,
const Vector<int>& col,
300 bool already_sorted =
false);
302 void AddInteractionColumn(
int i,
int nb,
const Vector<int>& row,
304 bool already_sorted =
false);
310 template <
class T,
class Prop,
class Allocator>
316 typedef typename Allocator::value_type value_type;
317 typedef Prop property;
319 typedef Allocator allocator;
323 explicit Matrix(
int i,
int j);
326 #ifdef SELDON_WITH_MODIFIABLE_PARENTHESIS_OPERATOR
327 T& operator() (
int i,
int j);
329 const T operator() (
int i,
int j)
const;
331 T& Get(
int i,
int j);
332 const T& Get(
int i,
int j)
const;
333 T& Val(
int i,
int j);
334 const T& Val(
int i,
int j)
const;
335 void Set(
int i,
int j,
const T& x);
336 void SetEntry(
int i,
int j,
const T& x);
339 void ClearRow(
int i);
340 void ReallocateRow(
int i,
int j);
341 void ResizeRow(
int i,
int j);
342 void SwapRow(
int i,
int i_);
343 void ReplaceIndexRow(
int i,
IVect& new_index);
345 int GetRowSize(
int i)
const;
346 void PrintRow(
int i)
const;
347 void AssembleRow(
int i);
349 void AddInteraction(
int i,
int j,
const T& val);
351 void AddInteractionRow(
int,
int,
int*, T*,
bool already_sorted =
false);
352 void AddInteractionColumn(
int,
int,
int*, T*,
bool sorted =
false);
354 void AddInteractionRow(
int i,
int nb,
const Vector<int>& col,
355 const Vector<T>& val,
bool already_sorted =
false);
357 void AddInteractionColumn(
int i,
int nb,
const Vector<int>& row,
358 const Vector<T>& val,
bool already_sorted =
false);
363 template <
class T,
class Prop,
class Allocator>
367 template <
class T,
class Prop,
class Allocator>
371 template <
class T,
class Prop,
class Allocator>
375 template <
class T,
class Prop,
class Allocator>
381 #define SELDON_FILE_MATRIX_ARRAY_SPARSE_HXX
int * GetIndex(int i) const
Returns (row or column) indices of non-zero entries in row.
void Read(string FileName)
Reads the matrix from a file.
void Print() const
Displays the matrix on the standard output.
void SetEntry(int i, int j, const T &x)
Sets an element of the matrix.
void Clear()
Clears the matrix.
T & Val(int i, int j)
Access method.
T & Get(int i, int j)
Access to element (i, j).
void SetIdentity()
Matrix is initialized to the identity matrix.
void SetData(int, int, Vector< T, VectSparse, Allocator > *)
Redefines the matrix.
~Matrix_ArraySparse()
Destructor.
size_t GetMemorySize() const
returns size of matrix in bytes
void RemoveSmallEntry(const T0 &epsilon)
Removes small coefficients from entries.
void Zero()
Non-zero entries are set to 0 (but not removed).
Vector< Vector< T, VectSparse, Allocator >, VectFull, NewAlloc< Vector< T, VectSparse, Allocator > > > val_
rows or columns
const T operator()(int i, int j) const
Access operator.
const T & Value(int num_row, int i) const
Returns j-th non-zero value of row/column i.
void WriteText(string FileName, bool cplx=false) const
Writes the matrix in a file.
void Fill()
Non-zero entries are filled with values 0, 1, 2, 3 ...
Row-major sparse-matrix class.
long GetDataSize() const
Returns the number of elements stored in memory.
void Resize(int i, int j)
Reallocates additional memory to resize the matrix.
long GetNonZeros() const
Returns the number of non-zero entries.
int Index(int num_row, int i) const
Returns column/row number of j-th non-zero value of row/column i.
Column-major symmetric sparse-matrix class.
Matrix_ArraySparse< T, Prop, Storage, Allocator > & operator=(const T0 &x)
Non-zero entries are set to a given value x.
void Set(int i, int j, const T &x)
Sets an element of the matrix.
void FillRand()
Non-zero entries take a random value.
void ReadText(string FileName, bool cplx=false)
Reads the matrix from a file.
Sparse Array-matrix class.
void Reallocate(int i, int j)
Reallocates memory to resize the matrix.
Vector< T, VectSparse, Allocator > * GetData() const
Returns values of non-zero entries.
Matrix_ArraySparse()
Default constructor.
Row-major symmetric sparse-matrix class.
ostream & operator<<(ostream &out, const Array< T, N, Allocator > &A)
operator<< overloaded for a 3D array.
void Write(string FileName) const
Writes the matrix in a file.
Column-major sparse-matrix class.
void Nullify()
Clears the matrix without releasing memory.
Abstract base class for all matrices.
void Assemble()
Assembles the matrix.