Module math

Class VMath

java.lang.Object
de.lmu.ifi.dbs.elki.math.linearalgebra.VMath

public final class VMath extends Object
Class providing basic vector mathematics, for low-level vectors stored as double[]. While this is less nice syntactically, it reduces memory usage and VM overhead.
Author:
Erich Schubert
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    A small number to handle numbers near 0 as 0.
    static final String
    Error message (in assertions!)
    static final String
    Error message (in assertions!)
    static final String
    Error message (in assertions!)
  • Method Summary

    Modifier and Type
    Method
    Description
    static final boolean
    almostEquals(double[][] m1, double[][] m2)
    Compare two matrices with a delta parameter to take numerical errors into account.
    static final boolean
    almostEquals(double[][] m1, double[][] m2, double maxdelta)
    Compare two matrices with a delta parameter to take numerical errors into account.
    static final double[][]
    appendColumns(double[][] m1, double[][] m2)
    Returns a matrix which consists of this matrix and the specified columns.
    static final void
    clear(double[] v1)
    Reset the Vector to 0.
    static final double[]
    columnPackedCopy(double[][] m1)
    Make a one-dimensional column packed copy of the internal array.
    static final double[]
    copy(double[] v)
    Returns a copy of this vector.
    static final double[][]
    copy(double[][] m1)
    Make a deep copy of a matrix.
    static void
    cross3D(double[] vo, double[] v1, double[] v2)
    Cross product for 3d vectors, i.e.
    static final double[][]
    diagonal(double[] v1)
    Returns a quadratic Matrix consisting of zeros and of the given values on the diagonal.
    static final boolean
    equals(double[][] m1, double[][] m2)
    Test for equality
    static final boolean
    equals(double[] v1, double[] v2)
    Compare for equality.
    static final double
    euclideanLength(double[] v1)
    Euclidean length of the vector
    static final double[]
    getCol(double[][] m1, int col)
    Get a column from a matrix as vector.
    static final int
    getColumnDimensionality(double[][] m1)
    Returns the dimensionality of the columns of this matrix.
    static final double[]
    getDiagonal(double[][] m1)
    getDiagonal returns array of diagonal-elements.
    static final double[][]
    getMatrix(double[][] m1, int[] r, int[] c)
    Get a submatrix.
    static final double[][]
    getMatrix(double[][] m1, int[] r, int c0, int c1)
    Get a submatrix.
    static final double[][]
    getMatrix(double[][] m1, int r0, int r1, int[] c)
    Get a submatrix.
    static final double[][]
    getMatrix(double[][] m1, int r0, int r1, int c0, int c1)
    Get a submatrix.
    static final double[]
    getRow(double[][] m1, int r)
    Returns the rth row of this matrix as vector.
    static final int
    getRowDimensionality(double[][] m1)
    Returns the dimensionality of the rows of this matrix.
    static final int
    hashCode(double[] v1)
    Compute the hash code for the vector
    static final int
    hashCode(double[][] m1)
    Compute hash code
    static final double[][]
    identity(int m, int n)
    Generate identity matrix
    static final double[][]
    minus(double[][] m1, double[][] m2)
    m3 = m1 - m2
    static final double[]
    minus(double[] v1, double d)
    Compute v1 - d
    static final double[]
    minus(double[] v1, double[] v2)
    Computes v1 - v2
    static final double[][]
    minusEquals(double[][] m1, double[][] m2)
    m1 = m1 - m2, overwriting m1
    static final double[]
    minusEquals(double[] v1, double d)
    Computes v1 = v1 - d, overwriting v1
    static final double[]
    minusEquals(double[] v1, double[] v2)
    Computes v1 = v1 - v2, overwriting v1
    static final double[][]
    minusTimes(double[][] m1, double[][] m2, double s2)
    m3 = m1 - s2 * m2
    static final double[]
    minusTimes(double[] v1, double[] v2, double s2)
    Computes v1 - v2 * s2
    static final double[][]
    minusTimesEquals(double[][] m1, double[][] m2, double s2)
    m1 = m1 - s2 * m2, overwriting m1
    static final double[]
    minusTimesEquals(double[] v1, double[] v2, double s2)
    Computes v1 = v1 - v2 * s2, overwriting v1
    static final double[]
    normalize(double[] v1)
    Normalizes v1 to the length of 1.0.
    static final void
    normalizeColumns(double[][] m1)
    Normalizes the columns of this matrix to length of 1.0.
    static final double[]
    normalizeEquals(double[] v1)
    Normalizes v1 to the length of 1.0.
    static final double[][]
    orthonormalize(double[][] m1)
    Returns an orthonormalization of this matrix.
    static final double[][]
    plus(double[][] m1, double[][] m2)
    m3 = m1 + m2
    static final double[]
    plus(double[] v1, double d)
    Computes v1 + d
    static final double[]
    plus(double[] v1, double[] v2)
    Computes v1 + v2 for vectors.
    static final double[][]
    plusEquals(double[][] m1, double[][] m2)
    m1 = m1 + m2, overwriting m1
    static final double[]
    plusEquals(double[] v1, double d)
    Computes v1 = v1 + d, overwriting v1
    static final double[]
    plusEquals(double[] v1, double[] v2)
    Computes v1 = v1 + v2, overwriting v1
    static final double[][]
    plusTimes(double[][] m1, double[][] m2, double s2)
    m3 = m1 + s2 * m2
    static final double[]
    plusTimes(double[] v1, double[] v2, double s2)
    Computes v1 + v2 * s2
    static final double[][]
    plusTimesEquals(double[][] m1, double[][] m2, double s2)
    m1 = m1 + s2 * m2, overwriting m1
    static final double[]
    plusTimesEquals(double[] v1, double[] v2, double s2)
    Computes v1 = v1 + v2 * s2, overwriting v1
    static final double[]
    project(double[] v1, double[][] m2)
    Projects this row vector into the subspace formed by the specified matrix v.
    static final double[][]
    random(int m, int n)
    Generate matrix with random elements
    static final double[]
    randomNormalizedVector(int dimensionality)
    Returns a randomly created vector of length 1.0
    static final double[]
    rotate90Equals(double[] v1)
    Rotate vector by 90 degrees.
    static final double[]
    rowPackedCopy(double[][] m1)
    Make a one-dimensional row packed copy of the internal array.
    static final double
    scalarProduct(double[] v1, double[] v2)
    Returns the scalar product (dot product) of this vector and the specified vector v.
    static final void
    setCol(double[][] m1, int c, double[] column)
    Sets the cth column of this matrix to the specified column.
    static final void
    setMatrix(double[][] m1, int[] r, int[] c, double[][] m2)
    Set a submatrix.
    static final void
    setMatrix(double[][] m1, int[] r, int c0, int c1, double[][] m2)
    Set a submatrix.
    static final void
    setMatrix(double[][] m1, int r0, int r1, int[] c, double[][] m2)
    Set a submatrix.
    static final void
    setMatrix(double[][] m1, int r0, int r1, int c0, int c1, double[][] m2)
    Set a submatrix.
    static final void
    setRow(double[][] m1, int r, double[] row)
    Sets the rth row of this matrix to the specified vector.
    static final double[][]
    times(double[][] m1, double s1)
    Multiply a matrix by a scalar, m3 = s1*m1
    static final double[]
    times(double[][] m1, double[] v2)
    Linear algebraic matrix multiplication, m1 * v2
    static final double[][]
    times(double[][] m1, double[][] m2)
    Linear algebraic matrix multiplication, m1 * m2
    static final double[]
    times(double[] v1, double s1)
    Computes v1 * s1
    static final double[][]
    times(double[] v1, double[][] m2)
    Matrix multiplication: v1 * m2
    static final double[][]
    timesEquals(double[][] m1, double s1)
    Multiply a matrix by a scalar in place, m1 = s1 * m1
    static final double[]
    timesEquals(double[] v1, double s)
    Computes v1 = v1 * s1, overwritings v1
    static final double[]
    timesMinus(double[] v1, double s1, double[] v2)
    Computes v1 * s1 - v2
    static final double[]
    timesMinusEquals(double[] v1, double s1, double[] v2)
    Computes v1 = v1 * s1 - v2, overwriting v1
    static final double[]
    timesMinusTimes(double[] v1, double s1, double[] v2, double s2)
    Computes v1 * s1 - v2 * s2
    static final double[]
    timesMinusTimesEquals(double[] v1, double s1, double[] v2, double s2)
    Computes v1 = v1 * s1 - v2 * s2, overwriting v1
    static final double[]
    timesPlus(double[] v1, double s1, double[] v2)
    Computes v1 * s1 + v2
    static final double[]
    timesPlusEquals(double[] v1, double s1, double[] v2)
    Computes v1 = v1 * s1 + v2, overwriting v1
    static final double[]
    timesPlusTimes(double[] v1, double s1, double[] v2, double s2)
    Computes v1 * s1 + v2 * s2
    static final double[]
    timesPlusTimesEquals(double[] v1, double s1, double[] v2, double s2)
    Computes v1 = v1 * s1 + v2 * s2, overwriting v1
    static final double[][]
    timesTranspose(double[][] m1, double[][] m2)
    Linear algebraic matrix multiplication, m1 * m2^T
    static final double[][]
    timesTranspose(double[] v1, double[] v2)
    Linear algebraic matrix multiplication, v1 * v2^T
    static final double[][]
    timesTranspose(double[] v1, double[][] m2)
    Linear algebraic matrix multiplication, v1 * m2^T
    static final double[][]
    transpose(double[] v)
    Transpose vector to a matrix.
    static final double[][]
    transpose(double[][] m1)
    Matrix transpose
    static final double[]
    transposeTimes(double[][] m1, double[] v2)
    Linear algebraic matrix multiplication, m1T * v2
    static final double[][]
    transposeTimes(double[][] m1, double[][] m2)
    Linear algebraic matrix multiplication, m1T * m2
    static final double
    transposeTimes(double[] v1, double[] v2)
    Linear algebraic matrix multiplication, v1T * v2
    static final double[][]
    transposeTimes(double[] v1, double[][] m2)
    Linear algebraic matrix multiplication, v1T * m2
    static double
    transposeTimesTimes(double[] a, double[][] B, double[] c)
    Linear algebraic matrix multiplication, aT * B * c
    static final double[][]
    transposeTimesTranspose(double[][] m1, double[][] m2)
    Linear algebraic matrix multiplication, m1^T * m2^T.
    static final double[][]
    unitMatrix(int dim)
    Returns the unit matrix of the specified dimension.
    static final double[]
    unitVector(int dimensionality, int i)
    Returns the ith unit vector of the specified dimensionality.
    static final double[][]
    zeroMatrix(int dim)
    Returns the zero matrix of the specified dimension.

    Methods inherited from class java.lang.Object

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

    • DELTA

      public static final double DELTA
      A small number to handle numbers near 0 as 0.
      See Also:
    • ERR_VEC_DIMENSIONS

      public static final String ERR_VEC_DIMENSIONS
      Error message (in assertions!) when vector dimensionalities do not agree.
      See Also:
    • ERR_MATRIX_DIMENSIONS

      public static final String ERR_MATRIX_DIMENSIONS
      Error message (in assertions!) when matrix dimensionalities do not agree.
      See Also:
    • ERR_MATRIX_INNERDIM

      public static final String ERR_MATRIX_INNERDIM
      Error message (in assertions!) when matrix dimensionalities do not agree.
      See Also:
  • Method Details

    • randomNormalizedVector

      public static final double[] randomNormalizedVector(int dimensionality)
      Returns a randomly created vector of length 1.0
      Parameters:
      dimensionality - dimensionality
      Returns:
      Random vector of length 1.0
    • unitVector

      public static final double[] unitVector(int dimensionality, int i)
      Returns the ith unit vector of the specified dimensionality.
      Parameters:
      dimensionality - the dimensionality of the vector
      i - the index
      Returns:
      the ith unit vector of the specified dimensionality
    • copy

      public static final double[] copy(double[] v)
      Returns a copy of this vector.
      Parameters:
      v - original vector
      Returns:
      a copy of this vector
    • transpose

      public static final double[][] transpose(double[] v)
      Transpose vector to a matrix.
      Parameters:
      v - Vector
      Returns:
      Matrix
    • plus

      public static final double[] plus(double[] v1, double[] v2)
      Computes v1 + v2 for vectors.
      Parameters:
      v1 - first vector
      v2 - second vector
      Returns:
      the sum v1 + v2
    • plusTimes

      public static final double[] plusTimes(double[] v1, double[] v2, double s2)
      Computes v1 + v2 * s2
      Parameters:
      v1 - first vector
      v2 - second vector
      s2 - the scalar
      Returns:
      the result of v1 + v2 * s2
    • timesPlus

      public static final double[] timesPlus(double[] v1, double s1, double[] v2)
      Computes v1 * s1 + v2
      Parameters:
      v1 - first vector
      s1 - the scalar for v1
      v2 - second vector
      Returns:
      the result of v1 * s1 + v2
    • timesPlusTimes

      public static final double[] timesPlusTimes(double[] v1, double s1, double[] v2, double s2)
      Computes v1 * s1 + v2 * s2
      Parameters:
      v1 - first vector
      s1 - the scalar for v1
      v2 - second vector
      s2 - the scalar for v2
      Returns:
      the result of v1 * s1 + v2 * s2
    • plusEquals

      public static final double[] plusEquals(double[] v1, double[] v2)
      Computes v1 = v1 + v2, overwriting v1
      Parameters:
      v1 - first vector (overwritten)
      v2 - second vector
      Returns:
      v1 = v1 + v2
    • plusTimesEquals

      public static final double[] plusTimesEquals(double[] v1, double[] v2, double s2)
      Computes v1 = v1 + v2 * s2, overwriting v1
      Parameters:
      v1 - first vector
      v2 - another vector
      s2 - scalar vor v2
      Returns:
      v1 = v1 + v2 * s2
    • timesPlusEquals

      public static final double[] timesPlusEquals(double[] v1, double s1, double[] v2)
      Computes v1 = v1 * s1 + v2, overwriting v1
      Parameters:
      v1 - first vector
      s1 - scalar for v1
      v2 - another vector
      Returns:
      v1 = v1 * s1 + v2
    • timesPlusTimesEquals

      public static final double[] timesPlusTimesEquals(double[] v1, double s1, double[] v2, double s2)
      Computes v1 = v1 * s1 + v2 * s2, overwriting v1
      Parameters:
      v1 - first vector
      s1 - scalar for v1
      v2 - another vector
      s2 - scalar for v2
      Returns:
      v1 = v1 * s1 + v2 * s2
    • plus

      public static final double[] plus(double[] v1, double d)
      Computes v1 + d
      Parameters:
      v1 - vector to add to
      d - value to add
      Returns:
      v1 + d
    • plusEquals

      public static final double[] plusEquals(double[] v1, double d)
      Computes v1 = v1 + d, overwriting v1
      Parameters:
      v1 - vector to add to
      d - value to add
      Returns:
      Modified vector
    • minus

      public static final double[] minus(double[] v1, double[] v2)
      Computes v1 - v2
      Parameters:
      v1 - first vector
      v2 - the vector to be subtracted from this vector
      Returns:
      v1 - v2
    • minusTimes

      public static final double[] minusTimes(double[] v1, double[] v2, double s2)
      Computes v1 - v2 * s2
      Parameters:
      v1 - first vector
      v2 - the vector to be subtracted from this vector
      s2 - the scaling factor for v2
      Returns:
      v1 - v2 * s2
    • timesMinus

      public static final double[] timesMinus(double[] v1, double s1, double[] v2)
      Computes v1 * s1 - v2
      Parameters:
      v1 - first vector
      s1 - the scaling factor for v1
      v2 - the vector to be subtracted from this vector
      Returns:
      v1 * s1 - v2
    • timesMinusTimes

      public static final double[] timesMinusTimes(double[] v1, double s1, double[] v2, double s2)
      Computes v1 * s1 - v2 * s2
      Parameters:
      v1 - first vector
      s1 - the scaling factor for v1
      v2 - the vector to be subtracted from this vector
      s2 - the scaling factor for v2
      Returns:
      v1 * s1 - v2 * s2
    • minusEquals

      public static final double[] minusEquals(double[] v1, double[] v2)
      Computes v1 = v1 - v2, overwriting v1
      Parameters:
      v1 - vector
      v2 - another vector
      Returns:
      v1 = v1 - v2
    • minusTimesEquals

      public static final double[] minusTimesEquals(double[] v1, double[] v2, double s2)
      Computes v1 = v1 - v2 * s2, overwriting v1
      Parameters:
      v1 - vector
      v2 - another vector
      s2 - scalar for v2
      Returns:
      v1 = v1 - v2 * s2
    • timesMinusEquals

      public static final double[] timesMinusEquals(double[] v1, double s1, double[] v2)
      Computes v1 = v1 * s1 - v2, overwriting v1
      Parameters:
      v1 - vector
      s1 - scalar for v1
      v2 - another vector
      Returns:
      v1 = v1 * s1 - v2
    • timesMinusTimesEquals

      public static final double[] timesMinusTimesEquals(double[] v1, double s1, double[] v2, double s2)
      Computes v1 = v1 * s1 - v2 * s2, overwriting v1
      Parameters:
      v1 - vector
      s1 - scalar for v1
      v2 - another vector
      s2 - Scalar
      Returns:
      v1 = v1 * s1 - v2 * s2
    • minus

      public static final double[] minus(double[] v1, double d)
      Compute v1 - d
      Parameters:
      v1 - original vector
      d - Value to subtract
      Returns:
      v1 - d
    • minusEquals

      public static final double[] minusEquals(double[] v1, double d)
      Computes v1 = v1 - d, overwriting v1
      Parameters:
      v1 - original vector
      d - Value to subtract
      Returns:
      v1 = v1 - d
    • times

      public static final double[] times(double[] v1, double s1)
      Computes v1 * s1
      Parameters:
      v1 - original vector
      s1 - the scalar to be multiplied
      Returns:
      v1 * s1
    • timesEquals

      public static final double[] timesEquals(double[] v1, double s)
      Computes v1 = v1 * s1, overwritings v1
      Parameters:
      v1 - original vector
      s - scalar
      Returns:
      v1 = v1 * s1
    • times

      public static final double[][] times(double[] v1, double[][] m2)
      Matrix multiplication: v1 * m2
      Parameters:
      v1 - vector
      m2 - other matrix
      Returns:
      Matrix product, v1 * m2
    • transposeTimes

      public static final double[][] transposeTimes(double[] v1, double[][] m2)
      Linear algebraic matrix multiplication, v1T * m2
      Parameters:
      v1 - vector
      m2 - other matrix
      Returns:
      Matrix product, v1T * m2
    • transposeTimes

      public static final double transposeTimes(double[] v1, double[] v2)
      Linear algebraic matrix multiplication, v1T * v2
      Parameters:
      v1 - vector
      v2 - other vector
      Returns:
      Matrix product, v1T * v2
    • timesTranspose

      public static final double[][] timesTranspose(double[] v1, double[][] m2)
      Linear algebraic matrix multiplication, v1 * m2^T
      Parameters:
      v1 - vector
      m2 - other matrix
      Returns:
      Matrix product, v1 * m2^T
    • timesTranspose

      public static final double[][] timesTranspose(double[] v1, double[] v2)
      Linear algebraic matrix multiplication, v1 * v2^T
      Parameters:
      v1 - vector
      v2 - other vector
      Returns:
      Matrix product, v1 * v2^T
    • scalarProduct

      public static final double scalarProduct(double[] v1, double[] v2)
      Returns the scalar product (dot product) of this vector and the specified vector v. This is the same as transposeTimes.
      Parameters:
      v1 - vector
      v2 - other vector
      Returns:
      double the scalar product of vectors v1 and v2
    • euclideanLength

      public static final double euclideanLength(double[] v1)
      Euclidean length of the vector
      Parameters:
      v1 - vector
      Returns:
      euclidean length of this vector
    • normalize

      public static final double[] normalize(double[] v1)
      Normalizes v1 to the length of 1.0.
      Parameters:
      v1 - vector
      Returns:
      normalized copy of v1
    • normalizeEquals

      public static final double[] normalizeEquals(double[] v1)
      Normalizes v1 to the length of 1.0.
      Parameters:
      v1 - vector
      Returns:
      normalized v1
    • project

      public static final double[] project(double[] v1, double[][] m2)
      Projects this row vector into the subspace formed by the specified matrix v.
      Parameters:
      m2 - the subspace matrix
      Returns:
      the projection of p into the subspace formed by v
    • hashCode

      public static final int hashCode(double[] v1)
      Compute the hash code for the vector
      Parameters:
      v1 - elements
      Returns:
      hash code
    • equals

      public static final boolean equals(double[] v1, double[] v2)
      Compare for equality.
      Parameters:
      v1 - first vector
      v2 - second vector
      Returns:
      comparison result
    • clear

      public static final void clear(double[] v1)
      Reset the Vector to 0.
      Parameters:
      v1 - vector
    • rotate90Equals

      public static final double[] rotate90Equals(double[] v1)
      Rotate vector by 90 degrees.
      Parameters:
      v1 - first vector
      Returns:
      modified v1, rotated by 90 degrees
    • unitMatrix

      public static final double[][] unitMatrix(int dim)
      Returns the unit matrix of the specified dimension.
      Parameters:
      dim - the dimensionality of the unit matrix
      Returns:
      the unit matrix of the specified dimension
    • zeroMatrix

      public static final double[][] zeroMatrix(int dim)
      Returns the zero matrix of the specified dimension.
      Parameters:
      dim - the dimensionality of the unit matrix
      Returns:
      the zero matrix of the specified dimension
    • random

      public static final double[][] random(int m, int n)
      Generate matrix with random elements
      Parameters:
      m - Number of rows.
      n - Number of columns.
      Returns:
      An m-by-n matrix with uniformly distributed random elements.
    • identity

      public static final double[][] identity(int m, int n)
      Generate identity matrix
      Parameters:
      m - Number of rows.
      n - Number of columns.
      Returns:
      An m-by-n matrix with ones on the diagonal and zeros elsewhere.
    • diagonal

      public static final double[][] diagonal(double[] v1)
      Returns a quadratic Matrix consisting of zeros and of the given values on the diagonal.
      Parameters:
      v1 - the values on the diagonal
      Returns:
      the resulting matrix
    • copy

      public static final double[][] copy(double[][] m1)
      Make a deep copy of a matrix.
      Parameters:
      m1 - Input matrix
      Returns:
      a new matrix containing the same values as this matrix
    • rowPackedCopy

      public static final double[] rowPackedCopy(double[][] m1)
      Make a one-dimensional row packed copy of the internal array.
      Parameters:
      m1 - Input matrix
      Returns:
      Matrix elements packed in a one-dimensional array by rows.
    • columnPackedCopy

      public static final double[] columnPackedCopy(double[][] m1)
      Make a one-dimensional column packed copy of the internal array.
      Parameters:
      m1 - Input matrix
      Returns:
      Matrix elements packed in a one-dimensional array by columns.
    • getMatrix

      public static final double[][] getMatrix(double[][] m1, int r0, int r1, int c0, int c1)
      Get a submatrix.
      Parameters:
      m1 - Input matrix
      r0 - Initial row index
      r1 - Final row index
      c0 - Initial column index
      c1 - Final column index
      Returns:
      m1(r0:r1,c0:c1)
    • getMatrix

      public static final double[][] getMatrix(double[][] m1, int[] r, int[] c)
      Get a submatrix.
      Parameters:
      m1 - Input matrix
      r - Array of row indices.
      c - Array of column indices.
      Returns:
      m1(r(:),c(:))
    • getMatrix

      public static final double[][] getMatrix(double[][] m1, int[] r, int c0, int c1)
      Get a submatrix.
      Parameters:
      m1 - Input matrix
      r - Array of row indices.
      c0 - Initial column index
      c1 - Final column index
      Returns:
      m1(r(:),c0:c1)
    • getMatrix

      public static final double[][] getMatrix(double[][] m1, int r0, int r1, int[] c)
      Get a submatrix.
      Parameters:
      m1 - Input matrix
      r0 - Initial row index
      r1 - Final row index
      c - Array of column indices.
      Returns:
      m1(r0:r1,c(:))
    • setMatrix

      public static final void setMatrix(double[][] m1, int r0, int r1, int c0, int c1, double[][] m2)
      Set a submatrix.
      Parameters:
      m1 - Original matrix
      r0 - Initial row index
      r1 - Final row index
      c0 - Initial column index
      c1 - Final column index
      m2 - New values for m1(r0:r1,c0:c1)
    • setMatrix

      public static final void setMatrix(double[][] m1, int[] r, int[] c, double[][] m2)
      Set a submatrix.
      Parameters:
      m1 - Original matrix
      r - Array of row indices.
      c - Array of column indices.
      m2 - New values for m1(r(:),c(:))
    • setMatrix

      public static final void setMatrix(double[][] m1, int[] r, int c0, int c1, double[][] m2)
      Set a submatrix.
      Parameters:
      m1 - Input matrix
      r - Array of row indices.
      c0 - Initial column index
      c1 - Final column index
      m2 - New values for m1(r(:),c0:c1)
    • setMatrix

      public static final void setMatrix(double[][] m1, int r0, int r1, int[] c, double[][] m2)
      Set a submatrix.
      Parameters:
      m1 - Input matrix
      r0 - Initial row index
      r1 - Final row index
      c - Array of column indices.
      m2 - New values for m1(r0:r1,c(:))
    • getRow

      public static final double[] getRow(double[][] m1, int r)
      Returns the rth row of this matrix as vector.
      Parameters:
      m1 - Input matrix
      r - the index of the row to be returned
      Returns:
      the rth row of this matrix
    • setRow

      public static final void setRow(double[][] m1, int r, double[] row)
      Sets the rth row of this matrix to the specified vector.
      Parameters:
      m1 - Original matrix
      r - the index of the column to be set
      row - the value of the column to be set
    • getCol

      public static final double[] getCol(double[][] m1, int col)
      Get a column from a matrix as vector.
      Parameters:
      m1 - Matrix to extract the column from
      col - Column number
      Returns:
      Column
    • setCol

      public static final void setCol(double[][] m1, int c, double[] column)
      Sets the cth column of this matrix to the specified column.
      Parameters:
      m1 - Input matrix
      c - the index of the column to be set
      column - the value of the column to be set
    • transpose

      public static final double[][] transpose(double[][] m1)
      Matrix transpose
      Parameters:
      m1 - Input matrix
      Returns:
      m1T as copy
    • plus

      public static final double[][] plus(double[][] m1, double[][] m2)
      m3 = m1 + m2
      Parameters:
      m1 - Input matrix
      m2 - another matrix
      Returns:
      m1 + m1 in a new Matrix
    • plusTimes

      public static final double[][] plusTimes(double[][] m1, double[][] m2, double s2)
      m3 = m1 + s2 * m2
      Parameters:
      m1 - Input matrix
      m2 - another matrix
      s2 - scalar
      Returns:
      m1 + s2 * m2 in a new Matrix
    • plusEquals

      public static final double[][] plusEquals(double[][] m1, double[][] m2)
      m1 = m1 + m2, overwriting m1
      Parameters:
      m1 - input matrix
      m2 - another matrix
      Returns:
      m1 = m1 + m2
    • plusTimesEquals

      public static final double[][] plusTimesEquals(double[][] m1, double[][] m2, double s2)
      m1 = m1 + s2 * m2, overwriting m1
      Parameters:
      m1 - input matrix
      m2 - another matrix
      s2 - scalar for s2
      Returns:
      m1 = m1 + s2 * m2, overwriting m1
    • minus

      public static final double[][] minus(double[][] m1, double[][] m2)
      m3 = m1 - m2
      Parameters:
      m1 - Input matrix
      m2 - another matrix
      Returns:
      m1 - m2 in a new matrix
    • minusTimes

      public static final double[][] minusTimes(double[][] m1, double[][] m2, double s2)
      m3 = m1 - s2 * m2
      Parameters:
      m1 - Input matrix
      m2 - another matrix
      s2 - Scalar
      Returns:
      m1 - s2 * m2 in a new Matrix
    • minusEquals

      public static final double[][] minusEquals(double[][] m1, double[][] m2)
      m1 = m1 - m2, overwriting m1
      Parameters:
      m1 - Input matrix
      m2 - another matrix
      Returns:
      m1 - m2, overwriting m1
    • minusTimesEquals

      public static final double[][] minusTimesEquals(double[][] m1, double[][] m2, double s2)
      m1 = m1 - s2 * m2, overwriting m1
      Parameters:
      m1 - Input matrix
      m2 - another matrix
      s2 - Scalar
      Returns:
      m1 = m1 - s2 * m2, overwriting m1
    • times

      public static final double[][] times(double[][] m1, double s1)
      Multiply a matrix by a scalar, m3 = s1*m1
      Parameters:
      m1 - Input matrix
      s1 - scalar
      Returns:
      s1*m1, in a new matrix
    • timesEquals

      public static final double[][] timesEquals(double[][] m1, double s1)
      Multiply a matrix by a scalar in place, m1 = s1 * m1
      Parameters:
      m1 - Input matrix
      s1 - scalar
      Returns:
      m1 = s1 * m1, overwriting m1
    • times

      public static final double[][] times(double[][] m1, double[][] m2)
      Linear algebraic matrix multiplication, m1 * m2
      Parameters:
      m1 - Input matrix
      m2 - another matrix
      Returns:
      Matrix product, m1 * m2
    • times

      public static final double[] times(double[][] m1, double[] v2)
      Linear algebraic matrix multiplication, m1 * v2
      Parameters:
      m1 - Input matrix
      v2 - a vector
      Returns:
      Matrix product, m1 * v2
    • transposeTimes

      public static final double[] transposeTimes(double[][] m1, double[] v2)
      Linear algebraic matrix multiplication, m1T * v2
      Parameters:
      m1 - Input matrix
      v2 - another matrix
      Returns:
      Matrix product, m1T * v2
    • transposeTimes

      public static final double[][] transposeTimes(double[][] m1, double[][] m2)
      Linear algebraic matrix multiplication, m1T * m2
      Parameters:
      m1 - Input matrix
      m2 - another matrix
      Returns:
      Matrix product, m1T * m2
    • transposeTimesTimes

      public static double transposeTimesTimes(double[] a, double[][] B, double[] c)
      Linear algebraic matrix multiplication, aT * B * c
      Parameters:
      B - matrix
      c - vector on the right
      Returns:
      Matrix product, aT * B * c
    • timesTranspose

      public static final double[][] timesTranspose(double[][] m1, double[][] m2)
      Linear algebraic matrix multiplication, m1 * m2^T
      Parameters:
      m1 - Input matrix
      m2 - another matrix
      Returns:
      Matrix product, m1 * m2^T
    • transposeTimesTranspose

      public static final double[][] transposeTimesTranspose(double[][] m1, double[][] m2)
      Linear algebraic matrix multiplication, m1^T * m2^T. Computed as (m2*m1)^T
      Parameters:
      m1 - Input matrix
      m2 - another matrix
      Returns:
      Matrix product, m1^T * m2^T
    • getDiagonal

      public static final double[] getDiagonal(double[][] m1)
      getDiagonal returns array of diagonal-elements.
      Parameters:
      m1 - Input matrix
      Returns:
      values on the diagonal of the Matrix
    • normalizeColumns

      public static final void normalizeColumns(double[][] m1)
      Normalizes the columns of this matrix to length of 1.0.
      Parameters:
      m1 - Input matrix
    • appendColumns

      public static final double[][] appendColumns(double[][] m1, double[][] m2)
      Returns a matrix which consists of this matrix and the specified columns.
      Parameters:
      m1 - Input matrix
      m2 - the columns to be appended
      Returns:
      the new matrix with the appended columns
    • orthonormalize

      public static final double[][] orthonormalize(double[][] m1)
      Returns an orthonormalization of this matrix.
      Parameters:
      m1 - Input matrix
      Returns:
      the orthonormalized matrix
    • hashCode

      public static final int hashCode(double[][] m1)
      Compute hash code
      Parameters:
      m1 - Input matrix
      Returns:
      Hash code
    • equals

      public static final boolean equals(double[][] m1, double[][] m2)
      Test for equality
      Parameters:
      m1 - Input matrix
      m2 - Other matrix
      Returns:
      Equality
    • almostEquals

      public static final boolean almostEquals(double[][] m1, double[][] m2, double maxdelta)
      Compare two matrices with a delta parameter to take numerical errors into account.
      Parameters:
      m1 - Input matrix
      m2 - other matrix to compare with
      maxdelta - maximum delta allowed
      Returns:
      true if delta smaller than maximum
    • almostEquals

      public static final boolean almostEquals(double[][] m1, double[][] m2)
      Compare two matrices with a delta parameter to take numerical errors into account.
      Parameters:
      m1 - Input matrix
      m2 - other matrix to compare with
      Returns:
      almost equals with delta DELTA
    • getRowDimensionality

      public static final int getRowDimensionality(double[][] m1)
      Returns the dimensionality of the rows of this matrix.
      Parameters:
      m1 - Input matrix
      Returns:
      the number of rows.
    • getColumnDimensionality

      public static final int getColumnDimensionality(double[][] m1)
      Returns the dimensionality of the columns of this matrix.
      Parameters:
      m1 - Input matrix
      Returns:
      the number of columns.
    • cross3D

      public static void cross3D(double[] vo, double[] v1, double[] v2)
      Cross product for 3d vectors, i.e. vo = v1 x v2
      Parameters:
      vo - Output vector
      v1 - First input vector
      v2 - Second input vector