Class BasicVector

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.Double>

    public class BasicVector
    extends DenseVector
    A basic dense vector implementation using an array. A dense data structure stores data in an underlying array. Even 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. BasicVector stores the underlying data in a standard array.
    • Field Detail

      • self

        private double[] self
    • Constructor Detail

      • BasicVector

        public BasicVector()
      • BasicVector

        public BasicVector​(int length)
      • BasicVector

        public BasicVector​(double[] array)
    • Method Detail

      • constant

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

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

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

        public static BasicVector fromBinary​(byte[] array)
        Decodes BasicVector from the given byte array.
        Parameters:
        array - the byte array representing a vector
        Returns:
        a decoded vector
      • fromCSV

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

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

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

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

        public double get​(int i)
        Description copied from class: Vector
        Gets the specified element of this vector.
        Specified by:
        get in class Vector
        Parameters:
        i - element's index
        Returns:
        the element of this vector
      • set

        public void set​(int i,
                        double value)
        Description copied from class: Vector
        Sets the specified element of this matrix to given value.
        Specified by:
        set in class Vector
        Parameters:
        i - element's index
        value - element's new value
      • swapElements

        public void swapElements​(int i,
                                 int j)
        Description copied from class: Vector
        Swaps the specified elements of this vector.
        Overrides:
        swapElements in class Vector
        Parameters:
        i - element's index
        j - element's index
      • copyOfLength

        public Vector copyOfLength​(int length)
        Description copied from class: Vector
        Copies this vector into the new vector with specified length.
        Specified by:
        copyOfLength in class Vector
        Parameters:
        length - the length of new vector
        Returns:
        the copy of this vector with new length
      • toArray

        public double[] toArray()
        Description copied from class: DenseVector
        Converts this dense vector to a double array.
        Specified by:
        toArray in class DenseVector
        Returns:
        an array representation of this vector
      • to

        public <T extends Vector> T to​(VectorFactory<T> factory)
        Description copied from class: Vector
        Converts this vector using the given factory.
        Overrides:
        to in class Vector
        Type Parameters:
        T - type of the result vector
        Parameters:
        factory - the factory that creates an output vector
        Returns:
        a converted vector
      • blankOfLength

        public Vector blankOfLength​(int length)
        Description copied from class: Vector
        Creates a blank (an empty vector) copy of this vector with the given length.
        Specified by:
        blankOfLength in class Vector
        Parameters:
        length - the length of the blank vector
        Returns:
        blank vector
      • toBinary

        public byte[] toBinary()
        Description copied from class: Vector
        Encodes this vector into a byte array.
        Specified by:
        toBinary in class Vector
        Returns:
        a byte array representing this vector