Class MatrixOps

java.lang.Object
org.bzdev.math.MatrixOps

public class MatrixOps extends Object
Basic matrix operations. This class contains only static methods. The matrix operations it supports include matrix addition, matrix multiplication (by both matrices and scalars), and computing the transpose of a matrix.

Matrices can be represented in two forms:

  • A two-dimensional array in which the first index is the row number and the second index is the column number. A matrix element Aij is thus represented as A[i][j] in Java.
  • A one dimensional array in either row-major order or column-major order. In row-major order, the elements of a row are adjacent to each other, listed in the order specified by their columns. In column-major order, the elements of a column are adjacent to each other, listed in the order specified by their rows. For multidimensional arrays, C uses row-major order and FORTRAN uses column-major order.
The functions flatten and unflatten convert between these two forms. One can convert a square matrix from row-major order and ( column-major order, and vice versa, by using the transpose(double[],int,int,double[],int,int,boolean) method. For example,

      MatrixOps.transpose(matrix, 20, 20, matrix, 20, 20, true);
 

With a flat representation, matrices can be interleaved. In this form, each element of the matrix is a vector, with each element in a matrix using vectors of the same length. These vectors are stored contiguously. When a matrix operation is performed for this case, the arguments for a method will include the vector length and the index of the component of the vector that will be used. This representation is convenient for cases such as Bézier patches: for the cubic case, each patch is represented by 16 control points, typically named by two indices, each of which can take on 4 values (0, 1, 2, and 3). Each control point itself consists of three values: the X, Y, and Z coordinates for the point. The internal representation uses a sequence of three double-precision numbers for each control point, with the control points in column-major order. For example,


      double[] controlPoints = {
                   P00x, P00y, P00z,
                   P10x, P10y, P10z,
                   ...
               };
 
where Pijx is the X component of the control point Pij, etc.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[][]
    add(double[][] A, double[][] B)
    Add two matrices.
    static double[][]
    add(double[][] R, double[][] A, double[][] B)
    Add two matrices and store the results.
    static double[]
    add(double[] A, double[] B)
    Add two flat matrices.
    static double[]
    add(double[] R, double[] A, double[] B)
    Add two flat matrices and store the results.
    static void
    add(int n, int m, double[] C, int offsetC, double[] A, int offsetA, double[] B, int offsetB, int indC, int vlenC, int indA, int vlenA, int indB, int vlenB)
    Add two flat, interleaved matrices and store the results.
    static double[]
    flatten(double[][] matrix, boolean colOrder)
    Convert a matrix represented by a two-dimensional array to a linear array in either row- or column-major order.
    static double[]
    flatten(double[] result, double[][] matrix, boolean colOrder)
    Convert a matrix represented by a two-dimensional array to a linear array in either row- or column-major order, providing an array in which to store the results.
    static double[]
    multiply(double[][] A, double[] B)
    Multiply a matrix with a vector
    static double[][]
    multiply(double[][] A, double[][] B)
    Multiple two matrices
    static double[][]
    multiply(double[][] C, double[][] A, double[][] B)
    Multiple two matrices, storing the results in a third matrix.
    static double[][]
    multiply(double[][] result, double s, double[][] matrix)
    Multiply a matrix by a scalar, storing the results.
    static double[]
    multiply(double[] C, double[][] A, double[] B)
    Multiply a matrix with a vector, storing the results in a specified vector
    static double[]
    multiply(double[] result, double s, double[] matrix)
    Multiply a flattened matrix (or a vector) by a scalar, storing the results.
    static double[]
    multiply(double[] A, int mA, int nA, double[] B, int mB, int nB, boolean colOrder)
    Multiply two flattened matrices and return a flattened matrix
    static double[]
    multiply(double[] C, int mC, int nC, double[] A, int mA, int nA, double[] B, int mB, int nB, boolean colOrder)
    Multiply two flattened matrices and store the results in a third flattened matrix.
    static void
    multiply(double[] C, int mC, int nC, int offsetC, double[] A, int mA, int nA, int offsetA, double[] B, int mB, int nB, int offsetB, boolean colOrder, int indC, int vlenC, int indA, int vlenA, int indB, int vlenB)
    Multiply flattened matrices and store the results in a third flattened matrix, when matrix elements are interleaved.
    static double[]
    multiply(double s, double[] matrix)
    Multiply a flattened matrix (or a vector) by a scalar.
    static double[][]
    multiply(double s, double[][] matrix)
    Multiply a matrix by a scalar
    static void
    multiply(int n, int m, double[] R, int offsetR, double s, double[] A, int offsetA, int indR, int vlenR, int indA, int vlenA)
    Multiply flattened matrix by a scalar and store the results in a second flattened matrix, when matrix elements are interleaved.
    static double[][]
    reflect(double[][] A)
    Reflect the rows and columns in a matrix.
    static double[][]
    reflect(double[][] R, double[][] A)
    Reflect the rows and columns in a matrix, providing a matrix to return.
    static double[][]
    reflect(double[][] R, double[][] A, int m, int n)
    Reflect the rows and columns in a matrix, providing a matrix to return and specifying dimensions.
    static double[][]
    reflect(double[][] A, int m, int n)
    Reflect the rows and columns in a matrix, specifying dimensions.
    static double[]
    reflect(double[] R, double[] A, int m, int n, boolean colOrder)
    Reflect the rows and columns in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results.
    static void
    reflect(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA)
    Reflect the rows and columns in an interleaved flat matrix, storing the results.
    static double[]
    reflect(double[] A, int m, int n, boolean colOrder)
    Reflect the rows and columns in a matrix, specifying dimensions and the column order..
    static void
    reflect(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA)
    Reflect the rows and columns in an interleaved flat matrix of single-precision real numbers, storing the results.
    static double[][]
    reflectColumns(double[][] A)
    Reflect the columns in a matrix.
    static double[][]
    reflectColumns(double[][] R, double[][] A)
    Reflect the columns in a matrix, providing a matrix to return.
    static double[][]
    reflectColumns(double[][] R, double[][] A, int m, int n)
    Reflect the columns in a matrix, providing a matrix to return and specifying dimensions.
    static double[][]
    reflectColumns(double[][] A, int m, int n)
    Reflect the columns in a matrix, specifying dimensions.
    static double[]
    reflectColumns(double[] R, double[] A, int m, int n, boolean colOrder)
    Reflect the columns in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results.
    static void
    reflectColumns(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA)
    Reflect the columns in an interleaved flat matrix, storing the results.
    static double[]
    reflectColumns(double[] A, int m, int n, boolean colOrder)
    Reflect the columns in a matrix, specifying dimensions and the column order..
    static void
    reflectColumns(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA)
    Reflect the columns in an interleaved flat matrix, storing the results and representing the matrices by arrays of floats.
    static double[][]
    reflectRows(double[][] A)
    Reflect the rows in a matrix.
    static double[][]
    reflectRows(double[][] R, double[][] A)
    Reflect the rows in a matrix, providing a matrix to return.
    static double[][]
    reflectRows(double[][] R, double[][] A, int m, int n)
    Reflect the rows in a matrix, providing a matrix to return and specifying dimensions.
    static double[][]
    reflectRows(double[][] A, int m, int n)
    Reflect the rows in a matrix, specifying dimensions.
    static double[]
    reflectRows(double[] R, double[] A, int m, int n, boolean colOrder)
    Reflect the rows in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results.
    static void
    reflectRows(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA)
    Reflect the rows in an interleaved flat matrix, storing the results.
    static double[]
    reflectRows(double[] A, int m, int n, boolean colOrder)
    Reflect the rows in a matrix, specifying dimensions and the column order..
    static void
    reflectRows(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA)
    Reflect the rows in an interleaved flat matrix, storing the results and representing the matrices by arrays of floats.
    static double[][]
    subtract(double[][] A, double[][] B)
    Subtract two matrices.
    static double[][]
    subtract(double[][] R, double[][] A, double[][] B)
    Subtract two matrices and store the results.
    static double[]
    subtract(double[] A, double[] B)
    Subtract two flat matrices.
    static double[]
    subtract(double[] R, double[] A, double[] B)
    Subtract two flat matrices and store the results.
    static double[][]
    transpose(double[][] A)
    Compute the transpose of a matrix.
    static double[][]
    transpose(double[][] R, double[][] A)
    Compute the transpose of a matrix.
    static double[][]
    transpose(double[][] R, double[][] A, int n, int m)
    Compute the transpose of a matrix given its dimensions.
    static double[][]
    transpose(double[][] A, int n, int m)
    Compute the transpose of a matrix of an m by n matrix.
    static double[]
    transpose(double[] A, int m, int n, boolean colOrder)
    Compute the transpose of a flat matrix.
    static double[]
    transpose(double[] R, int mR, int nR, double[] A, int mA, int nA, boolean colOrder)
    Compute the transpose of a flat matrix, storing the results.
    static void
    transpose(double[] R, int mR, int nR, int offsetR, double[] A, int mA, int nA, int offsetA, boolean colOrder, int indR, int vlenR, int indA, int vlenA)
    Compute the transpose of an interleaved, flat matrix, storing the results.
    static void
    transpose(float[] R, int mR, int nR, int offsetR, float[] A, int mA, int nA, int offsetA, boolean colOrder, int indR, int vlenR, int indA, int vlenA)
    Compute the transpose of an interleaved, flat, single-precision matrix, storing the results.
    static double[][]
    unflatten(double[][] result, double[] matrix, int m, int n, boolean colOrder)
    Convert a flattened matrix to an unflattened matrix.
    static double[][]
    unflatten(double[] matrix, int m, int n, boolean colOrder)
    Convert a flattened matrix to an unflattened matrix.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • flatten

      public static double[] flatten(double[][] matrix, boolean colOrder) throws IllegalArgumentException
      Convert a matrix represented by a two-dimensional array to a linear array in either row- or column-major order.
      Parameters:
      matrix - the matrix to convert
      colOrder - true for column-major order; false for row-major order
      Returns:
      return the converted matrix
      Throws:
      IllegalArgumentException - the array passed as the first argument is too short
    • flatten

      public static double[] flatten(double[] result, double[][] matrix, boolean colOrder) throws IllegalArgumentException
      Convert a matrix represented by a two-dimensional array to a linear array in either row- or column-major order, providing an array in which to store the results.
      Parameters:
      matrix - the matrix to convert
      colOrder - true for column-major order; false for row-major order
      result - the array in which to store the flattened matrix
      Returns:
      the matrix containing the result
      Throws:
      IllegalArgumentException - the array passed as the first argument is too short
    • unflatten

      public static double[][] unflatten(double[] matrix, int m, int n, boolean colOrder) throws IllegalArgumentException
      Convert a flattened matrix to an unflattened matrix. The flattened matrix can be in either row- or column-major order.
      Parameters:
      matrix - the flattened matrix
      m - the number of rows
      n - the number of columns
      colOrder - true for column-major order; false for row-major order
      Returns:
      the unflattened matrix
      Throws:
      IllegalArgumentException - The first argument has the wrong dimensions or the second argument has the wrong length
    • unflatten

      public static double[][] unflatten(double[][] result, double[] matrix, int m, int n, boolean colOrder) throws IllegalArgumentException
      Convert a flattened matrix to an unflattened matrix. The flattened matrix can be in either row- or column-major order. the length of the array matrix must be n*m and the matrix result must have n rows and m columns
      Parameters:
      result - the matrix (n rows and m columns) used to store the unflattened matrix
      matrix - the flattened matrix
      m - the number of rows
      n - the number of columns
      colOrder - true for column-major order; false for row-major order
      Returns:
      the unflattened matrix
      Throws:
      IllegalArgumentException - The first argument has the wrong dimensions or the second argument has the wrong length
    • add

      public static double[][] add(double[][] A, double[][] B) throws IllegalArgumentException
      Add two matrices.
      Parameters:
      A - the first matrix
      B - the second matrix
      Returns:
      the matrix sum A+B
      Throws:
      IllegalArgumentException - The matrix dimensions are not consistent
    • add

      public static double[][] add(double[][] R, double[][] A, double[][] B) throws IllegalArgumentException
      Add two matrices and store the results.
      Parameters:
      R - the result matrix
      A - the first matrix
      B - the second matrix All matrices must have the same number of rows and columns The matrices can be identical objects.
      Returns:
      the matrix sum A+B
      Throws:
      IllegalArgumentException - The matrix dimensions are not consistent
    • add

      public static double[] add(double[] A, double[] B) throws IllegalArgumentException
      Add two flat matrices.
      Parameters:
      A - the first matrix
      B - the second matrix
      Returns:
      the matrix sum A+B
      Throws:
      IllegalArgumentException - an argument was illegal
    • add

      public static double[] add(double[] R, double[] A, double[] B) throws IllegalArgumentException
      Add two flat matrices and store the results. The matrices can be identical objects.
      Parameters:
      R - the result matrix
      A - the first matrix
      B - the second matrix
      Returns:
      the matrix sum A+B
      Throws:
      IllegalArgumentException - the arrays R, A, and B do not have the same lengths
    • add

      public static void add(int n, int m, double[] C, int offsetC, double[] A, int offsetA, double[] B, int offsetB, int indC, int vlenC, int indA, int vlenA, int indB, int vlenB)
      Add two flat, interleaved matrices and store the results. The class documentation for MatrixOps describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap.
      Parameters:
      n - the number of rows
      m - the number of columns
      C - the result matrix
      offsetC - the index into C at which the results should be stored
      A - the first matrix
      offsetA - the offset into A for the first matrix
      B - the second matrix
      offsetB - the offset into B for the second matrix
      indC - the index specifying the component of the vector representing an element of C
      vlenC - the length of the vectors that are the components of C
      indA - the index specifying the component of the vector representing an element of A
      vlenA - the length of the vectors that are the components of A
      indB - the index specifying the component of the vector representing an element of B
      vlenB - the length of the vectors that are the components of B
    • transpose

      public static double[][] transpose(double[][] A) throws IllegalArgumentException
      Compute the transpose of a matrix.
      Parameters:
      A - the matrix
      Returns:
      a new matrix containing AT
      Throws:
      IllegalArgumentException - the matrix R does have dimensions compatible with the matrix A, or when R and A are the same matrix, that matrix is not a square matrix
    • transpose

      public static double[][] transpose(double[][] A, int n, int m) throws IllegalArgumentException
      Compute the transpose of a matrix of an m by n matrix.
      Parameters:
      A - the matrix
      n - the number of rows
      m - the number of columns
      Returns:
      a new matrix containing AT
      Throws:
      IllegalArgumentException - the matrix R does have dimensions compatible with the matrix A, or when R and A are the same matrix, that matrix is not a square matrix
    • transpose

      public static double[][] transpose(double[][] R, double[][] A) throws IllegalArgumentException
      Compute the transpose of a matrix. The matrices can be identical objects.
      Parameters:
      R - the matrix that will contain the transpose of A
      A - the matrix to transpose
      Returns:
      the matrix R = AT
      Throws:
      IllegalArgumentException - the matrix R does have dimensions compatible with the matrix A, or when R and A are the same matrix, that matrix is not a square matrix
    • transpose

      public static double[][] transpose(double[][] R, double[][] A, int n, int m) throws IllegalArgumentException
      Compute the transpose of a matrix given its dimensions. The matrices can be identical objects. The matrix A may have longer rows or columns than its dimensions (m by n) indicate. Similarly R may have longer rows or colums than its dimensions (n, m) indicate.
      Parameters:
      R - the matrix that will contain the transpose of A
      A - the matrix to transpose
      n - the number of rows of A and columns of R
      m - the number of columns of A and rows of R
      Returns:
      the matrix R = AT
      Throws:
      IllegalArgumentException - the matrix R does have dimensions compatible with the matrix A, or when R and A are the same matrix, that matrix is not a square matrix
    • transpose

      public static double[] transpose(double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException
      Compute the transpose of a flat matrix.
      Parameters:
      A - the matrix to transpose
      m - the number of rows
      n - the number of columns
      colOrder - true if the matrices are stored in column-major order; false if the matrices are stored in row-major order
      Returns:
      the transpose of A
      Throws:
      IllegalArgumentException - the array A is too short given the specified numbers of rows and columns
    • transpose

      public static double[] transpose(double[] R, int mR, int nR, double[] A, int mA, int nA, boolean colOrder) throws IllegalArgumentException
      Compute the transpose of a flat matrix, storing the results. The matrices can be identical objects but in that case they must be square matrices.
      Parameters:
      R - the matrix that will contain the transpose
      mR - the number of rows for R
      nR - the number of columns for R
      A - the matrix to transpose
      mA - the number of rows for A
      nA - the number of columns for A
      colOrder - true if the matrices are stored in column-major order; false if the matrices are stored in row-major order
      Returns:
      the matrix R = AT
      Throws:
      IllegalArgumentException - The matrix R must be an m by n matrix when A is an n by m matrix; the array A or the array R are too short given the specified numbers of rows and columns
    • transpose

      public static void transpose(double[] R, int mR, int nR, int offsetR, double[] A, int mA, int nA, int offsetA, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException
      Compute the transpose of an interleaved, flat matrix, storing the results. The class documentation for MatrixOps describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. If R and A are identical, they must be square matrices.
      Parameters:
      R - the matrix that will contain the transpose
      mR - the number of rows for the matrix contained by R
      nR - the number of columns for the matrix contained by R
      offsetR - the offset into R at which the matrix R starts
      A - the matrix to transpose
      mA - the number of rows for the matrix contained by A
      nA - the number of columns for the matrix contained by A
      offsetA - the offset into A at which the matrix A starts
      colOrder - true if the matrices are stored in column-major order; false if the matrices are stored in row-major order
      indR - The index into each vector provided by each element of R
      vlenR - the length of the vectors that are elements of R
      indA - The index into each vector provided by each element of A
      vlenA - the length of the vectors that are elements of A
      Throws:
      IllegalArgumentException - the dimensions of the matrices are not consistent, a square message was expected in the case where R == A, or the R and A arrays are too short given the specified offsets and vector dimensions
    • transpose

      public static void transpose(float[] R, int mR, int nR, int offsetR, float[] A, int mA, int nA, int offsetA, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException
      Compute the transpose of an interleaved, flat, single-precision matrix, storing the results. The class documentation for MatrixOps describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. If R and A are identical, they must be square matrices.

      Note: This method is provided because it is needed in the implementation of some Surface3D.Float methods.

      Parameters:
      R - the matrix that will contain the transpose
      mR - the number of rows for the matrix contained by R
      nR - the number of columns for the matrix contained by R
      offsetR - the offset into R at which the matrix R starts
      A - the matrix to transpose
      mA - the number of rows for the matrix contained by A
      nA - the number of columns for the matrix contained by A
      offsetA - the offset into A at which the matrix A starts
      colOrder - true if the matrices are stored in column-major order; false if the matrices are stored in row-major order
      indR - The index into each vector provided by each element of R
      vlenR - the length of the vectors that are elements of R
      indA - The index into each vector provided by each element of A
      vlenA - the length of the vectors that are elements of A
      Throws:
      IllegalArgumentException - the dimensions of the matrices are not consistent, a square message was expected in the case where R == A, or the R and A arrays are too short given the specified offsets and vector dimensions
    • reflectRows

      public static double[][] reflectRows(double[][] A) throws IllegalArgumentException
      Reflect the rows in a matrix. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.
      Parameters:
      A - the orgininal matrix
      Returns:
      the reflected matrix
      Throws:
      IllegalArgumentException
    • reflectRows

      public static double[][] reflectRows(double[][] R, double[][] A) throws IllegalArgumentException
      Reflect the rows in a matrix, providing a matrix to return. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.

      R and A must have the same dimensions.

      Parameters:
      R - the reflected matrix
      A - the orgininal matrix
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflectRows

      public static double[][] reflectRows(double[][] R, double[][] A, int m, int n) throws IllegalArgumentException
      Reflect the rows in a matrix, providing a matrix to return and specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.

      R and A must have the dimensions large enough so that R[i][j] or A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored.

      Parameters:
      R - the reflected matrix
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflectRows

      public static double[][] reflectRows(double[][] A, int m, int n)
      Reflect the rows in a matrix, specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible.

      Parameters:
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      Returns:
      the reflected matrix R
    • reflectRows

      public static double[] reflectRows(double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException
      Reflect the rows in a matrix, specifying dimensions and the column order.. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflectRows

      public static double[] reflectRows(double[] R, double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException
      Reflect the rows in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      R - the reflected matrix, the elements of which will be set
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflectRows

      public static void reflectRows(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException
      Reflect the rows in an interleaved flat matrix, storing the results. The class documentation for MatrixOps describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      R - the reflected matrix, the elements of which will be set
      offsetR - the offset into the array R at which the reflected matrix starts
      A - the orgininal matrix
      offsetA - the offset in the array A at which the matrix to be reflected starts
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      indR - The index into each vector provided by each element of R
      vlenR - the length of the vectors that are elements of R
      indA - The index into each vector provided by each element of A
      vlenA - the length of the vectors that are elements of A
      Throws:
      IllegalArgumentException
    • reflectRows

      public static void reflectRows(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException
      Reflect the rows in an interleaved flat matrix, storing the results and representing the matrices by arrays of floats. The class documentation for MatrixOps describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      R - the reflected matrix, the elements of which will be set
      offsetR - the offset into the array R at which the reflected matrix starts
      A - the orgininal matrix
      offsetA - the offset in the array A at which the matrix to be reflected starts
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      indR - The index into each vector provided by each element of R
      vlenR - the length of the vectors that are elements of R
      indA - The index into each vector provided by each element of A
      vlenA - the length of the vectors that are elements of A
      Throws:
      IllegalArgumentException
    • reflectColumns

      public static double[][] reflectColumns(double[][] A) throws IllegalArgumentException
      Reflect the columns in a matrix. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.
      Parameters:
      A - the orgininal matrix
      Returns:
      the reflected matrix
      Throws:
      IllegalArgumentException
    • reflectColumns

      public static double[][] reflectColumns(double[][] R, double[][] A) throws IllegalArgumentException
      Reflect the columns in a matrix, providing a matrix to return. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      R and A must have the same dimensions.

      Parameters:
      R - the reflected matrix
      A - the orgininal matrix
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflectColumns

      public static double[][] reflectColumns(double[][] R, double[][] A, int m, int n) throws IllegalArgumentException
      Reflect the columns in a matrix, providing a matrix to return and specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      R and A must have the dimensions large enough so that R[i][j] or A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored.

      Parameters:
      R - the reflected matrix
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflectColumns

      public static double[][] reflectColumns(double[][] A, int m, int n)
      Reflect the columns in a matrix, specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible.

      Parameters:
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      Returns:
      the reflected matrix R
    • reflectColumns

      public static double[] reflectColumns(double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException
      Reflect the columns in a matrix, specifying dimensions and the column order.. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflectColumns

      public static double[] reflectColumns(double[] R, double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException
      Reflect the columns in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      R - the reflected matrix, the elements of which will be set
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflectColumns

      public static void reflectColumns(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException
      Reflect the columns in an interleaved flat matrix, storing the results. The class documentation for MatrixOps describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      R - the reflected matrix, the elements of which will be set
      offsetR - the offset into the array R at which the reflected matrix starts
      A - the orgininal matrix
      offsetA - the offset in the array A at which the matrix to be reflected starts
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      indR - The index into each vector provided by each element of R
      vlenR - the length of the vectors that are elements of R
      indA - The index into each vector provided by each element of A
      vlenA - the length of the vectors that are elements of A
      Throws:
      IllegalArgumentException
    • reflectColumns

      public static void reflectColumns(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException
      Reflect the columns in an interleaved flat matrix, storing the results and representing the matrices by arrays of floats. The class documentation for MatrixOps describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      R - the reflected matrix, the elements of which will be set
      offsetR - the offset into the array R at which the reflected matrix starts
      A - the orgininal matrix
      offsetA - the offset in the array A at which the matrix to be reflected starts
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      indR - The index into each vector provided by each element of R
      vlenR - the length of the vectors that are elements of R
      indA - The index into each vector provided by each element of A
      vlenA - the length of the vectors that are elements of A
      Throws:
      IllegalArgumentException
    • reflect

      public static double[][] reflect(double[][] A) throws IllegalArgumentException
      Reflect the rows and columns in a matrix. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.
      Parameters:
      A - the orgininal matrix
      Returns:
      the reflected matrix
      Throws:
      IllegalArgumentException
    • reflect

      public static double[][] reflect(double[][] R, double[][] A) throws IllegalArgumentException
      Reflect the rows and columns in a matrix, providing a matrix to return. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      R and A must have the same dimensions.

      Parameters:
      R - the reflected matrix
      A - the orgininal matrix
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflect

      public static double[][] reflect(double[][] R, double[][] A, int m, int n) throws IllegalArgumentException
      Reflect the rows and columns in a matrix, providing a matrix to return and specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      R and A must have the dimensions large enough so that R[i][j] or A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored.

      Parameters:
      R - the reflected matrix
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflect

      public static double[][] reflect(double[][] A, int m, int n)
      Reflect the rows and columns in a matrix, specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible.

      Parameters:
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      Returns:
      the reflected matrix R
    • reflect

      public static double[] reflect(double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException
      Reflect the rows and columns in a matrix, specifying dimensions and the column order.. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflect

      public static double[] reflect(double[] R, double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException
      Reflect the rows and columns in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      R - the reflected matrix, the elements of which will be set
      A - the orgininal matrix
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      Returns:
      the reflected matrix R
      Throws:
      IllegalArgumentException
    • reflect

      public static void reflect(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException
      Reflect the rows and columns in an interleaved flat matrix, storing the results. The class documentation for MatrixOps describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      R - the reflected matrix, the elements of which will be set
      offsetR - the offset into the array R at which the reflected matrix starts
      A - the orgininal matrix
      offsetA - the offset in the array A at which the matrix to be reflected starts
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      indR - The index into each vector provided by each element of R
      vlenR - the length of the vectors that are elements of R
      indA - The index into each vector provided by each element of A
      vlenA - the length of the vectors that are elements of A
      Throws:
      IllegalArgumentException
    • reflect

      public static void reflect(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException
      Reflect the rows and columns in an interleaved flat matrix of single-precision real numbers, storing the results. The class documentation for MatrixOps describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.

      A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.

      Parameters:
      R - the reflected matrix, the elements of which will be set
      offsetR - the offset into the array R at which the reflected matrix starts
      A - the orgininal matrix
      offsetA - the offset in the array A at which the matrix to be reflected starts
      m - the number of rows
      n - the number of columns
      colOrder - true for column major order; false for row major order
      indR - The index into each vector provided by each element of R
      vlenR - the length of the vectors that are elements of R
      indA - The index into each vector provided by each element of A
      vlenA - the length of the vectors that are elements of A
      Throws:
      IllegalArgumentException
    • multiply

      public static double[][] multiply(double s, double[][] matrix)
      Multiply a matrix by a scalar
      Parameters:
      s - the scalar
      matrix - a matrix
      Returns:
      the product matrix
    • multiply

      public static double[][] multiply(double[][] result, double s, double[][] matrix) throws IllegalArgumentException
      Multiply a matrix by a scalar, storing the results. The matrices may be identical.
      Parameters:
      result - the matrix to store the results
      s - the scalar
      matrix - a matrix
      Returns:
      the product matrix
      Throws:
      IllegalArgumentException - the dimensions of the matrices are not compatible
    • multiply

      public static double[] multiply(double s, double[] matrix) throws IllegalArgumentException
      Multiply a flattened matrix (or a vector) by a scalar. The matrices may be identical.
      Parameters:
      s - the scalar
      matrix - a matrix
      Returns:
      the product matrix
      Throws:
      IllegalArgumentException - the dimensions of the matrices are not compatible
    • multiply

      public static double[] multiply(double[] result, double s, double[] matrix) throws IllegalArgumentException
      Multiply a flattened matrix (or a vector) by a scalar, storing the results.
      Parameters:
      result - the matrix to store the results
      s - the scalar
      matrix - a matrix
      Returns:
      the matrix result
      Throws:
      IllegalArgumentException - the result matrix has the wrong length
    • multiply

      public static void multiply(int n, int m, double[] R, int offsetR, double s, double[] A, int offsetA, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException
      Multiply flattened matrix by a scalar and store the results in a second flattened matrix, when matrix elements are interleaved. The class documentation for MatrixOps describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap.
      Parameters:
      n - the number of rows
      m - the number of columns
      R - the result matrix
      offsetR - the index into R at which the results should be stored
      s - the scalar
      A - the matrix being multiplied
      offsetA - the offset into A for the first matrix
      indR - the index specifying the component of the vector representing an element of R
      vlenR - the length of the vectors that are the components of R
      indA - the index specifying the component of the vector representing an element of A
      vlenA - the length of the vectors that are the components of A
      Throws:
      IllegalArgumentException - arguments are out of range or inconsistent
    • multiply

      public static double[] multiply(double[][] A, double[] B) throws IllegalArgumentException
      Multiply a matrix with a vector
      Parameters:
      A - the matrix
      B - the vector
      Returns:
      the vector containing the product
      Throws:
      IllegalArgumentException - The dimensions of A and B are not compatible with matrix multiplication, or C has the wrong length
    • multiply

      public static double[] multiply(double[] C, double[][] A, double[] B)
      Multiply a matrix with a vector, storing the results in a specified vector
      Parameters:
      C - the vector storing the result
      A - the matrix
      B - the vector
      Returns:
      the vector containing the product
      Throws:
      IllegalArgumentException - The dimensions of A and B are not compatible with matrix multiplication, or C has the wrong length
    • multiply

      public static double[][] multiply(double[][] A, double[][] B) throws IllegalArgumentException
      Multiple two matrices
      Parameters:
      A - the first matrix
      B - the second matrix
      Returns:
      the matrix product AB
      Throws:
      IllegalArgumentException - the dimensions of A, B and C are not compatible
    • multiply

      public static double[][] multiply(double[][] C, double[][] A, double[][] B) throws IllegalArgumentException
      Multiple two matrices, storing the results in a third matrix. The result matrix C may be equal to A or B, provided these are square matrices.
      Parameters:
      C - the matrix whose value will be changed to the matrix product AB
      A - the first matrix
      B - the second matrix
      Returns:
      the result matrix C
      Throws:
      IllegalArgumentException - the dimensions of A, B and C are not compatible
    • multiply

      public static double[] multiply(double[] A, int mA, int nA, double[] B, int mB, int nB, boolean colOrder) throws IllegalArgumentException
      Multiply two flattened matrices and return a flattened matrix
      Parameters:
      A - the first matrix
      B - the second matrix
      mA - the number of rows for matrix A
      nA - the number of columns for matrix A
      mB - the number of rows for matrix B
      nB - the number of columns for matrix B
      colOrder - true for column-major order; false for row-major order
      Returns:
      a flattened matrix containing the matrix product AB
      Throws:
      IllegalArgumentException - one of more of the matrices, represented by an array, are too short or the dimensions of the matrices are not compatible for matrix multiplication
    • multiply

      public static double[] multiply(double[] C, int mC, int nC, double[] A, int mA, int nA, double[] B, int mB, int nB, boolean colOrder)
      Multiply two flattened matrices and store the results in a third flattened matrix. The matrix C may be equal to A or B provided that these are square matrices.
      Parameters:
      C - the flattened matrix that will hold the result
      mC - the number of rows for matrix A
      nC - the number of columns for matrix A
      A - the first flattened matrix
      mA - the number of rows for matrix A
      nA - the number of columns for matrix A
      B - the second flattened matrix
      mB - the number of rows for matrix B
      nB - the number of columns for matrix B
      colOrder - true for column-major order; false for row-major order
      Returns:
      the matrix C
      Throws:
      IllegalArgumentException - one of more of the matrices, represented by an array, are too short or the dimensions of the matrices are not compatible for matrix multiplication
    • multiply

      public static void multiply(double[] C, int mC, int nC, int offsetC, double[] A, int mA, int nA, int offsetA, double[] B, int mB, int nB, int offsetB, boolean colOrder, int indC, int vlenC, int indA, int vlenA, int indB, int vlenB) throws IllegalArgumentException
      Multiply flattened matrices and store the results in a third flattened matrix, when matrix elements are interleaved. The class documentation for MatrixOps describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector.

      This method has a large number of parameters. It is used by some classes in the org.bzdev.geom package involving Bézier surfaces. For example, the control points of a Bézier patch with coordinate (u, v) can be represented by a 4 by 4 matrix P whose components Pij are points in a three dimensional space. The index i is used with u and the index j with v. Points with the same value of v are stored together in the order of increasing i in a flattened matrix (i.e., the points are stored in column-major order). Each of these points is represented by three contiguous numbers representing the control points' X, Y, and Z coordinates. Splitting a Bézier involves computing the control points for a new patch, and this can be done by creating a matrix with the same indices but containing only one of the coordinates (X, Y, or Z). This matrix is then multiplied with two fixed matrices. This method allows the multiplication to be done in place. For example,

      
         for (int k = 0; k < 3; k++) {
             MatrixOps.multiply(C, 4, 4, 0,
                                P, 4, 4, patchOffset,
                               SR, 4, 4, 0,
                               true,
                               k, 3,
                               k, 3,
                               0, 1);
         }
       
      will perform one of these multiplications. The matrix SR is a constant matrix - the same for X, Y, and Z - so its elements are a one dimensional vector (i.e., a single number). The other two are vectors with three dimensions. The patch offset allows one out of a multiple of matrices stored in the same array to be referenced.

      The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap.

      Parameters:
      C - the flattened matrix that will hold the result, the matrix product AB
      mC - the number of rows for matrix C
      nC - the number of columns for matrix C
      offsetC - the offset into C at which the matrix starts (i.e, the index in C of the first element of the matrix)
      A - the first flattened matrix
      mA - the number of rows for matrix A
      nA - the number of columns for matrix A
      offsetA - the offset into A at which the matrix starts (i.e, the index in A of the first element of the matrix)
      B - the second flattened matrix
      mB - the number of rows for matrix B
      nB - the number of columns for matrix B
      offsetB - the offset into B at which the matrix starts (i.e, the index in B of the first element of the matrix)
      colOrder - true for column-major order; false for row-major order
      indC - the index of the vector component for C to use for this computation
      vlenC - the vector length for an element of C
      indA - the index of the vector component for A to use for this computation
      vlenA - the vector length for an element of A
      indB - the index of the vector component for B to use for this computation
      vlenB - the vector length for an element of B
      Throws:
      IllegalArgumentException - if the vector lengths are not incorrect or an array is not long enough to hold the specified number of rows and columns, or the offsets are not appropriate
    • subtract

      public static double[][] subtract(double[][] A, double[][] B) throws IllegalArgumentException
      Subtract two matrices.
      Parameters:
      A - the first matrix
      B - the second matrix
      Returns:
      the matrix difference A-B
      Throws:
      IllegalArgumentException - The matrix dimensions are not consistent
    • subtract

      public static double[][] subtract(double[][] R, double[][] A, double[][] B) throws IllegalArgumentException
      Subtract two matrices and store the results.
      Parameters:
      R - the result matrix
      A - the first matrix
      B - the second matrix All matrices must have the same number of rows and columns The matrices can be identical objects.
      Returns:
      the matrix difference A-B
      Throws:
      IllegalArgumentException - The matrix dimensions are not consistent
    • subtract

      public static double[] subtract(double[] A, double[] B) throws IllegalArgumentException
      Subtract two flat matrices.
      Parameters:
      A - the first matrix
      B - the second matrix
      Returns:
      the matrix difference A-B
      Throws:
      IllegalArgumentException - if the arguments are not valid
    • subtract

      public static double[] subtract(double[] R, double[] A, double[] B) throws IllegalArgumentException
      Subtract two flat matrices and store the results. The matrices can be identical objects.
      Parameters:
      R - the result matrix
      A - the first matrix
      B - the second matrix
      Returns:
      the matrix difference A-B
      Throws:
      IllegalArgumentException - the arrays R, A, and B do not have the same lengths