diff --git a/main/ejml-simple/src/org/ejml/simple/ConstMatrix.java b/main/ejml-simple/src/org/ejml/simple/ConstMatrix.java
index 7eb155fe..f2af9de9 100644
--- a/main/ejml-simple/src/org/ejml/simple/ConstMatrix.java
+++ b/main/ejml-simple/src/org/ejml/simple/ConstMatrix.java
@@ -188,7 +188,7 @@ public interface ConstMatrix> {
T plus( double beta, ConstMatrix> B );
/**
- * Computes the dot product (a.k.a. inner product) between this vector and vector 'v'.
+ * Computes the dot product (or inner product) between this vector and vector 'v'.
*
* @param v The second vector in the dot product. Not modified.
* @return dot product
@@ -237,6 +237,16 @@ public interface ConstMatrix> {
*/
T divide( double val );
+ /**
+ * Divides each element in the matrix by the complex number. If the matrix is real, then it will
+ * return a complex matrix unless the imaginary component of the scalar is zero.
+ *
+ * @param real Real component of scalar value
+ * @param imag Imaginary component of scalar value
+ * @return Scaled matrix
+ */
+ T divideComplex( double real, double imag );
+
/**
*
* Returns the inverse of this matrix.
diff --git a/main/ejml-simple/src/org/ejml/simple/SimpleBase.java b/main/ejml-simple/src/org/ejml/simple/SimpleBase.java
index ec712bfd..e514efd0 100644
--- a/main/ejml-simple/src/org/ejml/simple/SimpleBase.java
+++ b/main/ejml-simple/src/org/ejml/simple/SimpleBase.java
@@ -104,32 +104,80 @@ protected T createComplexMatrix( int numRows, int numCols ) {
* when an operation is needed that is not provided by this class.
*
*
- * @return Reference to the internal DMatrixRMaj.
+ * @return Reference to the internal matrix.
*/
public InnerType getMatrix() {
return (InnerType)mat;
}
+ /**
+ *
+ * Returns a reference to the matrix that it uses internally if this is a {@link DMatrixRMaj}.
+ * Otherwise attempts to convert the internal matrix to a {@link DMatrixRMaj}.
+ *
+ *
+ * @return Reference to the internal matrix or converted internal matrix.
+ */
public DMatrixRMaj getDDRM() {
return (mat.getType() == MatrixType.DDRM) ? (DMatrixRMaj)mat : (DMatrixRMaj)ConvertMatrixType.convert(mat, MatrixType.DDRM);
}
+ /**
+ *
+ * Returns a reference to the matrix that it uses internally if this is a {@link FMatrixRMaj}.
+ * Otherwise attempts to convert the internal matrix to a {@link FMatrixRMaj}.
+ *
+ *
+ * @return Reference to the internal matrix or converted internal matrix.
+ */
public FMatrixRMaj getFDRM() {
return (mat.getType() == MatrixType.FDRM) ? (FMatrixRMaj)mat : (FMatrixRMaj)ConvertMatrixType.convert(mat, MatrixType.FDRM);
}
+ /**
+ *
+ * Returns a reference to the matrix that it uses internally if this is a {@link ZMatrixRMaj}.
+ * Otherwise attempts to convert the internal matrix to a {@link ZMatrixRMaj}.
+ *
+ *
+ * @return Reference to the internal matrix or converted internal matrix.
+ */
public ZMatrixRMaj getZDRM() {
return (mat.getType() == MatrixType.ZDRM) ? (ZMatrixRMaj)mat : (ZMatrixRMaj)ConvertMatrixType.convert(mat, MatrixType.ZDRM);
}
+ /**
+ *
+ * Returns a reference to the matrix that it uses internally if this is a {@link CMatrixRMaj}.
+ * Otherwise attempts to convert the internal matrix to a {@link CMatrixRMaj}.
+ *
+ *
+ * @return Reference to the internal matrix or converted internal matrix.
+ */
public CMatrixRMaj getCDRM() {
return (mat.getType() == MatrixType.CDRM) ? (CMatrixRMaj)mat : (CMatrixRMaj)ConvertMatrixType.convert(mat, MatrixType.CDRM);
}
+ /**
+ *
+ * Returns a reference to the matrix that it uses internally if this is a {@link DMatrixSparseCSC}.
+ * Otherwise attempts to convert the internal matrix to a {@link DMatrixSparseCSC}.
+ *
+ *
+ * @return Reference to the internal matrix or converted internal matrix.
+ */
public DMatrixSparseCSC getDSCC() {
return (mat.getType() == MatrixType.DSCC) ? (DMatrixSparseCSC)mat : (DMatrixSparseCSC)ConvertMatrixType.convert(mat, MatrixType.DSCC);
}
+ /**
+ *
+ * Returns a reference to the matrix that it uses internally if this is a {@link FMatrixSparseCSC}.
+ * Otherwise attempts to convert the internal matrix to a {@link FMatrixSparseCSC}.
+ *
+ *
+ * @return Reference to the internal matrix or converted internal matrix.
+ */
public FMatrixSparseCSC getFSCC() {
return (mat.getType() == MatrixType.FSCC) ? (FMatrixSparseCSC)mat : (FMatrixSparseCSC)ConvertMatrixType.convert(mat, MatrixType.FSCC);
}
@@ -339,6 +387,20 @@ protected static SimpleOperations lookupOps( MatrixType type ) {
return ret;
}
+ /** {@inheritDoc} */
+ @Override public T divideComplex( double real, double imag ) {
+ try {
+ T ret = createLike();
+ ops.divideComplex(mat, real, imag, ret.getMatrix());
+ return ret;
+ } catch (ConvertToImaginaryException e) {
+ // Input matrix isn't complex therefor output isn't complex either
+ T converted = createComplexMatrix(1, 1);
+ converted.setMatrix(ConvertMatrixType.convert(mat, converted.getType()));
+ return converted.divideComplex(real, imag);
+ }
+ }
+
/** {@inheritDoc} */
@Override public T invert() {
T ret = createLike();
diff --git a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java
index 66299c5e..13369fc5 100644
--- a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java
+++ b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java
@@ -40,26 +40,38 @@
* management and writing of code in general. It also allows operations to be chained, as is shown
* below:
*
- * SimpleMatrix K = P.mult(H.transpose().mult(S.invert()));
+ * {@code SimpleMatrix K = P.mult(H.transpose().mult(S.invert()));}
*
*
*
* Working with both a primitive matrix and SimpleMatrix in the same code base is easy.
- * To access the internal DMatrixRMaj in a SimpleMatrix simply call {@link SimpleMatrix#getMatrix()}.
- * To turn a DMatrixRMaj into a SimpleMatrix use {@link SimpleMatrix#wrap(org.ejml.data.Matrix)}. Not
+ * To access the internal Matrix in a SimpleMatrix simply call {@link SimpleMatrix#getMatrix()}.
+ * To turn a Matrix into a SimpleMatrix use {@link SimpleMatrix#wrap(org.ejml.data.Matrix)}. Not
* all operations in EJML are provided for SimpleMatrix, but can be accessed by extracting the internal
* matrix.
*
*
*
- * EXTENDING: SimpleMatrix contains a list of narrowly focused functions for linear algebra. To harness
+ * The object oriented approach used in SimpleMatrix was originally inspired by
+ * JAMA.
+ *
+ *
+ * Extending
+ *
+ * SimpleMatrix contains a list of narrowly focused functions for linear algebra. To harness
* the functionality for another application and to the number of functions it supports it is recommended
* that one extends {@link SimpleBase} instead. This way the returned matrix type's of SimpleMatrix functions
* will be of the appropriate types. See StatisticsMatrix inside of the examples directory.
*
*
*
- * PERFORMANCE: The disadvantage of using this class is that it is more resource intensive, since
+ * If SimpleMatrix is extended then the protected function {@link #createMatrix} should be extended and return
+ * the child class. The results of SimpleMatrix operations will then be of the correct matrix type.
+ *
+ *
+ * Performance
+ *
+ * The disadvantage of using this class is that it is more resource intensive, since
* it creates a new matrix each time an operation is performed. This makes the JavaVM work harder and
* Java automatically initializes the matrix to be all zeros. Typically operations on small matrices
* or operations that have a runtime linear with the number of elements are the most affected. More
@@ -73,15 +85,354 @@
* neck is a more computationally complex operation. The best approach is benchmark and then optimize the code.
*
*
- *
- * If SimpleMatrix is extended then the protected function {link #createMatrix} should be extended and return
- * the child class. The results of SimpleMatrix operations will then be of the correct matrix type.
- *
+ * Creating matrices
+ *
+ * | Method | Description |
+ * | {@link #SimpleMatrix(int, int, Class)} |
+ * Create a matrix filled with zeros with the specified internal type. |
+ * | {@link #SimpleMatrix(int, int, MatrixType)} |
+ * Create a matrix filled with zeros with the specified internal matrix type. |
+ * | {@link #SimpleMatrix(int, int)} |
+ * Create a matrix filled with zeros. |
+ * | {@link #SimpleMatrix(int, int, boolean, double...)} |
+ * Create a matrix with the provided double values, in either row-major or column-major order. |
+ * | {@link #SimpleMatrix(int, int, boolean, float...)} |
+ * Create a matrix with the provided float values, in either row-major or column-major order. |
+ * | {@link #SimpleMatrix(double[][])} |
+ * Create a matrix from a 2D double array. |
+ * | {@link #SimpleMatrix(float[][])} |
+ * Create a matrix from a 2D float array. |
+ * | {@link #SimpleMatrix(double[])} |
+ * Create a column vector from a 1D double array. |
+ * | {@link #SimpleMatrix(float[])} |
+ * Create a column vector from a 1D float array. |
+ * | {@link #SimpleMatrix(Matrix)} |
+ * Create a matrix copying the provided Matrix. |
+ * | {@link #SimpleMatrix(SimpleMatrix)} |
+ * Create a matrix copying the provided SimpleMatrix. |
+ * | {@link #wrap(Matrix)} |
+ * Create a matrix wrapping the provided Matrix. |
+ * | {@link #filled(int, int, double)} |
+ * Create a matrix filled with the specified value. |
+ * | {@link #ones(int, int)} |
+ * Create a matrix filled with ones. |
+ * | {@link #diag(double...)} |
+ * Create a diagonal matrix. |
+ * | {@link #diag(Class, double...)} |
+ * Create a diagonal matrix with the specified internal type. |
+ * | {@link #identity(int)} |
+ * Create an identity matrix. |
+ * | {@link #identity(int, Class)} |
+ * Create an identity matrix with the specified internal type. |
+ * | {@link #random(int, int)} |
+ * Create a random {@link DMatrixRMaj} with values drawn from a continuous uniform distribution on the
+ * unit interval. |
+ * | {@link #random_DDRM(int, int, double, double, Random)} |
+ * Create a random {@link DMatrixRMaj} with values drawn from a continuous uniform distribution using the
+ * provided random number generator. |
+ * | {@link #random_DDRM(int, int)} |
+ * Create a random {@link DMatrixRMaj} with values drawn from a continuous uniform distribution on the
+ * unit interval. |
+ * | {@link #random_FDRM(int, int, float, float, Random)} |
+ * Create a random {@link FMatrixRMaj} with values drawn from a continuous uniform distribution using the
+ * provided random number generator. |
+ * | {@link #random_FDRM(int, int)} |
+ * Create a random {@link FMatrixRMaj} with values drawn from a continuous uniform distribution on the
+ * unit interval. |
+ * | {@link #random_ZDRM(int, int, double, double, Random)} |
+ * Create a random {@link ZMatrixRMaj} with values drawn from a continuous uniform distribution using the
+ * provided random number generator. |
+ * | {@link #random_ZDRM(int, int)} |
+ * Create a random {@link ZMatrixRMaj} with values drawn from a continuous uniform distribution on the
+ * unit interval. |
+ * | {@link #random_CDRM(int, int, float, float, Random)} |
+ * Create a random {@link CMatrixRMaj} with values drawn from a continuous uniform distribution using the
+ * provided random number generator. |
+ * | {@link #random_CDRM(int, int)} |
+ * Create a random {@link CMatrixRMaj} with values drawn from a continuous uniform distribution on the
+ * unit interval. |
+ * | {@link #randomNormal(SimpleMatrix, Random)} |
+ * Create a random vector drawn from a multivariate normal distribution
+ * with the specified covariance. |
+ * | {@link #createLike()} |
+ * Create a matrix with the same shape and internal type as this matrix. |
+ * | {@link #copy()} |
+ * Create a copy of this matrix. |
+ *
*
- *
- * The object oriented approach used in SimpleMatrix was originally inspired by Jama.
- * http://math.nist.gov/javanumerics/jama/
- *
+ * Getting elements, rows and columns
+ *
+ * | Method | Description |
+ * | {@link #get(int)} |
+ * Get the value of the {@code i}th entry in row-major order. |
+ * | {@link #get(int, int)} |
+ * Get the value of the {@code i,j}th entry. |
+ * | {@link #get(int, int, Complex_F64)} |
+ * Get the value of the {@code i,j}th entry as a complex number. |
+ * | {@link #getReal(int, int)} |
+ * Get the real component of the {@code i,j}th entry. |
+ * | {@link #getImaginary(int, int)} |
+ * Get the imaginary component of the {@code i,j}th entry. |
+ * | {@link #getImag(int, int)} |
+ * Alias for {@link #getImaginary(int, int)} |
+ * | {@link #getRow(int)} |
+ * Get the {@code i}th row. |
+ * | {@link #getColumn(int)} |
+ * Get the {@code j}th column. |
+ * | {@link #extractVector(boolean, int)} |
+ * Extract the specified row or column vector. |
+ * | {@link #extractMatrix(int, int, int, int)} |
+ * Extract the specified submatrix. |
+ * | {@link #rows(int, int)} |
+ * Extract the specified rows. |
+ * | {@link #cols(int, int)} |
+ * Extract the specified columns. |
+ * | {@link #diag()} |
+ * Extract the matrix diagonal, or construct a diagonal matrix from a vector. |
+ *
+ *
+ * Setting elements, rows and columns
+ *
+ * | Method | Description |
+ * | {@link #set(int, double)} |
+ * Set the value of the {@code i}th entry in row-major order. |
+ * | {@link #set(int, int, double)} |
+ * Set the value of the {@code i,j}th entry. |
+ * | {@link #set(int, int, Complex_F64)} |
+ * Set the value of the {@code i,j}th entry as a complex number. |
+ * | {@link #set(int, int, double, double)} |
+ * Set the real and imaginary components of the {@code i,j}th entry. |
+ * | {@link #setRow(int, ConstMatrix)} |
+ * Set the {@code i}th row. |
+ * | {@link #setRow(int, int, double...)} |
+ * Set the values in the {@code i}th row. |
+ * | {@link #setColumn(int, ConstMatrix)} |
+ * Set the {@code j}th column. |
+ * | {@link #setColumn(int, int, double...)} |
+ * Set the values in the {@code j}th column. |
+ * | {@link #setTo(SimpleBase)} |
+ * Set the elements of this matrix to be equal to elements from another matrix. |
+ * | {@link #insertIntoThis(int, int, SimpleBase)} |
+ * Insert values from another matrix, starting in position {@code i,j}. |
+ * | {@link #fill(double)} |
+ * Set all elements of this matrix to be equal to specified value. |
+ * | {@link #fillComplex(double, double)} |
+ * Set all elements of this matrix to be equal to specified complex value. |
+ * | {@link #zero()} |
+ * Set all elements of this matrix to zero. |
+ *
+ *
+ * Basic operations
+ *
+ * | Method | Description |
+ * | {@link #plus(double)} |
+ * Add a scalar value. |
+ * | {@link #plusComplex(double, double)} |
+ * Add a complex scalar value. |
+ * | {@link #plus(ConstMatrix)} |
+ * Add another matrix. |
+ * | {@link #plus(double, ConstMatrix)} |
+ * Add another matrix, first applying the specified scale factor. |
+ * | {@link #minus(double)} |
+ * Subtract a scalar value. |
+ * | {@link #minusComplex(double, double)} |
+ * Subtract a complex scalar value. |
+ * | {@link #minus(ConstMatrix)} |
+ * Subtract another matrix. |
+ * | {@link #scale(double)} |
+ * Multiply by a scalar value. |
+ * | {@link #scaleComplex(double, double)} |
+ * Multiply by a complex scalar value. |
+ * | {@link #divide(double)} |
+ * Divide by a scalar value. |
+ * | {@link #divideComplex(double, double)} |
+ * Divide by a complex scalar value. |
+ * | {@link #mult(ConstMatrix)} |
+ * Multiply with another matrix. |
+ * | {@link #dot(ConstMatrix)} |
+ * Calculate the dot product with another vector. |
+ * | {@link #negative()} |
+ * Get the negative of each entry. |
+ * | {@link #real()} |
+ * Get the real component of each entry. |
+ * | {@link #imaginary()} |
+ * Get the imaginary component of each entry. |
+ * | {@link #imag()} |
+ * Alias for {@link #imaginary()}. |
+ * | {@link #magnitude()} |
+ * Get the imaginary component of each entry. |
+ * | {@link #transpose()} |
+ * Get the transpose. |
+ * | {@link #transposeConjugate()} |
+ * Get the conjugate transpose. |
+ * | {@link #equation(String, Object...)} |
+ * Perform an equation in place on the matrix. |
+ *
+ *
+ * Elementwise operations
+ *
+ * | Method | Description |
+ * | {@link #elementMult(ConstMatrix)} |
+ * Perform element by element multiplication with another matrix. |
+ * | {@link #elementDiv(ConstMatrix)} |
+ * Perform element by element division with another matrix. |
+ * | {@link #elementPower(double)} |
+ * Raise each entry to the specified power. |
+ * | {@link #elementPower(ConstMatrix)} |
+ * Raise each entry to the corresponding power in another matrix. |
+ * | {@link #elementExp()} |
+ * Compute the exponent of each entry. |
+ * | {@link #elementLog()} |
+ * Compute the logarithm of each entry. |
+ * | {@link #elementOp(SimpleOperations.ElementOpReal)} |
+ * Apply the specified real-valued function to each entry. |
+ * | {@link #elementOp(SimpleOperations.ElementOpComplex)} |
+ * Apply the specified complex-valued function to each entry. |
+ *
+ *
+ * Aggregations
+ *
+ * | Method | Description |
+ * | {@link #elementSum()} |
+ * Compute the sum of all elements of this matrix. |
+ * | {@link #elementSumComplex()} |
+ * Compute the sum of all elements of a complex matrix. |
+ * | {@link #elementMax()} |
+ * Compute the maximum of all elements of this matrix. |
+ * | {@link #elementMaxAbs()} |
+ * Compute the maximum absolute value of all elements of this matrix. |
+ * | {@link #elementMin()} |
+ * Compute the minimum of all elements of this matrix. |
+ * | {@link #elementMinAbs()} |
+ * Compute the minimum absolute value of all elements of this matrix. |
+ *
+ *
+ * Linear algebra
+ *
+ * | Method | Description |
+ * | {@link #solve(ConstMatrix)} |
+ * Solve the equation {@code Ax = b}. |
+ * | {@link #conditionP2()} |
+ * Compute the matrix condition number. |
+ * | {@link #invert()} |
+ * Compute the matrix inverse. |
+ * | {@link #pseudoInverse()} |
+ * Compute the Moore-Penrose pseudo-inverse. |
+ * | {@link #determinant()} |
+ * Compute the determinant. |
+ * | {@link #determinantComplex()} |
+ * Compute the determinant of a complex matrix. |
+ * | {@link #trace()} |
+ * Compute the trace. |
+ * | {@link #traceComplex()} |
+ * Compute the trace of a complex matrix. |
+ * | {@link #normF()} |
+ * Compute the Frobenius norm. |
+ * | {@link #eig()} |
+ * Compute the eigenvalue decomposition. |
+ * | {@link #svd()} |
+ * Compute the singular value decomposition. |
+ * | {@link #svd(boolean)} |
+ * Compute the singular value decomposition in compact or full format. |
+ *
+ *
+ * Combining matrices
+ *
+ * | Method | Description |
+ * | {@link #combine(int, int, ConstMatrix)} |
+ * Combine with another matrix. |
+ * | {@link #concatRows(ConstMatrix...)} |
+ * Concatenate vertically with one or more other matrices. |
+ * | {@link #concatColumns(ConstMatrix...)} |
+ * Concatenate horizontally with one or more other matrices. |
+ * | {@link #kron(ConstMatrix)} |
+ * Compute the Kronecker product with another matrix. |
+ *
+ *
+ * Matrix properties
+ *
+ * | Method | Description |
+ * | {@link #getNumRows()} |
+ * Get the number of rows. |
+ * | {@link #getNumCols()} |
+ * Get the number of columns. |
+ * | {@link #getNumElements()} |
+ * Get the number of elements. |
+ * | {@link #bits()} |
+ * Get the size of the internal array elements (32 or 64). |
+ * | {@link #isVector()} |
+ * Check if this matrix is a vector. |
+ * | {@link #isIdentical(ConstMatrix, double)} |
+ * Check if this matrix is the same as another matrix, up to the specified tolerance. |
+ * | {@link #hasUncountable()} |
+ * Check if any of the matrix elements are NaN or infinite. |
+ *
+ *
+ * Converting and reshaping
+ *
+ * | Method | Description |
+ * | {@link #convertToComplex()} |
+ * Convert to a complex matrix. |
+ * | {@link #convertToDense()} |
+ * Convert to a dense matrix. |
+ * | {@link #convertToSparse()} |
+ * Convert to a sparse matrix. |
+ * | {@link #reshape(int, int)} |
+ * Change the number of rows and columns. |
+ *
+ *
+ * Accessing the internal matrix
+ *
+ * | Method | Description |
+ * | {@link #getType()} |
+ * Get the type of the wrapped matrix. |
+ * | {@link #getMatrix()} |
+ * Get the wrapped matrix. |
+ * | {@link #getDDRM()} |
+ * Get the wrapped matrix as a {@link DMatrixRMaj}. |
+ * | {@link #getFDRM()} |
+ * Get the wrapped matrix as a {@link FMatrixRMaj}. |
+ * | {@link #getZDRM()} |
+ * Get the wrapped matrix as a {@link ZMatrixRMaj}. |
+ * | {@link #getCDRM()} |
+ * Get the wrapped matrix as a {@link CMatrixRMaj}. |
+ * | {@link #getDSCC()} |
+ * Get the wrapped matrix as a {@link DMatrixSparseCSC}. |
+ * | {@link #getFSCC()} |
+ * Get the wrapped matrix as a {@link FMatrixSparseCSC}. |
+ *
+ *
+ * Loading and saving
+ *
+ * | Method | Description |
+ * | {@link #loadCSV(String)} |
+ * Load a matrix from a CSV file. |
+ * | {@link #saveToFileCSV(String)} |
+ * Save this matrix to a CSV file. |
+ * | {@link #saveToMatrixMarket(String)} |
+ * Save this matrix in matrix market format. |
+ *
+ *
+ * Miscellaneous
+ *
+ * | Method | Description |
+ * | {@link #iterator(boolean, int, int, int, int)} |
+ * Create an iterator for traversing a submatrix. |
+ * | {@link #getIndex(int, int)} |
+ * Get the row-major index corresponding to {@code i,j}. |
+ * | {@link #isInBounds(int, int)} |
+ * Check if the indices {@code i,j} are in bounds. |
+ * | {@link #toString()} |
+ * Get the string representation of the matrix. |
+ * | {@link #toArray2()} |
+ * Convert the matrix to a 2D array of doubles. |
+ * | {@link #print()} |
+ * Print the matrix to standard out. |
+ * | {@link #print(String)} |
+ * Print the matrix to standard out using the specified floating point format. |
+ * | {@link #printDimensions()} |
+ * Print the number of rows and columns. |
+ *
*
* @author Peter Abeles
*/
@@ -203,12 +554,19 @@ public SimpleMatrix( int numRows, int numCols ) {
setMatrix(new DMatrixRMaj(numRows, numCols));
}
- public SimpleMatrix( int numRows, int numCols, Class type ) {
+ /**
+ * Creates a new matrix that is initially set to zero with the specified dimensions and type.
+ *
+ * @param numRows The number of rows in the matrix.
+ * @param numCols The number of columns in the matrix.
+ * @param type The matrix type
+ */
+ public SimpleMatrix( int numRows, int numCols, Class> type ) {
this(numRows, numCols, MatrixType.lookup(type));
}
/**
- * Create a simple matrix of the specified type
+ * Creates a new matrix that is initially set to zero with the specified dimensions and matrix type.
*
* @param numRows The number of rows in the matrix.
* @param numCols The number of columns in the matrix.
@@ -262,10 +620,10 @@ public SimpleMatrix( Matrix orig ) {
protected SimpleMatrix() {}
/**
- * Creates a new SimpleMatrix with the specified DMatrixRMaj used as its internal matrix. This means
- * that the reference is saved and calls made to the returned SimpleMatrix will modify the passed in DMatrixRMaj.
+ * Creates a new SimpleMatrix with the specified Matrix used as its internal matrix. This means
+ * that the reference is saved and calls made to the returned SimpleMatrix will modify the passed in Matrix.
*
- * @param internalMat The internal DMatrixRMaj of the returned SimpleMatrix. Will be modified.
+ * @param internalMat The internal Matrix of the returned SimpleMatrix. Will be modified.
*/
public static SimpleMatrix wrap( Matrix internalMat ) {
var ret = new SimpleMatrix();
@@ -274,10 +632,11 @@ public static SimpleMatrix wrap( Matrix internalMat ) {
}
/**
- * Returns a filled matrix (numRows x numCols) of the value a.
- * @param numRows The number of numRows.
- * @param numCols The number of columns.
- * @param a The number to fill the matrix with.
+ * Creates a new matrix filled with the specified value. This will wrap a {@link DMatrixRMaj}.
+ *
+ * @param numRows The number of rows in the matrix.
+ * @param numCols The number of columns in the matrix.
+ * @param a The value to fill the matrix with.
* @return A matrix filled with the value a.
*/
public static SimpleMatrix filled( int numRows, int numCols, double a ) {
@@ -287,9 +646,10 @@ public static SimpleMatrix filled( int numRows, int numCols, double a ) {
}
/**
- * Returns a matrix of ones.
- * @param numRows The number of numRows.
- * @param numCols The number of columns.
+ * Creates a new matrix filled with ones. This will wrap a {@link DMatrixRMaj}.
+ *
+ * @param numRows The number of rows in the matrix.
+ * @param numCols The number of columns in the matrix.
* @return A matrix of ones.
*/
public static SimpleMatrix ones( int numRows, int numCols ) {
@@ -297,7 +657,7 @@ public static SimpleMatrix ones( int numRows, int numCols ) {
}
/**
- * Creates a new identity matrix with the specified size.
+ * Creates a new identity matrix with the specified size. This will wrap a {@link DMatrixRMaj}.
*
* @param width The width and height of the matrix.
* @return An identity matrix.
@@ -307,6 +667,13 @@ public static SimpleMatrix identity( int width ) {
return identity(width, DMatrixRMaj.class);
}
+ /**
+ * Creates a new identity matrix with the specified size and type.
+ *
+ * @param width The width and height of the matrix.
+ * @param type The matrix type
+ * @return An identity matrix.
+ */
public static SimpleMatrix identity( int width, Class> type ) {
var ret = new SimpleMatrix(width, width, type);
ret.ops.setIdentity(ret.mat);
@@ -316,7 +683,7 @@ public static SimpleMatrix identity( int width, Class> type ) {
/**
*
* Creates a matrix where all but the diagonal elements are zero. The values
- * of the diagonal elements are specified by the parameter 'vals'.
+ * of the diagonal elements are specified by the parameter 'vals'. This will wrap a {@link DMatrixRMaj}.
*
*
*
@@ -332,7 +699,12 @@ public static SimpleMatrix diag( double... vals ) {
}
/**
- * Creates a real valued diagonal matrix of the specified type
+ * Creates a matrix where all but the diagonal elements are zero. The values
+ * of the diagonal elements are specified by the parameter 'vals'.
+ *
+ * @param type The matrix type
+ * @param vals The values of the diagonal elements.
+ * @return A diagonal matrix.
*/
public static SimpleMatrix diag( Class> type, double... vals ) {
var M = new SimpleMatrix(vals.length, vals.length, type);
@@ -343,16 +715,16 @@ public static SimpleMatrix diag( Class> type, double... vals ) {
}
/**
- *
- * Creates a new SimpleMatrix with random elements drawn from a uniform distribution from minValue to maxValue.
- *
+ * Creates a random matrix with values drawn from the continuous uniform distribution from minValue (inclusive) to
+ * maxValue (exclusive). This will wrap a {@link DMatrixRMaj}.
*
* @param numRows The number of rows in the new matrix
* @param numCols The number of columns in the new matrix
* @param minValue Lower bound
* @param maxValue Upper bound
- * @param rand The random number generator that's used to fill the matrix. @return The new random matrix.
- * @see RandomMatrices_DDRM#fillUniform(DMatrixRMaj, java.util.Random)
+ * @param rand The random number generator that's used to fill the matrix.
+ * @return The new random matrix.
+ * @see RandomMatrices_DDRM#fillUniform(DMatrixD1, double, double, java.util.Random)
*/
public static SimpleMatrix random_DDRM( int numRows, int numCols, double minValue, double maxValue, Random rand ) {
var ret = new SimpleMatrix(numRows, numCols);
@@ -361,21 +733,41 @@ public static SimpleMatrix random_DDRM( int numRows, int numCols, double minValu
}
/**
- * Creates a DDRM random matrix with values from 0.0 to 1.0. Random number generator is
- * {@link ThreadLocalRandom#current()}.
+ * Creates a random matrix with values drawn from the continuous uniform distribution from 0.0 (inclusive) to
+ * 1.0 (exclusive).
+ *
+ * @param numRows The number of rows in the new matrix
+ * @param numCols The number of columns in the new matrix
+ * @see #random_DDRM(int, int)
*/
public static SimpleMatrix random( int numRows, int numCols ) {
return random_DDRM(numRows, numCols, 0.0, 1.0, ThreadLocalRandom.current());
}
/**
- * Creates a DDRM random matrix with values from 0.0 to 1.0. Random number generator is
- * {@link ThreadLocalRandom#current()}.
+ * Creates a random matrix with values drawn from the continuous uniform distribution from 0.0 (inclusive) to
+ * 1.0 (exclusive).
+ * The random number generator is {@link ThreadLocalRandom#current()}. This will wrap a {@link DMatrixRMaj}.
+ *
+ * @param numRows The number of rows in the new matrix
+ * @param numCols The number of columns in the new matrix
*/
public static SimpleMatrix random_DDRM( int numRows, int numCols ) {
return random_DDRM(numRows, numCols, 0.0, 1.0, ThreadLocalRandom.current());
}
+ /**
+ * Creates a random matrix with values drawn from the continuous uniform distribution from minValue (inclusive) to
+ * maxValue (exclusive). This will wrap a {@link FMatrixRMaj}.
+ *
+ * @param numRows The number of rows in the new matrix
+ * @param numCols The number of columns in the new matrix
+ * @param minValue Lower bound
+ * @param maxValue Upper bound
+ * @param rand The random number generator that's used to fill the matrix.
+ * @return The new random matrix.
+ * @see RandomMatrices_FDRM#fillUniform(FMatrixD1, float, float, java.util.Random)
+ */
public static SimpleMatrix random_FDRM( int numRows, int numCols, float minValue, float maxValue, Random rand ) {
var ret = new SimpleMatrix(numRows, numCols, FMatrixRMaj.class);
RandomMatrices_FDRM.fillUniform((FMatrixRMaj)ret.mat, minValue, maxValue, rand);
@@ -383,13 +775,29 @@ public static SimpleMatrix random_FDRM( int numRows, int numCols, float minValue
}
/**
- * Creates a FDRM random matrix with values from 0.0 to 1.0. Random number generator is
- * {@link ThreadLocalRandom#current()}.
+ * Creates a random matrix with values drawn from the continuous uniform distribution from 0.0 (inclusive) to
+ * 1.0 (exclusive). The random number generator is {@link ThreadLocalRandom#current()}.
+ * This will wrap a {@link FMatrixRMaj}.
+ *
+ * @param numRows The number of rows in the new matrix
+ * @param numCols The number of columns in the new matrix
*/
public static SimpleMatrix random_FDRM( int numRows, int numCols ) {
return random_FDRM(numRows, numCols, 0.0f, 1.0f, ThreadLocalRandom.current());
}
+ /**
+ * Creates a random matrix with real and complex components drawn from the continuous uniform distribution from
+ * minValue (inclusive) to maxValue (exclusive). This will wrap a {@link ZMatrixRMaj}.
+ *
+ * @param numRows The number of rows in the new matrix
+ * @param numCols The number of columns in the new matrix
+ * @param minValue Lower bound
+ * @param maxValue Upper bound
+ * @param rand The random number generator that's used to fill the matrix.
+ * @return The new random matrix.
+ * @see RandomMatrices_ZDRM#fillUniform(ZMatrixD1, double, double, java.util.Random)
+ */
public static SimpleMatrix random_ZDRM( int numRows, int numCols, double minValue, double maxValue, Random rand ) {
var ret = new SimpleMatrix(numRows, numCols, MatrixType.ZDRM);
RandomMatrices_ZDRM.fillUniform((ZMatrixRMaj)ret.mat, minValue, maxValue, rand);
@@ -397,13 +805,29 @@ public static SimpleMatrix random_ZDRM( int numRows, int numCols, double minValu
}
/**
- * Creates a ZDRM random matrix with values from 0.0 to 1.0. Random number generator is
- * {@link ThreadLocalRandom#current()}.
+ * Creates a random matrix with values drawn from the continuous uniform distribution from 0.0 (inclusive) to
+ * 1.0 (exclusive). The random number generator is {@link ThreadLocalRandom#current()}.
+ * This will wrap a {@link ZMatrixRMaj}.
+ *
+ * @param numRows The number of rows in the new matrix
+ * @param numCols The number of columns in the new matrix
*/
public static SimpleMatrix random_ZDRM( int numRows, int numCols ) {
return random_ZDRM(numRows, numCols, 0.0, 1.0, ThreadLocalRandom.current());
}
+ /**
+ * Creates a random matrix with real and complex components drawn from the continuous uniform distribution from
+ * minValue (inclusive) to maxValue (exclusive). This will wrap a {@link CMatrixRMaj}.
+ *
+ * @param numRows The number of rows in the new matrix
+ * @param numCols The number of columns in the new matrix
+ * @param minValue Lower bound
+ * @param maxValue Upper bound
+ * @param rand The random number generator that's used to fill the matrix.
+ * @return The new random matrix.
+ * @see RandomMatrices_CDRM#fillUniform(CMatrixD1, float, float, java.util.Random)
+ */
public static SimpleMatrix random_CDRM( int numRows, int numCols, float minValue, float maxValue, Random rand ) {
var ret = new SimpleMatrix(numRows, numCols, MatrixType.CDRM);
RandomMatrices_CDRM.fillUniform((CMatrixRMaj)ret.mat, minValue, maxValue, rand);
@@ -411,8 +835,12 @@ public static SimpleMatrix random_CDRM( int numRows, int numCols, float minValue
}
/**
- * Creates a CDRM random matrix with values from 0.0 to 1.0. Random number generator is
- * {@link ThreadLocalRandom#current()}.
+ * Creates a random matrix with values drawn from the continuous uniform distribution from 0.0 (inclusive) to
+ * 1.0 (exclusive). The random number generator is {@link ThreadLocalRandom#current()}.
+ * This will wrap a {@link CMatrixRMaj}.
+ *
+ * @param numRows The number of rows in the new matrix
+ * @param numCols The number of columns in the new matrix
*/
public static SimpleMatrix random_CDRM( int numRows, int numCols ) {
return random_CDRM(numRows, numCols, 0.0f, 1.0f, ThreadLocalRandom.current());
@@ -425,6 +853,7 @@ public static SimpleMatrix random_CDRM( int numRows, int numCols ) {
*
*
* @param covariance Covariance of the multivariate normal distribution
+ * @param random The random number generator that's used to fill the matrix.
* @return Vector randomly drawn from the distribution
* @see CovarianceRandomDraw_DDRM
*/
@@ -498,4 +927,5 @@ protected SimpleMatrix wrapMatrix( Matrix m ) {
//
// return ret;
// }
+
}
diff --git a/main/ejml-simple/src/org/ejml/simple/SimpleOperations.java b/main/ejml-simple/src/org/ejml/simple/SimpleOperations.java
index 441dcaa5..a88d194a 100644
--- a/main/ejml-simple/src/org/ejml/simple/SimpleOperations.java
+++ b/main/ejml-simple/src/org/ejml/simple/SimpleOperations.java
@@ -104,6 +104,15 @@ default void scaleComplex( T A, double real, double imag, T output ) {
/** Divides each element by val. Val is a real number */
void divide( T A, double val, T output );
+ default void divideComplex( T A, double real, double imag, T output ) {
+ // If the value isn't actually complex, treat it like a real value
+ if (imag == 0.0) {
+ divide(A, real, output);
+ return;
+ }
+ throw new ConvertToImaginaryException();
+ }
+
boolean invert( T A, T output );
void setIdentity( T A );
diff --git a/main/ejml-simple/src/org/ejml/simple/ops/SimpleOperations_ZDRM.java b/main/ejml-simple/src/org/ejml/simple/ops/SimpleOperations_ZDRM.java
index 91ad246b..ea5b10e2 100644
--- a/main/ejml-simple/src/org/ejml/simple/ops/SimpleOperations_ZDRM.java
+++ b/main/ejml-simple/src/org/ejml/simple/ops/SimpleOperations_ZDRM.java
@@ -162,6 +162,11 @@ public class SimpleOperations_ZDRM implements SimpleOperations {
CommonOps_ZDRM.elementDivide(A, (double)val, 0.0, output);
}
+ @Override public void divideComplex( ZMatrixRMaj A, /**/double real, /**/double imag, ZMatrixRMaj output ) {
+ output.setTo(A);
+ CommonOps_ZDRM.elementDivide(A, (double)real, (double)imag, output);
+ }
+
@Override public boolean invert( ZMatrixRMaj A, ZMatrixRMaj output ) {
return CommonOps_ZDRM.invert(A, output);
}