Class DenseData

  • All Implemented Interfaces:
    MatrixAccess, Table, DeepCopyable

    public abstract class DenseData
    extends Object
    implements MatrixAccess, DeepCopyable
    This implementation of the storage of a dense matrix stores the data of a 2D matrix as an 1D array. In general, computing index for a double[] is faster than that for a double[][]. Hence for most operations, e.g., element-by-element add, minus, this implementation has a better performance.
    • Constructor Detail

      • DenseData

        public DenseData​(double[] data,
                         int nRows,
                         int nCols,
                         DoubleArrayOperation operation)
        Construct a storage, and specify the implementations of the element-wise operations.
        Parameters:
        data - the data
        nRows - the number of rows
        nCols - the number of columns
        operation - the implementations of the element-wise operations
      • DenseData

        public DenseData​(double[] data,
                         int nRows,
                         int nCols)
        Construct a storage.
        Parameters:
        data - the data
        nRows - the number of rows
        nCols - the number of columns
    • Method Detail

      • position

        protected abstract int position​(int nRows,
                                        int nCols,
                                        int i,
                                        int j)
      • set

        public void set​(int i,
                        int j,
                        double value)
                 throws MatrixAccessException
        Description copied from interface: MatrixAccess
        Set the matrix entry at [i,j] to a value. This is the only method that may change a matrix.
        Specified by:
        set in interface MatrixAccess
        Parameters:
        i - the row index
        j - the column index
        value - the value to set A[i,j] to
        Throws:
        MatrixAccessException - if i or j is out of range
      • nRows

        public int nRows()
        Description copied from interface: Table
        Gets the number of rows. Rows count from 1.
        Specified by:
        nRows in interface Table
        Returns:
        the number of rows
      • nCols

        public int nCols()
        Description copied from interface: Table
        Gets the number of columns. Columns count from 1.
        Specified by:
        nCols in interface Table
        Returns:
        the number of columns
      • deepCopy

        public DenseData deepCopy()
        Description copied from interface: DeepCopyable
        The implementation returns an instance created from this by the copy constructor of the class, or just this if the instance itself is immutable.
        Specified by:
        deepCopy in interface DeepCopyable
        Returns:
        an independent (deep) copy of the instance
      • asArray

        public double[] asArray()
        Cast this data structure as a double[]. Modifying the returned value modifies the internal data.
        Returns:
        itself as a double[]
      • add

        public DenseData add​(DenseData that)
        Add up the elements in this and that, element-by-element.
        Parameters:
        that - an array of data
        Returns:
        the sums of elements
      • minus

        public DenseData minus​(DenseData that)
        Subtract the elements in this by that, element-by-element.
        Parameters:
        that - an array of data
        Returns:
        the differences of elements
      • scaled

        public DenseData scaled​(double c)
        Multiply the elements in this by a scalar, element-by-element.
        Parameters:
        c - the scaling constant
        Returns:
        the scaled elements
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object