Sparse Complex Matrices
|
Sparse complex matrices are structures for which real part and imaginary part are stored independently. The aim is to reduce the required storage when the imaginary part contains much less non-zero entries than the real part. These matrices are not available by default, the file "SeldonComplexMatrix.hxx" (or "SeldonLib.hxx") has to be included in order to use those matrices. Unitary tests are present in the file sparse_complex_matrices.html
These matrices are available only after SeldonComplexMatrix.hxx
has been included (or SeldonLib.hxx).
Matrix<T, Prop, ArrayRowComplexSparse>
Matrix<T, Prop, ArrayColComplexSparse>
Matrix<T, Prop, ArrayRowSymComplexSparse>
Matrix<T, Prop, ArrayColSymComplexSparse>
#include "SeldonComplexMatrix.hxx" // sparse complex matrix of doubles Matrix<complex<double>, General, ArrayRowComplexSparse> A; // sparse complex symmetric matrix Matrix<complex<float>, Symmetric, ArrayRowSymComplexSparse> B; // changing size of the matrix A.Reallocate(m, n); // a_13 = a_13 + (1.5,0.7) A.AddInteraction(1, 3, complex<double>(1.5, 0.7));
Matrix constructors | |
Matrix operators | |
GetM | returns the number of rows in the matrix |
GetN | returns the number of columns in the matrix |
GetDataSize | returns the number of elements effectively stored |
GetMemorySize | returns the memory used to store the matrix |
GetRealDataSize | returns the number of elements effectively stored for the real part |
GetImagDataSize | returns the number of elements effectively stored for the imaginary part |
GetNonZeros | returns the number of elements effectively stored |
GetRealNonZeros | returns the number of elements effectively stored for the real part |
GetImagNonZeros | returns the number of elements effectively stored for the imaginary part |
GetRealData | returns a pointer to the array containing the values of the real part |
GetImagData | returns a pointer to the array containing the values of the imaginary part |
GetRealInd | returns a pointer to the array containing the column indexes of the real part |
GetImagInd | returns a pointer to the array containing the column indexes of the imaginary part |
ValReal | returns a reference to real part of A(i, j) |
ValImag | returns a reference to imaginary part of A(i, j) |
GetReal | returns a reference to real part of A(i, j) |
GetImag | returns a reference to imaginary part of A(i, j) |
Set | sets real and imaginary part of A(i, j) |
NullifyReal | removes real part of the matrix without releasing memory |
NullifyImag | removes imaginary part of the matrix without releasing memory |
SetRealData | sets real part of the matrix |
SetImagData | sets imaginary part of the matrix |
Clear | removes all elements of the matrix |
Reallocate | changes the size of matrix (does not keep previous elements) |
Resize | changes the size of matrix (keeps previous elements) |
ValueReal | direct access to a real value |
ValueImag | direct access to an imaginary value |
IndexReal | direct access to a column number of real part |
IndexImag | direct access to a column number of imaginary part |
RemoveSmallEntry | drops small values of the matrix |
Zero | sets all elements to zero |
SetIdentity | sets matrix to identity matrix |
Fill | sets all elements to a given value |
FillRand | fills randomly the matrix |
ReallocateRealRow / ReallocateRealColumn | changes the size of a row of the real part |
ReallocateImagRow / ReallocateImagColumn | changes the size of a row of the imaginary part |
ResizeRealRow / ResizeRealColumn | changes the size of a row of real part and keeps previous values |
ResizeImagRow / ResizeImagColumn | changes the size of a row of imaginary part and keeps previous values |
ClearRealRow / ClearRealColumn | clears a row of real part |
ClearImagRow / ClearImagColumn | clears a row of imaginary part |
SwapRealRow / SwapRealColumn | exchanges two rows of real part |
SwapImagRow / SwapImagColumn | exchanges two rows of imaginary part |
ReplaceRealIndexRow / ReplaceRealIndexColumn | changes column numbers of real part |
ReplaceImagIndexRow / ReplaceImagIndexColumn | changes column numbers of imaginary part |
GetRealRowSize / GetRealColumnSize | returns the number of elements in the row of real part |
GetImagRowSize / GetImagColumnSize | returns the number of elements in the row of imaginary part |
PrintRealRow / PrintRealColumn | prints a row of real part |
PrintImagRow / PrintImagColumn | prints a row of imaginary part |
AssembleRealRow / AssembleRealColumn | assembles a row of real part |
AssembleImagRow / AssembleImagColumn | assembles a row of imaginary part |
AddInteraction | adds/inserts an element in the matrix |
AddInteractionRow | adds/inserts an element in a matrix row |
AddInteractionColumn | adds/inserts elements in a matrix column |
displays the matrix | |
Write | writes the vector in binary format |
Read | reads the vector in binary format |
WriteText | writes the vector in text format |
ReadText | reads the vector in text format |
As for sparse matrices, Harwell-Boeing format can also be used :
Matrix<T, Prop, RowComplexSparse>
Matrix<T, Prop, ColComplexSparse>
Matrix<T, Prop, RowSymComplexSparse>
Matrix<T, Prop, ColSymComplexSparse>
#include "SeldonComplexMatrix.hxx" // complex sparse matrix of doubles Matrix<complex<double>, General, RowComplexSparse> A; // sparse symmetric matrix Matrix<complex<float>, Symmetric, RowSymComplexSparse> B;
Matrix constructors | |
Matrix operators | |
GetM | returns the number of rows in the matrix |
GetN | returns the number of columns in the matrix |
GetRealDataSize | returns the number of elements effectively stored in the real part |
GetImagDataSize | returns the number of elements effectively stored in the imaginary part |
GetDataSize | returns the number of elements effectively stored |
GetMemorySize | returns the memory used to store the matrix |
GetRealNonZeros | returns the number of elements effectively stored in the real part |
GetImagNonZeros | returns the number of elements effectively stored in the imaginary part |
GetNonZeros | returns the number of elements effectively stored |
GetRealData | returns a pointer to the array containing the values of real part |
GetImagData | returns a pointer to the array containing the values of imaginary part |
GetRealInd | returns a pointer to the array containing column numbers of real part |
GetImagInd | returns a pointer to the array containing column numbers of imaginary part |
GetRealPtr | returns a pointer to the array containing row numbers of real part |
GetImagPtr | returns a pointer to the array containing row numbers of imaginary part |
GetRealPtrSize | returns size of array Ptr of real part |
GetImagPtrSize | returns size of array Ptr of imaginary part |
GetRealIndSize | returns size of array Ind of real part |
GetImagIndSize | returns size of array Ind of imaginary part |
Clear | removes all elements of the matrix |
SetData | sets the pointer to the array containing the values |
Nullify | clears the matrix without releasing memory |
Reallocate | modifies the size of the matrix |
Resize | modifies the size of the matrix |
ValReal | direct access to real part of A(i, j) |
ValImag | direct access to imaginary part of A(i, j) |
GetReal | access to real part of A(i, j) |
GetImag | access to imaginary part of A(i, j) |
Val | modification of A(i, j) |
SetIdentity | initializes the sparse matrix to identity |
Fill | fills non-zero entries to a given value |
Fill | fills non-zero entries to random values |
displays the matrix | |
Write | writes the vector in binary format |
Read | reads the vector in binary format |
WriteText | writes the vector in text format |
ReadText | reads the vector in text format |
Matrix(); Matrix(int m, int n);
// default constructor -> empty matrix Matrix<complex<double>, General, ArrayRowComplexSparse> V; cout << "Number of elements "<< V.GetDataSize() << endl; // should return 0 // then you can use Reallocate to set the number of rows and columns V.Reallocate(3, 2); // the last command doesn't create any non-zero element // you can create one with AddInteraction for example V.AddInteraction(0, 1, complex<double>(1.5, 0.0) ); // we construct symmetric matrix with 4 rows Matrix<complex<double>, Symmetric, ArrayRowSymComplexSparse> W(4, 4);
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix(); Matrix(int m, int n); Matrix(int m, int n, int real_nnz, int imag_nnz); Matrix(m, n, real_values, real_ptr, real_ind, imag_values, imag_ptr, imag_ind);
// default constructor -> empty matrix Matrix<complex<double>, General, RowComplexSparse> V; cout << "Number of elements "<< V.GetDataSize() << endl; // should return 0 // with this constructor, an empty matrix with 4 rows and columns is constructed Matrix<complex<double>, Symmetric, RowSymComplexSparse> W(4, 4); // Here a matrix with 3 rows, 4 columns and 10 non-zero entries // for the real part, and 2 non-zero entries for imaginary part // however non-zero entries are not initialized, you can // set them by modifying arrays returned by GetRealPtr(), GetRealInd(), GetRealData() Matrix<complex<double>, General, RowComplexSparse> A(3, 4, 10, 2); // in the last constructor you provide int m = 5; // number of rows int n = 6; // number of columns int real_nnz = 12; // number of non-zero entries for real part int imag_nnz = 4; // number of non-zero entries for imaginary part Vector<double> real_values(real_nnz), imag_values(imag_nnz); // values real_values.FillRand(); // you have to initialize values imag_values.FillRand(); // you have to initialize values Vector<int> real_col(real_nnz), imag_col(imag_nnz); // for each value column number // for each row, column numbers are sorted // first row real_col(0) = 0; real_col(1) = 2; real_col(2) = 4; // second row real_col(3) = 1; imag_col(0) = 2; // third row real_col(4) = 0; real_col(5) = 1; real_col(6) = 3; imag_col(1) = 0; imag_col(2) = 3; // fourth row real_col(7) = 4; real_col(8) = 5; // last row real_col(9) = 2; real_col(10) = 3; real_col(11) = 5; imag_col(3) = 4; // for each row, index of first value Vector<int> real_ptr(m+1), imag_ptr(m+1); real_ptr(0) = 0; real_ptr(1) = 3; real_ptr(2) = 4; real_ptr(3) = 7; real_ptr(4) = 9; real_ptr(5) = 12; imag_ptr(0) = 0; imag_ptr(1) = 0; imag_ptr(2) = 1; imag_ptr(3) = 3; imag_ptr(4) = 3; imag_ptr(5) = 4; // values on the row are to be seeked between xx_ptr(i) and xx_ptr(i+1) // Now the constructor: Matrix<complex<double>, General, RowComplexSparse> M(m, n, real_values, real_ptr, real_col, imag_values, imag_ptr, imag_col); // Note that 'values', 'ptr' and 'columns' are nullified (that is, emptied): // the arrays to which they pointed have been transferred to M.
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
const T& operator (int i, int j) const; Matrix& operator =(const T0& alpha)
The operator () cannot be used to insert or modify elements of matrix. Use rather the methods GetReal or ValReal for the real part, and corresponding methods for the imaginary part.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(3, 3); // use of operator () to know the value of A(i, j); cout << V(2, 0) << endl; // set all elements to a given value V = 1;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
int GetM() const
This method returns the numbers of rows of the matrix.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // GetM() should return 4 cout << "Number of rows of V : " << V.GetM() << endl;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
int GetN() const
This method returns the numbers of columns of the matrix.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // GetN() should return 3 cout << "Number of columns of V : " << V.GetN() << endl;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
int GetDataSize() const int GetNonZeros() const
This method returns the elements effectively stored in the matrix.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // GetDataSize() should return 0 cout << "Number of elements in V : " << V.GetDataSize() << endl; // then we add some values V.AddInteraction(0, 2, complex<double>(1.0, 0)); V.AddInteraction(1, 0, complex<double>(0, 0.3)); V.AddInteraction(3, 1, complex<double>(2.3, 0)); V.AddInteraction(2, 0, complex<double>(-0.5, 0.8)); V.AddInteraction(2, 2, complex<double>(1.2, 0)); // GetDataSize should return 6 (four element in real part, two in imaginary part) cout << "Number of elements in V : " << V.GetDataSize() << endl;
GetRealDataSize
GetImagDataSize
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
size_t GetMemorySize() const
This method returns the memory used to store the matrix in bytes.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // GetDataSize() should return 0 cout << "Number of elements in V : " << V.GetDataSize() << endl; // then we add some values V.AddInteraction(0, 2, complex<double>(1.0, 0)); V.AddInteraction(1, 0, complex<double>(0, 0.3)); V.AddInteraction(3, 1, complex<double>(2.3, 0)); V.AddInteraction(2, 0, complex<double>(-0.5, 0.8)); V.AddInteraction(2, 2, complex<double>(1.2, 0)); // GetMemorySize returns the memory used to store V (in bytes) cout << "Memory used to store V : " << V.GetMemorySize() << endl;
GetRealDataSize
GetImagDataSize
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
int GetRealDataSize() const int GetRealNonZeros() const
This method returns the elements effectively stored in the real part of the matrix.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // GetRealDataSize() should return 0 cout << "Number of elements in V : " << V.GetRealDataSize() << endl; // then we add some values V.AddInteraction(0, 2, complex<double>(1.0, 0)); V.AddInteraction(1, 0, complex<double>(0, 0.3)); V.AddInteraction(3, 1, complex<double>(2.3, 0)); V.AddInteraction(2, 0, complex<double>(-0.5, 0.8)); V.AddInteraction(2, 2, complex<double>(1.2, 0)); // GetRealDataSize should return 4 cout << "Number of elements in V : " << V.GetRealDataSize() << endl;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
int GetImagDataSize() const int GetImagNonZeros() const
This method returns the elements effectively stored in the imaginary part of the matrix.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // GetImagDataSize() should return 0 cout << "Number of elements in V : " << V.GetImagDataSize() << endl; // then we add some values V.AddInteraction(0, 2, complex<double>(1.0, 0)); V.AddInteraction(1, 0, complex<double>(0, 0.3)); V.AddInteraction(3, 1, complex<double>(2.3, 0)); V.AddInteraction(2, 0, complex<double>(-0.5, 0.8)); V.AddInteraction(2, 2, complex<double>(1.2, 0)); // GetImagDataSize should return 2 cout << "Number of elements in V : " << V.GetImagDataSize() << endl;
GetRealDataSize
GetImagDataSize
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
T* GetRealData(int i) const Vector<T, VectSparse>* GetRealData() const
This method returns a pointer to the values stored in the row i, or if no argument is provided, it returns the pointer to the vector of sparse vectors (each sparse vector is a row of the real part of the matrix).
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with real values of second row : double* data = A.GetRealData(1); // size of this array int size_row = A.GetRealRowSize(1); // for example we sum real parts double sum = 0; for (int i = 0; i < size_row; i++) sum += data[i]; // if you want a pointer to all the real part Vector<double, VectSparse>* ptr = A.GetRealData(); // size of this array is the number of rows for (int i = 0; i < A.GetM(); i++) cout << "Number of elements in real part of row " << i << " : " << ptr[i].GetM() << endl;
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
T* GetImagData(int i) const Vector<T, VectSparse>* GetImagData() const
This method returns a pointer to the values stored in the row i, or if no argument is provided, it returns the pointer to the vector of sparse vectors (each sparse vector is a row of the imaginary part of the matrix).
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with imaginary values of third row : double* data = A.GetImagData(2); // size of this array int size_row = A.GetImagRowSize(2); // for example we sum imaginary parts double sum = 0; for (int i = 0; i < size_row; i++) sum += data[i]; // if you want a pointer to all the imaginary part Vector<double, VectSparse>* ptr = A.GetImagData(); // size of this array is the number of rows for (int i = 0; i < A.GetM(); i++) cout << "Number of elements in imaginary part of row " << i << " : " << ptr[i].GetM() << endl;
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
T* GetRealData() const
This method returns a pointer to the values stored in the matrix (only real part).
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with real values of the matrix : double* data = A.GetRealData(); // size of this array int size_data = A.GetRealDataSize(1); // for example we sum all the non-zero entries double sum = 0; for (int i = 0; i < size_data; i++) sum += data[i];
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
T* GetImagData() const
This method returns a pointer to the values stored in the matrix (only imaginary part).
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with imaginary values of the matrix : double* data = A.GetImagData(); // size of this array int size_data = A.GetImagDataSize(1); // for example we sum all the non-zero entries double sum = 0; for (int i = 0; i < size_data; i++) sum += data[i];
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
int* GetRealInd() const
This method returns a pointer to the column numbers of the matrix (only real part).
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with columns numbers of the real part of matrix : int* ind = A.GetRealInd(); // we retrieve values and offsets as well double* data = A.GetRealInd(); int* ptr = A.GetRealPtr(); // for example we sum all the non-zero entries not on the diagonal double sum = 0; for (int i = 0; i < A.GetM(); i++) for (int j = ptr[i]; j < ptr[i+1]; j++) if (ind[j] != i) sum += data[i];
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
int* GetImagInd() const
This method returns a pointer to the column numbers of the matrix (only imaginary part).
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with columns numbers of the imaginary part of matrix : int* ind = A.GetImagInd(); // we retrieve values and offsets as well double* data = A.GetImagInd(); int* ptr = A.GetImagPtr(); // for example we sum all the non-zero entries not on the diagonal double sum = 0; for (int i = 0; i < A.GetM(); i++) for (int j = ptr[i]; j < ptr[i+1]; j++) if (ind[j] != i) sum += data[i];
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
int* GetRealPtr() const
This method returns a pointer to the array containing starting indices of rows (only real part).
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with columns numbers of the real part of matrix : int* ind = A.GetRealInd(); // we retrieve values and offsets as well double* data = A.GetRealInd(); int* ptr = A.GetRealPtr(); // for example we sum all the non-zero entries not on the diagonal double sum = 0; for (int i = 0; i < A.GetM(); i++) for (int j = ptr[i]; j < ptr[i+1]; j++) if (ind[j] != i) sum += data[i];
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
int* GetImagPtr() const
This method returns a pointer to the array containing starting indices of rows (only imaginary part).
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with columns numbers of the imaginary part of matrix : int* ind = A.GetImagInd(); // we retrieve values and offsets as well double* data = A.GetImagInd(); int* ptr = A.GetImagPtr(); // for example we sum all the non-zero entries not on the diagonal double sum = 0; for (int i = 0; i < A.GetM(); i++) for (int j = ptr[i]; j < ptr[i+1]; j++) if (ind[j] != i) sum += data[i];
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void SetData(int m, int n, int real_nz, T* real_data, int* real_ptr, int* real_ind, T* imag_data, int* imag_ptr, int* imag_ind); void SetData(int m, int n, Vector<T> real_data, Vector<int> real_ptr, Vector<int> real_ind, Vector<T> imag_data, Vector<int> imag_ptr, Vector<int> imag_ind)
This method initializes directly the matrix by providing the arrays Ptr, Ind and Data.
int m = 5; // number of rows int n = 6; // number of columns int real_nnz = 12; // number of non-zero entries for real part int imag_nnz = 4; // number of non-zero entries for imaginary part Vector<double> real_values(real_nnz), imag_values(imag_nnz); // values real_values.FillRand(); // you have to initialize values imag_values.FillRand(); // you have to initialize values Vector<int> real_col(real_nnz), imag_col(imag_nnz); // for each value column number // for each row, column numbers are sorted // first row real_col(0) = 0; real_col(1) = 2; real_col(2) = 4; // second row real_col(3) = 1; imag_col(0) = 2; // third row real_col(4) = 0; real_col(5) = 1; real_col(6) = 3; imag_col(1) = 0; imag_col(2) = 3; // fourth row real_col(7) = 4; real_col(8) = 5; // last row real_col(9) = 2; real_col(10) = 3; real_col(11) = 5; imag_col(3) = 4; // for each row, index of first value Vector<int> real_ptr(m+1), imag_ptr(m+1); real_ptr(0) = 0; real_ptr(1) = 3; real_ptr(2) = 4; real_ptr(3) = 7; real_ptr(4) = 9; real_ptr(5) = 12; imag_ptr(0) = 0; imag_ptr(1) = 0; imag_ptr(2) = 1; imag_ptr(3) = 3; imag_ptr(4) = 3; imag_ptr(5) = 4; // values on the row are to be seeked between xx_ptr(i) and xx_ptr(i+1) Matrix<complex<double>, General, RowComplexSparse> A; // Initialisation of A A.SetData(m, n, real_values, real_ptr, real_col, imag_values, imag_ptr, imag_col); // Note that 'values', 'ptr' and 'columns' are nullified (that is, emptied): // the arrays to which they pointed have been transferred to M.
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void Nullify()
This method nullifies pointer without releasing the memory. On output, the matrix is 0x0 with 0 non-zero entries.
// reading A from a file Matrix<complex<double>, General, RowComplexSparse> A; A.ReadText("mat.dat"); // then retrieving C-pointers int m = A.GetM(); int nnz = A.GetDataSize(); int* ptr = A.GetPtr(); int* ind = A.GetInd(); double* data = A.GetData(); // if you wish to handle deallocation of these pointers by your-self : A.Nullify();
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
int* GetRealInd(int i) const
This method returns a pointer to the column numbers of the real part of sparse row i.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with real values of second row : double* data = A.GetRealData(1); // and wish the column indexes as well int* col = A.GetRealInd(1); // size of this array int size_row = A.GetRealRowSize(1); // for example we sum real parts except diagonal double sum = 0; for (int i = 0; i < size_row; i++) if (col[i] != 1) sum += data[i];
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
int* GetImagInd(int i) const
This method returns a pointer to the column numbers of the imaginary part of sparse row i.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with imaginary values of third row : double* data = A.GetImagData(2); // and column indexes : int* col = A.GetImagInd(2); // size of this array int size_row = A.GetImagRowSize(2); // for example we sum imaginary parts except on diagonal double sum = 0; for (int i = 0; i < size_row; i++) if (col[i] != 2) sum += data[i];
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
T& ValReal(int i, int j)
This method returns a reference to real part of A(i, j) so that you can modify directly the matrix. If the position (i, j) does not correspond to a non-zero entry, an exception is raised (in debug mode). This method does not create new non-zero entries, use rather GetReal to this aim.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(10, 4); // in a first step, you fill the matrix A.GetReal(0, 3) = 2.0; A.GetImag(0, 2) = 1.5; A.GetReal(1, 1) = -2.3; A.GetImag(1, 1) = 0.2; // then you can modify the real part with ValReal A.ValReal(0, 3) = 1.0; // next line should raise an exception A.ValReal(2, 3) = 0.2;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
T& ValImag(int i, int j)
This method returns a reference to imaginary part of A(i, j) so that you can modify directly the matrix. If the position (i, j) does not correspond to a non-zero entry, an exception is raised (in debug mode). This method does not create new non-zero entries, use rather GetImag to this aim.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(10, 4); // in a first step, you fill the matrix A.GetReal(0, 3) = 2.0; A.GetImag(0, 2) = 1.5; A.GetReal(1, 1) = -2.3; A.GetImag(1, 1) = 0.2; // then you can modify the imaginary part with ValImag A.ValImag(0, 2) = 1.0; // next line should raise an exception A.ValImag(2, 3) = 0.2;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
T& GetReal(int i, int j)
This method returns a reference to real part of A(i, j) so that you can modify directly the matrix. If the position (i, j) does not correspond to a non-zero entry, a new non-zero entry is created.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(10, 4); // you can fill the matrix with GetReal/GetImag A.GetReal(0, 3) = 2.0; A.GetImag(0, 2) = 1.5; A.GetReal(1, 1) = -2.3; A.GetImag(1, 1) = 0.2;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
T& GetImag(int i, int j)
This method returns a reference to imaginary part of A(i, j) so that you can modify directly the matrix. If the position (i, j) does not correspond to a non-zero entry, a new non-zero entry is created.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(10, 4); // you can fill the matrix with GetReal/GetImag A.GetReal(0, 3) = 2.0; A.GetImag(0, 2) = 1.5; A.GetReal(1, 1) = -2.3; A.GetImag(1, 1) = 0.2; A.ValImag(2, 3) = 0.2;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void Set(int i, int j, const complex<T>& val);
This method sets real and imaginary part A(i, j) so that you can modify directly the matrix. If the position (i, j) does not correspond to a non-zero entry, a new non-zero entry is created.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(10, 4); // you can fill the matrix with Set A.Set(0, 3, complex<double>(2.0, -0.5)); A.Set(0, 2, complex<double>(1.5, 0.2)); A.Set(1, 1, complex<double>(-2.3, 0)); A.Set(2, 3, complex<double>(0, 0.2));
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void NullifyReal(int i) void NullifyReal()
This method empties a single row of the matrix or the entire matrix (only real part) without releasing the memory. It should be used carefully and usually in conjunction with SetRealData.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with real values of second row : double* data = A.GetRealData(1); // and column indexes int* col = A.GetRealInd(1); // size of this array int size_row = A.GetRealRowSize(1); // you can initialize a sparse vector with those pointers Vector<double, VectSparse> single_row; single_row.SetData(size_row, data, col); // then to avoid multiple deallocations, NullifyReal is useful : A.NullifyReal(1); // if you want a pointer to all the real part Vector<double, VectSparse>* ptr = A.GetRealData(); int m = A.GetM(); // and nullify all the real part A.NullifyReal();
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void NullifyImag(int i) void NullifyImag()
This method empties a single row of the matrix or the entire matrix (only imaginary part) without releasing the memory. It should be used carefully and usually in conjunction with SetImagData.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // if you want to have a C-array with imaginary values of second row : double* data = A.GetImagData(1); // and column indexes int* col = A.GetImagInd(1); // size of this array int size_row = A.GetImagRowSize(1); // you can initialize a sparse vector with those pointers Vector<double, VectSparse> single_row; single_row.SetData(size_row, data, col); // then to avoid multiple deallocations, NullifyImag is useful : A.NullifyImag(1); // if you want a pointer to all the imaginary part Vector<double, VectSparse>* ptr = A.GetImagData(); int m = A.GetM(); // and nullify all the imaginary part A.NullifyImag();
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void SetRealData(int m, int n, Vector<T, VectSparse>* real_part) void SetRealData(int i, int size_row, T* val, int* col);
With this method, you can set directly the pointers containing the real part of a single row, or the real part of the entire matrix. This low-level method should be used cautiously.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 6); // you initialize values and column numbers of a row int size_row = 3; Vector<double> values(size_row); Vector<int> cols(size_row); values(0) = 1.3; cols(0) = 0; values(1) = -3.5; cols(1) = 2; values(2) = 5.2; cols(2) = 5; // then you initialize a row with these datas int irow = 2; A.SetRealData(irow, size_row, values.GetData(), cols.GetData()); // nullify values and cols to avoid multiple deallocations values.Nullify(); cols.Nullify(); // you can also construct all the rows of real part int m = 4, n = 6; Vector<Vector<double, VectSparse> > all_rows(m); all_rows(0).Get(1) = 2.3; all_rows(0).Get(3) = 1.8; all_rows(1).Get(1) = -0.3; all_rows(2).Get(5) = 9.1; all_rows(2).Get(2) = 0.2; all_rows(3).Get(4) = 0.9; // and feed the real part of the matrix with all_rows A.SetRealData(m, n, all_rows.GetData()); // nullify all_rows to avoid multiple deallocations all_rows.Nullify();
NullifyReal
NullifyImag
SetImagData
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void SetImagData(int m, int n, Vector<T, VectSparse>* real_part) void SetImagData(int i, int size_row, T* val, int* col);
With this method, you can set directly the pointers containing the imaginary part of a single row, or the real part of the entire matrix. This low-level method should be used cautiously.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 6); // you initialize values and column numbers of a row int size_row = 3; Vector<double> values(size_row); Vector<int> cols(size_row); values(0) = 1.3; cols(0) = 0; values(1) = -3.5; cols(1) = 2; values(2) = 5.2; cols(2) = 5; // then you initialize a row with these datas int irow = 2; A.SetImagData(irow, size_row, values.GetData(), cols.GetData()); // nullify values and cols to avoid multiple deallocations values.Nullify(); cols.Nullify(); // you can also construct all the rows of imaginary part int m = 4, n = 6; Vector<Vector<double, VectSparse> > all_rows(m); all_rows(0).Get(1) = 2.3; all_rows(0).Get(3) = 1.8; all_rows(1).Get(1) = -0.3; all_rows(2).Get(5) = 9.1; all_rows(2).Get(2) = 0.2; all_rows(3).Get(4) = 0.9; // and feed the imaginary part of the matrix with all_rows A.SetImagData(m, n, all_rows.GetData()); // nullify all_rows to avoid multiple deallocations all_rows.Nullify();
NullifyReal
NullifyImag
SetRealData
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void Clear()
This method clears the matrix. On output, the matrix is 0x0 with 0 non-zero entries.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // GetM() should return 4 cout << "Number of rows of V : " << V.GetM() << endl; // the matrix is cleared V.Clear(); // GetM() should return 0 cout << "Number of rows of V : " << V.GetM() << endl;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void Reallocate(int m, int n)
This method reallocates the matrix, previous non-zero entries are removed (you don't need to call Clear).
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // GetM() should return 4 cout << "Number of rows of V : " << V.GetM() << endl; // the matrix is reallocated // new matrix will contain 0 non-zero entries V.Reallocate(6, 10); cout << "Number of rows of V : " << V.GetM() << endl;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void Resize(int m, int n)
This method resizes the matrix, previous non-zero entries are kept if they are always in the scope of the matrix (if you reduce the numbers of rows or columns of the matrix, some non-zero entries will be removed).
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // filling the matrix A.Set(1, 2, complex<double>(0.3, 1.5)); A.Set(0, 3, complex<double>(0, 1.8)); A.Set(0, 0, complex<double>(2.3, 0)); A.Set(2, 1, complex<double>(-1.1, 0.7)); // the matrix is resized // new matrix will contain the previous non-zero entries V.Resize(6, 10); cout << "Number of non-zero entries of V : " << V.GetDataSize() << endl;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
T ValueReal(int i, int j)
This method returns the j-th non-zero entry of real part of i-th row. It can be used to fill directly the matrix with IndexReal, and ReallocateRealRow.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // filling the real part with IndexReal, ValueReal A.ReallocateRealRow(0, 2); A.IndexReal(0, 0) = 3; A.ValueReal(0, 0) = 1.8; A.IndexReal(0, 1) = 0; A.ValueReal(0, 1) = 2.3; // for row 0, the column indexes are not sorted -> call AssembleRealRow A.AssembleRealRow(0); // or provide sorted column indexes A.ReallocateRealRow(1, 1); A.IndexReal(1, 0) = 2; A.ValueReal(1, 0) = 0.3; A.ReallocateRealRow(2, 1); A.IndexReal(2, 0) = 1; A.ValueReal(2, 0) = -1.1;
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
T ValueImag(int i, int j)
This method returns the j-th non-zero entry of imaginary part of i-th row. It can be used to fill directly the matrix with IndexImag, and ReallocateImagRow.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // filling the imaginary part with IndexImag, ValueImag A.ReallocateImagRow(0, 2); A.IndexImag(0, 0) = 3; A.ValueImag(0, 0) = 1.8; A.IndexImag(0, 1) = 0; A.ValueImag(0, 1) = 2.3; // for row 0, the column indexes are not sorted -> call AssembleImagRow A.AssembleImagRow(0); // or provide sorted column indexes A.ReallocateImagRow(1, 1); A.IndexImag(1, 0) = 2; A.ValueImag(1, 0) = 0.3; A.ReallocateImagRow(2, 1); A.IndexImag(2, 0) = 1; A.ValueImag(2, 0) = -1.1;
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
int IndexReal(int i, int j)
This method returns the column index of j-th non-zero entry of real part of i-th row. It can be used to fill directly the matrix with ValueReal, and ReallocateRealRow.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // filling the real part with IndexReal, ValueReal A.ReallocateRealRow(0, 2); A.IndexReal(0, 0) = 3; A.ValueReal(0, 0) = 1.8; A.IndexReal(0, 1) = 0; A.ValueReal(0, 1) = 2.3; // for row 0, the column indexes are not sorted -> call AssembleRealRow A.AssembleRealRow(0); // or provide sorted column indexes A.ReallocateRealRow(1, 1); A.IndexReal(1, 0) = 2; A.ValueReal(1, 0) = 0.3; A.ReallocateRealRow(2, 1); A.IndexReal(2, 0) = 1; A.ValueReal(2, 0) = -1.1;
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
T IndexImag(int i, int j)
This method returns the column number of j-th non-zero entry of imaginary part of i-th row. It can be used to fill directly the matrix with ValueImag, and ReallocateImagRow.
Matrix<complex<double>, General, ArrayRowComplexSparse> V(4, 3); // filling the imaginary part with IndexImag, ValueImag A.ReallocateImagRow(0, 2); A.IndexImag(0, 0) = 3; A.ValueImag(0, 0) = 1.8; A.IndexImag(0, 1) = 0; A.ValueImag(0, 1) = 2.3; // for row 0, the column indexes are not sorted -> call AssembleImagRow A.AssembleImagRow(0); // or provide sorted column indexes A.ReallocateImagRow(1, 1); A.IndexImag(1, 0) = 2; A.ValueImag(1, 0) = 0.3; A.ReallocateImagRow(2, 1); A.IndexImag(2, 0) = 1; A.ValueImag(2, 0) = -1.1;
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void RemoveSmallEntry(T epsilon)
This method drops non-zero entries which are smaller than a given epsilon.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // you fill the matrix A // then you can remove small non-zero entries // i.e values such that |Re(A(i, j))| < epsilon and // |Im(A(i, j))| < epsilon are removed A.RemoveSmallEntry(1e-3);
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void Zero();
This method sets the value of non-zero entries to 0. It may be useful if you want to keep the pattern of a matrix and reset the values.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); // you fill the matrix A A.GetReal(1, 3) = 2.5; A.GetImag(2, 4) = -0.6; // ... // then you can zero non-zero entries A.Zero(); // and modify values of the pattern A.ValReal(1, 3) = 0.8;
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void SetIdentity();
This method forms the identity matrix.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(10, 10); // you can initialize A with identity A.SetIdentity();
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void Fill(); void Fill(T val);
This method sets values of non-zero entries to 0, 1, 2, 3, etc or with a given value val. The sparsity pattern of the matrix keeps unchanged.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(10, 10); // fill the matrix A A.GetReal(0, 2) = 1.4; A.GetReal(0, 1) = 0.5; A.GetReal(1, 7) = -2.1; A.GetReal(2, 3) = 1.7; A.GetImag(2, 3) = 0.9; A.GetImag(3, 5) = -3.3; // then you can put the same value on all non-zero entries : A.Fill(complex<double>(2.0, 1.0)); // A will be equal to // 0 1 (2.0, 0) // 0 2 (2.0, 0) // 1 7 (2.0, 0) // 2 3 (2.0, 1.0) // 3 5 (0.0, 1.0) // if you call Fill without argument, there will be 0, 1, 2, ... A.Fill(); // A will be equal to // 0 1 (0, 0) // 0 2 (1, 0) // 1 7 (2, 0) // 2 3 (3, 4) // 3 5 (0, 5)
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void FillRand();
This method sets randomly values of non-zero entries, the profile of the matrix is not modified.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(10, 10); // fill the matrix A A.GetReal(0, 2) = 1.4; A.GetReal(0, 1) = 0.5; A.GetReal(1, 7) = -2.1; A.GetReal(2, 3) = 1.7; A.GetImag(2, 3) = 0.9; A.GetImag(3, 5) = -3.3; // then you can put random values on non-zero entries A.FillRand(); // A will be equal to // 0 1 (x0, 0) // 0 2 (x1, 0) // 1 7 (x2, 0) // 2 3 (x3, x4) // 3 5 (0.0, x5) // where x0, x1, x2, x3, x4, x5 are random numbers
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void ReallocateRealRow(int i, int size_row)
This method modifies the number of non-zero entries contained in real part of row i. All non-zero entries of the real part of the row are resetted, you need to initialize them with IndexReal, ValueReal.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateRealRow(0, 3); A.IndexReal(0, 0) = 0; A.ValueReal(0, 0) = 2.3; A.IndexReal(0, 1) = 3; A.ValueReal(0, 1) = -0.8; A.IndexReal(0, 2) = 7; A.ValueReal(0, 2) = 1.9; // row 1 with 4 non-zero entries A.ReallocateRealRow(1, 4); A.IndexReal(1, 0) = 5; A.ValueReal(1, 0) = 3.1; A.IndexReal(1, 1) = 1; A.ValueReal(1, 1) = -1.3; A.IndexReal(1, 2) = 0; A.ValueReal(1, 2) = 2.4; A.IndexReal(1, 3) = 2; A.ValueReal(1, 3) = 0.4; // column numbers are not sorted -> AssembleRealRow A.AssembleRealRow(1);
AssembleRealRow
ValueReal
IndexReal
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void ReallocateImagRow(int i, int size_row)
This method modifies the number of non-zero entries contained in imaginary part of row i. All non-zero entries of the imaginary part of the row are resetted, you need to initialize them with IndexImag, ValueImag.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateImagRow(0, 3); A.IndexImag(0, 0) = 0; A.ValueImag(0, 0) = 2.3; A.IndexImag(0, 1) = 3; A.ValueImag(0, 1) = -0.8; A.IndexImag(0, 2) = 7; A.ValueImag(0, 2) = 1.9; // row 1 with 4 non-zero entries A.ReallocateImagRow(1, 4); A.IndexImag(1, 0) = 5; A.ValueImag(1, 0) = 3.1; A.IndexImag(1, 1) = 1; A.ValueImag(1, 1) = -1.3; A.IndexImag(1, 2) = 0; A.ValueImag(1, 2) = 2.4; A.IndexImag(1, 3) = 2; A.ValueImag(1, 3) = 0.4; // column numbers are not sorted -> AssembleImagRow A.AssembleImagRow(1);
AssembleImagRow
ValueImag
IndexImag
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void ResizeRealRow(int i, int size_row)
This method modifies the number of non-zero entries contained in real part of row i. Previous non-zero entries of the real part of the row are kept. If there are new non-zero entries, you need to initialize them with IndexReal, ValueReal.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateRealRow(0, 3); A.IndexReal(0, 0) = 0; A.ValueReal(0, 0) = 2.3; A.IndexReal(0, 1) = 3; A.ValueReal(0, 1) = -0.8; A.IndexReal(0, 2) = 7; A.ValueReal(0, 2) = 1.9; // row 1 with 4 non-zero entries A.ReallocateRealRow(1, 4); A.IndexReal(1, 0) = 5; A.ValueReal(1, 0) = 3.1; A.IndexReal(1, 1) = 1; A.ValueReal(1, 1) = -1.3; A.IndexReal(1, 2) = 0; A.ValueReal(1, 2) = 2.4; A.IndexReal(1, 3) = 2; A.ValueReal(1, 3) = 0.4; // column numbers are not sorted -> AssembleRealRow A.AssembleRealRow(1); // adding a new zero-entry in row 0 : A.ResizeRealRow(0, 4); A.IndexReal(0, 3) = 4; A.ValueReal(0, 3) = 4.5; // column numbers are not sorted -> Assemble A.AssembleRealRow(0); // removing last non-zero entry in row (col 5 value 3.1) A.ResizeRealRow(1, 3);
AssembleRealRow
ValueReal
IndexReal
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void ResizeImagRow(int i, int size_row)
This method modifies the number of non-zero entries contained in imaginary part of row i. Previous non-zero entries of the imaginary part of the row are kept. If there are new non-zero entries, you need to initialize them with IndexImag, ValueImag.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateImagRow(0, 3); A.IndexImag(0, 0) = 0; A.ValueImag(0, 0) = 2.3; A.IndexImag(0, 1) = 3; A.ValueImag(0, 1) = -0.8; A.IndexImag(0, 2) = 7; A.ValueImag(0, 2) = 1.9; // row 1 with 4 non-zero entries A.ReallocateImagRow(1, 4); A.IndexImag(1, 0) = 5; A.ValueImag(1, 0) = 3.1; A.IndexImag(1, 1) = 1; A.ValueImag(1, 1) = -1.3; A.IndexImag(1, 2) = 0; A.ValueImag(1, 2) = 2.4; A.IndexImag(1, 3) = 2; A.ValueImag(1, 3) = 0.4; // column numbers are not sorted -> AssembleImagRow A.AssembleImagRow(1); // adding a new zero-entry in row 0 : A.ResizeImagRow(0, 4); A.IndexImag(0, 3) = 4; A.ValueImag(0, 3) = 4.5; // column numbers are not sorted -> Assemble A.AssembleImagRow(0); // removing last non-zero entry in row (col 5 value 3.1) A.ResizeImagRow(1, 3);
AssembleImagRow
ValueImag
IndexImag
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void ClearRealRow(int i)
This method clears the real part of row i.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateRealRow(0, 3); A.IndexReal(0, 0) = 0; A.ValueReal(0, 0) = 2.3; A.IndexReal(0, 1) = 3; A.ValueReal(0, 1) = -0.8; A.IndexReal(0, 2) = 7; A.ValueReal(0, 2) = 1.9; // row 1 with 4 non-zero entries A.ReallocateRealRow(1, 4); A.IndexReal(1, 0) = 5; A.ValueReal(1, 0) = 3.1; A.IndexReal(1, 1) = 1; A.ValueReal(1, 1) = -1.3; A.IndexReal(1, 2) = 0; A.ValueReal(1, 2) = 2.4; A.IndexReal(1, 3) = 2; A.ValueReal(1, 3) = 0.4; // column numbers are not sorted -> AssembleRealRow A.AssembleRealRow(1); // removing all non-zero entries of row 0 A.ClearRealRow(0);
ReallocateRealRow
ResizeRealRow
Clear
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void ClearImagRow(int i)
This method clears the imaginary part of row i.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateImagRow(0, 3); A.IndexImag(0, 0) = 0; A.ValueImag(0, 0) = 2.3; A.IndexImag(0, 1) = 3; A.ValueImag(0, 1) = -0.8; A.IndexImag(0, 2) = 7; A.ValueImag(0, 2) = 1.9; // row 1 with 4 non-zero entries A.ReallocateRealRow(1, 4); A.IndexImag(1, 0) = 5; A.ValueImag(1, 0) = 3.1; A.IndexImag(1, 1) = 1; A.ValueImag(1, 1) = -1.3; A.IndexImag(1, 2) = 0; A.ValueImag(1, 2) = 2.4; A.IndexImag(1, 3) = 2; A.ValueImag(1, 3) = 0.4; // column numbers are not sorted -> AssembleImagRow A.AssembleImagRow(1); // removing all non-zero entries of row 0 A.ClearImagRow(0);
ReallocateImagRow
ResizeImagRow
Clear
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void SwapRealRow(int i, int j)
This method swaps the rows i and j (only real part), the columns numbers are unchanged. This method should be considered carefully for symmetric matrices, since the condition i <= j may be not satisfied anymore after swapping the rows.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateRealRow(0, 3); A.IndexReal(0, 0) = 0; A.ValueReal(0, 0) = 2.3; A.IndexReal(0, 1) = 3; A.ValueReal(0, 1) = -0.8; A.IndexReal(0, 2) = 7; A.ValueReal(0, 2) = 1.9; // row 1 with 4 non-zero entries A.ReallocateRealRow(1, 4); A.IndexReal(1, 0) = 5; A.ValueReal(1, 0) = 3.1; A.IndexReal(1, 1) = 1; A.ValueReal(1, 1) = -1.3; A.IndexReal(1, 2) = 0; A.ValueReal(1, 2) = 2.4; A.IndexReal(1, 3) = 2; A.ValueReal(1, 3) = 0.4; // column numbers are not sorted -> AssembleRealRow A.AssembleRealRow(1); // exchanging contents of row 0 and row 1 A.SwapRealRow(0, 1);
ReallocateRealRow
ResizeRealRow
Clear
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void SwapImagRow(int i, int j)
This method swaps the rows i and j (only imaginary part), the columns numbers are unchanged. This method should be considered carefully for symmetric matrices, since the condition i <= j may be not satisfied anymore after swapping the rows.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateImagRow(0, 3); A.IndexImag(0, 0) = 0; A.ValueImag(0, 0) = 2.3; A.IndexImag(0, 1) = 3; A.ValueImag(0, 1) = -0.8; A.IndexImag(0, 2) = 7; A.ValueImag(0, 2) = 1.9; // row 1 with 4 non-zero entries A.ReallocateImagRow(1, 4); A.IndexImag(1, 0) = 5; A.ValueImag(1, 0) = 3.1; A.IndexImag(1, 1) = 1; A.ValueImag(1, 1) = -1.3; A.IndexImag(1, 2) = 0; A.ValueImag(1, 2) = 2.4; A.IndexImag(1, 3) = 2; A.ValueImag(1, 3) = 0.4; // column numbers are not sorted -> AssembleImagRow A.AssembleImagRow(1); // exchanging contents of row 0 and row 1 A.SwapImagRow(0, 1);
ReallocateImagRow
ResizeImagRow
Clear
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void ReplaceRealIndexRow(int i, Vector<int>& ind)
This method replaces column numbers of real part of row i. The size of array ind must be greater or equal to the size of the row i.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateRealRow(0, 3); A.IndexReal(0, 0) = 0; A.ValueReal(0, 0) = 2.3; A.IndexReal(0, 1) = 3; A.ValueReal(0, 1) = -0.8; A.IndexReal(0, 2) = 7; A.ValueReal(0, 2) = 1.9; // column numbers are not 0, 3, 7, but 1, 2, 6 => IVect new_col(3); new_col(0) = 1; new_col(1) = 2; new_col(2) = 6; A.ReplaceRealIndexRow(0, new_col);
ReallocateRealRow
ResizeRealRow
AssembleRealRow
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void ReplaceImagIndexRow(int i, Vector<int>& ind)
This method replaces column numbers of imaginary part of row i. The size of array ind must be greater or equal to the size of the row i.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateImagRow(0, 3); A.IndexImag(0, 0) = 0; A.ValueImag(0, 0) = 2.3; A.IndexImag(0, 1) = 3; A.ValueImag(0, 1) = -0.8; A.IndexImag(0, 2) = 7; A.ValueImag(0, 2) = 1.9; // column numbers are not 0, 3, 7, but 1, 2, 6 => IVect new_col(3); new_col(0) = 1; new_col(1) = 2; new_col(2) = 6; A.ReplaceImagIndexRow(0, new_col);
ReallocateImagRow
ResizeImagRow
AssembleImagRow
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
int GetRealRowSize(int i) const
This method returns the number of non-zero entries contained in the real part of i-th row.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateRealRow(0, 3); A.IndexReal(0, 0) = 0; A.ValueReal(0, 0) = 2.3; A.IndexReal(0, 1) = 3; A.ValueReal(0, 1) = -0.8; A.IndexReal(0, 2) = 7; A.ValueReal(0, 2) = 1.9; // GetRealRowSize should return 3 cout << "Number of non-zero entries in row 0 : " << A.GetRealRowSize(0, 3) << endl;
ReallocateRealRow
ResizeRealRow
AssembleRealRow
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
int GetImagRowSize(int i) const
This method returns the number of non-zero entries contained in the imaginary part of i-th row.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateImagRow(0, 3); A.IndexImag(0, 0) = 0; A.ValueImag(0, 0) = 2.3; A.IndexImag(0, 1) = 3; A.ValueImag(0, 1) = -0.8; A.IndexImag(0, 2) = 7; A.ValueImag(0, 2) = 1.9; // GetImagRowSize should return 3 cout << "Number of non-zero entries in row 0 : " << A.GetImagRowSize(0, 3) << endl;
ReallocateImagRow
ResizeImagRow
AssembleImagRow
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void PrintRealRow(int i) const
This method displays the real part of i-th row.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // displaying row 3 cout << "Row 3 = " << endl; A.PrintRealRow(3);
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void PrintImagRow(int i) const
This method displays the imaginary part of i-th row.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // displaying row 3 cout << "Row 3 = " << endl; A.PrintImagRow(3);
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void AssembleRealRow(int i)
This method sorts column numbers of real part of a row, and adds values if there are duplicate column numbers. This method is not necessary if you are using AddInteraction, AddInteractionRow, GetReal, GetImag or Set.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateRealRow(0, 3); A.IndexReal(0, 0) = 0; A.ValueReal(0, 0) = 2.3; A.IndexReal(0, 1) = 3; A.ValueReal(0, 1) = -0.8; A.IndexReal(0, 2) = 7; A.ValueReal(0, 2) = 1.9; // row 1 with 4 non-zero entries A.ReallocateRealRow(1, 4); A.IndexReal(1, 0) = 5; A.ValueReal(1, 0) = 3.1; A.IndexReal(1, 1) = 1; A.ValueReal(1, 1) = -1.3; A.IndexReal(1, 2) = 0; A.ValueReal(1, 2) = 2.4; A.IndexReal(1, 3) = 2; A.ValueReal(1, 3) = 0.4; // column numbers are not sorted -> AssembleRealRow A.AssembleRealRow(1);
AddInteraction
AddInteractionRow
Set
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void AssembleImagRow(int i)
This method sorts column numbers of imaginary part of a row, and adds values if there are duplicate column numbers. This method is not necessary if you are using AddInteraction, AddInteractionRow, GetReal, GetImag or Set.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // initializing row 0 with 3 non-zero entries : A.ReallocateImagRow(0, 3); A.IndexImag(0, 0) = 0; A.ValueImag(0, 0) = 2.3; A.IndexImag(0, 1) = 3; A.ValueImag(0, 1) = -0.8; A.IndexImag(0, 2) = 7; A.ValueImag(0, 2) = 1.9; // row 1 with 4 non-zero entries A.ReallocateImagRow(1, 4); A.IndexImag(1, 0) = 5; A.ValueImag(1, 0) = 3.1; A.IndexImag(1, 1) = 1; A.ValueImag(1, 1) = -1.3; A.IndexImag(1, 2) = 0; A.ValueImag(1, 2) = 2.4; A.IndexImag(1, 3) = 2; A.ValueImag(1, 3) = 0.4; // column numbers are not sorted -> AssembleImagRow A.AssembleImagRow(1);
AddInteraction
AddInteractionRow
Set
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void AddInteraction(int i, int j, complex<T> val)
This method adds val to A(i, j). If there is no non-zero entry at this position, a new non-zero entry is created.
// initially the matrix is equal to 0 (empty) Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // then you add values with AddInteraction A.AddInteraction(0, 1, complex<double>(1.2, 0)); A.AddInteraction(1, 2, complex<double>(1.8, 0.2)); A.AddInteraction(3, 0, complex<double>(0, 0.5)); A.AddInteraction(4, 5, complex<double>(0, 1.6)); A.AddInteraction(6, 2, complex<double>(-2.0, 0.2)); // you can also use AddInteractionRow, if there are several values // to add in the same time, these values may be not sorted int nb_val = 4; IVect col(nb_val); Vector<complex<double> > values(nb_val); col(0) = 0; values(0) = complex<double>(2.1, 0); col(1) = 7; values(1) = complex<double>(0, 0.8); col(2) = 3; values(2) = complex<double>(-2.6, 0); col(3) = 2; values(3) = complex<double>(0.9, -3.4); A.AddInteractionRow(6, nb_val, col, values);
AddInteractionRow
AddInteractionColumn
Set
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void AddInteractionRow(int i, int nb_values, const IVect col, const Vector<complex<T> > val)
This method adds nb_values values in row i. For each value to add, you provide the column number and the value.
// initially the matrix is equal to 0 (empty) Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // then you add values with AddInteraction A.AddInteraction(0, 1, complex<double>(1.2, 0)); A.AddInteraction(1, 2, complex<double>(1.8, 0.2)); A.AddInteraction(3, 0, complex<double>(0, 0.5)); A.AddInteraction(4, 5, complex<double>(0, 1.6)); A.AddInteraction(6, 2, complex<double>(-2.0, 0.2)); // you can also use AddInteractionRow, if there are several values // to add in the same time, these values may be not sorted int nb_val = 4; IVect col(nb_val); Vector<complex<double> > values(nb_val); col(0) = 0; values(0) = complex<double>(2.1, 0); col(1) = 7; values(1) = complex<double>(0, 0.8); col(2) = 3; values(2) = complex<double>(-2.6, 0); col(3) = 2; values(3) = complex<double>(0.9, -3.4); A.AddInteractionRow(6, nb_val, col, values);
AddInteraction
AddInteractionColumn
Set
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void AddInteractionColumn(int i, int nb_values, const IVect row, const Vector<complex<T> > val)
This method adds nb_values values in column i. For each value to add, you provide the row number and the value.
// initially the matrix is equal to 0 (empty) Matrix<complex<double>, General, ArrayRowComplexSparse> A(12, 8); // then you add values with AddInteraction A.AddInteraction(0, 1, complex<double>(1.2, 0)); A.AddInteraction(1, 2, complex<double>(1.8, 0.2)); A.AddInteraction(3, 0, complex<double>(0, 0.5)); A.AddInteraction(4, 5, complex<double>(0, 1.6)); A.AddInteraction(6, 2, complex<double>(-2.0, 0.2)); // you can also use AddInteractionColumn, if there are several values // to add in the same time, these values may be not sorted int nb_val = 4; IVect row(nb_val); Vector<complex<double> > values(nb_val); row(0) = 0; values(0) = complex<double>(2.1, 0); row(1) = 7; values(1) = complex<double>(0, 0.8); row(2) = 3; values(2) = complex<double>(-2.6, 0); row(3) = 2; values(3) = complex<double>(0.9, -3.4); A.AddInteractionColumn(5, nb_val, col, values);
AddInteractionRow
AddInteraction
Set
Class Matrix_ArrayComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
void Print()
This method displays the matrix.
Matrix<complex<double>, General, ArrayRowComplexSparse> A(4, 3); cout << " A = " << endl; A.Print();
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void Write(string name)
This method writes the matrix on a file in binary format. This format is not portable, so if you read a matrix with method Read, the storage should be the same as the storage used when the matrix has been written.
// storage ArrayRowSymComplexSparse when writing Matrix<complex<double>, General, ArrayRowSymComplexSparse> A(8, 8); A.Write("MyMatrix.dat"); // same storage when reading the matrix Matrix<complex<double>, General, ArrayRowSymComplexSparse> B; B.Read("MyMatrix.dat");
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void Read(string name)
This method reads the matrix from a file in binary format. This format is not portable, so if you read a matrix with method Read, the storage should be the same as the storage used when the matrix has been written.
// storage ArrayRowSymComplexSparse when writing Matrix<complex<double>, General, ArrayRowSymComplexSparse> A(8, 8); A.Write("MyMatrix.dat"); // same storage when reading the matrix Matrix<complex<double>, General, ArrayRowSymComplexSparse> B; B.Read("MyMatrix.dat");
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void WriteText(string name) void WriteText(string name, bool without_brackets) void WriteText(ostream out) void WriteText(ostream out, bool without_brackets)
This method writes the matrix on a file in ascii format. The row and column numbers are incremented in order to satisfy the 1-index convention (used by Matlab). The complex values are written by default with parenthesis. The file will look like
1 3 (0.5432143,-2.34433) 2 4 (2.90843,0.0) 3 2 (-1.232409,-0.090982)
If you prefer to not have those brackets, but real part and imaginary part in separated columns, you have to put true in the optional argument. In that case, the file will be :
1 3 0.5432143 -2.34433 2 4 2.90843 0.0 3 2 -1.232409 -0.090982
The Matlab code would be in that last case :
M = load('matrix.dat'); A = spconvert(M(:,1:3)) + 1i*spconvert(M(:,[1,2,4]));
With Python, it is similar :
from scipy.sparse import *
A = loadtxt('matrix.dat') B = coo_matrix((A[:,2],(A[:,0]-1,A[:,1]-1))) + 1j*coo_matrix((A[:,3],(A[:,0]-1,A[:,1]-1)))
Matrix<complex<double>, General, ArrayRowComplexSparse> A(8, 8); // filling the matrix A.AddInteraction(0, 3, complex<double>(0.3, 1.2)); // ... // then writing on the disk A.WriteText("my_matrix.dat");
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx
void ReadText(string name) void ReadText(string name, bool without_brackets) void ReadText(istream in) void ReadText(istream in, bool without_brackets)
This method reads the matrix from a file in ascii format. The row and column numbers on the file should be based on the 1-index convention (used by Matlab). The complex values are expected to be by default with parenthesis. The file would look like (row numbers are placed on the first column, column numbers in the second column, and values and the third column)
1 3 (0.5432143,-2.34433) 2 4 (2.90843,0.0) 3 2 (-1.232409,-0.090982)
If your file is written without those brackets, but real part and imaginary part in separated columns, you have to put true in the optional argument. In that case, the file should be :
1 3 0.5432143 -2.34433 2 4 2.90843 0.0 3 2 -1.232409 -0.090982
Matrix<complex<double>, General, ArrayRowComplexSparse> A; // you can read A from a file A.ReadText("my_matrix.dat");
Class Matrix_ArrayComplexSparse
Class Matrix_ComplexSparse
Class Matrix_SymComplexSparse
Matrix_ArrayComplexSparse.hxx Matrix_ArrayComplexSparse.cxx
Matrix_ComplexSparse.hxx Matrix_ComplexSparse.cxx
Matrix_SymComplexSparse.hxx Matrix_SymComplexSparse.cxx