Class DenseVector

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.Double>
    Direct Known Subclasses:
    BasicVector

    public abstract class DenseVector
    extends Vector
    A dense vector. A vector represents an array of elements. It can be re-sized. A dense data structure usually stores data in an underlying array. Zero elements take up memory space. If you want a data structure that will not have zero elements take up memory space, try a sparse structure. However, fetch/store operations on dense data structures only take O(1) time, instead of the O(log n) time on sparse structures.
    • Constructor Detail

      • DenseVector

        public DenseVector​(int length)
    • Method Detail

      • constant

        public static DenseVector constant​(int length,
                                           double value)
        Creates a constant DenseVector of the given length with the given value.
      • random

        public static DenseVector random​(int length,
                                         java.util.Random random)
        Creates a random DenseVector of the given length with the given Random.
      • fromArray

        public static DenseVector fromArray​(double[] array)
        Creates a new DenseVector from the given array w/o copying the underlying array.
      • fromCSV

        public static DenseVector fromCSV​(java.lang.String csv)
        Parses DenseVector from the given CSV string.
        Parameters:
        csv - the CSV string representing a vector
        Returns:
        a parsed vector
      • fromMatrixMarket

        public static DenseVector fromMatrixMarket​(java.lang.String mm)
        Parses DenseVector from the given Matrix Market string.
        Parameters:
        mm - the string in Matrix Market format
        Returns:
        a parsed vector
      • fromCollection

        public static DenseVector fromCollection​(java.util.Collection<? extends java.lang.Number> list)
        Creates new DenseVector from
        Parameters:
        list - list containing doubles
        Returns:
        new vector from given double list
      • fromMap

        public static DenseVector fromMap​(java.util.Map<java.lang.Integer,​? extends java.lang.Number> map,
                                          int length)
        Creates new DenseVector from index-value map
        Parameters:
        map - index-value map
        length - vector length
        Returns:
        created vector
      • apply

        public <T> T apply​(VectorOperation<T> operation)
        Description copied from class: Vector
        Pipes this vector to a given operation.
        Specified by:
        apply in class Vector
        Type Parameters:
        T - the result type
        Parameters:
        operation - the vector operation (an operation that take vector and returns T)
        Returns:
        the result of an operation applied to this vector
      • apply

        public <T> T apply​(VectorVectorOperation<T> operation,
                           Vector that)
        Description copied from class: Vector
        Pipes this vector to a given operation.
        Specified by:
        apply in class Vector
        Type Parameters:
        T - the result type
        Parameters:
        operation - the vector-vector operation (an operation that takes two vectors and returns T)
        that - the right hand vector for the given operation
        Returns:
        the result of an operation applied to this and that vector
      • apply

        public <T> T apply​(VectorMatrixOperation<T> operation,
                           Matrix that)
        Description copied from class: Vector
        Pipes this vector to a given operation.
        Specified by:
        apply in class Vector
        Type Parameters:
        T - the result type
        Parameters:
        operation - the vector-matrix operation (an operation that takes vector and matrix and returns T)
        that - the right hand matrix for the given operation
        Returns:
        the result of an operation applied to this vector and that matrix
      • toArray

        public abstract double[] toArray()
        Converts this dense vector to a double array.
        Returns:
        an array representation of this vector
      • toRowMatrix

        public Matrix toRowMatrix()
        Description copied from class: Vector
        Converts this vector to matrix with only one row.
        Specified by:
        toRowMatrix in class Vector
        Returns:
        the row matrix
      • toColumnMatrix

        public Matrix toColumnMatrix()
        Description copied from class: Vector
        Converts this vector to matrix with only one column.
        Specified by:
        toColumnMatrix in class Vector
        Returns:
        the column matrix
      • toDiagonalMatrix

        public Matrix toDiagonalMatrix()
        Description copied from class: Vector
        Converts this vector to a diagonal matrix.
        Specified by:
        toDiagonalMatrix in class Vector
        Returns:
        a diagonal matrix
      • toMatrixMarket

        public java.lang.String toMatrixMarket​(java.text.NumberFormat formatter)
        Description copied from class: Vector
        Converts this vector into the string in Matrix Market format using the given formatter;
        Specified by:
        toMatrixMarket in class Vector
        Parameters:
        formatter - the number formater
        Returns:
        a Matrix Market string representing this vector