The sparse-matrix classes of CPPLapack is designed in the following policies.
Each sparse-matrix object has the following important member variables.
int cap |
size of matrix data array (capacity of the number of components) |
int vol |
current volume of array size (current number of non-zero component) |
int* indx |
row index of matrix data |
int* jndx |
column index of matrix data |
The size of array
is determined by cap
.
The volume of the matrix vol
is changed each time when a non-zero component is put or deleted.
For example, CPPL::dssmatrix A(m,n,cap);
makes a m
xn
matrix A
which has cap
free data space.
Its vol
is automatically set to zero in this case.
To assign a value to a component of dssmatrix or zssmatrix, use "put" or "fput" function.
The "put(i,j,v)"
function checks if the (i,j) component already exists.
When the (i,j) component exists, put
function overwrite the existing value.
When the (i,j) component doesn't exist, put
function creates a new element and increase the volume(VOL++;).
In case VOL=CAP, put
function calls expand
function before creating a new element.
On the other hand, the "fput(i,j,v)"
function doesn't check if the (i,j) component already exists and if VOL=CAP.
The fput
function always suppose that the (i,j) component doesn't exist and VOL<CAP,
and simply creates a new element and increase the volume(VOL++;).
The "fput(i,j,v)"
function is faster but more dangerous than the "put(i,j,v)"
function.
To add, subtract, multiply, and divide a component of dssmatrix or zssmatrix, use the add
, sub
, mult
, and div
functions, respectively.
These functions check if the (i,j) component already exists.
When the (i,j) component exists, these functions operate the existing value.
When the (i,j) component doesn't exist, the add
and sub
functions create a new element, set to v and -v respectively, and VOL++, and the mult
and div
functions do nothing.
To delete a component of dssmatrix or zssmatrix, use del
or fdel
function.
The del(i,j)
function deletes the (i,j) component when it exists.
The fdel(c)
function deletes the cth element of the array when it exists.
When you use del
or fdel
in a loop, you must pay a lot of attention to what they do.
For example, the following for-loop doesn't work as it seems to be.
for(int c=0; c
}
To make the code work as we expect,
for(int c=0; c
}
The expand
function creates an array which is "a little bit" larger than the current array, copies the data of current array to the new array, and deletes the current array.
The size of "a little bit" is defined in cpplapack.h as a macro "CPPL_SS_SECTOR".
You can edit cpplapack.h and change the value of "CPPL_SS_SECTOR".
The isListed(i,j)
function checks if the (i,j) component is listed.
When the (i,j) component is listed, this function returns 1, otherwise 0.
The number(i,j)
function returns the element number of the (i,j) component if it is listed.
When the (i,j) component is no listed, this function returns -1.
After using fput, read, etc., you may break the consistency of the object.
The checkup
function is helpful for the debugging.
It checks the bounds of cap
, vol
, indx
, and jndx
, and the double-entry of the elements.