org.apache.ignite.ml.math.primitives.vector.impl

## Class DelegatingVector

- java.lang.Object
- - org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector

- All Implemented Interfaces:
    Externalizable, Serializable, Destroyable, MetaAttributes, Vector, StorageOpsMetrics
  Direct Known Subclasses:
    DelegatingNamedVector

      public class DelegatingVector
      extends Object
      implements Vector

  Convenient class that can be used to add decorations to an existing vector. Subclasses can add weights, indices, etc. while maintaining full vector functionality.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.apache.ignite.ml.math.primitives.vector.Vector

      `Vector.Element`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DelegatingVector()`
    `DelegatingVector(Vector dlg)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Iterable<Vector.Element>` | `all()` Gets iterator over all elements in this vector.
    `Spliterator<Double>` | `allSpliterator()` Gets spliterator for all values in this vector.
    `Vector` | `assign(double val)` Assigns given value to all elements of this vector.
    `Vector` | `assign(double[] vals)` Assigns values from given array to this vector.
    `Vector` | `assign(IntToDoubleFunction fun)` Assigns each vector element to the value generated by given function.
    `Vector` | `assign(Vector vec)` Copies values from the argument vector to this one.
    `void` | `compute(int i, IgniteIntDoubleToDoubleBiFunction f)` Replace vector entry with value oldVal at i with result of computing f(i, oldVal).
    `Vector` | `copy()` Creates new copy of this vector.
    `Vector` | `copyOfRange(int from, int to)` Copies the specified range of the vector into a new vector.
    `Matrix` | `cross(Vector vec)` Gets the cross product of this vector and the other vector.
    `void` | `destroy()` Destroys object if managed outside of JVM.
    `Vector` | `divide(double x)` Creates new vector containing values from this vector divided by the argument.
    `double` | `dot(Vector vec)` Gets dot product of two vectors.
    `boolean` | `equals(Object o)`
    `<T> T` | `foldMap(IgniteBiFunction<T,Double,T> foldFun, IgniteDoubleFunction<Double> mapFun, T zeroVal)` Folds this vector into a single value.
    `<T> T` | `foldMap(Vector vec, IgniteBiFunction<T,Double,T> foldFun, IgniteBiFunction<Double,Double,Double> combFun, T zeroVal)` Combines & maps two vector and folds them into a single value.
    `double` | `get(int idx)` Gets the value at specified index.
    `double` | `getDistanceSquared(Vector vec)` Get the square of the distance between this vector and the argument vector.
    `Vector.Element` | `getElement(int idx)` Gets element at the given index.
    `double` | `getLengthSquared()` Gets the sum of squares of all elements in this vector.
    `Map<String,Object>` | `getMetaStorage()` Implementation should return an instance of the map to store meta attributes.
    `<T extends Serializable> T` | `getRaw(int idx)` Gets the value at specified index.
    `<T extends Serializable> T` | `getRawX(int idx)` Gets the value at specified index without checking for index boundaries.
    `VectorStorage` | `getStorage()` Gets vector storage model.
    `Vector` | `getVector()` Get the delegating vector
    `double` | `getX(int idx)` Gets the value at specified index without checking for index boundaries.
    `IgniteUuid` | `guid()` Auto-generated globally unique vector ID.
    `int` | `hashCode()`
    `Vector` | `increment(int idx, double val)` Increments value at given index.
    `Vector` | `incrementX(int idx, double val)` Increments value at given index without checking for index boundaries.
    `boolean` | `isArrayBased()` Checks if implementation is based on Java arrays.
    `boolean` | `isDense()` Checks if this implementation should be considered dense so that it explicitly represents every value.
    `boolean` | `isNumeric()`
    `double` | `kNorm(double power)` Gets the k-norm of the vector.
    `Vector` | `like(int crd)` Creates new empty vector of the same underlying class but of different cardinality.
    `Matrix` | `likeMatrix(int rows, int cols)` Creates new matrix of compatible flavor with given size.
    `Vector` | `logNormalize()` Creates new vector containing the `log(1 + entry) / L_2 norm` values of this vector.
    `Vector` | `logNormalize(double power)` Creates new vector with a normalized value calculated as `log_power(1 + entry) / L_power norm`.
    `Vector` | `map(IgniteBiFunction<Double,Double,Double> fun, double y)` Maps all elements of this vector by applying given function to each element with a constant second parameter `y`.
    `Vector` | `map(IgniteDoubleFunction<Double> fun)` Maps all values in this vector through a given function.
    `Vector` | `map(Vector vec, IgniteBiFunction<Double,Double,Double> fun)` Maps all values in this vector through a given function.
    `Vector.Element` | `maxElement()` Gets maximum element in this vector.
    `double` | `maxValue()` Gets maximum value in this vector.
    `Vector.Element` | `minElement()` Gets minimal element in this vector.
    `Vector` | `minus(Vector vec)` Creates new vector containing element by element difference between this vector and the argument one.
    `double` | `minValue()` Gets minimal value in this vector.
    `int` | `nonZeroElements()` Gets number of non-zero elements in this vector.
    `Iterable<Vector.Element>` | `nonZeroes()` Iterates ove all non-zero elements in this vector.
    `Spliterator<Double>` | `nonZeroSpliterator()` Gets spliterator for all non-zero values in this vector.
    `Vector` | `normalize()` Creates new vector containing the normalized (L_2 norm) values of this vector.
    `Vector` | `normalize(double power)` Creates new vector containing the normalized (L_power norm) values of this vector.
    `Vector` | `plus(double x)` Creates new vector containing sum of each element in this vector and argument.
    `Vector` | `plus(Vector vec)` Creates new vector containing element by element sum from both vectors.
    `void` | `readExternal(ObjectInput in)`
    `Vector` | `set(int idx, double val)` Sets value.
    `Vector` | `setRaw(int idx, Serializable val)` Sets value.
    `Vector` | `setRawX(int idx, Serializable val)` Sets value without checking for index boundaries.
    `Vector` | `setX(int idx, double val)` Sets value without checking for index boundaries.
    `int` | `size()` Gets cardinality of this vector (maximum number of the elements).
    `Vector` | `sort()` Sorts this vector in ascending order.
    `double` | `sum()` Gets the sum of all elements in this vector.
    `Vector` | `times(double x)` Gets a new vector that contains product of each element and the argument.
    `Vector` | `times(Vector vec)` Gets a new vector that is an element-wie product of this vector and the argument.
    `Matrix` | `toMatrix(boolean rowLike)` Converts this vector into [N x 1] or [1 x N] matrix where N is this vector cardinality.
    `Matrix` | `toMatrixPlusOne(boolean rowLike, double zeroVal)` Converts this vector into [N+1 x 1] or [1 x N+1] matrix where N is this vector cardinality
    `Vector` | `viewPart(int off, int len)`
    `void` | `writeExternal(ObjectOutput out)`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.ignite.ml.math.primitives.vector.Vector

      `asArray, labeled`

    - ### Methods inherited from interface org.apache.ignite.ml.math.MetaAttributes

      `getAttribute, hasAttribute, removeAttribute, setAttribute`

- - ### Constructor Detail

    - #### DelegatingVector

          public DelegatingVector()

    - #### DelegatingVector

          public DelegatingVector(Vector dlg)

      Parameters:
        `dlg` - Parent vector.

  - ### Method Detail

    - #### getVector

          public Vector getVector()

      Get the delegating vector

    - #### writeExternal

          public void writeExternal(ObjectOutput out)
                             throws IOException

      Specified by:
        `writeExternal` in interface `Externalizable`
      Throws:
        `IOException`

    - #### readExternal

          public void readExternal(ObjectInput in)
                            throws IOException,
                                   ClassNotFoundException

      Specified by:
        `readExternal` in interface `Externalizable`
      Throws:
        `IOException`
        `ClassNotFoundException`

    - #### getMetaStorage

          public Map<String,Object> getMetaStorage()

      Implementation should return an instance of the map to store meta attributes.
      Specified by:
        `getMetaStorage` in interface `MetaAttributes`

    - #### likeMatrix

          public Matrix likeMatrix(int rows,
                                   int cols)

      Creates new matrix of compatible flavor with given size.
      Specified by:
        `likeMatrix` in interface `Vector`
      Parameters:
        `rows` - Number of rows.
        `cols` - Number of columns.
      Returns:
        New matrix.

    - #### toMatrix

          public Matrix toMatrix(boolean rowLike)

      Converts this vector into [N x 1] or [1 x N] matrix where N is this vector cardinality.
      Specified by:
        `toMatrix` in interface `Vector`
      Parameters:
        `rowLike` - `true` for rowLike [N x 1], or `false` for column [1 x N] matrix.
      Returns:
        Newly created matrix.

    - #### toMatrixPlusOne

          public Matrix toMatrixPlusOne(boolean rowLike,
                                        double zeroVal)

      Converts this vector into [N+1 x 1] or [1 x N+1] matrix where N is this vector cardinality. (0,0) element of this matrix will be `zeroVal` parameter.
      Specified by:
        `toMatrixPlusOne` in interface `Vector`
      Parameters:
        `rowLike` - `true` for rowLike [N+1 x 1], or `false` for column [1 x N+1] matrix.
      Returns:
        Newly created matrix.

    - #### size

          public int size()

      Gets cardinality of this vector (maximum number of the elements).
      Specified by:
        `size` in interface `Vector`
      Returns:
        This vector's cardinality.

    - #### isDense

          public boolean isDense()

      Checks if this implementation should be considered dense so that it explicitly represents every value.
      Specified by:
        `isDense` in interface `StorageOpsMetrics`

    - #### minValue

          public double minValue()

      Gets minimal value in this vector.
      Specified by:
        `minValue` in interface `Vector`
      Returns:
        Minimal value.

    - #### maxValue

          public double maxValue()

      Gets maximum value in this vector.
      Specified by:
        `maxValue` in interface `Vector`
      Returns:
        Maximum c.

    - #### isArrayBased

          public boolean isArrayBased()

      Checks if implementation is based on Java arrays.
      Specified by:
        `isArrayBased` in interface `StorageOpsMetrics`

    - #### copy

          public Vector copy()

      Creates new copy of this vector.
      Specified by:
        `copy` in interface `Vector`
      Returns:
        New copy vector.

    - #### all

          public Iterable<Vector.Element> all()

      Gets iterator over all elements in this vector. NOTE: implementation can choose to reuse `Vector.Element` instance so you need to copy it if you want to retain it outside of iteration.
      Specified by:
        `all` in interface `Vector`
      Returns:
        Iterator.

    - #### nonZeroes

          public Iterable<Vector.Element> nonZeroes()

      Iterates ove all non-zero elements in this vector. NOTE: implementation can choose to reuse `Vector.Element` instance so you need to copy it if you want to retain it outside of iteration.
      Specified by:
        `nonZeroes` in interface `Vector`
      Returns:
        Iterator.

    - #### sort

          public Vector sort()

      Sorts this vector in ascending order.
      Specified by:
        `sort` in interface `Vector`

    - #### copyOfRange

          public Vector copyOfRange(int from,
                                    int to)

      Copies the specified range of the vector into a new vector.
      Specified by:
        `copyOfRange` in interface `Vector`
      Parameters:
        `from` - the initial index of the range to be copied, inclusive
        `to` - the final index of the range to be copied, exclusive. (This index may lie outside the array.)
      Returns:
        A new vector containing the specified range from the original vector

    - #### allSpliterator

          public Spliterator<Double> allSpliterator()

      Gets spliterator for all values in this vector.
      Specified by:
        `allSpliterator` in interface `Vector`
      Returns:
        Spliterator for all values.

    - #### nonZeroSpliterator

          public Spliterator<Double> nonZeroSpliterator()

      Gets spliterator for all non-zero values in this vector.
      Specified by:
        `nonZeroSpliterator` in interface `Vector`
      Returns:
        Spliterator for all non-zero values.

    - #### getElement

          public Vector.Element getElement(int idx)

      Gets element at the given index. NOTE: implementation can choose to reuse `Vector.Element` instance so you need to copy it if you want to retain it outside of iteration.
      Specified by:
        `getElement` in interface `Vector`
      Parameters:
        `idx` - Element's index.
      Returns:
        Vector's element at the given index.

    - #### assign

          public Vector assign(double val)

      Assigns given value to all elements of this vector.
      Specified by:
        `assign` in interface `Vector`
      Parameters:
        `val` - Value to assign.
      Returns:
        This vector.

    - #### assign

          public Vector assign(double[] vals)

      Assigns values from given array to this vector.
      Specified by:
        `assign` in interface `Vector`
      Parameters:
        `vals` - Values to assign.
      Returns:
        This vector.

    - #### assign

          public Vector assign(Vector vec)

      Copies values from the argument vector to this one.
      Specified by:
        `assign` in interface `Vector`
      Parameters:
        `vec` - Argument vector.
      Returns:
        This vector.

    - #### assign

          public Vector assign(IntToDoubleFunction fun)

      Assigns each vector element to the value generated by given function.
      Specified by:
        `assign` in interface `Vector`
      Parameters:
        `fun` - Function that takes the index and returns value.
      Returns:
        This vector.

    - #### map

          public Vector map(IgniteDoubleFunction<Double> fun)

      Maps all values in this vector through a given function.
      Specified by:
        `map` in interface `Vector`
      Parameters:
        `fun` - Mapping function.
      Returns:
        This vector.

    - #### map

          public Vector map(Vector vec,
                            IgniteBiFunction<Double,Double,Double> fun)

      Maps all values in this vector through a given function. For this vector `A`, argument vector `B` and the function `F` this method maps every element `x` as: `A(x) = F(A(x), B(x))`
      Specified by:
        `map` in interface `Vector`
      Parameters:
        `vec` - Argument vector.
        `fun` - Mapping function.
      Returns:
        This function.

    - #### map

          public Vector map(IgniteBiFunction<Double,Double,Double> fun,
                            double y)

      Maps all elements of this vector by applying given function to each element with a constant second parameter `y`.
      Specified by:
        `map` in interface `Vector`
      Parameters:
        `fun` - Mapping function.
        `y` - Second parameter for mapping function.
      Returns:
        This vector.

    - #### divide

          public Vector divide(double x)

      Creates new vector containing values from this vector divided by the argument.
      Specified by:
        `divide` in interface `Vector`
      Parameters:
        `x` - Division argument.
      Returns:
        New vector.

    - #### dot

          public double dot(Vector vec)

      Gets dot product of two vectors.
      Specified by:
        `dot` in interface `Vector`
      Parameters:
        `vec` - Argument vector.
      Returns:
        Dot product of two vectors.

    - #### get

          public double get(int idx)

      Gets the value at specified index.
      Specified by:
        `get` in interface `Vector`
      Parameters:
        `idx` - Vector index.
      Returns:
        Vector value.

    - #### getX

          public double getX(int idx)

      Gets the value at specified index without checking for index boundaries.
      Specified by:
        `getX` in interface `Vector`
      Parameters:
        `idx` - Vector index.
      Returns:
        Vector value.

    - #### getRaw

          public <T extends Serializable> T getRaw(int idx)

      Gets the value at specified index.
      Specified by:
        `getRaw` in interface `Vector`
      Parameters:
        `idx` - Vector index.
      Returns:
        Vector value.

    - #### getRawX

          public <T extends Serializable> T getRawX(int idx)

      Gets the value at specified index without checking for index boundaries.
      Specified by:
        `getRawX` in interface `Vector`
      Parameters:
        `idx` - Vector index.
      Returns:
        Vector value.

    - #### like

          public Vector like(int crd)

      Creates new empty vector of the same underlying class but of different cardinality.
      Specified by:
        `like` in interface `Vector`
      Parameters:
        `crd` - Cardinality for new vector.
      Returns:
        New vector.

    - #### minus

          public Vector minus(Vector vec)

      Creates new vector containing element by element difference between this vector and the argument one.
      Specified by:
        `minus` in interface `Vector`
      Parameters:
        `vec` - Argument vector.
      Returns:
        New vector.

    - #### normalize

          public Vector normalize()

      Creates new vector containing the normalized (L_2 norm) values of this vector.
      Specified by:
        `normalize` in interface `Vector`
      Returns:
        New vector.

    - #### normalize

          public Vector normalize(double power)

      Creates new vector containing the normalized (L_power norm) values of this vector. See http://en.wikipedia.org/wiki/Lp_space for details.
      Specified by:
        `normalize` in interface `Vector`
      Parameters:
        `power` - The power to use. Must be >= 0. May also be `Double.POSITIVE_INFINITY`.
      Returns:
        New vector `x` such that `norm(x, power) == 1`

    - #### logNormalize

          public Vector logNormalize()

      Creates new vector containing the `log(1 + entry) / L_2 norm` values of this vector.
      Specified by:
        `logNormalize` in interface `Vector`
      Returns:
        New vector.

    - #### logNormalize

          public Vector logNormalize(double power)

      Creates new vector with a normalized value calculated as `log_power(1 + entry) / L_power norm`.
      Specified by:
        `logNormalize` in interface `Vector`
      Parameters:
        `power` - The power to use. Must be > 1. Cannot be `Double.POSITIVE_INFINITY`.
      Returns:
        New vector

    - #### kNorm

          public double kNorm(double power)

      Gets the k-norm of the vector. See http://en.wikipedia.org/wiki/Lp_space for more details.
      Specified by:
        `kNorm` in interface `Vector`
      Parameters:
        `power` - The power to use.
      See Also:
        `Vector.normalize(double)`

    - #### minElement

          public Vector.Element minElement()

      Gets minimal element in this vector.
      Specified by:
        `minElement` in interface `Vector`
      Returns:
        Minimal element.

    - #### maxElement

          public Vector.Element maxElement()

      Gets maximum element in this vector.
      Specified by:
        `maxElement` in interface `Vector`
      Returns:
        Maximum element.

    - #### plus

          public Vector plus(double x)

      Creates new vector containing sum of each element in this vector and argument.
      Specified by:
        `plus` in interface `Vector`
      Parameters:
        `x` - Argument value.
      Returns:
        New vector.

    - #### plus

          public Vector plus(Vector vec)

      Creates new vector containing element by element sum from both vectors.
      Specified by:
        `plus` in interface `Vector`
      Parameters:
        `vec` - Other argument vector to add.
      Returns:
        New vector.

    - #### set

          public Vector set(int idx,
                            double val)

      Sets value.
      Specified by:
        `set` in interface `Vector`
      Parameters:
        `idx` - Vector index to set value at.
        `val` - Value to set.
      Returns:
        This vector.

    - #### setX

          public Vector setX(int idx,
                             double val)

      Sets value without checking for index boundaries.
      Specified by:
        `setX` in interface `Vector`
      Parameters:
        `idx` - Vector index to set value at.
        `val` - Value to set.
      Returns:
        This vector.

    - #### setRaw

          public Vector setRaw(int idx,
                               Serializable val)

      Sets value.
      Specified by:
        `setRaw` in interface `Vector`
      Parameters:
        `idx` - Vector index to set value at.
        `val` - Value to set.
      Returns:
        This vector.

    - #### setRawX

          public Vector setRawX(int idx,
                                Serializable val)

      Sets value without checking for index boundaries.
      Specified by:
        `setRawX` in interface `Vector`
      Parameters:
        `idx` - Vector index to set value at.
        `val` - Value to set.
      Returns:
        This vector.

    - #### incrementX

          public Vector incrementX(int idx,
                                   double val)

      Increments value at given index without checking for index boundaries.
      Specified by:
        `incrementX` in interface `Vector`
      Parameters:
        `idx` - Vector index.
        `val` - Increment value.
      Returns:
        This vector.

    - #### increment

          public Vector increment(int idx,
                                  double val)

      Increments value at given index.
      Specified by:
        `increment` in interface `Vector`
      Parameters:
        `idx` - Vector index.
        `val` - Increment value.
      Returns:
        This vector.

    - #### nonZeroElements

          public int nonZeroElements()

      Gets number of non-zero elements in this vector.
      Specified by:
        `nonZeroElements` in interface `Vector`
      Returns:
        Number of non-zero elements in this vector.

    - #### times

          public Vector times(double x)

      Gets a new vector that contains product of each element and the argument.
      Specified by:
        `times` in interface `Vector`
      Parameters:
        `x` - Multiply argument.
      Returns:
        New vector.

    - #### times

          public Vector times(Vector vec)

      Gets a new vector that is an element-wie product of this vector and the argument.
      Specified by:
        `times` in interface `Vector`
      Parameters:
        `vec` - Vector to multiply by.
      Returns:
        New vector.

    - #### viewPart

          public Vector viewPart(int off,
                                 int len)

      Specified by:
        `viewPart` in interface `Vector`
      Parameters:
        `off` - Offset into parent vector.
        `len` - Length of the view.

    - #### getStorage

          public VectorStorage getStorage()

      Gets vector storage model.
      Specified by:
        `getStorage` in interface `Vector`

    - #### sum

          public double sum()

      Gets the sum of all elements in this vector.
      Specified by:
        `sum` in interface `Vector`
      Returns:
        Vector's sum

    - #### cross

          public Matrix cross(Vector vec)

      Gets the cross product of this vector and the other vector.
      Specified by:
        `cross` in interface `Vector`
      Parameters:
        `vec` - Second vector.
      Returns:
        New matrix as a cross product of two vectors.

    - #### foldMap

          public <T> T foldMap(IgniteBiFunction<T,Double,T> foldFun,
                               IgniteDoubleFunction<Double> mapFun,
                               T zeroVal)

      Folds this vector into a single value.
      Specified by:
        `foldMap` in interface `Vector`
      Type Parameters:
        `T` - Type of the folded value.
      Parameters:
        `foldFun` - Folding function that takes two parameters: accumulator and the current value.
        `mapFun` - Mapping function that is called on each vector element before its passed to the accumulator (as its second parameter).
        `zeroVal` - Zero value for fold operation.
      Returns:
        Folded value of this vector.

    - #### foldMap

          public <T> T foldMap(Vector vec,
                               IgniteBiFunction<T,Double,T> foldFun,
                               IgniteBiFunction<Double,Double,Double> combFun,
                               T zeroVal)

      Combines & maps two vector and folds them into a single value.
      Specified by:
        `foldMap` in interface `Vector`
      Type Parameters:
        `T` - Type of the folded value.
      Parameters:
        `vec` - Another vector to combine with.
        `foldFun` - Folding function.
        `combFun` - Combine function.
        `zeroVal` - Zero value for fold operation.
      Returns:
        Folded value of these vectors.

    - #### getLengthSquared

          public double getLengthSquared()

      Gets the sum of squares of all elements in this vector.
      Specified by:
        `getLengthSquared` in interface `Vector`
      Returns:
        Length squared value.

    - #### getDistanceSquared

          public double getDistanceSquared(Vector vec)

      Get the square of the distance between this vector and the argument vector.
      Specified by:
        `getDistanceSquared` in interface `Vector`
      Parameters:
        `vec` - Another vector.
      Returns:
        Distance squared.

    - #### isNumeric

          public boolean isNumeric()

      Specified by:
        `isNumeric` in interface `StorageOpsMetrics`
      Returns:
        true if all stored data are values of Number class.

    - #### guid

          public IgniteUuid guid()

      Auto-generated globally unique vector ID.
      Specified by:
        `guid` in interface `Vector`
      Returns:
        Vector GUID.

    - #### compute

          public void compute(int i,
                              IgniteIntDoubleToDoubleBiFunction f)

      Replace vector entry with value oldVal at i with result of computing f(i, oldVal).
      Specified by:
        `compute` in interface `Vector`
      Parameters:
        `i` - Position.
        `f` - Function used for replacing.

    - #### destroy

          public void destroy()

      Destroys object if managed outside of JVM. It's a no-op in all other cases.
      Specified by:
        `destroy` in interface `Destroyable`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

2022 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.13.0
Release Date | : April 20 2022