Class SparseDoubleMatrix2D

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class SparseDoubleMatrix2D
    extends cern.colt.matrix.DoubleMatrix2D
    Class for sparse 2-d matrices holding double elements in the sparse format expected by the C library libsvm. See the documentation for libsvm for more details.
    Author:
    anders.gidenstam(at)hb.se
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected long Cptr
      C-side pointer to an array of svm_node arrays storing the matrix contents.
      protected SparseDoubleMatrix1D[] rowViews
      SparseDoubleMatrix1D views of rows in this matrix.
      • Fields inherited from class cern.colt.matrix.impl.AbstractMatrix2D

        columns, columnStride, columnZero, rows, rowStride, rowZero
      • Fields inherited from class cern.colt.matrix.impl.AbstractMatrix

        isNoView
      • Fields inherited from class cern.colt.PersistentObject

        serialVersionUID
    • Constructor Summary

      Constructors 
      Constructor Description
      SparseDoubleMatrix2D​(int rows, int columns)
      Constructs a matrix with a given number of rows and columns.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void finalize()  
      double getQuick​(int row, int column)
      Returns the matrix cell value at coordinate [row,column].
      SparseDoubleMatrix1D getRow​(int row)
      Returns one row of the matrix as a SparseDoubleMatrix1D.
      cern.colt.matrix.DoubleMatrix2D like​(int rows, int columns)
      Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified number of rows and columns.
      cern.colt.matrix.DoubleMatrix1D like1D​(int size)
      Construct and returns a new 1-d matrix of the corresponding dynamic type, entirelly independent of the receiver.
      protected cern.colt.matrix.DoubleMatrix1D like1D​(int size, int zero, int stride)
      Construct and returns a new 1-d matrix of the corresponding dynamic type, sharing the same cells.
      void setQuick​(int row, int column, double value)
      Sets the matrix cell at coordinate [row,column] to the specified value.
      void setRow​(int row, int[] indices, double[] values)
      Replaces one row of the matrix.
      protected void setUp​(int rows, int columns)
      Sets up a matrix with a given number of rows and columns.
      cern.colt.matrix.DoubleMatrix1D viewRow​(int row)
      Constructs and returns a new slice view representing the columns of the given row.
      protected cern.colt.matrix.DoubleMatrix2D viewSelectionLike​(int[] rowOffsets, int[] columnOffsets)
      Construct and returns a new selection view.
      • Methods inherited from class cern.colt.matrix.DoubleMatrix2D

        aggregate, aggregate, assign, assign, assign, assign, assign, cardinality, copy, equals, equals, forEachNonZero, get, getContent, getNonZeros, haveSharedCells, haveSharedCellsRaw, like, set, toArray, toString, view, viewColumn, viewColumnFlip, viewDice, viewPart, viewRowFlip, viewSelection, viewSelection, viewSorted, viewStrides, zAssign8Neighbors, zMult, zMult, zMult, zMult, zSum
      • Methods inherited from class cern.colt.matrix.impl.AbstractMatrix2D

        _columnOffset, _columnRank, _rowOffset, _rowRank, checkBox, checkColumn, checkColumnIndexes, checkRow, checkRowIndexes, checkShape, checkShape, columns, index, rows, setUp, size, toStringShort, vColumnFlip, vDice, vPart, vRowFlip, vStrides
      • Methods inherited from class cern.colt.matrix.impl.AbstractMatrix

        ensureCapacity, isView, trimToSize
      • Methods inherited from class cern.colt.PersistentObject

        clone
      • Methods inherited from class java.lang.Object

        getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • Cptr

        protected long Cptr
        C-side pointer to an array of svm_node arrays storing the matrix contents.
      • rowViews

        protected SparseDoubleMatrix1D[] rowViews
        SparseDoubleMatrix1D views of rows in this matrix. These are created and stored on demand.
    • Constructor Detail

      • SparseDoubleMatrix2D

        public SparseDoubleMatrix2D​(int rows,
                                    int columns)
        Constructs a matrix with a given number of rows and columns. All entries are initially 0.
        Parameters:
        rows - the number of rows the matrix shall have.
        columns - the number of columns the matrix shall have.
        Throws:
        java.lang.IllegalArgumentException - if rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE.
    • Method Detail

      • like

        public cern.colt.matrix.DoubleMatrix2D like​(int rows,
                                                    int columns)
        Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified number of rows and columns. For example, if the receiver is an instance of type SparseDoubleMatrix2D the new matrix must also be of type DenseDoubleMatrix2D, if the receiver is an instance of type SparseDoubleMatrix2D the new matrix must also be of type SparseDoubleMatrix2D, etc. In general, the new matrix should have internal parametrization as similar as possible.
        Specified by:
        like in class cern.colt.matrix.DoubleMatrix2D
        Parameters:
        rows - the number of rows the matrix shall have.
        columns - the number of columns the matrix shall have.
        Returns:
        a new empty matrix of the same dynamic type.
      • like1D

        public cern.colt.matrix.DoubleMatrix1D like1D​(int size)
        Construct and returns a new 1-d matrix of the corresponding dynamic type, entirelly independent of the receiver. For example, if the receiver is an instance of type DenseDoubleMatrix2D the new matrix must be of type DenseDoubleMatrix1D, if the receiver is an instance of type SparseDoubleMatrix2D the new matrix must be of type SparseDoubleMatrix1D, etc.
        Specified by:
        like1D in class cern.colt.matrix.DoubleMatrix2D
        Parameters:
        size - the number of cells the matrix shall have.
        Returns:
        a new matrix of the corresponding dynamic type.
      • like1D

        protected cern.colt.matrix.DoubleMatrix1D like1D​(int size,
                                                         int zero,
                                                         int stride)
        Construct and returns a new 1-d matrix of the corresponding dynamic type, sharing the same cells. For example, if the receiver is an instance of type DenseDoubleMatrix2D the new matrix must be of type DenseDoubleMatrix1D, if the receiver is an instance of type SparseDoubleMatrix2D the new matrix must be of type SparseDoubleMatrix1D, etc.
        Specified by:
        like1D in class cern.colt.matrix.DoubleMatrix2D
        Parameters:
        size - the number of cells the matrix shall have.
        zero - the index of the first element.
        stride - the number of indexes between any two elements, i.e. index(i+1)-index(i).
        Returns:
        a new matrix of the corresponding dynamic type.
      • getQuick

        public double getQuick​(int row,
                               int column)
        Returns the matrix cell value at coordinate [row,column].

        Provided with invalid parameters this method may return invalid objects without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): 0 <= column < columns() && 0 <= row < rows().

        Specified by:
        getQuick in class cern.colt.matrix.DoubleMatrix2D
        Parameters:
        row - the index of the row-coordinate.
        column - the index of the column-coordinate.
        Returns:
        the value at the specified coordinate.
      • setQuick

        public void setQuick​(int row,
                             int column,
                             double value)
        Sets the matrix cell at coordinate [row,column] to the specified value.

        Provided with invalid parameters this method may access illegal indexes without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): 0 <= column < columns() && 0 <= row < rows().

        Specified by:
        setQuick in class cern.colt.matrix.DoubleMatrix2D
        Parameters:
        row - the index of the row-coordinate.
        column - the index of the column-coordinate.
        value - the value to be filled into the specified cell.
      • getRow

        public SparseDoubleMatrix1D getRow​(int row)
        Returns one row of the matrix as a SparseDoubleMatrix1D. The resulting matrix will share storage with this instance.
        Parameters:
        row - the row to return.
        Returns:
        a SparseDoubleMatrix1D representing a view of the row.
      • viewRow

        public cern.colt.matrix.DoubleMatrix1D viewRow​(int row)
        Constructs and returns a new slice view representing the columns of the given row. The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. To obtain a slice view on subranges, construct a sub-ranging view (viewPart( ...)), then apply this method to the sub-range view.

        Example:

        2 x 3 matrix:
        1, 2, 3
        4, 5, 6
        viewRow(0) ==> Matrix1D of size 3:
        1, 2, 3
        Overrides:
        viewRow in class cern.colt.matrix.DoubleMatrix2D
        Parameters:
        row - the row to fix.
        Returns:
        a new slice view.
        Throws:
        java.lang.IndexOutOfBoundsException - if row < 0 || row >= rows().
        See Also:
        DoubleMatrix2D.viewColumn(int)
      • setRow

        public void setRow​(int row,
                           int[] indices,
                           double[] values)
        Replaces one row of the matrix. FIXME: Verify the RC handling - is the old row RC decreased enough? Should the SparseDoubleMatrix1D row object be replaced instead of updated, i.e. should old row views see the new state?
        Parameters:
        row - the row to replace.
        indices - the indices to be filled in the new row.
        values - the values to be filled into the new row.
      • viewSelectionLike

        protected cern.colt.matrix.DoubleMatrix2D viewSelectionLike​(int[] rowOffsets,
                                                                    int[] columnOffsets)
        Construct and returns a new selection view.
        Specified by:
        viewSelectionLike in class cern.colt.matrix.DoubleMatrix2D
        Parameters:
        rowOffsets - the offsets of the visible elements.
        columnOffsets - the offsets of the visible elements.
        Returns:
        a new view.
      • setUp

        protected void setUp​(int rows,
                             int columns)
        Sets up a matrix with a given number of rows and columns.
        Overrides:
        setUp in class cern.colt.matrix.impl.AbstractMatrix2D
        Parameters:
        rows - the number of rows the matrix shall have.
        columns - the number of columns the matrix shall have.
        Throws:
        java.lang.IllegalArgumentException - if rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable