Class CCommonOps
- java.lang.Object
-
- org.ejml.ops.CCommonOps
-
public class CCommonOps extends java.lang.ObjectCommon operations on complex numbers
-
-
Constructor Summary
Constructors Constructor and Description CCommonOps()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static voidadd(CD1Matrix64F a, CD1Matrix64F b, CD1Matrix64F c)Performs the following operation:
c = a + b
cij = aij + bijstatic CDenseMatrix64F[]columnsToVector(CDenseMatrix64F A, CDenseMatrix64F[] v)Converts the columns in a matrix into a set of vectors.static voidconjugate(CD1Matrix64F input, CD1Matrix64F output)Computes the complex conjugate of the input matrix.
reali,j = reali,j
imaginaryi,j = -1*imaginaryi,jstatic voidconvert(D1Matrix64F input, CD1Matrix64F output)Converts the real matrix into a complex matrix.static Complex64Fdet(CDenseMatrix64F mat)Returns the determinant of the matrix.static CDenseMatrix64Fdiag(double... data)Creates a new square matrix whose diagonal elements are specified by data and all the other elements are zero.
aij = 0 if i ≤ j
aij = diag[i] if i = jstatic voidelementDivide(CD1Matrix64F input, double real, double imaginary, CD1Matrix64F output)Performs element by element division operation with a complex number on the right
outputij = inputij / (real + imaginary*i)static voidelementDivide(double real, double imaginary, CD1Matrix64F input, CD1Matrix64F output)Performs element by element division operation with a complex number on the right
outputij = (real + imaginary*i) / inputijstatic doubleelementMaxAbs(CDenseMatrix64F a)Returns the absolute value of the element in the matrix that has the largest absolute value.
Max{ |aij| } for all i and jstatic doubleelementMaxImaginary(CD1Matrix64F a)Returns the value of the imaginary element in the matrix that has the minimum value.
Min{ aij } for all i and jstatic doubleelementMaxMagnitude2(CD1Matrix64F a)Returns the magnitude squared of the complex element with the largest magnitude
Max{ |aij|^2 } for all i and jstatic doubleelementMaxReal(CD1Matrix64F a)Returns the value of the real element in the matrix that has the minimum value.
Min{ aij } for all i and jstatic doubleelementMinImaginary(CD1Matrix64F a)Returns the value of the imaginary element in the matrix that has the minimum value.
Min{ aij } for all i and jstatic doubleelementMinReal(CD1Matrix64F a)Returns the value of the real element in the matrix that has the minimum value.
Min{ aij } for all i and jstatic voidelementMultiply(CD1Matrix64F input, double real, double imaginary, CD1Matrix64F output)Performs element by element multiplication operation with a complex numbert
outputij = inputij * (real + imaginary*i)static CDenseMatrix64Fextract(CDenseMatrix64F src, int srcY0, int srcY1, int srcX0, int srcX1)Creates a new matrix which is the specified submatrix of 'src'static voidextract(CDenseMatrix64F src, int srcY0, int srcY1, int srcX0, int srcX1, CDenseMatrix64F dst, int dstY0, int dstX0)Extracts a submatrix from 'src' and inserts it in a submatrix in 'dst'.static voidfill(CD1Matrix64F a, double real, double imaginary)Sets every element in the matrix to the specified value.
aij = valuestatic CDenseMatrix64Fidentity(int width)Creates an identity matrix of the specified size.
aij = 0+0i if i ≠ j
aij = 1+0i if i = jstatic CDenseMatrix64Fidentity(int width, int height)Creates a matrix with diagonal elements set to 1 and the rest 0.
aij = 0+0i if i ≠ j
aij = 1+0i if i = jstatic booleaninvert(CDenseMatrix64F A)Performs a matrix inversion operation on the specified matrix and stores the results in the same matrix.
a = a-1static booleaninvert(CDenseMatrix64F input, CDenseMatrix64F output)Performs a matrix inversion operation that does not modify the original and stores the results in another matrix.static voidmagnitude(CD1Matrix64F input, D1Matrix64F output)Computes the magnitude of the complex number in the input matrix and stores the results in the output matrix.static voidmult(CDenseMatrix64F a, CDenseMatrix64F b, CDenseMatrix64F c)Performs the following operation:
c = a * b
cij = ∑k=1:n { * aik * bkj}static voidmult(double realAlpha, double imgAlpha, CDenseMatrix64F a, CDenseMatrix64F b, CDenseMatrix64F c)Performs the following operation:
c = α * a * b
cij = α ∑k=1:n { * aik * bkj}static voidmultAdd(CDenseMatrix64F a, CDenseMatrix64F b, CDenseMatrix64F c)Performs the following operation:
c = c + a * b
cij = cij + ∑k=1:n { aik * bkj}static voidmultAdd(double realAlpha, double imgAlpha, CDenseMatrix64F a, CDenseMatrix64F b, CDenseMatrix64F c)Performs the following operation:
c = c + α * a * b
cij = cij + α * ∑k=1:n { aik * bkj}static voidsetIdentity(CDenseMatrix64F mat)Sets all the diagonal elements equal to one and everything else equal to zero.static booleansolve(CDenseMatrix64F a, CDenseMatrix64F b, CDenseMatrix64F x)Solves for x in the following equation:
A*x = bstatic DenseMatrix64FstripImaginary(CD1Matrix64F input, DenseMatrix64F output)Places the imaginary component of the input matrix into the output matrix.static DenseMatrix64FstripReal(CD1Matrix64F input, DenseMatrix64F output)Places the real component of the input matrix into the output matrix.static voidsubtract(CD1Matrix64F a, CD1Matrix64F b, CD1Matrix64F c)Performs the following operation:
c = a - b
cij = aij - bijstatic voidtranspose(CDenseMatrix64F mat)Performs an "in-place" transpose.static CDenseMatrix64Ftranspose(CDenseMatrix64F input, CDenseMatrix64F output)Transposes input matrix 'a' and stores the results in output matrix 'b':
bij = aji
where 'b' is the transpose of 'a'.static voidtransposeConjugate(CDenseMatrix64F mat)Performs an "in-place" conjugate transpose.static CDenseMatrix64FtransposeConjugate(CDenseMatrix64F input, CDenseMatrix64F output)Conjugate transposes input matrix 'a' and stores the results in output matrix 'b':
b-reali,j = a-realj,i
b-imaginaryi,j = -1*a-imaginaryj,i
where 'b' is the transpose of 'a'.
-
-
-
Method Detail
-
identity
public static CDenseMatrix64F identity(int width)
Creates an identity matrix of the specified size.
aij = 0+0i if i ≠ j
aij = 1+0i if i = j
- Parameters:
width- The width and height of the identity matrix.- Returns:
- A new instance of an identity matrix.
-
identity
public static CDenseMatrix64F identity(int width, int height)
Creates a matrix with diagonal elements set to 1 and the rest 0.
aij = 0+0i if i ≠ j
aij = 1+0i if i = j
- Parameters:
width- The width of the identity matrix.height- The height of the identity matrix.- Returns:
- A new instance of an identity matrix.
-
diag
public static CDenseMatrix64F diag(double... data)
Creates a new square matrix whose diagonal elements are specified by data and all the other elements are zero.
aij = 0 if i ≤ j
aij = diag[i] if i = j
- Parameters:
data- Contains the values of the diagonal elements of the resulting matrix.- Returns:
- A new complex matrix.
-
convert
public static void convert(D1Matrix64F input, CD1Matrix64F output)
Converts the real matrix into a complex matrix.- Parameters:
input- Real matrix. Not modified.output- Complex matrix. Modified.
-
stripReal
public static DenseMatrix64F stripReal(CD1Matrix64F input, DenseMatrix64F output)
Places the real component of the input matrix into the output matrix.- Parameters:
input- Complex matrix. Not modified.output- real matrix. Modified.
-
stripImaginary
public static DenseMatrix64F stripImaginary(CD1Matrix64F input, DenseMatrix64F output)
Places the imaginary component of the input matrix into the output matrix.- Parameters:
input- Complex matrix. Not modified.output- real matrix. Modified.
-
magnitude
public static void magnitude(CD1Matrix64F input, D1Matrix64F output)
Computes the magnitude of the complex number in the input matrix and stores the results in the output matrix.
magnitude = sqrt(real^2 + imaginary^2)- Parameters:
input- Complex matrix. Not modified.output- real matrix. Modified.
-
conjugate
public static void conjugate(CD1Matrix64F input, CD1Matrix64F output)
Computes the complex conjugate of the input matrix.
reali,j = reali,j
imaginaryi,j = -1*imaginaryi,j
- Parameters:
input- Input matrix. Not modified.output- The complex conjugate of the input matrix. Modified.
-
fill
public static void fill(CD1Matrix64F a, double real, double imaginary)
Sets every element in the matrix to the specified value.
aij = value- Parameters:
a- A matrix whose elements are about to be set. Modified.real- The real componentimaginary- The imaginary component
-
add
public static void add(CD1Matrix64F a, CD1Matrix64F b, CD1Matrix64F c)
Performs the following operation:
c = a + b
cij = aij + bij
Matrix C can be the same instance as Matrix A and/or B.
- Parameters:
a- A Matrix. Not modified.b- A Matrix. Not modified.c- A Matrix where the results are stored. Modified.
-
subtract
public static void subtract(CD1Matrix64F a, CD1Matrix64F b, CD1Matrix64F c)
Performs the following operation:
c = a - b
cij = aij - bij
Matrix C can be the same instance as Matrix A and/or B.
- Parameters:
a- A Matrix. Not modified.b- A Matrix. Not modified.c- A Matrix where the results are stored. Modified.
-
mult
public static void mult(CDenseMatrix64F a, CDenseMatrix64F b, CDenseMatrix64F c)
Performs the following operation:
c = a * b
cij = ∑k=1:n { * aik * bkj}- Parameters:
a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
mult
public static void mult(double realAlpha, double imgAlpha, CDenseMatrix64F a, CDenseMatrix64F b, CDenseMatrix64F c)Performs the following operation:
c = α * a * b
cij = α ∑k=1:n { * aik * bkj}- Parameters:
realAlpha- real component of scaling factor.imgAlpha- imaginary component of scaling factor.a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multAdd
public static void multAdd(CDenseMatrix64F a, CDenseMatrix64F b, CDenseMatrix64F c)
Performs the following operation:
c = c + a * b
cij = cij + ∑k=1:n { aik * bkj}- Parameters:
a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
multAdd
public static void multAdd(double realAlpha, double imgAlpha, CDenseMatrix64F a, CDenseMatrix64F b, CDenseMatrix64F c)Performs the following operation:
c = c + α * a * b
cij = cij + α * ∑k=1:n { aik * bkj}- Parameters:
realAlpha- real component of scaling factor.imgAlpha- imaginary component of scaling factor.a- The left matrix in the multiplication operation. Not modified.b- The right matrix in the multiplication operation. Not modified.c- Where the results of the operation are stored. Modified.
-
transpose
public static void transpose(CDenseMatrix64F mat)
Performs an "in-place" transpose.
For square matrices the transpose is truly in-place and does not require additional memory. For non-square matrices, internally a temporary matrix is declared and
transpose(org.ejml.data.CDenseMatrix64F, org.ejml.data.CDenseMatrix64F)is invoked.- Parameters:
mat- The matrix that is to be transposed. Modified.
-
transposeConjugate
public static void transposeConjugate(CDenseMatrix64F mat)
Performs an "in-place" conjugate transpose.
- Parameters:
mat- The matrix that is to be transposed. Modified.- See Also:
transpose(org.ejml.data.CDenseMatrix64F)
-
transpose
public static CDenseMatrix64F transpose(CDenseMatrix64F input, CDenseMatrix64F output)
Transposes input matrix 'a' and stores the results in output matrix 'b':
bij = aji
where 'b' is the transpose of 'a'.- Parameters:
input- The original matrix. Not modified.output- Where the transpose is stored. If null a new matrix is created. Modified.- Returns:
- The transposed matrix.
-
transposeConjugate
public static CDenseMatrix64F transposeConjugate(CDenseMatrix64F input, CDenseMatrix64F output)
Conjugate transposes input matrix 'a' and stores the results in output matrix 'b':
b-reali,j = a-realj,i
b-imaginaryi,j = -1*a-imaginaryj,i
where 'b' is the transpose of 'a'.- Parameters:
input- The original matrix. Not modified.output- Where the transpose is stored. If null a new matrix is created. Modified.- Returns:
- The transposed matrix.
-
invert
public static boolean invert(CDenseMatrix64F A)
Performs a matrix inversion operation on the specified matrix and stores the results in the same matrix.
a = a-1If the algorithm could not invert the matrix then false is returned. If it returns true that just means the algorithm finished. The results could still be bad because the matrix is singular or nearly singular.
- Parameters:
A- The matrix that is to be inverted. Results are stored here. Modified.- Returns:
- true if it could invert the matrix false if it could not.
-
invert
public static boolean invert(CDenseMatrix64F input, CDenseMatrix64F output)
Performs a matrix inversion operation that does not modify the original and stores the results in another matrix. The two matrices must have the same dimension.
b = a-1If the algorithm could not invert the matrix then false is returned. If it returns true that just means the algorithm finished. The results could still be bad because the matrix is singular or nearly singular.
For medium to large matrices there might be a slight performance boost to using
CLinearSolverFactoryinstead.- Parameters:
input- The matrix that is to be inverted. Not modified.output- Where the inverse matrix is stored. Modified.- Returns:
- true if it could invert the matrix false if it could not.
-
solve
public static boolean solve(CDenseMatrix64F a, CDenseMatrix64F b, CDenseMatrix64F x)
Solves for x in the following equation:
A*x = bIf the system could not be solved then false is returned. If it returns true that just means the algorithm finished operating, but the results could still be bad because 'A' is singular or nearly singular.
If repeat calls to solve are being made then one should consider using
CLinearSolverFactoryinstead.It is ok for 'b' and 'x' to be the same matrix.
- Parameters:
a- A matrix that is m by n. Not modified.b- A matrix that is n by k. Not modified.x- A matrix that is m by k. Modified.- Returns:
- true if it could invert the matrix false if it could not.
-
det
public static Complex64F det(CDenseMatrix64F mat)
Returns the determinant of the matrix. If the inverse of the matrix is also needed, then usingLUDecompositionAlt_CD64directly (or any similar algorithm) can be more efficient.- Parameters:
mat- The matrix whose determinant is to be computed. Not modified.- Returns:
- The determinant.
-
elementMultiply
public static void elementMultiply(CD1Matrix64F input, double real, double imaginary, CD1Matrix64F output)
Performs element by element multiplication operation with a complex numbert
outputij = inputij * (real + imaginary*i)
- Parameters:
input- The left matrix in the multiplication operation. Not modified.real- Real component of the number it is multiplied byimaginary- Imaginary component of the number it is multiplied byoutput- Where the results of the operation are stored. Modified.
-
elementDivide
public static void elementDivide(CD1Matrix64F input, double real, double imaginary, CD1Matrix64F output)
Performs element by element division operation with a complex number on the right
outputij = inputij / (real + imaginary*i)
- Parameters:
input- The left matrix in the multiplication operation. Not modified.real- Real component of the number it is multiplied byimaginary- Imaginary component of the number it is multiplied byoutput- Where the results of the operation are stored. Modified.
-
elementDivide
public static void elementDivide(double real, double imaginary, CD1Matrix64F input, CD1Matrix64F output)Performs element by element division operation with a complex number on the right
outputij = (real + imaginary*i) / inputij
- Parameters:
real- Real component of the number it is multiplied byimaginary- Imaginary component of the number it is multiplied byinput- The right matrix in the multiplication operation. Not modified.output- Where the results of the operation are stored. Modified.
-
elementMinReal
public static double elementMinReal(CD1Matrix64F a)
Returns the value of the real element in the matrix that has the minimum value.
Min{ aij } for all i and j
- Parameters:
a- A matrix. Not modified.- Returns:
- The the minimum value out of all the real values.
-
elementMinImaginary
public static double elementMinImaginary(CD1Matrix64F a)
Returns the value of the imaginary element in the matrix that has the minimum value.
Min{ aij } for all i and j
- Parameters:
a- A matrix. Not modified.- Returns:
- The the minimum value out of all the real values.
-
elementMaxReal
public static double elementMaxReal(CD1Matrix64F a)
Returns the value of the real element in the matrix that has the minimum value.
Min{ aij } for all i and j
- Parameters:
a- A matrix. Not modified.- Returns:
- The the minimum value out of all the real values.
-
elementMaxImaginary
public static double elementMaxImaginary(CD1Matrix64F a)
Returns the value of the imaginary element in the matrix that has the minimum value.
Min{ aij } for all i and j
- Parameters:
a- A matrix. Not modified.- Returns:
- The the minimum value out of all the real values.
-
elementMaxMagnitude2
public static double elementMaxMagnitude2(CD1Matrix64F a)
Returns the magnitude squared of the complex element with the largest magnitude
Max{ |aij|^2 } for all i and j
- Parameters:
a- A matrix. Not modified.- Returns:
- The max magnitude squared
-
setIdentity
public static void setIdentity(CDenseMatrix64F mat)
Sets all the diagonal elements equal to one and everything else equal to zero. If this is a square matrix then it will be an identity matrix.- Parameters:
mat- A square matrix.
-
extract
public static CDenseMatrix64F extract(CDenseMatrix64F src, int srcY0, int srcY1, int srcX0, int srcX1)
Creates a new matrix which is the specified submatrix of 'src'
si-y0 , j-x0 = oij for all y0 ≤ i < y1 and x0 ≤ j < x1
where 'sij' is an element in the submatrix and 'oij' is an element in the original matrix.- Parameters:
src- The original matrix which is to be copied. Not modified.srcX0- Start column.srcX1- Stop column+1.srcY0- Start row.srcY1- Stop row+1.- Returns:
- Extracted submatrix.
-
extract
public static void extract(CDenseMatrix64F src, int srcY0, int srcY1, int srcX0, int srcX1, CDenseMatrix64F dst, int dstY0, int dstX0)
Extracts a submatrix from 'src' and inserts it in a submatrix in 'dst'.
si-y0 , j-x0 = oij for all y0 ≤ i < y1 and x0 ≤ j < x1
where 'sij' is an element in the submatrix and 'oij' is an element in the original matrix.- Parameters:
src- The original matrix which is to be copied. Not modified.srcX0- Start column.srcX1- Stop column+1.srcY0- Start row.srcY1- Stop row+1.dst- Where the submatrix are stored. Modified.dstY0- Start row in dst.dstX0- start column in dst.
-
columnsToVector
public static CDenseMatrix64F[] columnsToVector(CDenseMatrix64F A, CDenseMatrix64F[] v)
Converts the columns in a matrix into a set of vectors.- Parameters:
A- Matrix. Not modified.v- Optional storage for columns.- Returns:
- An array of vectors.
-
elementMaxAbs
public static double elementMaxAbs(CDenseMatrix64F a)
Returns the absolute value of the element in the matrix that has the largest absolute value.
Max{ |aij| } for all i and j
- Parameters:
a- A matrix. Not modified.- Returns:
- The max abs element value of the matrix.
-
-
DMelt 3.0 © DataMelt by jWork.ORG