Class Tensor2D

All Implemented Interfaces:
Tensor, Serializable

public final class Tensor2D extends TensorBase
A 2D tensor / matrix with specified number of rows and columns..
See Also:
  • Constructor Details

    • Tensor2D

      public Tensor2D(int rows, int cols)
      Creates a tensor with specified number of rows and columns (matrix).
      Parameters:
      rows - number of rows
      cols - number of columns
    • Tensor2D

      public Tensor2D(int rows, int cols, float[] values)
    • Tensor2D

      public Tensor2D(float[][] vals)
      Creates a 2D tensor / matrix filled with given 2d array. First dimension corresponds to number of rows, while second dimension corresponds to number of columns.
      Parameters:
      vals - values to store into matrix
  • Method Details

    • cols

      public final int cols()
      Returns a number of columns in this matrix.
      Returns:
    • rows

      public final int rows()
      Returns a number of rows in this matrix.
      Returns:
    • get

      public final float get(int row, int col)
      Returns a value at specified row, col position in this tensor.
      Parameters:
      row -
      col -
      Returns:
      value at [row, col]
    • set

      public final void set(float val, int row, int col)
      Set value at specified [row, col] position in this tensor.
      Parameters:
      val - value to set
      row - tensor's row index
      col - tensor's col index
    • setRow

      public void setRow(int rowIdx, float[] rowData)
    • setCol

      public void setCol(int colIdx, float[] colData)
    • createRowsCache

      public void createRowsCache()
    • createColsCache

      public void createColsCache()
    • createRowsAndColsCache

      public void createRowsAndColsCache()
    • getRow

      public float[] getRow(int rowIdx, float[] rowBuff)
    • getCol

      public float[] getCol(int col, float[] colBuff)
    • add

      public final void add(float value, int row, int col)
      Adds specified value to matrix value at position x, y
      Parameters:
      value -
      row -
      col -
    • add

      public final Tensor2D add(Tensor1D toAdd)
    • sub

      public final void sub(float val, int row, int col)
    • copy

      public TensorBase copy()
      Overrides:
      copy in class TensorBase
    • clone

      public Object clone()
      Overrides:
      clone in class TensorBase
    • getTransposed

      public Tensor2D getTransposed()
    • transposeInto

      public Tensor2D transposeInto(Tensor2D transposed)
    • setValuesFromStringTransposed

      public void setValuesFromStringTransposed(String values)
      Overrides:
      setValuesFromStringTransposed in class TensorBase
    • fromFile

      public static Tensor2D fromFile(String filePath) throws IOException
      Throws:
      IOException
    • toFile

      public void toFile(String filePath)
    • sqrSumByCol

      public Tensor1D sqrSumByCol(Tensor1D sumSqr)
    • matMul

      public Tensor2D matMul(Tensor2D matrixB, Tensor2D result)
      Performs dot product operation on this tensor and matrib, and stores results in result tensor.
      Parameters:
      matrixB -
      result -
      Returns:
    • matMul

      public Tensor1D matMul(Tensor1D vectorB, Tensor1D result)
      Performs matrix multiplication with this 2d tensor and vector , and stores results in result tensor.
      Parameters:
      vectorB -
      result -
      Returns:
    • getRowsCache

      public float[] getRowsCache(int rowIdx)
    • getColsCache

      public float[] getColsCache(int colIdx)
    • matMulVectorized

      public Tensor1D matMulVectorized(Tensor1D vector, Tensor1D result)
    • matMulVectorized

      public Tensor2D matMulVectorized(Tensor2D matrixB, Tensor2D result)
    • outerProductAccumulate

      public void outerProductAccumulate(Tensor2D inputs, Tensor2D result)
    • matMulMT

      public Tensor2D matMulMT(Tensor2D matrixB, Tensor2D result)
    • setThreadPool

      public void setThreadPool(DeepNettsThreadPool threadPool)
    • sumByColInto

      public Tensor1D sumByColInto(Tensor1D sumTensor)