Documentation API of the 'cern.colt.matrix.tfloat.impl.SparseRCFloatMatrix2D' Java class
SparseRCFloatMatrix2D
cern.colt.matrix.tfloat.impl

Class SparseRCFloatMatrix2D

  • All Implemented Interfaces:
    Serializable, Cloneable


    public class SparseRCFloatMatrix2Dextends WrapperFloatMatrix2D
    Sparse row-compressed 2-d matrix holding float elements. First see the package summary and javadoc tree view to get the broad picture.

    Implementation:

    Internally uses the standard sparse row-compressed format
    Note that this implementation is not synchronized.

    Memory requirements:

    Cells that

    • are never set to non-zero values do not use any memory.
    • switch from zero to non-zero state do use memory.
    • switch back from non-zero to zero state also do use memory. Their memory is not automatically reclaimed (because of the lists vs. arrays). Reclamation can be triggered via trimToSize().

    memory [bytes] = 4*rows + 12 * nonZeros.
    Where nonZeros = cardinality() is the number of non-zero cells. Thus, a 1000 x 1000 matrix with 1000000 non-zero cells consumes 11.5 MB. The same 1000 x 1000 matrix with 1000 non-zero cells consumes 15 KB.

    Time complexity:

    Getting a cell value takes time O(log nzr) where nzr is the number of non-zeros of the touched row. This is usually quick, because typically there are only few nonzeros per row. So, in practice, get has expected constant time. Setting a cell value takes worst-case time O(nz) where nzr is the total number of non-zeros in the matrix. This can be extremely slow, but if you traverse coordinates properly (i.e. upwards), each write is done much quicker:

     // rather quick matrix.assign(0); for (int row = 0; row < rows; row++) {     for (int column = 0; column < columns; column++) {         if (someCondition)             matrix.setQuick(row, column, someValue);     } }  // poor matrix.assign(0); for (int row = rows; --row >= 0;) {     for (int column = columns; --column >= 0;) {         if (someCondition)             matrix.setQuick(row, column, someValue);     } } 
    If for whatever reasons you can't iterate properly, consider to create an empty dense matrix, store your non-zeros in it, then call sparse.assign(dense). Under the circumstances, this is still rather quick.

    Fast iteration over non-zeros can be done via forEachNonZero(cern.colt.function.tfloat.IntIntFloatFunction), which supplies your function with row, column and value of each nonzero. Although the internally implemented version is a bit more sophisticated, here is how a quite efficient user-level matrix-vector multiplication could look like:

     // Linear algebraic y = A * x A.forEachNonZero(new cern.colt.function.IntIntFloatFunction() {     public float apply(int row, int column, float value) {         y.setQuick(row, y.getQuick(row) + value * x.getQuick(column));         return value;     } }); 

    Here is how a a quite efficient user-level combined scaling operation could look like:

     // Elementwise A = A + alpha*B B.forEachNonZero(new cern.colt.function.IntIntFloatFunction() {     public float apply(int row, int column, float value) {         A.setQuick(row, column, A.getQuick(row, column) + alpha * value);         return value;     } }); 
    Method assign(FloatMatrix2D,cern.colt.function.tfloat.FloatFloatFunction) does just that if you supply FloatFunctions.plusMultSecond(float) as argument.
    See Also:
    Serialized Form

Warning: You cannot see the full API documentation of this class since the access to the DatMelt documentation for third-party Java classes is denied. Guests can only view jhplot Java API. To view the complete description of this class and its methods, please request the full DataMelt membership.

If you are already a full member, please login to the DataMelt member area before visiting this documentation.