Documentation of 'mikera.vectorz.impl.ZeroVector' Java class
ZeroVector
mikera.vectorz.impl

Class ZeroVector

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<java.lang.Double>, INDArray, ISparse, ISparseVector, IVector


    public final class ZeroVector
    extends ASparseVector
    Specialised immutable vector containing nothing but zeros. This enables significant optimisations on operations involving zeros and composite arrays that have zero areas. Must have length 1 or more: use Vector0 instead for immutable length 0 vectors.
    See Also:
    Serialized Form
    • Method Detail

      • create

        public static ZeroVector create(int dimensions)
        Create a ZeroVector with the specified number of dimensions
        Parameters:
        dimensions -
        Returns:
      • createNew

        public static ZeroVector createNew(int dimensions)
      • createCached

        public static ZeroVector createCached(int dimensions)
      • create

        public static ZeroVector create(INDArray array)
        Creates a ZeroVector with the same number of elements as the given array.
        Parameters:
        arraySize -
        Returns:
      • dotProduct

        public double dotProduct(AVector v)
        Description copied from class: AVector
        Returns the dot product of this vector with another vector The vectors must have the same length: if not the result is undefined
        Specified by:
        dotProduct in class ASparseVector
        Returns:
      • 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
        Specified by:
        dotProduct in class AVector
      • innerProduct

        public AVector innerProduct(AMatrix m)
        Description copied from class: AVector
        Computes the inner product of this vector with a matrix
        Overrides:
        innerProduct in class ASparseVector
        Returns:
        a vector representing the inner product
      • 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 AVector
      • 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 AVector
      • setSparse

        public void setSparse(double value)
        Description copied from interface: INDArray
        Sets the non-sparse elements of this array to the specified value May throw an exception if non-sparse elements are not mutable
        Specified by:
        setSparse in interface INDArray
        Overrides:
        setSparse in class AVector
      • 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
        Overrides:
        unsafeGet in class AVector
      • 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
        Overrides:
        unsafeSet in class AVector
      • addSparse

        public void addSparse(AVector v)
        Description copied from class: AVector
        Adds the corresponding elements of the source vector to the non-sparse elements of this vector
        Overrides:
        addSparse in class AVector
      • addCopy

        public AVector addCopy(AVector a)
        Description copied from interface: IVector
        Adds a vector element-wise to this vector, returning a new vector.
        Specified by:
        addCopy in interface IVector
        Overrides:
        addCopy in class AVector
        Returns:
      • addCopy

        public AVector addCopy(double a)
        Description copied from interface: INDArray
        Creates a new array equal to this array with a constant value added to every element
        Specified by:
        addCopy in interface INDArray
        Overrides:
        addCopy in class AVector
        Returns:
      • subCopy

        public AVector subCopy(AVector a)
        Description copied from interface: IVector
        Subtracts a vector element-wise from this vector, returning a new vector.
        Specified by:
        subCopy in interface IVector
        Overrides:
        subCopy in class AVector
        Returns:
      • absCopy

        public ZeroVector absCopy()
        Description copied from interface: INDArray
        Returns a copy of the array with the abs operator applied to each element
        Specified by:
        absCopy in interface INDArray
        Overrides:
        absCopy in class AVector
        Returns:
        A new array containing the absolute element values
      • multiply

        public void multiply(AVector a)
        Description copied from class: AVector
        Multiplies this vector by another vector, elementwise.
        Overrides:
        multiply 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 AVector
        Parameters:
        factor - Factor by which to multiply each component of the vector
      • multiplyCopy

        public ZeroVector 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
      • normaliseCopy

        public AVector normaliseCopy()
        Description copied from class: AVector
        Returns a copy of this vector normalised to a Euclidean length of 1.0 Has no effect on a zero-length vector (i.e. it will return a zero length vector)
        Specified by:
        normaliseCopy in interface IVector
        Overrides:
        normaliseCopy in class AVector
        Returns:
      • magnitude

        public double magnitude()
        Description copied from class: AVector
        Returns the magnitude (Euclidean length) of the vector
        Overrides:
        magnitude in class AVector
        Returns:
      • 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 AVector
      • 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 AVector
      • maxElementIndex

        public int maxElementIndex()
        Description copied from class: AVector
        Returns the index of the maximum element of a vector
        Overrides:
        maxElementIndex in class AVector
        Returns:
      • maxAbsElement

        public double maxAbsElement()
        Description copied from class: AVector
        Returns the maximum absolute element value of a vector
        Overrides:
        maxAbsElement in class AVector
        Returns:
      • maxAbsElementIndex

        public int maxAbsElementIndex()
        Description copied from class: AVector
        Returns the index of the maximum absolute element of a vector
        Overrides:
        maxAbsElementIndex in class AVector
        Returns:
      • minElementIndex

        public int minElementIndex()
        Description copied from class: AVector
        Returns the index of the minimum element of a vector
        Overrides:
        minElementIndex in class AVector
      • nonZeroValues

        public double[] nonZeroValues()
        Description copied from class: AVector
        Return an double array specifying the values in this vector which are non-zero
        Overrides:
        nonZeroValues in class AVector
        Returns:
      • isZero

        public boolean isZero()
        Description copied from class: AVector
        Returns true if this vector is a zero vector (all components zero)
        Specified by:
        isZero in interface INDArray
        Overrides:
        isZero in class ASparseVector
      • isRangeZero

        public boolean isRangeZero(int start,
                                   int length)
        Description copied from class: AVector
        Returns true if a sub-vector range is completely zero. Unsafe operation - does not perform bounds checking, results are undefined if sub-vector is out of range
        Overrides:
        isRangeZero in class AVector
        Returns:
      • isBoolean

        public boolean isBoolean()
        Description copied from interface: INDArray
        Returns true if the array is boolean (contains only 0.0 or 1.0 values)
        Specified by:
        isBoolean in interface INDArray
        Overrides:
        isBoolean in class AbstractArray<java.lang.Double>
      • isMutable

        public boolean isMutable()
        Description copied from class: AVector
        Returns true if this vector is mutable.
        Specified by:
        isMutable in interface INDArray
        Overrides:
        isMutable in class AVector
      • isFullyMutable

        public boolean isFullyMutable()
        Description copied from class: AVector
        Returns true if this vector is fully mutable, i.e. can contain any unconstrained double values
        Specified by:
        isFullyMutable in interface INDArray
        Overrides:
        isFullyMutable in class AVector
      • isUnitLengthVector

        public boolean isUnitLengthVector()
        Description copied from class: AVector
        Returns true if the vector has unit length
        Overrides:
        isUnitLengthVector in class AVector
        Returns:
      • reduce

        public double reduce(Op2 op,
                             double init)
        Description copied from interface: INDArray
        Reduces over all elements of the array in row-major order. Applies the operator to the initial/previous result at each step. Returns the final result.
        Specified by:
        reduce in interface INDArray
        Overrides:
        reduce in class ASparseVector
      • reduce

        public double reduce(Op2 op)
        Description copied from interface: INDArray
        Reduces over all elements of the array in row-major order. Applies the operator to the previous result at each step. Returns the final result.
        Specified by:
        reduce in interface INDArray
        Overrides:
        reduce in class ASparseVector
      • addToArray

        public void addToArray(int offset,
                               double[] array,
                               int arrayOffset,
                               int length)
        Description copied from class: AVector
        Adds a subvector of this vector into a double array at the specified offset
        Overrides:
        addToArray in class AVector
      • copyTo

        public void copyTo(int offset,
                           double[] dest,
                           int destOffset,
                           int length,
                           int stride)
        Description copied from class: AVector
        Copies a subset of this vector to a specified destination array offset using the given stride. Unsafe operation: performs no bounds checking
        Overrides:
        copyTo in class ASparseVector
      • addToArray

        public void addToArray(double[] dest,
                               int offset,
                               int stride)
        Description copied from class: AVector
        Adds this vector to a double[] array, using the specified offset and stride into the destination array
        Overrides:
        addToArray in class AVector
      • addMultipleToArray

        public void addMultipleToArray(double factor,
                                       int offset,
                                       double[] array,
                                       int arrayOffset,
                                       int length)
        Description copied from class: AVector
        Adds a multiple of a subvector of this vector into a double array at the specified offset
        Overrides:
        addMultipleToArray in class AVector
      • slice

        public final ImmutableScalar slice(int i)
        Description copied from interface: INDArray
        Returns the specified major slice of this array as a view (slice along dimension 0) 0 dimensional slice results are permitted, but attempting to slice a 0 dimensional array will result in an error.
        Specified by:
        slice in interface INDArray
        Overrides:
        slice in class AVector
      • iterator

        public java.util.Iterator<java.lang.Double> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Double>
        Overrides:
        iterator in class AVector
      • density

        public double density()
        Description copied from interface: ISparse
        Computes the density ratio of this sparse array (proportion of non-zero elements)
        Specified by:
        density in interface ISparse
        Overrides:
        density in class ASparseVector
        Returns:
      • subVector

        public AVector subVector(int offset,
                                 int length)
        Description copied from class: AVector
        Obtains a sub-vector view that refers to this vector. Changes to the sub-vector will be reflected in this vector
        Overrides:
        subVector in class AVector
      • tryEfficientJoin

        public AVector tryEfficientJoin(AVector a)
        Description copied from class: AVector
        Attempts to perform an efficient join with a second vector. An efficient join is guaranteed to be better than a simple JoinedVector(left,right) If possible, returns the joined vector. If not, returns null
        Overrides:
        tryEfficientJoin in class AVector
      • select

        public AVector select(int... order)
        Description copied from class: AVector
        Selects a subset of indices from a vector
        Overrides:
        select in class AVector
        Returns:
      • nonSparseElementCount

        public int nonSparseElementCount()
        Description copied from class: ASparseVector
        Returns the number of non-sparse elements in the sparse vector. This will be greater or equal to the number of non-zero elements
        Specified by:
        nonSparseElementCount in class ASparseVector
        Returns:
      • nonSparseIndex

        public Index nonSparseIndex()
        Description copied from class: AVector
        Returns an Index indicating which elements of this vector are defined as non-sparse. A sparse index must be zero. A non-sparse element may be zero, but is typically expected be non-zero.
        Specified by:
        nonSparseIndex in interface ISparseVector
        Specified by:
        nonSparseIndex in class ASparseVector
        Returns:
      • nonZeroIndices

        public int[] nonZeroIndices()
        Description copied from class: AVector
        Return an int array specifying the positions in this vector which are non-zero
        Overrides:
        nonZeroIndices in class AVector
        Returns:
      • includesIndex

        public boolean includesIndex(int i)
        Description copied from class: ASparseVector
        Returns true iff the sparse vector contains the index i
        Specified by:
        includesIndex in class ASparseVector
        Returns:
      • 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 ZeroVector 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
      • getElements

        public void getElements(double[] dest,
                                int offset)
        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 AVector
      • getElements

        public void getElements(java.lang.Object[] dest,
                                int offset)
        Description copied from interface: INDArray
        Copies all elements of this array into an object array at the specified offset
        Specified by:
        getElements in interface INDArray
        Overrides:
        getElements in class AVector
      • selectClone

        public AVector selectClone(int... inds)
        Description copied from class: AVector
        Selects a subset of indices from a vector, returning a mutable clone of data
        Overrides:
        selectClone in class AVector
        Returns:
        a new mutable vector containing the selected indices
      • selectView

        public AVector selectView(int... inds)
        Description copied from class: AVector
        Selects a subset of indices from a vector, returning a view
        Overrides:
        selectView in class AVector
        Returns:
        a view of the selected indices
      • equals

        public boolean equals(AVector v)
        Description copied from class: AbstractArray
        Returns true if this array is exactly equal to a vector.
        Overrides:
        equals in class ASparseVector
        Returns:
      • equalsArray

        public boolean equalsArray(double[] data,
                                   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 ASizedVector
        Parameters:
        data - Array of double element values to check for equality
        offset - Offset into the data array
        Returns:
      • elementsEqual

        public boolean elementsEqual(double value)
        Description copied from interface: INDArray
        Returns true if all elements are equal to a specific value
        Specified by:
        elementsEqual in interface INDArray
        Overrides:
        elementsEqual in class AVector
      • hasUncountable

        public boolean hasUncountable()
        Description copied from class: AbstractArray
        Returns true if any element is this array is NaN or infinite
        Specified by:
        hasUncountable in interface INDArray
        Overrides:
        hasUncountable in class ASparseVector
        Returns:
        True if any element is this array is NaN or infinite, false otherwise
      • dotProduct

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

        public double visitNonZero(IndexedElementVisitor elementVisitor)
        Description copied from class: AVector
        Visits all non-zero elements of this vector. Visitor may return a non-zero value to terminate early, which will return the given value. Returns 0.0 otherwise.
        Overrides:
        visitNonZero in class ASparseVector

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.