org.apache.ignite.ml.math.util

## Class MatrixUtil

- java.lang.Object
- - org.apache.ignite.ml.math.util.MatrixUtil

-     public final class MatrixUtil
      extends Object

  Utility class for various matrix operations.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static DenseMatrix` | `asDense(SparseMatrix m, int acsMode)`
    `static Matrix` | `copy(Matrix matrix)` Create the copy of matrix with read-only matrices support.
    `static Matrix` | `elementWiseMinus(Matrix mtx1, Matrix mtx2)` Performs in-place matrix subtraction.
    `static Matrix` | `elementWiseTimes(Matrix mtx1, Matrix mtx2)` Performs in-place matrix multiplication.
    `static double[]` | `flatten(double[][] arr, int stoMode)`
    `static DenseMatrix` | `fromList(List<Vector> vecs, boolean entriesAreRows)`
    `static Matrix` | `identity(int n)` Creates the identity matrix with the given size.
    `static Matrix` | `identityLike(Matrix matrix, int n)` Create the identity matrix like a given matrix.
    `static Matrix` | `like(Matrix matrix)` Create the like matrix with read-only matrices support.
    `static Matrix` | `like(Matrix matrix, int rows, int cols)` Create the like matrix with specified size with read-only matrices support.
    `static Vector` | `likeVector(Matrix matrix)` Create the like vector with read-only matrices support.
    `static Vector` | `likeVector(Matrix matrix, int crd)` Create the like vector with read-only matrices support.
    `static DenseVector` | `localCopyOf(Vector vec)` TODO: IGNITE-5723, rewrite in a more optimal way.
    `static double[][]` | `unflatten(double[] fArr, int colsCnt, int stoMode)`
    `static void` | `unflatten(double[] fArr, Matrix mtx)`
    `static Vector` | `zipFoldByColumns(Matrix mtx1, Matrix mtx2, IgniteBiFunction<Vector,Vector,Double> fun)` Zips two matrices by column-by-column with specified function.
    `static Vector` | `zipFoldByRows(Matrix mtx1, Matrix mtx2, IgniteBiFunction<Vector,Vector,Double> fun)` Zips two matrices by row-by-row with specified function.
    `static Vector` | `zipWith(Vector v1, Vector v2, IgniteTriFunction<Double,Double,Integer,Double> f)` Zip two vectors with given tri-function taking as third argument position in vector (i.e. apply binary function to both vector elementwise and construct vector from results).

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

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

- - ### Method Detail

    - #### like

          public static Matrix like(Matrix matrix)

      Create the like matrix with read-only matrices support.
      Parameters:
        `matrix` - Matrix for like.
      Returns:
        Like matrix.

    - #### identityLike

          public static Matrix identityLike(Matrix matrix,
                                            int n)

      Create the identity matrix like a given matrix.
      Parameters:
        `matrix` - Matrix for like.
      Returns:
        Identity matrix.

    - #### identity

          public static Matrix identity(int n)

      Creates the identity matrix with the given size.
      Parameters:
        `n` - N.

    - #### like

          public static Matrix like(Matrix matrix,
                                    int rows,
                                    int cols)

      Create the like matrix with specified size with read-only matrices support.
      Parameters:
        `matrix` - Matrix for like.
      Returns:
        Like matrix.

    - #### likeVector

          public static Vector likeVector(Matrix matrix,
                                          int crd)

      Create the like vector with read-only matrices support.
      Parameters:
        `matrix` - Matrix for like.
        `crd` - Cardinality of the vector.
      Returns:
        Like vector.

    - #### likeVector

          public static Vector likeVector(Matrix matrix)

      Create the like vector with read-only matrices support.
      Parameters:
        `matrix` - Matrix for like.
      Returns:
        Like vector.

    - #### copy

          public static Matrix copy(Matrix matrix)

      Create the copy of matrix with read-only matrices support.
      Parameters:
        `matrix` - Matrix for copy.
      Returns:
        Copy.

    - #### asDense

          public static DenseMatrix asDense(SparseMatrix m,
                                            int acsMode)

    - #### fromList

          public static DenseMatrix fromList(List<Vector> vecs,
                                             boolean entriesAreRows)

    - #### localCopyOf

          public static DenseVector localCopyOf(Vector vec)

      TODO: IGNITE-5723, rewrite in a more optimal way.

    - #### unflatten

          public static double[][] unflatten(double[] fArr,
                                             int colsCnt,
                                             int stoMode)

    - #### unflatten

          public static void unflatten(double[] fArr,
                                       Matrix mtx)

    - #### zipWith

          public static Vector zipWith(Vector v1,
                                       Vector v2,
                                       IgniteTriFunction<Double,Double,Integer,Double> f)

      Zip two vectors with given tri-function taking as third argument position in vector (i.e. apply binary function to both vector elementwise and construct vector from results). Example zipWith({200, 400, 600}, {100, 300, 500}, plusAndMultiplyByIndex) = {(200 + 100) * 0, (400 + 300) * 1, (600 + 500) * 3}. Length of result is length of shortest of vectors.
      Parameters:
        `v1` - First vector.
        `v2` - Second vector.
        `f` - Function to zip with.
      Returns:
        Result of zipping.

    - #### zipFoldByColumns

          public static Vector zipFoldByColumns(Matrix mtx1,
                                                Matrix mtx2,
                                                IgniteBiFunction<Vector,Vector,Double> fun)

      Zips two matrices by column-by-column with specified function. Result is matrix same flavour as first matrix.
      Parameters:
        `mtx1` - First matrix.
        `mtx2` - Second matrix.
        `fun` - Function to zip with.
      Returns:
        Vector consisting from values resulted from zipping column-by-column.

    - #### zipFoldByRows

          public static Vector zipFoldByRows(Matrix mtx1,
                                             Matrix mtx2,
                                             IgniteBiFunction<Vector,Vector,Double> fun)

      Zips two matrices by row-by-row with specified function. Result is matrix same flavour as first matrix.
      Parameters:
        `mtx1` - First matrix.
        `mtx2` - Second matrix.
        `fun` - Function to zip with.
      Returns:
        Vector consisting from values resulted from zipping row-by-row.

    - #### flatten

          public static double[] flatten(double[][] arr,
                                         int stoMode)

    - #### elementWiseMinus

          public static Matrix elementWiseMinus(Matrix mtx1,
                                                Matrix mtx2)

      Performs in-place matrix subtraction.
      Parameters:
        `mtx1` - Operand to be changed and subtracted from.
        `mtx2` - Operand to subtract.
      Returns:
        Updated first operand.

    - #### elementWiseTimes

          public static Matrix elementWiseTimes(Matrix mtx1,
                                                Matrix mtx2)

      Performs in-place matrix multiplication.
      Parameters:
        `mtx1` - Operand to be changed and first multiplication operand.
        `mtx2` - Second multiplication operand.
      Returns:
        Updated first operand.

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