Class RowMajorRealMatrix

java.lang.Object
com.apple.foundationdb.linear.RowMajorRealMatrix
All Implemented Interfaces:
LinearOperator, RealMatrix, VectorOperator

public class RowMajorRealMatrix extends Object implements RealMatrix
  • Constructor Details

    • RowMajorRealMatrix

      public RowMajorRealMatrix(@Nonnull double[][] data)
  • Method Details

    • getNumRowDimensions

      public int getNumRowDimensions()
      Specified by:
      getNumRowDimensions in interface LinearOperator
    • getNumColumnDimensions

      public int getNumColumnDimensions()
      Specified by:
      getNumColumnDimensions in interface LinearOperator
    • getEntry

      public double getEntry(int row, int column)
      Specified by:
      getEntry in interface RealMatrix
    • getRow

      @Nonnull public double[] getRow(int row)
    • transpose

      @Nonnull public RowMajorRealMatrix transpose()
      Specified by:
      transpose in interface RealMatrix
    • apply

      @Nonnull public DoubleRealVector apply(@Nonnull RealVector vector)
      Description copied from interface: VectorOperator
      Apply this operator to the vector passed in.
      Specified by:
      apply in interface RealMatrix
      Specified by:
      apply in interface VectorOperator
      Parameters:
      vector - the vector
      Returns:
      a new vector
    • transposedApply

      @Nonnull public DoubleRealVector transposedApply(@Nonnull RealVector vector)
      Specified by:
      transposedApply in interface LinearOperator
      Specified by:
      transposedApply in interface RealMatrix
    • multiply

      @Nonnull public RowMajorRealMatrix multiply(@Nonnull RealMatrix otherMatrix)
      Multiplies this matrix by otherMatrix and returns the row-major product.

      The implementation provides two SIMD fast paths plus a scalar triple-loop fallback. This is asymmetric to ColumnMajorRealMatrix.multiply(com.apple.foundationdb.linear.RealMatrix), which gets by with a single universal AXPY path. The asymmetry is forced by storage layout — not an oversight — so the rest of this comment explains why the two methods can't share a shape.

      Matrix multiplication has two SIMD-able decompositions:

      1. Output-stationary dot: C[i][j] = dot(A.row(i), B.col(j)). Requires A.row(i) and B.col(j) to both be contiguous in memory.
      2. Input-stationary AXPY: C.row(i) += A[i][k] · B.row(k). Requires C.row(i) and B.row(k) to both be contiguous.

      What's contiguous depends on layout: a row-major matrix exposes contiguous rows and strided columns; a column-major matrix exposes contiguous columns and strided rows. So for row-major A (this method), the decompositions split cleanly along B's layout — shape (1) needs column-major B, shape (2) needs row-major B — and we need both specialized branches to keep every layout combination on a SIMD path. The scalar fallback below is dead code today (no other RealMatrix subtypes exist), but it preserves correctness for any future layout that doesn't surface a contiguous strip on either axis.

      Column-major A dodges the split: ColumnMajorRealMatrix.multiply(com.apple.foundationdb.linear.RealMatrix) writes C.col(j) += B[k][j] · A.col(k), where the contiguous arrays it cares about (A.col(k) and C.col(j)) come from A and C themselves — never from B. The only thing B contributes per inner step is a single scalar B[k][j], which a virtual getEntry call delivers cheaply regardless of B's layout. One universal AXPY path covers every B there.

      Specified by:
      multiply in interface RealMatrix
      Parameters:
      otherMatrix - the right-hand operand; must satisfy otherMatrix.getNumRowDimensions() == this.getNumColumnDimensions()
      Returns:
      a new RowMajorRealMatrix containing the product
    • subMatrix

      @Nonnull public RowMajorRealMatrix subMatrix(int startRow, int lengthRow, int startColumn, int lengthColumn)
      Specified by:
      subMatrix in interface RealMatrix
    • toRowMajor

      @Nonnull public RowMajorRealMatrix toRowMajor()
      Specified by:
      toRowMajor in interface RealMatrix
    • getRowMajorData

      @Nonnull public double[][] getRowMajorData()
      Specified by:
      getRowMajorData in interface RealMatrix
    • toColumnMajor

      @Nonnull public ColumnMajorRealMatrix toColumnMajor()
      Specified by:
      toColumnMajor in interface RealMatrix
    • getColumnMajorData

      @Nonnull public double[][] getColumnMajorData()
      Specified by:
      getColumnMajorData in interface RealMatrix
    • quickTranspose

      @Nonnull public ColumnMajorRealMatrix quickTranspose()
      Specified by:
      quickTranspose in interface RealMatrix
    • flipMajor

      @Nonnull public ColumnMajorRealMatrix flipMajor()
      Specified by:
      flipMajor in interface RealMatrix
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object