org.apache.ignite.ml.math.primitives.matrix

## Class AbstractMatrix

- java.lang.Object
- - org.apache.ignite.ml.math.primitives.matrix.AbstractMatrix

- All Implemented Interfaces:
    Externalizable, Serializable, Destroyable, MetaAttributes, Matrix, StorageOpsMetrics
  Direct Known Subclasses:
    DenseMatrix, SparseMatrix, ViewMatrix

      public abstract class AbstractMatrix
      extends Object
      implements Matrix

  This class provides a helper implementation of the `Matrix` interface to minimize the effort required to implement it. Subclasses may override some of the implemented methods if a more specific or optimized implementation is desirable.
  See Also:
    Serialized Form

- - ### Nested Class Summary

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

      `Matrix.Element`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractMatrix()`
    `AbstractMatrix(MatrixStorage sto)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Spliterator<Double>` | `allSpliterator()` Gets spliterator for all values in this matrix.
    `Matrix` | `assign(double val)` Assigns given value to all elements of this matrix.
    `Matrix` | `assign(double[][] vals)` Assigns given values to this matrix.
    `Matrix` | `assign(IntIntToDoubleFunction fun)` Assigns each matrix element to the value generated by given function.
    `Matrix` | `assign(Matrix mtx)` Assigns values from given matrix to this matrix.
    `Matrix` | `assignColumn(int col, Vector vec)` Assigns values from given vector to the specified column in this matrix.
    `Matrix` | `assignRow(int row, Vector vec)` Assigns values from given vector to the specified row in this matrix.
    `int` | `columnSize()` Gets number of columns in this matrix.
    `void` | `compute(int row, int col, IgniteTriFunction<Integer,Integer,Double,Double> f)` Replace matrix entry with value oldVal at (row, col) with result of computing f(row, col, oldVal).
    `Matrix` | `copy()` Clones this matrix.
    `boolean` | `density(double threshold)` Calculates the density of the matrix based on supplied criteria.
    `void` | `destroy()` Destroys object if managed outside of JVM.
    `double` | `determinant()` Returns matrix determinant using Laplace theorem.
    `Matrix` | `divide(double d)` Divides each value in this matrix by the argument.
    `boolean` | `equals(Object o)` We ignore guid's for comparisons.
    `Vector` | `foldColumns(IgniteFunction<Vector,Double> fun)` Collects the results of applying a given function to all columns in this matrix.
    `<T> T` | `foldMap(IgniteBiFunction<T,Double,T> foldFun, IgniteDoubleFunction<Double> mapFun, T zeroVal)` Folds this matrix into a single value.
    `Vector` | `foldRows(IgniteFunction<Vector,Double> fun)` Collects the results of applying a given function to all rows in this matrix.
    `double` | `get(int row, int col)` Gets the matrix value at the provided location.
    `Vector` | `getCol(int col)` Get a specific row from matrix.
    `Matrix.Element` | `getElement(int row, int col)` Gets the matrix's element at the given coordinates.
    `Map<String,Object>` | `getMetaStorage()` Implementation should return an instance of the map to store meta attributes.
    `Vector` | `getRow(int row)` Get a specific row from matrix.
    `MatrixStorage` | `getStorage()` Gets matrix storage model.
    `double` | `getX(int row, int col)` Gets the matrix value at the provided location without checking boundaries.
    `IgniteUuid` | `guid()` Auto-generated globally unique matrix ID.
    `int` | `hashCode()`
    `Matrix` | `inverse()` Returns the inverse matrix of this matrix
    `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.
    `protected Matrix` | `likeIdentity()`
    `Matrix` | `map(IgniteDoubleFunction<Double> fun)` Maps all values in this matrix through a given function.
    `Matrix` | `map(Matrix mtx, IgniteBiFunction<Double,Double,Double> fun)` Maps all values in this matrix through a given function.
    `Matrix.Element` | `maxElement()` Gets the maximum element in this matrix.
    `double` | `maxValue()` Gets the maximum value in this matrix.
    `Matrix.Element` | `minElement()` Gets the minimum element in this matrix.
    `Matrix` | `minus(Matrix mtx)` Creates new matrix where each value is a difference between corresponding value of this matrix and passed in argument matrix.
    `double` | `minValue()` Gets the minimum value in this matrix.
    `int` | `nonZeroElements()` Gets number of non-zero elements in this matrix.
    `Spliterator<Double>` | `nonZeroSpliterator()` Gets spliterator for all non-zero values in this matrix.
    `Matrix` | `plus(double x)` Creates new matrix where each value is a sum of the corresponding value of this matrix and argument value.
    `Matrix` | `plus(Matrix mtx)` Creates new matrix where each value is a sum of corresponding values of this matrix and passed in argument matrix.
    `void` | `readExternal(ObjectInput in)`
    `int` | `rowSize()` Gets number of rows in this matrix.
    `Matrix` | `set(int row, int col, double val)` Sets given value.
    `Matrix` | `setColumn(int col, double[] data)` Sets values for given column.
    `Matrix` | `setRow(int row, double[] data)` Sets values for given row.
    `protected void` | `setStorage(MatrixStorage sto)`
    `Matrix` | `setX(int row, int col, double val)` Sets given value without checking for index bounds.
    `protected double` | `storageGet(int row, int col)`
    `protected void` | `storageSet(int row, int col, double v)`
    `double` | `sum()` Gets sum of all elements in the matrix.
    `Matrix` | `swapColumns(int col1, int col2)` Swaps two columns in this matrix.
    `Matrix` | `swapRows(int row1, int row2)` Swaps two rows in this matrix.
    `Matrix` | `times(double x)` Creates new matrix containing the product of given value and values in this matrix.
    `Matrix` | `times(Matrix mtx)` Creates new matrix that is the product of multiplying this matrix and the argument matrix.
    `Vector` | `times(Vector vec)` Creates new matrix that is the product of multiplying this matrix and the argument vector.
    `String` | `toString()`
    `Matrix` | `transpose()` Creates new matrix that is transpose of this matrix.
    `Vector` | `viewColumn(int col)` Creates new view into matrix column .
    `Vector` | `viewDiagonal()` Creates new view into matrix diagonal.
    `Vector` | `viewRow(int row)` Creates new view into matrix row.
    `void` | `writeExternal(ObjectOutput out)`

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

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

    - ### Methods inherited from interface org.apache.ignite.ml.math.primitives.matrix.Matrix

      `isNumeric, like, likeVector`

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

      `getAttribute, hasAttribute, removeAttribute, setAttribute`

