public final class VMath extends Object
double[]
. While this is less nice syntactically, it reduces memory
usage and VM overhead.Modifier and Type | Field and Description |
---|---|
static double |
DELTA
A small number to handle numbers near 0 as 0.
|
private static String |
ERR_DIMENSIONS
Error message (in assertions!)
|
static String |
ERR_MATRIX_DIMENSIONS
Error message (in assertions!)
|
static String |
ERR_MATRIX_INNERDIM
Error message (in assertions!)
|
static String |
ERR_VEC_DIMENSIONS
Error message (in assertions!)
|
Modifier | Constructor and Description |
---|---|
private |
VMath()
Fake constructor.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
almostEquals(double[][] m1,
double[][] m2)
Compare two matrices with a delta parameter to take numerical errors into
account.
|
static boolean |
almostEquals(double[][] m1,
double[][] m2,
double maxdelta)
Compare two matrices with a delta parameter to take numerical errors into
account.
|
static double[][] |
appendColumns(double[][] m1,
double[][] m2)
Returns a matrix which consists of this matrix and the specified columns.
|
static void |
clear(double[] v1)
Reset the Vector to 0.
|
static double[] |
columnPackedCopy(double[][] m1)
Make a one-dimensional column packed copy of the internal array.
|
static double[] |
copy(double[] v)
Returns a copy of this vector.
|
static 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 double[][] |
diagonal(double[] v1)
Returns a quadratic Matrix consisting of zeros and of the given values on
the diagonal.
|
static boolean |
equals(double[][] m1,
double[][] m2)
Test for equality
|
static boolean |
equals(double[] v1,
double[] v2)
Compare for equality.
|
static double |
euclideanLength(double[] v1)
Euclidean length of the vector
|
static double[] |
getCol(double[][] m1,
int col)
Get a column from a matrix as vector.
|
static int |
getColumnDimensionality(double[][] m1)
Returns the dimensionality of the columns of this matrix.
|
static double[] |
getDiagonal(double[][] m1)
getDiagonal returns array of diagonal-elements.
|
static double[][] |
getMatrix(double[][] m1,
int[] r,
int[] c)
Get a submatrix.
|
static double[][] |
getMatrix(double[][] m1,
int[] r,
int c0,
int c1)
Get a submatrix.
|
static double[][] |
getMatrix(double[][] m1,
int r0,
int r1,
int[] c)
Get a submatrix.
|
static double[][] |
getMatrix(double[][] m1,
int r0,
int r1,
int c0,
int c1)
Get a submatrix.
|
static double[] |
getRow(double[][] m1,
int r)
Returns the
r th row of this matrix as vector. |
static int |
getRowDimensionality(double[][] m1)
Returns the dimensionality of the rows of this matrix.
|
static int |
hashCode(double[] v1)
Compute the hash code for the vector
|
static int |
hashCode(double[][] m1)
Compute hash code
|
static double[][] |
identity(int m,
int n)
Generate identity matrix
|
static double[][] |
minus(double[][] m1,
double[][] m2)
m3 = m1 - m2
|
static double[] |
minus(double[] v1,
double d)
Compute v1 - d
|
static double[] |
minus(double[] v1,
double[] v2)
Computes v1 - v2
|
static double[][] |
minusEquals(double[][] m1,
double[][] m2)
m1 = m1 - m2, overwriting m1
|
static double[] |
minusEquals(double[] v1,
double d)
Computes v1 = v1 - d, overwriting v1
|
static double[] |
minusEquals(double[] v1,
double[] v2)
Computes v1 = v1 - v2, overwriting v1
|
static double[][] |
minusTimes(double[][] m1,
double[][] m2,
double s2)
m3 = m1 - s2 * m2
|
static double[] |
minusTimes(double[] v1,
double[] v2,
double s2)
Computes v1 - v2 * s2
|
static double[][] |
minusTimesEquals(double[][] m1,
double[][] m2,
double s2)
m1 = m1 - s2 * m2, overwriting m1
|
static double[] |
minusTimesEquals(double[] v1,
double[] v2,
double s2)
Computes v1 = v1 - v2 * s2, overwriting v1
|
static double[] |
normalize(double[] v1)
Normalizes v1 to the length of 1.0.
|
static void |
normalizeColumns(double[][] m1)
Normalizes the columns of this matrix to length of 1.0.
|
static double[] |
normalizeEquals(double[] v1)
Normalizes v1 to the length of 1.0.
|
static double[][] |
orthonormalize(double[][] m1)
Returns an orthonormalization of this matrix.
|
static double[][] |
plus(double[][] m1,
double[][] m2)
m3 = m1 + m2
|
static double[] |
plus(double[] v1,
double d)
Computes v1 + d
|
static double[] |
plus(double[] v1,
double[] v2)
Computes v1 + v2 for vectors.
|
static double[][] |
plusEquals(double[][] m1,
double[][] m2)
m1 = m1 + m2, overwriting m1
|
static double[] |
plusEquals(double[] v1,
double d)
Computes v1 = v1 + d, overwriting v1
|
static double[] |
plusEquals(double[] v1,
double[] v2)
Computes v1 = v1 + v2, overwriting v1
|
static double[][] |
plusTimes(double[][] m1,
double[][] m2,
double s2)
m3 = m1 + s2 * m2
|
static double[] |
plusTimes(double[] v1,
double[] v2,
double s2)
Computes v1 + v2 * s2
|
static double[][] |
plusTimesEquals(double[][] m1,
double[][] m2,
double s2)
m1 = m1 + s2 * m2, overwriting m1
|
static double[] |
plusTimesEquals(double[] v1,
double[] v2,
double s2)
Computes v1 = v1 + v2 * s2, overwriting v1
|
static double[] |
project(double[] v1,
double[][] m2)
Projects this row vector into the subspace formed by the specified matrix
v.
|
static double[][] |
random(int m,
int n)
Generate matrix with random elements
|
static double[] |
randomNormalizedVector(int dimensionality)
Returns a randomly created vector of length 1.0
|
static double[] |
rotate90Equals(double[] v1)
Rotate vector by 90 degrees.
|
static double[] |
rowPackedCopy(double[][] m1)
Make a one-dimensional row packed copy of the internal array.
|
static double |
scalarProduct(double[] v1,
double[] v2)
Returns the scalar product (dot product) of this vector and the specified vector v.
|
static void |
setCol(double[][] m1,
int c,
double[] column)
Sets the
c th column of this matrix to the specified column. |
static void |
setMatrix(double[][] m1,
int[] r,
int[] c,
double[][] m2)
Set a submatrix.
|
static void |
setMatrix(double[][] m1,
int[] r,
int c0,
int c1,
double[][] m2)
Set a submatrix.
|
static void |
setMatrix(double[][] m1,
int r0,
int r1,
int[] c,
double[][] m2)
Set a submatrix.
|
static void |
setMatrix(double[][] m1,
int r0,
int r1,
int c0,
int c1,
double[][] m2)
Set a submatrix.
|
static void |
setRow(double[][] m1,
int r,
double[] row)
Sets the
r th row of this matrix to the specified vector. |
static double[][] |
times(double[][] m1,
double s1)
Multiply a matrix by a scalar, m3 = s1*m1
|
static double[] |
times(double[][] m1,
double[] v2)
Linear algebraic matrix multiplication, m1 * v2
|
static double[][] |
times(double[][] m1,
double[][] m2)
Linear algebraic matrix multiplication, m1 * m2
|
static double[] |
times(double[] v1,
double s1)
Computes v1 * s1
|
static double[][] |
times(double[] v1,
double[][] m2)
Matrix multiplication: v1 * m2
|
static double[][] |
timesEquals(double[][] m1,
double s1)
Multiply a matrix by a scalar in place, m1 = s1 * m1
|
static double[] |
timesEquals(double[] v1,
double s)
Computes v1 = v1 * s1, overwriting v1
|
static double[] |
timesMinus(double[] v1,
double s1,
double[] v2)
Computes v1 * s1 - v2
|
static double[] |
timesMinusEquals(double[] v1,
double s1,
double[] v2)
Computes v1 = v1 * s1 - v2, overwriting v1
|
static double[] |
timesMinusTimes(double[] v1,
double s1,
double[] v2,
double s2)
Computes v1 * s1 - v2 * s2
|
static double[] |
timesMinusTimesEquals(double[] v1,
double s1,
double[] v2,
double s2)
Computes v1 = v1 * s1 - v2 * s2, overwriting v1
|
static double[] |
timesPlus(double[] v1,
double s1,
double[] v2)
Computes v1 * s1 + v2
|
static double[] |
timesPlusEquals(double[] v1,
double s1,
double[] v2)
Computes v1 = v1 * s1 + v2, overwriting v1
|
static double[] |
timesPlusTimes(double[] v1,
double s1,
double[] v2,
double s2)
Computes v1 * s1 + v2 * s2
|
static double[] |
timesPlusTimesEquals(double[] v1,
double s1,
double[] v2,
double s2)
Computes v1 = v1 * s1 + v2 * s2, overwriting v1
|
static double[][] |
timesTranspose(double[][] m1,
double[][] m2)
Linear algebraic matrix multiplication, m1 * m2^T
|
static double[][] |
timesTranspose(double[] v1,
double[] v2)
Linear algebraic matrix multiplication, v1 * v2^T
|
static double[][] |
timesTranspose(double[] v1,
double[][] m2)
Linear algebraic matrix multiplication, v1 * m2^T
|
static double[][] |
transpose(double[] v)
Transpose vector to a matrix.
|
static double[][] |
transpose(double[][] m1)
Matrix transpose
|
static double[] |
transposeTimes(double[][] m1,
double[] v2)
Linear algebraic matrix multiplication, m1T * v2
|
static double[][] |
transposeTimes(double[][] m1,
double[][] m2)
Linear algebraic matrix multiplication, m1T * m2
|
static double |
transposeTimes(double[] v1,
double[] v2)
Linear algebraic matrix multiplication, v1T * v2
|
static 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 double[][] |
transposeTimesTranspose(double[][] m1,
double[][] m2)
Linear algebraic matrix multiplication, m1^T * m2^T.
|
static double[][] |
unitMatrix(int dim)
Returns the unit matrix of the specified dimension.
|
static double[] |
unitVector(int dimensionality,
int i)
Returns the ith unit vector of the specified dimensionality.
|
static double[][] |
zeroMatrix(int dim)
Returns the zero matrix of the specified dimension.
|
public static final double DELTA
public static final String ERR_VEC_DIMENSIONS
public static final String ERR_MATRIX_DIMENSIONS
public static final String ERR_MATRIX_INNERDIM
private static final String ERR_DIMENSIONS
public static final double[] randomNormalizedVector(int dimensionality)
dimensionality
- dimensionalitypublic static final double[] unitVector(int dimensionality, int i)
dimensionality
- the dimensionality of the vectori
- the indexpublic static final double[] copy(double[] v)
v
- original vectorpublic static final double[][] transpose(double[] v)
v
- Vectorpublic static final double[] plus(double[] v1, double[] v2)
v1
- first vectorv2
- second vectorpublic static final double[] plusTimes(double[] v1, double[] v2, double s2)
v1
- first vectorv2
- second vectors2
- the scalarpublic static final double[] timesPlus(double[] v1, double s1, double[] v2)
v1
- first vectors1
- the scalar for v1v2
- second vectorpublic static final double[] timesPlusTimes(double[] v1, double s1, double[] v2, double s2)
v1
- first vectors1
- the scalar for v1v2
- second vectors2
- the scalar for v2public static final double[] plusEquals(double[] v1, double[] v2)
v1
- first vector (overwritten)v2
- second vectorpublic static final double[] plusTimesEquals(double[] v1, double[] v2, double s2)
v1
- first vectorv2
- another vectors2
- scalar factor for v2public static final double[] timesPlusEquals(double[] v1, double s1, double[] v2)
v1
- first vectors1
- scalar factor for v1v2
- another vectorpublic static final double[] timesPlusTimesEquals(double[] v1, double s1, double[] v2, double s2)
v1
- first vectors1
- scalar for v1v2
- another vectors2
- scalar for v2public static final double[] plus(double[] v1, double d)
v1
- vector to add tod
- value to addpublic static final double[] plusEquals(double[] v1, double d)
v1
- vector to add tod
- value to addpublic static final double[] minus(double[] v1, double[] v2)
v1
- first vectorv2
- the vector to be subtracted from this vectorpublic static final double[] minusTimes(double[] v1, double[] v2, double s2)
v1
- first vectorv2
- the vector to be subtracted from this vectors2
- the scaling factor for v2public static final double[] timesMinus(double[] v1, double s1, double[] v2)
v1
- first vectors1
- the scaling factor for v1v2
- the vector to be subtracted from this vectorpublic static final double[] timesMinusTimes(double[] v1, double s1, double[] v2, double s2)
v1
- first vectors1
- the scaling factor for v1v2
- the vector to be subtracted from this vectors2
- the scaling factor for v2public static final double[] minusEquals(double[] v1, double[] v2)
v1
- vectorv2
- another vectorpublic static final double[] minusTimesEquals(double[] v1, double[] v2, double s2)
v1
- vectorv2
- another vectors2
- scalar for v2public static final double[] timesMinusEquals(double[] v1, double s1, double[] v2)
v1
- vectors1
- scalar for v1v2
- another vectorpublic static final double[] timesMinusTimesEquals(double[] v1, double s1, double[] v2, double s2)
v1
- vectors1
- scalar for v1v2
- another vectors2
- Scalarpublic static final double[] minus(double[] v1, double d)
v1
- original vectord
- Value to subtractpublic static final double[] minusEquals(double[] v1, double d)
v1
- original vectord
- Value to subtractpublic static final double[] times(double[] v1, double s1)
v1
- original vectors1
- the scalar to be multipliedpublic static final double[] timesEquals(double[] v1, double s)
v1
- original vectors
- scalarpublic static final double[][] times(double[] v1, double[][] m2)
v1
- vectorm2
- other matrixpublic static final double[][] transposeTimes(double[] v1, double[][] m2)
v1
- vectorm2
- other matrixpublic static final double transposeTimes(double[] v1, double[] v2)
v1
- vectorv2
- other vectorpublic static final double[][] timesTranspose(double[] v1, double[][] m2)
v1
- vectorm2
- other matrixpublic static final double[][] timesTranspose(double[] v1, double[] v2)
v1
- vectorv2
- other vectorpublic static final double scalarProduct(double[] v1, double[] v2)
v1
- vectorv2
- other vectorpublic static final double euclideanLength(double[] v1)
v1
- vectorpublic static final double[] normalize(double[] v1)
v1
- vectorpublic static final double[] normalizeEquals(double[] v1)
v1
- vectorpublic static final double[] project(double[] v1, double[][] m2)
m2
- the subspace matrixpublic static final int hashCode(double[] v1)
v1
- elementspublic static final boolean equals(double[] v1, double[] v2)
v1
- first vectorv2
- second vectorpublic static final void clear(double[] v1)
v1
- vectorpublic static final double[] rotate90Equals(double[] v1)
v1
- first vectorpublic static final double[][] unitMatrix(int dim)
dim
- the dimensionality of the unit matrixpublic static final double[][] zeroMatrix(int dim)
dim
- the dimensionality of the unit matrixpublic static final double[][] random(int m, int n)
m
- Number of rows.n
- Number of columns.public static final double[][] identity(int m, int n)
m
- Number of rows.n
- Number of columns.public static final double[][] diagonal(double[] v1)
v1
- the values on the diagonalpublic static final double[][] copy(double[][] m1)
m1
- Input matrixpublic static final double[] rowPackedCopy(double[][] m1)
m1
- Input matrixpublic static final double[] columnPackedCopy(double[][] m1)
m1
- Input matrixpublic static final double[][] getMatrix(double[][] m1, int r0, int r1, int c0, int c1)
m1
- Input matrixr0
- Initial row indexr1
- Final row indexc0
- Initial column indexc1
- Final column indexpublic static final double[][] getMatrix(double[][] m1, int[] r, int[] c)
m1
- Input matrixr
- Array of row indices.c
- Array of column indices.public static final double[][] getMatrix(double[][] m1, int[] r, int c0, int c1)
m1
- Input matrixr
- Array of row indices.c0
- Initial column indexc1
- Final column indexpublic static final double[][] getMatrix(double[][] m1, int r0, int r1, int[] c)
m1
- Input matrixr0
- Initial row indexr1
- Final row indexc
- Array of column indices.public static final void setMatrix(double[][] m1, int r0, int r1, int c0, int c1, double[][] m2)
m1
- Original matrixr0
- Initial row indexr1
- Final row indexc0
- Initial column indexc1
- Final column indexm2
- New values for m1(r0:r1,c0:c1)public static final void setMatrix(double[][] m1, int[] r, int[] c, double[][] m2)
m1
- Original matrixr
- Array of row indices.c
- Array of column indices.m2
- New values for m1(r(:),c(:))public static final void setMatrix(double[][] m1, int[] r, int c0, int c1, double[][] m2)
m1
- Input matrixr
- Array of row indices.c0
- Initial column indexc1
- Final column indexm2
- New values for m1(r(:),c0:c1)public static final void setMatrix(double[][] m1, int r0, int r1, int[] c, double[][] m2)
m1
- Input matrixr0
- Initial row indexr1
- Final row indexc
- Array of column indices.m2
- New values for m1(r0:r1,c(:))public static final double[] getRow(double[][] m1, int r)
r
th row of this matrix as vector.m1
- Input matrixr
- the index of the row to be returnedr
th row of this matrixpublic static final void setRow(double[][] m1, int r, double[] row)
r
th row of this matrix to the specified vector.m1
- Original matrixr
- the index of the column to be setrow
- the value of the column to be setpublic static final double[] getCol(double[][] m1, int col)
m1
- Matrix to extract the column fromcol
- Column numberpublic static final void setCol(double[][] m1, int c, double[] column)
c
th column of this matrix to the specified column.m1
- Input matrixc
- the index of the column to be setcolumn
- the value of the column to be setpublic static final double[][] transpose(double[][] m1)
m1
- Input matrixpublic static final double[][] plus(double[][] m1, double[][] m2)
m1
- Input matrixm2
- another matrixpublic static final double[][] plusTimes(double[][] m1, double[][] m2, double s2)
m1
- Input matrixm2
- another matrixs2
- scalarpublic static final double[][] plusEquals(double[][] m1, double[][] m2)
m1
- input matrixm2
- another matrixpublic static final double[][] plusTimesEquals(double[][] m1, double[][] m2, double s2)
m1
- input matrixm2
- another matrixs2
- scalar for s2public static final double[][] minus(double[][] m1, double[][] m2)
m1
- Input matrixm2
- another matrixpublic static final double[][] minusTimes(double[][] m1, double[][] m2, double s2)
m1
- Input matrixm2
- another matrixs2
- Scalarpublic static final double[][] minusEquals(double[][] m1, double[][] m2)
m1
- Input matrixm2
- another matrixpublic static final double[][] minusTimesEquals(double[][] m1, double[][] m2, double s2)
m1
- Input matrixm2
- another matrixs2
- Scalarpublic static final double[][] times(double[][] m1, double s1)
m1
- Input matrixs1
- scalarpublic static final double[][] timesEquals(double[][] m1, double s1)
m1
- Input matrixs1
- scalarpublic static final double[][] times(double[][] m1, double[][] m2)
m1
- Input matrixm2
- another matrixpublic static final double[] times(double[][] m1, double[] v2)
m1
- Input matrixv2
- a vectorpublic static final double[] transposeTimes(double[][] m1, double[] v2)
m1
- Input matrixv2
- another matrixpublic static final double[][] transposeTimes(double[][] m1, double[][] m2)
m1
- Input matrixm2
- another matrixpublic static double transposeTimesTimes(double[] a, double[][] B, double[] c)
B
- matrixc
- vector on the rightpublic static final double[][] timesTranspose(double[][] m1, double[][] m2)
m1
- Input matrixm2
- another matrixpublic static final double[][] transposeTimesTranspose(double[][] m1, double[][] m2)
m1
- Input matrixm2
- another matrixpublic static final double[] getDiagonal(double[][] m1)
m1
- Input matrixpublic static final void normalizeColumns(double[][] m1)
m1
- Input matrixpublic static final double[][] appendColumns(double[][] m1, double[][] m2)
m1
- Input matrixm2
- the columns to be appendedpublic static final double[][] orthonormalize(double[][] m1)
m1
- Input matrixpublic static final int hashCode(double[][] m1)
m1
- Input matrixpublic static final boolean equals(double[][] m1, double[][] m2)
m1
- Input matrixm2
- Other matrixpublic static final boolean almostEquals(double[][] m1, double[][] m2, double maxdelta)
m1
- Input matrixm2
- other matrix to compare withmaxdelta
- maximum delta allowedpublic static final boolean almostEquals(double[][] m1, double[][] m2)
m1
- Input matrixm2
- other matrix to compare withDELTA
public static final int getRowDimensionality(double[][] m1)
m1
- Input matrixpublic static final int getColumnDimensionality(double[][] m1)
m1
- Input matrixpublic static void cross3D(double[] vo, double[] v1, double[] v2)
vo = v1 x v2
vo
- Output vectorv1
- First input vectorv2
- Second input vector