Documentation of 'mikera.vectorz.Vector' Java class
Vector
mikera.vectorz

Class Vector

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<java.lang.Double>, IDense, IDenseArray, IStridedArray, INDArray, IVector


    public final class Vector
    extends ADenseArrayVector
    General purpose vector of arbitrary length, backed by an densely packed double[] array. This is the most efficient type for general purpose dense 1D vectors.
    See Also:
    Serialized Form
    • Field Detail

      • EMPTY

        public static final Vector EMPTY
    • Constructor Detail

      • Vector

        public Vector(AVector source)
        Copy constructor from an arbitrary vector
        Parameters:
        source -
    • Method Detail

      • wrap

        public static Vector wrap(double[] source)
        Wraps a double array into a Vector, does *no defensive copy* so use with caution
        Parameters:
        source -
        Returns:
      • create

        public static Vector create(double[] data)
        Creates a new Vector from the given double[] data. Takes a defensive copy.
      • create

        public static Vector create(java.util.ArrayList<java.lang.Number> al)
      • create

        public static Vector create(java.util.List<java.lang.Number> al)
      • create

        public static Vector create(java.lang.Iterable<java.lang.Number> iterable)
        Creates a Vector from the specified Iterable object
        Parameters:
        iterable - An Iterable containing java.lang.Number instances
        Returns:
      • create

        public static Vector create(java.util.Iterator<java.lang.Number> iterator)
        Creates a Vector from the specified Iterator object
        Parameters:
        iterator - An Iterator over java.lang.Number instances
        Returns:
      • create

        public static Vector create(java.lang.Object o)
      • create

        public static Vector create(double[] data,
                                    int start,
                                    int length)
        Creates a new Vector from the given double[] data. Takes a defensive copy.
      • createFromVector

        public static Vector createFromVector(AVector source,
                                              int length)
        Creates a new vector using the elements in the specified vector. Truncates or zero-pads the data as required to fill the new vector
        Parameters:
        data -
        Returns:
      • of

        public static Vector of(double... values)
        Create a vector with specific component values. Creates a copy of the value array
        Parameters:
        values -
        Returns:
      • createLength

        public static Vector createLength(int length)
        Create an empty (zero-filled) vector of a specified length
        Parameters:
        length -
        Returns:
      • get

        public double get(int i)
        Description copied from interface: INDArray
        Returns the double value at the specified position in a 1D vector
        Specified by:
        get in interface INDArray
        Specified by:
        get in interface IVector
        Specified by:
        get in class ADenseArrayVector
      • unsafeGet

        public double unsafeGet(int i)
        Description copied from class: AVector
        Like get, but performs no bounds checking. Results are undefined if the index is out of range
        Specified by:
        unsafeGet in class ADenseArrayVector
      • set

        public void set(int i,
                        double value)
        Description copied from interface: INDArray
        Sets a value at a given position in a mutable 1D array
        Specified by:
        set in interface INDArray
        Specified by:
        set in interface IVector
        Specified by:
        set in class ADenseArrayVector
      • unsafeSet

        public void unsafeSet(int i,
                              double value)
        Description copied from class: AVector
        Like set, but performs no bounds checking. Results are undefined if the index is out of range
        Specified by:
        unsafeSet in class ADenseArrayVector
      • set

        public void set(AVector a)
        Description copied from class: AVector
        Sets the vector to equal the value of another vector
        Overrides:
        set in class ADenseArrayVector
      • getElements

        public void getElements(double[] data,
                                int offset,
                                int[] indices)
        Description copied from class: AVector
        Gets the elements in this vector from the specified indices, storing at the specified offset in the destination array
        Overrides:
        getElements in class AStridedVector
      • applyOp

        public void applyOp(Op op)
        Description copied from interface: INDArray
        Applies a unary operator to all elements of the array (in-place)
        Specified by:
        applyOp in interface INDArray
        Specified by:
        applyOp in class AStridedVector
      • fill

        public void fill(double value)
        Description copied from class: AVector
        Fills the entire vector with a given value
        Specified by:
        fill in interface INDArray
        Overrides:
        fill in class ADenseArrayVector
      • clamp

        public void clamp(double min,
                          double max)
        Description copied from class: AVector
        Clamps all values in the vector to a given range
        Specified by:
        clamp in interface INDArray
        Overrides:
        clamp in class ADenseArrayVector
      • tanh

        public void tanh()
        Description copied from class: AVector
        Computes the tanh of every element in this vector. Mutates this vector.
        Overrides:
        tanh in class AVector
      • logistic

        public void logistic()
        Description copied from class: AVector
        Computes the logistic function for every element in this vector. Mutates this vector.
        Overrides:
        logistic in class AVector
      • elementMax

        public double elementMax()
        Description copied from interface: INDArray
        Returns the maximum element value in this array. Throws an error if there are no elements.
        Specified by:
        elementMax in interface INDArray
        Overrides:
        elementMax in class ADenseArrayVector
      • elementMin

        public double elementMin()
        Description copied from interface: INDArray
        Returns the maximum element value in this array. Throws an error if there are no elements.
        Specified by:
        elementMin in interface INDArray
        Overrides:
        elementMin in class ADenseArrayVector
      • signum

        public void signum()
        Description copied from interface: INDArray
        Calculates the signum of all elements of this mutable array Sets each component of the array to its sign value (-1, 0 or 1)
        Specified by:
        signum in interface INDArray
        Overrides:
        signum in class ADenseArrayVector
      • abs

        public void abs()
        Description copied from interface: INDArray
        Replaces all elements of this array with their absolute values, according to Math.abs(double)
        Specified by:
        abs in interface INDArray
        Overrides:
        abs in class AVector
      • add

        public void add(double[] srcData,
                        int srcOffset)
        Description copied from class: AVector
        Adds to this vector from a given double array.
        Overrides:
        add in class ADenseArrayVector
      • scaleAdd

        public void scaleAdd(double factor,
                             double constant)
        Description copied from class: AVector
        Scales this vector and adds a constant to every element
        Specified by:
        scaleAdd in interface INDArray
        Overrides:
        scaleAdd in class ADenseArrayVector
      • add

        public void add(double constant)
        Description copied from interface: INDArray
        Adds a double value to all elements in this array. Implementations may optimize the case of 0.0
        Specified by:
        add in interface INDArray
        Overrides:
        add in class ADenseArrayVector
      • addProduct

        public void addProduct(Vector a,
                               Vector b,
                               double factor)
      • addAt

        public void addAt(int i,
                          double v)
        Description copied from class: AVector
        Adds a value to a specific element of the vector This function does not perform bounds checking, i.e. is an unsafe operation
        Specified by:
        addAt in class AStridedVector
      • sub

        public void sub(AVector v)
        Description copied from class: AVector
        Subtracts a vector from this vector
        Overrides:
        sub in class AVector
      • dotProduct

        public double dotProduct(AVector v,
                                 Index ix)
        Description copied from class: AVector
        Returns the dotProduct of this vector with the elements of another vector mapped to specified indexes in this vector.
        Overrides:
        dotProduct in class AVector
        Returns:
      • dotProduct

        public double dotProduct(Vector v,
                                 Index ix)
      • dotProduct

        public double dotProduct(double[] data,
                                 int offset)
        Description copied from class: AVector
        Fast dot product with a double[] array. Performs no bounds checking. Likely to be faster than most other dot product operations
        Overrides:
        dotProduct in class ADenseArrayVector
      • multiplyCopy

        public Vector multiplyCopy(double factor)
        Description copied from interface: INDArray
        Returns a copy of the array with all elements multiplied by a single constant value
        Specified by:
        multiplyCopy in interface INDArray
        Overrides:
        multiplyCopy in class AVector
        Parameters:
        factor - A scalar factor
        Returns:
        A new array, with all element values scaled by the given factor
      • distanceSquared

        public double distanceSquared(Vector v)
      • distance

        public double distance(AVector v)
        Description copied from class: AVector
        Returns the Euclidean distance to another vector.
        Overrides:
        distance in class AVector
        Returns:
      • addMultiple

        public void addMultiple(AVector v,
                                double factor)
        Description copied from class: AVector
        Adds a scaled multiple of another vector to this vector
        Overrides:
        addMultiple in class ADenseArrayVector
      • addMultiple

        public void addMultiple(Vector source,
                                Index index,
                                double factor)
        Description copied from class: AVector
        Adds source vector to this vector at the specified indexes which should map from source->this
        Overrides:
        addMultiple in class AVector
      • multiply

        public void multiply(double factor)
        Description copied from class: AVector
        Multiplies the vector by a constant factor
        Specified by:
        multiply in interface INDArray
        Overrides:
        multiply in class ADenseArrayVector
        Parameters:
        factor - Factor by which to multiply each component of the vector
      • multiply

        public void multiply(Vector v)
      • divide

        public void divide(Vector v)
        Performance Override for divide
      • divide

        public void divide(double factor)
        Description copied from interface: INDArray
        Divides all elements by a given factor
        Specified by:
        divide in interface INDArray
        Overrides:
        divide in class AVector
      • isView

        public boolean isView()
        Description copied from class: AVector
        Returns true if this vector is of a view type that references other vectors / data.
        Specified by:
        isView in interface INDArray
        Overrides:
        isView in class ADenseArrayVector
      • clone

        public Vector clone()
        Description copied from class: AVector
        Clones the vector, creating a new mutable copy of all data. The clone is: - not guaranteed to be of the same type. - guaranteed to be fully mutable - guaranteed not to contain a reference (i.e. is a full deep copy)
        Specified by:
        clone in interface INDArray
        Specified by:
        clone in interface IVector
        Overrides:
        clone in class AStridedVector
      • hashCode

        public int hashCode()
        Description copied from class: AVector
        Computes the hashcode of a vector. Currently defined to be equal to List.hashCode for a equivalent list of Double values, this may change in future versions.
        Overrides:
        hashCode in class AVector
      • exactClone

        public Vector exactClone()
        Description copied from class: AVector
        Returns an exact clone of this vector, i.e. of the same type
        Specified by:
        exactClone in interface INDArray
        Specified by:
        exactClone in class AVector
        Returns:
        A clone of the original array
      • toNormal

        public Vector toNormal()
        Description copied from class: AVector
        Creates a new mutable vector representing the normalised value of this vector Returns null if the vector cannot be normalised (i.e. is a zero length vector)
        Overrides:
        toNormal in class AVector
        Returns:
      • toVector

        public Vector toVector()
        Description copied from class: AVector
        Coerces this vector to the standard dense Vector format. May return the same vector is this is already a dense Vector, otherwise returns a Vector containing a new clone of the vector elements.
        Specified by:
        toVector in interface INDArray
        Overrides:
        toVector in class AVector
      • asDoubleArray

        public double[] asDoubleArray()
        Description copied from interface: INDArray
        Returns the underlying double array representing the densely packed elements of this array. Modifications to this double array will change the original array. Returns null if there is no such array.
        Specified by:
        asDoubleArray in interface INDArray
        Overrides:
        asDoubleArray in class AStridedVector
      • dense

        public Vector dense()
        Description copied from interface: INDArray
        Coerces this INDArray to a dense format, without changing its element values. May return the same INDArray if already dense. May also mutate the internal structure of the original NDArray, or create a view over parts of the original INDArray. You should take a defensive copy of the original NDArray if any of this concerns you. The returned dense array may not be fully mutable in all elements.
        Specified by:
        dense in interface INDArray
        Overrides:
        dense in class ADenseArrayVector
      • equalsArray

        public boolean equalsArray(double[] arr,
                                   int offset)
        Description copied from class: AVector
        Returns true if this vector exactly matches the elements in double[] array, starting from the specified offset
        Specified by:
        equalsArray in interface INDArray
        Overrides:
        equalsArray in class ADenseArrayVector
        Parameters:
        arr - Array of double element values to check for equality
        offset - Offset into the data array
        Returns:
      • setElements

        public void setElements(double[] values,
                                int offset)
        Description copied from interface: INDArray
        Sets all elements in an array using the given double values
        Specified by:
        setElements in interface INDArray
        Specified by:
        setElements in class AStridedVector
        Parameters:
        values - Element values in a double[] array. There must be at least as many element values as elements in this array.
        offset - Position in the values array from which to start taking values.
      • getElements

        public void getElements(double[] dest,
                                int destOffset)
        Description copied from interface: INDArray
        Copies all elements of this array a double array at the specified offset
        Specified by:
        getElements in interface INDArray
        Overrides:
        getElements in class ADenseArrayVector

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.