- - ### Constructor Detail

    - #### AbstractMatrix

          public AbstractMatrix(MatrixStorage sto)

      Parameters:
        `sto` - Backing `MatrixStorage`.

    - #### AbstractMatrix

          public AbstractMatrix()

  - ### Method Detail

    - #### setStorage

          protected void setStorage(MatrixStorage sto)

      Parameters:
        `sto` - Backing `MatrixStorage`.

    - #### storageSet

          protected void storageSet(int row,
                                    int col,
                                    double v)

      Parameters:
        `row` - Row index in the matrix.
        `col` - Column index in the matrix.
        `v` - Value to set.

    - #### storageGet

          protected double storageGet(int row,
                                      int col)

      Parameters:
        `row` - Row index in the matrix.
        `col` - Column index in the matrix.

    - #### maxElement

          public Matrix.Element maxElement()

      Gets the maximum element in this matrix.
      Specified by:
        `maxElement` in interface `Matrix`
      Returns:
        Maximum element in this matrix.

    - #### minElement

          public Matrix.Element minElement()

      Gets the minimum element in this matrix.
      Specified by:
        `minElement` in interface `Matrix`
      Returns:
        Minimum element in this matrix.

    - #### maxValue

          public double maxValue()

      Gets the maximum value in this matrix.
      Specified by:
        `maxValue` in interface `Matrix`
      Returns:
        Maximum value in this matrix.

    - #### minValue

          public double minValue()

      Gets the minimum value in this matrix.
      Specified by:
        `minValue` in interface `Matrix`
      Returns:
        Minimum value in this matrix.

    - #### getElement

          public Matrix.Element getElement(int row,
                                           int col)

      Gets the matrix's element at the given coordinates.
      Specified by:
        `getElement` in interface `Matrix`
      Parameters:
        `row` - Row index.
        `col` - Column index.
      Returns:
        Element at the given coordinates.

    - #### swapRows

          public Matrix swapRows(int row1,
                                 int row2)

      Swaps two rows in this matrix.
      Specified by:
        `swapRows` in interface `Matrix`
      Parameters:
        `row1` - Row #1.
        `row2` - Row #2.
      Returns:
        This matrix.

    - #### swapColumns

          public Matrix swapColumns(int col1,
                                    int col2)

      Swaps two columns in this matrix.
      Specified by:
        `swapColumns` in interface `Matrix`
      Parameters:
        `col1` - Column #1.
        `col2` - Column #2.
      Returns:
        This matrix.

    - #### getStorage

          public MatrixStorage getStorage()

      Gets matrix storage model.
      Specified by:
        `getStorage` in interface `Matrix`

    - #### 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`

    - #### isArrayBased

          public boolean isArrayBased()

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

    - #### writeExternal

          public void writeExternal(ObjectOutput out)
                             throws IOException

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

    - #### getMetaStorage

          public Map<String,Object> getMetaStorage()

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

    - #### readExternal

          public void readExternal(ObjectInput in)
                            throws IOException,
                                   ClassNotFoundException

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

    - #### assign

          public Matrix assign(double val)

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

    - #### assign

          public Matrix assign(IntIntToDoubleFunction fun)

      Assigns each matrix element to the value generated by given function.
      Specified by:
        `assign` in interface `Matrix`
      Parameters:
        `fun` - Function that takes the row and column and returns the value to assign.
      Returns:
        This matrix.

    - #### assign

          public Matrix assign(double[][] vals)

      Assigns given values to this matrix.
      Specified by:
        `assign` in interface `Matrix`
      Parameters:
        `vals` - Values to assign.
      Returns:
        This matrix.

    - #### assign

          public Matrix assign(Matrix mtx)

      Assigns values from given matrix to this matrix.
      Specified by:
        `assign` in interface `Matrix`
      Parameters:
        `mtx` - Matrix to assign to this matrix.
      Returns:
        This matrix.

    - #### map

          public Matrix map(IgniteDoubleFunction<Double> fun)

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

    - #### map

          public Matrix map(Matrix mtx,
                            IgniteBiFunction<Double,Double,Double> fun)

      Maps all values in this matrix through a given function.

      For this matrix `A`, argument matrix `B` and the function `F` this method maps every cell `x, y` as: `A(x,y) = fun(A(x,y), B(x,y))`.

      Specified by:
        `map` in interface `Matrix`
      Parameters:
        `mtx` - Argument matrix.
        `fun` - Mapping function.
      Returns:
        This function.

    - #### allSpliterator

          public Spliterator<Double> allSpliterator()

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

    - #### nonZeroElements

          public int nonZeroElements()

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

    - #### nonZeroSpliterator

          public Spliterator<Double> nonZeroSpliterator()

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

    - #### assignColumn

          public Matrix assignColumn(int col,
                                     Vector vec)

      Assigns values from given vector to the specified column in this matrix.
      Specified by:
        `assignColumn` in interface `Matrix`
      Parameters:
        `col` - Column index.
        `vec` - Vector to get values from.
      Returns:
        This matrix.

    - #### assignRow

          public Matrix assignRow(int row,
                                  Vector vec)

      Assigns values from given vector to the specified row in this matrix.
      Specified by:
        `assignRow` in interface `Matrix`
      Parameters:
        `row` - Row index.
        `vec` - Vector to get values from.
      Returns:
        This matrix.

    - #### foldRows

          public Vector foldRows(IgniteFunction<Vector,Double> fun)

      Collects the results of applying a given function to all rows in this matrix.
      Specified by:
        `foldRows` in interface `Matrix`
      Parameters:
        `fun` - Aggregating function.
      Returns:
        Vector of row aggregates.

    - #### foldColumns

          public Vector foldColumns(IgniteFunction<Vector,Double> fun)

      Collects the results of applying a given function to all columns in this matrix.
      Specified by:
        `foldColumns` in interface `Matrix`
      Parameters:
        `fun` - Aggregating function.
      Returns:
        Vector of column aggregates.

    - #### foldMap

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

      Folds this matrix into a single value.
      Specified by:
        `foldMap` in interface `Matrix`
      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 matrix cell before its passed to the accumulator (as its second parameter).
        `zeroVal` - Zero value for fold function.
      Returns:
        Folded value of this matrix.

    - #### columnSize

          public int columnSize()

      Gets number of columns in this matrix.
      Specified by:
        `columnSize` in interface `Matrix`
      Returns:
        The number of columns in this matrix.

    - #### rowSize

          public int rowSize()

      Gets number of rows in this matrix.
      Specified by:
        `rowSize` in interface `Matrix`
      Returns:
        The number of rows in this matrix.

    - #### divide

          public Matrix divide(double d)

      Divides each value in this matrix by the argument.
      Specified by:
        `divide` in interface `Matrix`
      Parameters:
        `d` - Divider value.
      Returns:
        This matrix.

    - #### get

          public double get(int row,
                            int col)

      Gets the matrix value at the provided location.
      Specified by:
        `get` in interface `Matrix`
      Parameters:
        `row` - Row index.
        `col` - Column index.
      Returns:
        Matrix value.

    - #### getX

          public double getX(int row,
                             int col)

      Gets the matrix value at the provided location without checking boundaries. This method is marginally quicker than its `Matrix.get(int, int)` sibling.
      Specified by:
        `getX` in interface `Matrix`
      Parameters:
        `row` - Row index.
        `col` - Column index.
      Returns:
        Matrix value.

    - #### minus

          public Matrix minus(Matrix mtx)

      Creates new matrix where each value is a difference between corresponding value of this matrix and passed in argument matrix.
      Specified by:
        `minus` in interface `Matrix`
      Parameters:
        `mtx` - Argument matrix.
      Returns:
        New matrix of the same underlying class and size.

    - #### plus

          public Matrix plus(double x)

      Creates new matrix where each value is a sum of the corresponding value of this matrix and argument value.
      Specified by:
        `plus` in interface `Matrix`
      Parameters:
        `x` - Value to add.
      Returns:
        New matrix of the same underlying class and size.

    - #### plus

          public Matrix plus(Matrix mtx)

      Creates new matrix where each value is a sum of corresponding values of this matrix and passed in argument matrix.
      Specified by:
        `plus` in interface `Matrix`
      Parameters:
        `mtx` - Argument matrix.
      Returns:
        New matrix of the same underlying class and size.

    - #### guid

          public IgniteUuid guid()

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

    - #### set

          public Matrix set(int row,
                            int col,
                            double val)

      Sets given value.
      Specified by:
        `set` in interface `Matrix`
      Parameters:
        `row` - Row index.
        `col` - Column index.
        `val` - Value to set.
      Returns:
        This matrix.

    - #### setRow

          public Matrix setRow(int row,
                               double[] data)

      Sets values for given row.
      Specified by:
        `setRow` in interface `Matrix`
      Parameters:
        `row` - Row index.
        `data` - Row data to set.
      Returns:
        This matrix.

    - #### getRow

          public Vector getRow(int row)

      Get a specific row from matrix.
      Specified by:
        `getRow` in interface `Matrix`
      Parameters:
        `row` - Row index.
      Returns:
        row.

    - #### setColumn

          public Matrix setColumn(int col,
                                  double[] data)

      Sets values for given column.
      Specified by:
        `setColumn` in interface `Matrix`
      Parameters:
        `col` - Column index.
        `data` - Column data to set.
      Returns:
        This matrix.

    - #### getCol

          public Vector getCol(int col)

      Get a specific row from matrix.
      Specified by:
        `getCol` in interface `Matrix`
      Parameters:
        `col` - Col index.
      Returns:
        Col.

    - #### setX

          public Matrix setX(int row,
                             int col,
                             double val)

      Sets given value without checking for index bounds. This method is marginally faster than its `Matrix.set(int, int, double)` sibling.
      Specified by:
        `setX` in interface `Matrix`
      Parameters:
        `row` - Row index.
        `col` - Column index.
        `val` - Value to set.
      Returns:
        This matrix.

    - #### times

          public Matrix times(double x)

      Creates new matrix containing the product of given value and values in this matrix.
      Specified by:
        `times` in interface `Matrix`
      Parameters:
        `x` - Value to multiply.
      Returns:
        New matrix.

    - #### times

          public Vector times(Vector vec)

      Creates new matrix that is the product of multiplying this matrix and the argument vector.
      Specified by:
        `times` in interface `Matrix`
      Parameters:
        `vec` - Argument vector.
      Returns:
        New matrix.

    - #### times

          public Matrix times(Matrix mtx)

      Creates new matrix that is the product of multiplying this matrix and the argument matrix.
      Specified by:
        `times` in interface `Matrix`
      Parameters:
        `mtx` - Argument matrix.
      Returns:
        New matrix.

    - #### sum

          public double sum()

      Gets sum of all elements in the matrix.
      Specified by:
        `sum` in interface `Matrix`
      Returns:
        Sum of all elements in this matrix.

    - #### transpose

          public Matrix transpose()

      Creates new matrix that is transpose of this matrix.
      Specified by:
        `transpose` in interface `Matrix`
      Returns:
        New transposed matrix.

    - #### density

          public boolean density(double threshold)

      Calculates the density of the matrix based on supplied criteria. Returns `true` if this matrix is denser than threshold with at least 80% confidence.
      Specified by:
        `density` in interface `Matrix`
      Parameters:
        `threshold` - the threshold value [0, 1] of non-zero elements above which the matrix is considered dense.

    - #### viewRow

          public Vector viewRow(int row)

      Creates new view into matrix row. Changes to the view will be propagated to this matrix.
      Specified by:
        `viewRow` in interface `Matrix`
      Parameters:
        `row` - Row index.
      Returns:
        New view.

    - #### viewColumn

          public Vector viewColumn(int col)

      Creates new view into matrix column . Changes to the view will be propagated to this matrix.
      Specified by:
        `viewColumn` in interface `Matrix`
      Parameters:
        `col` - Column index.
      Returns:
        New view.

    - #### viewDiagonal

          public Vector viewDiagonal()

      Creates new view into matrix diagonal. Changes to the view will be propagated to this matrix.
      Specified by:
        `viewDiagonal` in interface `Matrix`
      Returns:
        New view.

    - #### 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`
      Specified by:
        `destroy` in interface `Matrix`

    - #### copy

          public Matrix copy()

      Clones this matrix.

      NOTE: new matrix will have the same flavor as the this matrix but a different ID.

      Specified by:
        `copy` in interface `Matrix`
      Returns:
        New matrix of the same underlying class, the same size and the same values.

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals(Object o)

      We ignore guid's for comparisons.
      Overrides:
        `equals` in class `Object`

    - #### compute

          public void compute(int row,
                              int col,
                              IgniteTriFunction<Integer,Integer,Double,Double> f)

      Replace matrix entry with value oldVal at (row, col) with result of computing f(row, col, oldVal).
      Specified by:
        `compute` in interface `Matrix`
      Parameters:
        `row` - Row.
        `col` - Column.
        `f` - Function used for replacing.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### determinant

          public double determinant()

      Returns matrix determinant using Laplace theorem.
      Specified by:
        `determinant` in interface `Matrix`
      Returns:
        A determinant for this matrix.

    - #### inverse

          public Matrix inverse()

      Returns the inverse matrix of this matrix
      Specified by:
        `inverse` in interface `Matrix`
      Returns:
        Inverse of this matrix

    - #### likeIdentity

          protected Matrix likeIdentity()

2021 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.11.0
Release Date | : September 11 2021