java.lang.Object
de.lmu.ifi.dbs.elki.math.linearalgebra.VMath
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 equalitystatic final boolean
equals
(double[] v1, double[] v2) Compare for equality.static final double
euclideanLength
(double[] v1) Euclidean length of the vectorstatic 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 ther
th 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 vectorstatic final int
hashCode
(double[][] m1) Compute hash codestatic final double[][]
identity
(int m, int n) Generate identity matrixstatic final double[][]
minus
(double[][] m1, double[][] m2) m3 = m1 - m2static final double[]
minus
(double[] v1, double d) Compute v1 - dstatic final double[]
minus
(double[] v1, double[] v2) Computes v1 - v2static final double[][]
minusEquals
(double[][] m1, double[][] m2) m1 = m1 - m2, overwriting m1static final double[]
minusEquals
(double[] v1, double d) Computes v1 = v1 - d, overwriting v1static final double[]
minusEquals
(double[] v1, double[] v2) Computes v1 = v1 - v2, overwriting v1static final double[][]
minusTimes
(double[][] m1, double[][] m2, double s2) m3 = m1 - s2 * m2static final double[]
minusTimes
(double[] v1, double[] v2, double s2) Computes v1 - v2 * s2static final double[][]
minusTimesEquals
(double[][] m1, double[][] m2, double s2) m1 = m1 - s2 * m2, overwriting m1static final double[]
minusTimesEquals
(double[] v1, double[] v2, double s2) Computes v1 = v1 - v2 * s2, overwriting v1static 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 + m2static final double[]
plus
(double[] v1, double d) Computes v1 + dstatic final double[]
plus
(double[] v1, double[] v2) Computes v1 + v2 for vectors.static final double[][]
plusEquals
(double[][] m1, double[][] m2) m1 = m1 + m2, overwriting m1static final double[]
plusEquals
(double[] v1, double d) Computes v1 = v1 + d, overwriting v1static final double[]
plusEquals
(double[] v1, double[] v2) Computes v1 = v1 + v2, overwriting v1static final double[][]
plusTimes
(double[][] m1, double[][] m2, double s2) m3 = m1 + s2 * m2static final double[]
plusTimes
(double[] v1, double[] v2, double s2) Computes v1 + v2 * s2static final double[][]
plusTimesEquals
(double[][] m1, double[][] m2, double s2) m1 = m1 + s2 * m2, overwriting m1static final double[]
plusTimesEquals
(double[] v1, double[] v2, double s2) Computes v1 = v1 + v2 * s2, overwriting v1static 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 elementsstatic final double[]
randomNormalizedVector
(int dimensionality) Returns a randomly created vector of length 1.0static 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 thec
th 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 ther
th row of this matrix to the specified vector.static final double[][]
times
(double[][] m1, double s1) Multiply a matrix by a scalar, m3 = s1*m1static final double[]
times
(double[][] m1, double[] v2) Linear algebraic matrix multiplication, m1 * v2static final double[][]
times
(double[][] m1, double[][] m2) Linear algebraic matrix multiplication, m1 * m2static final double[]
times
(double[] v1, double s1) Computes v1 * s1static final double[][]
times
(double[] v1, double[][] m2) Matrix multiplication: v1 * m2static final double[][]
timesEquals
(double[][] m1, double s1) Multiply a matrix by a scalar in place, m1 = s1 * m1static final double[]
timesEquals
(double[] v1, double s) Computes v1 = v1 * s1, overwritings v1static final double[]
timesMinus
(double[] v1, double s1, double[] v2) Computes v1 * s1 - v2static final double[]
timesMinusEquals
(double[] v1, double s1, double[] v2) Computes v1 = v1 * s1 - v2, overwriting v1static final double[]
timesMinusTimes
(double[] v1, double s1, double[] v2, double s2) Computes v1 * s1 - v2 * s2static final double[]
timesMinusTimesEquals
(double[] v1, double s1, double[] v2, double s2) Computes v1 = v1 * s1 - v2 * s2, overwriting v1static final double[]
timesPlus
(double[] v1, double s1, double[] v2) Computes v1 * s1 + v2static final double[]
timesPlusEquals
(double[] v1, double s1, double[] v2) Computes v1 = v1 * s1 + v2, overwriting v1static final double[]
timesPlusTimes
(double[] v1, double s1, double[] v2, double s2) Computes v1 * s1 + v2 * s2static final double[]
timesPlusTimesEquals
(double[] v1, double s1, double[] v2, double s2) Computes v1 = v1 * s1 + v2 * s2, overwriting v1static final double[][]
timesTranspose
(double[][] m1, double[][] m2) Linear algebraic matrix multiplication, m1 * m2^Tstatic final double[][]
timesTranspose
(double[] v1, double[] v2) Linear algebraic matrix multiplication, v1 * v2^Tstatic final double[][]
timesTranspose
(double[] v1, double[][] m2) Linear algebraic matrix multiplication, v1 * m2^Tstatic final double[][]
transpose
(double[] v) Transpose vector to a matrix.static final double[][]
transpose
(double[][] m1) Matrix transposestatic final double[]
transposeTimes
(double[][] m1, double[] v2) Linear algebraic matrix multiplication, m1T * v2static final double[][]
transposeTimes
(double[][] m1, double[][] m2) Linear algebraic matrix multiplication, m1T * m2static final double
transposeTimes
(double[] v1, double[] v2) Linear algebraic matrix multiplication, v1T * v2static final double[][]
transposeTimes
(double[] v1, double[][] m2) Linear algebraic matrix multiplication, v1T * m2static double
transposeTimesTimes
(double[] a, double[][] B, double[] c) Linear algebraic matrix multiplication, aT * B * cstatic 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.
-
Field Details
-
DELTA
public static final double DELTAA small number to handle numbers near 0 as 0.- See Also:
-
ERR_VEC_DIMENSIONS
Error message (in assertions!) when vector dimensionalities do not agree.- See Also:
-
ERR_MATRIX_DIMENSIONS
Error message (in assertions!) when matrix dimensionalities do not agree.- See Also:
-
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 vectori
- 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 vectorv2
- 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 vectorv2
- second vectors2
- 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 vectors1
- the scalar for v1v2
- 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 vectors1
- the scalar for v1v2
- second vectors2
- 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 vectorv2
- another vectors2
- 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 vectors1
- scalar for v1v2
- 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 vectors1
- scalar for v1v2
- another vectors2
- 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 tod
- 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 tod
- value to add- Returns:
- Modified vector
-
minus
public static final double[] minus(double[] v1, double[] v2) Computes v1 - v2- Parameters:
v1
- first vectorv2
- 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 vectorv2
- the vector to be subtracted from this vectors2
- 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 vectors1
- the scaling factor for v1v2
- 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 vectors1
- the scaling factor for v1v2
- the vector to be subtracted from this vectors2
- 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
- vectorv2
- 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
- vectorv2
- another vectors2
- 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
- vectors1
- scalar for v1v2
- 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
- vectors1
- scalar for v1v2
- another vectors2
- Scalar- Returns:
- v1 = v1 * s1 - v2 * s2
-
minus
public static final double[] minus(double[] v1, double d) Compute v1 - d- Parameters:
v1
- original vectord
- 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 vectord
- Value to subtract- Returns:
- v1 = v1 - d
-
times
public static final double[] times(double[] v1, double s1) Computes v1 * s1- Parameters:
v1
- original vectors1
- 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 vectors
- scalar- Returns:
- v1 = v1 * s1
-
times
public static final double[][] times(double[] v1, double[][] m2) Matrix multiplication: v1 * m2- Parameters:
v1
- vectorm2
- 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
- vectorm2
- 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
- vectorv2
- 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
- vectorm2
- 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
- vectorv2
- 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
- vectorv2
- 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 vectorv2
- 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 matrixr0
- Initial row indexr1
- Final row indexc0
- Initial column indexc1
- 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 matrixr
- 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 matrixr
- Array of row indices.c0
- Initial column indexc1
- 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 matrixr0
- Initial row indexr1
- Final row indexc
- 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 matrixr0
- Initial row indexr1
- Final row indexc0
- Initial column indexc1
- Final column indexm2
- 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 matrixr
- 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 matrixr
- Array of row indices.c0
- Initial column indexc1
- Final column indexm2
- 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 matrixr0
- Initial row indexr1
- Final row indexc
- Array of column indices.m2
- New values for m1(r0:r1,c(:))
-
getRow
public static final double[] getRow(double[][] m1, int r) Returns ther
th row of this matrix as vector.- Parameters:
m1
- Input matrixr
- the index of the row to be returned- Returns:
- the
r
th row of this matrix
-
setRow
public static final void setRow(double[][] m1, int r, double[] row) Sets ther
th row of this matrix to the specified vector.- Parameters:
m1
- Original matrixr
- the index of the column to be setrow
- 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 fromcol
- Column number- Returns:
- Column
-
setCol
public static final void setCol(double[][] m1, int c, double[] column) Sets thec
th column of this matrix to the specified column.- Parameters:
m1
- Input matrixc
- the index of the column to be setcolumn
- 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 matrixm2
- 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 matrixm2
- another matrixs2
- 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 matrixm2
- 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 matrixm2
- another matrixs2
- 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 matrixm2
- 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 matrixm2
- another matrixs2
- 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 matrixm2
- 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 matrixm2
- another matrixs2
- 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 matrixs1
- 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 matrixs1
- 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 matrixm2
- 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 matrixv2
- 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 matrixv2
- 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 matrixm2
- 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
- matrixc
- 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 matrixm2
- 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 matrixm2
- 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 matrixm2
- 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 matrixm2
- 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 matrixm2
- other matrix to compare withmaxdelta
- 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 matrixm2
- 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 vectorv1
- First input vectorv2
- Second input vector
-