From f30a6b3c884de3f2c986ac29f87c4899eea67319 Mon Sep 17 00:00:00 2001 From: Jozsef Kutas Date: Wed, 21 Jun 2023 17:29:04 +0100 Subject: [PATCH 1/8] Update SimpleMatrix docs --- .../src/org/ejml/simple/SimpleMatrix.java | 140 +++++++++++++----- 1 file changed, 107 insertions(+), 33 deletions(-) diff --git a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java index 66299c5e..e3b1e2a6 100644 --- a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java +++ b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java @@ -40,13 +40,13 @@ * 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. *

@@ -74,13 +74,13 @@ *

* *

- * If SimpleMatrix is extended then the protected function {link #createMatrix} should be extended and return + * 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. *

* *

- * The object oriented approach used in SimpleMatrix was originally inspired by Jama. - * http://math.nist.gov/javanumerics/jama/ + * The object oriented approach used in SimpleMatrix was originally inspired by + * JAMA. *

* * @author Peter Abeles @@ -203,12 +203,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 type. * * @param numRows The number of rows in the matrix. * @param numCols The number of columns in the matrix. @@ -274,10 +281,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 +295,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 +306,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 +316,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 +332,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 +348,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 +364,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 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 +382,39 @@ 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 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 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 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 +422,28 @@ 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 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 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 +451,28 @@ 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 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 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 +480,11 @@ 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 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 +497,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 +571,5 @@ protected SimpleMatrix wrapMatrix( Matrix m ) { // // return ret; // } + } From 6a77d1f058152c60af903bb089949abcc2962e19 Mon Sep 17 00:00:00 2001 From: Jozsef Kutas Date: Thu, 22 Jun 2023 03:21:00 +0100 Subject: [PATCH 2/8] Add list of methods --- .../src/org/ejml/simple/SimpleMatrix.java | 213 +++++++++++++++++- 1 file changed, 203 insertions(+), 10 deletions(-) diff --git a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java index e3b1e2a6..057ad01d 100644 --- a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java +++ b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java @@ -52,14 +52,26 @@ *

* *

- * 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,196 @@ * 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

+ * * - *

- * The object oriented approach used in SimpleMatrix was originally inspired by - * JAMA. - *

+ * + * + *

Getting elements, rows and columns

+ * + * + *

Setting elements, rows and columns

+ * + * + *

Matrix arithmetic

+ * + * + *

Elementwise operations

+ * + * + *

Aggregations

+ * + * + *

Linear algebra

+ * + * + *

Combining matrices

+ * + * + *

Matrix properties

+ * + * + *

Converting and reshaping

+ * + * + *

Accessing the internal matrix

+ * + * + *

Loading and saving

+ * + * + *

Miscellaneous

+ * * * @author Peter Abeles */ From 740a708f926af6ba603291195210135fbc67a1bf Mon Sep 17 00:00:00 2001 From: Jozsef Kutas Date: Thu, 22 Jun 2023 20:21:12 +0100 Subject: [PATCH 3/8] Add javadoc for get internal matrix methods --- .../src/org/ejml/simple/SimpleBase.java | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/main/ejml-simple/src/org/ejml/simple/SimpleBase.java b/main/ejml-simple/src/org/ejml/simple/SimpleBase.java index ec712bfd..964e6bab 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); } From 78fa797ee514c988f30e5a5cef8fa056821b704d Mon Sep 17 00:00:00 2001 From: Jozsef Kutas Date: Thu, 22 Jun 2023 21:21:47 +0100 Subject: [PATCH 4/8] Replace a.k.a. by or to trimmed javadoc snippet --- main/ejml-simple/src/org/ejml/simple/ConstMatrix.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/ejml-simple/src/org/ejml/simple/ConstMatrix.java b/main/ejml-simple/src/org/ejml/simple/ConstMatrix.java index 7eb155fe..acf38b29 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 From 9f86c85fed2c3d913bacb5c7c85ef57b5dd3abb5 Mon Sep 17 00:00:00 2001 From: Jozsef Kutas Date: Thu, 22 Jun 2023 21:22:21 +0100 Subject: [PATCH 5/8] Add method tables --- .../src/org/ejml/simple/SimpleMatrix.java | 519 ++++++++++++------ 1 file changed, 337 insertions(+), 182 deletions(-) diff --git a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java index 057ad01d..49ab0fd5 100644 --- a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java +++ b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java @@ -86,195 +86,345 @@ *

* *

Creating matrices

- *
    - *
  • {@link #SimpleMatrix()}
  • - *
  • {@link #SimpleMatrix(double[])}
  • - *
  • {@link #SimpleMatrix(double[][])}
  • - *
  • {@link #SimpleMatrix(float[])}
  • - *
  • {@link #SimpleMatrix(float[][])}
  • - *
  • {@link #SimpleMatrix(int, int)}
  • - *
  • {@link #SimpleMatrix(int, int, boolean, double...)}
  • - *
  • {@link #SimpleMatrix(int, int, boolean, float...)}
  • - *
  • {@link #SimpleMatrix(int, int, Class)}
  • - *
  • {@link #SimpleMatrix(int, int, MatrixType)}
  • - *
  • {@link #SimpleMatrix(Matrix)}
  • - *
  • {@link #SimpleMatrix(SimpleMatrix)}
  • - *
  • {@link #wrap(Matrix)}
  • - *
  • {@link #filled(int, int, double)}
  • - *
  • {@link #ones(int, int)}
  • - *
  • {@link #diag(double...)}
  • - *
  • {@link #diag(Class, double...)}
  • - *
  • {@link #identity(int)}
  • - *
  • {@link #identity(int, Class)}
  • - *
  • {@link #random(int, int)}
  • - *
  • {@link #random_DDRM(int, int, double, double, Random)}
  • - *
  • {@link #random_DDRM(int, int)}
  • - *
  • {@link #random_FDRM(int, int, float, float, Random)}
  • - *
  • {@link #random_FDRM(int, int)}
  • - *
  • {@link #random_ZDRM(int, int, double, double, Random)}
  • - *
  • {@link #random_ZDRM(int, int)}
  • - *
  • {@link #random_CDRM(int, int, float, float, Random)}
  • - *
  • {@link #random_CDRM(int, int)}
  • - *
  • {@link #randomNormal(SimpleMatrix, Random)}
  • - *
  • {@link #createLike()}
  • - *
  • {@link #copy()}
  • - *
- * - *
    - *
  • {@link #createLike()}
  • - *
  • {@link #copy()}
  • - *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@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.
* *

Getting elements, rows and columns

- *
    - *
  • {@link #get(int)}
  • - *
  • {@link #get(int, int)}
  • - *
  • {@link #get(int, int, Complex_F64)}
  • - *
  • {@link #getReal(int, int)}
  • - *
  • {@link #getImaginary(int, int)}
  • - *
  • {@link #getRow(int)} (int)}
  • - *
  • {@link #getColumn(int)}
  • - *
  • {@link #rows(int, int)} (int)}
  • - *
  • {@link #cols(int, int)}
  • - *
  • {@link #extractVector(boolean, int)}
  • - *
  • {@link #extractMatrix(int, int, int, int)}
  • - *
  • {@link #diag()}
  • - *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@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 #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)} (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

- *
    - *
  • {@link #set(int, double)}
  • - *
  • {@link #set(int, int, double)}
  • - *
  • {@link #set(int, int, Complex_F64)}
  • - *
  • {@link #set(int, int, double, double)}
  • - *
  • {@link #setRow(int, int, double...)}
  • - *
  • {@link #setRow(int, ConstMatrix)}
  • - *
  • {@link #setColumn(int, int, double...)}
  • - *
  • {@link #setColumn(int, ConstMatrix)}
  • - *
  • {@link #setTo(SimpleBase)}
  • - *
  • {@link #insertIntoThis(int, int, SimpleBase)}
  • - *
  • {@link #fill(double)}
  • - *
  • {@link #fillComplex(double, double)}
  • - *
  • {@link #zero()}
  • - *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@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.
* - *

Matrix arithmetic

- *
    - *
  • {@link #plus(double)}
  • - *
  • {@link #plusComplex(double, double)}
  • - *
  • {@link #plus(ConstMatrix)}
  • - *
  • {@link #plus(double, ConstMatrix)}
  • - *
  • {@link #minus(double)}
  • - *
  • {@link #minusComplex(double, double)}
  • - *
  • {@link #minus(ConstMatrix)}
  • - *
  • {@link #scale(double)}
  • - *
  • {@link #scaleComplex(double, double)}
  • - *
  • {@link #mult(ConstMatrix)}
  • - *
  • {@link #dot(ConstMatrix)}
  • - *
  • {@link #divide(double)}
  • - *
  • {@link #negative()}
  • - *
  • {@link #real()}
  • - *
  • {@link #imaginary()}
  • - *
  • {@link #magnitude()}
  • - *
  • {@link #transpose()}
  • - *
  • {@link #transposeConjugate()}
  • - *
+ *

Basic operations

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@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)}Divided by a 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 #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

- *
    - *
  • {@link #elementMult(ConstMatrix)}
  • - *
  • {@link #elementDiv(ConstMatrix)}
  • - *
  • {@link #elementPower(double)}
  • - *
  • {@link #elementPower(ConstMatrix)}
  • - *
  • {@link #elementExp()}
  • - *
  • {@link #elementLog()}
  • - *
  • {@link #elementOp(SimpleOperations.ElementOpReal)}
  • - *
  • {@link #elementOp(SimpleOperations.ElementOpComplex)}
  • - *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@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

- *
    - *
  • {@link #elementSum()}
  • - *
  • {@link #elementSumComplex()}
  • - *
  • {@link #elementMax()}
  • - *
  • {@link #elementMaxAbs()}
  • - *
  • {@link #elementMin()}
  • - *
  • {@link #elementMinAbs()}
  • - *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@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

- *
    - *
  • {@link #solve(ConstMatrix)}
  • - *
  • {@link #invert()}
  • - *
  • {@link #pseudoInverse()}
  • - *
  • {@link #kron(ConstMatrix)}
  • - *
  • {@link #determinant()}
  • - *
  • {@link #determinantComplex()}
  • - *
  • {@link #trace()}
  • - *
  • {@link #traceComplex()}
  • - *
  • {@link #normF()}
  • - *
  • {@link #conditionP2()}
  • - *
  • {@link #eig()}
  • - *
  • {@link #svd()}
  • - *
  • {@link #svd(boolean)}
  • - *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@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

- *
    - *
  • {@link #combine(int, int, ConstMatrix)}
  • - *
  • {@link #concatRows(ConstMatrix[])}
  • - *
  • {@link #concatColumns(ConstMatrix[])}
  • - *
+ * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@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

- *
    - *
  • {@link #getNumRows()}
  • - *
  • {@link #getNumCols()}
  • - *
  • {@link #getType()}
  • - *
  • {@link #bits()}
  • - *
  • {@link #isVector()}
  • - *
  • {@link #isIdentical(ConstMatrix, double)}
  • - *
  • {@link #hasUncountable()}
  • - *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@link #getNumRows()}Get the number of rows.
{@link #getNumCols()}Get the number of columns.
{@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

- *
    - *
  • {@link #convertToDense()}
  • - *
  • {@link #convertToComplex()}
  • - *
  • {@link #convertToSparse()}
  • - *
  • {@link #reshape(int, int)}
  • - *
+ * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@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

- *
    - *
  • {@link #getMatrix()}
  • - *
  • {@link #getDDRM()}
  • - *
  • {@link #getFDRM()}
  • - *
  • {@link #getZDRM()}
  • - *
  • {@link #getCDRM()}
  • - *
  • {@link #getDSCC()}
  • - *
  • {@link #getFSCC()}
  • - *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@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

- *
    - *
  • {@link #loadCSV(String)}
  • - *
  • {@link #saveToFileCSV(String)}
  • - *
  • {@link #saveToMatrixMarket(String)}
  • - *
+ * + * + * + * + * + * + * + * + *
MethodDescription
{@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

- *
    - *
  • {@link #iterator(boolean, int, int, int, int)}
  • - *
  • {@link #getIndex(int, int)}
  • - *
  • {@link #isInBounds(int, int)}
  • - *
  • {@link #equation(String, Object...)}
  • - *
  • {@link #toString()}
  • - *
  • {@link #toArray2()}
  • - *
  • {@link #print()}
  • - *
  • {@link #print(String)}
  • - *
  • {@link #printDimensions()}
  • - *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
MethodDescription
{@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 */ @@ -408,7 +558,7 @@ public SimpleMatrix( int numRows, int numCols, Class type ) { } /** - * Creates a new matrix that is initially set to zero with the specified dimensions and 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. @@ -462,10 +612,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(); @@ -557,7 +707,7 @@ public static SimpleMatrix diag( Class type, double... vals ) { } /** - * Creates a random matrix with values drawn from the uniform distribution from minValue (inclusive) to + * 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 @@ -575,7 +725,8 @@ public static SimpleMatrix random_DDRM( int numRows, int numCols, double minValu } /** - * Creates a random matrix with values drawn from the uniform distribution from 0.0 (inclusive) to 1.0 (exclusive). + * 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 @@ -586,7 +737,8 @@ public static SimpleMatrix random( int numRows, int numCols ) { } /** - * Creates a random matrix with values drawn from the uniform distribution from 0.0 (inclusive) to 1.0 (exclusive). + * 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 @@ -597,7 +749,7 @@ public static SimpleMatrix random_DDRM( int numRows, int numCols ) { } /** - * Creates a random matrix with values drawn from the uniform distribution from minValue (inclusive) to + * 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 @@ -615,8 +767,9 @@ public static SimpleMatrix random_FDRM( int numRows, int numCols, float minValue } /** - * Creates a random matrix with values drawn from the uniform distribution from 0.0 (inclusive) to 1.0 (exclusive). - * The random number generator is {@link ThreadLocalRandom#current()}. This will wrap a {@link FMatrixRMaj}. + * 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 @@ -626,7 +779,7 @@ public static SimpleMatrix random_FDRM( int numRows, int numCols ) { } /** - * Creates a random matrix with real and complex components drawn from the uniform distribution from + * 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 @@ -644,8 +797,9 @@ public static SimpleMatrix random_ZDRM( int numRows, int numCols, double minValu } /** - * Creates a random matrix with values drawn from the uniform distribution from 0.0 (inclusive) to 1.0 (exclusive). - * The random number generator is {@link ThreadLocalRandom#current()}. This will wrap a {@link ZMatrixRMaj}. + * 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 @@ -655,7 +809,7 @@ public static SimpleMatrix random_ZDRM( int numRows, int numCols ) { } /** - * Creates a random matrix with real and complex components drawn from the uniform distribution from + * 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 @@ -673,8 +827,9 @@ public static SimpleMatrix random_CDRM( int numRows, int numCols, float minValue } /** - * Creates a random matrix with values drawn from the uniform distribution from 0.0 (inclusive) to 1.0 (exclusive). - * The random number generator is {@link ThreadLocalRandom#current()}. This will wrap a {@link CMatrixRMaj}. + * 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 From f30c647f073c2a9a67e4a65cc70247b9608019bf Mon Sep 17 00:00:00 2001 From: Jozsef Kutas Date: Thu, 22 Jun 2023 22:42:34 +0100 Subject: [PATCH 6/8] Minor documentation fix --- main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java index 49ab0fd5..a276022e 100644 --- a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java +++ b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java @@ -181,7 +181,7 @@ * Extract the specified row or column vector. * {@link #extractMatrix(int, int, int, int)} * Extract the specified submatrix. - * {@link #rows(int, int)} (int)} + * {@link #rows(int, int)} * Extract the specified rows. * {@link #cols(int, int)} * Extract the specified columns. From 6944517a1acd34a20613af7b993cb66cd250a7d0 Mon Sep 17 00:00:00 2001 From: Jozsef Kutas Date: Thu, 22 Jun 2023 22:51:17 +0100 Subject: [PATCH 7/8] Add methods from ConstMatrix --- main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java index a276022e..f1127e07 100644 --- a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java +++ b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java @@ -173,6 +173,8 @@ * 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)} @@ -253,6 +255,8 @@ * 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()} @@ -350,6 +354,8 @@ * 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()} From 50ed7b36bfd67bd85c2cea1bfb3291511a3c96dc Mon Sep 17 00:00:00 2001 From: Jozsef Kutas Date: Thu, 22 Jun 2023 23:15:15 +0100 Subject: [PATCH 8/8] Deprecate rows/cols in favour of getRows/getColumns --- .../src/org/ejml/simple/ConstMatrix.java | 58 +++++++++++++------ .../src/org/ejml/simple/SimpleBase.java | 32 ++++++---- .../src/org/ejml/simple/SimpleMatrix.java | 8 +-- .../org/ejml/simple/TestSimpleMatrix.java | 44 +++++++------- 4 files changed, 88 insertions(+), 54 deletions(-) diff --git a/main/ejml-simple/src/org/ejml/simple/ConstMatrix.java b/main/ejml-simple/src/org/ejml/simple/ConstMatrix.java index acf38b29..9ce5ba5d 100644 --- a/main/ejml-simple/src/org/ejml/simple/ConstMatrix.java +++ b/main/ejml-simple/src/org/ejml/simple/ConstMatrix.java @@ -526,6 +526,46 @@ default int getNumElements() { */ T getColumn( int col ); + /** + * Extracts the specified rows from the matrix. + * + * @param begin First row (inclusive). + * @param end Last row (exclusive). + * @return Submatrix that contains the specified rows. + * @deprecated Inconsistent API. Use {@link #getRows(int, int)} instead. + */ + @Deprecated + T rows( int begin, int end ); + + /** + * Extracts the specified rows from the matrix. + * + * @param begin First row (inclusive). + * @param end Last row (exclusive). + * @return Submatrix that contains the specified rows. + */ + T getRows( int begin, int end ); + + /** + * Extracts the specified columns from the matrix. + * + * @param begin First column (inclusive). + * @param end Last column (exclusive). + * @return Submatrix that contains the specified columns. + * @deprecated Inconsistent API. Use {@link #getColumns(int, int)} instead. + */ + @Deprecated + T cols( int begin, int end ); + + /** + * Extracts the specified columns from the matrix. + * + * @param begin First column (inclusive). + * @param end Last column (exclusive). + * @return Submatrix that contains the specified columns. + */ + T getColumns( int begin, int end ); + /** *

* If a vector then a square matrix is returned if a matrix then a vector of diagonal ements is returned @@ -750,24 +790,6 @@ default int getNumElements() { */ int bits(); - /** - * Extracts the specified rows from the matrix. - * - * @param begin First row (inclusive). - * @param end Last row (exclusive). - * @return Submatrix that contains the specified rows. - */ - T rows( int begin, int end ); - - /** - * Extracts the specified columns from the matrix. - * - * @param begin First column (inclusive). - * @param end Last column (exclusive). - * @return Submatrix that contains the specified columns. - */ - T cols( int begin, int end ); - /** *

Concatenates all the matrices together along their columns. If the rows do not match the upper elements * are set to zero.

diff --git a/main/ejml-simple/src/org/ejml/simple/SimpleBase.java b/main/ejml-simple/src/org/ejml/simple/SimpleBase.java index 964e6bab..50679ed3 100644 --- a/main/ejml-simple/src/org/ejml/simple/SimpleBase.java +++ b/main/ejml-simple/src/org/ejml/simple/SimpleBase.java @@ -709,6 +709,28 @@ public void setColumn( int column, ConstMatrix src ) { // NOTE: For sparse to sparse this method is very inefficient... } + /** {@inheritDoc} */ + @Deprecated + @Override public T rows( int begin, int end ) { + return extractMatrix(begin, end, 0, SimpleMatrix.END); + } + + /** {@inheritDoc} */ + @Override public T getRows( int begin, int end ) { + return extractMatrix(begin, end, 0, SimpleMatrix.END); + } + + /** {@inheritDoc} */ + @Deprecated + @Override public T cols( int begin, int end ) { + return extractMatrix(0, SimpleMatrix.END, begin, end); + } + + /** {@inheritDoc} */ + @Override public T getColumns( int begin, int end ) { + return extractMatrix(0, SimpleMatrix.END, begin, end); + } + /** * Converts a real array/vector into a complex one by setting imaginary component to zero */ @@ -1321,16 +1343,6 @@ public void printDimensions() { return (T)combined; } - /** {@inheritDoc} */ - @Override public T rows( int begin, int end ) { - return extractMatrix(begin, end, 0, SimpleMatrix.END); - } - - /** {@inheritDoc} */ - @Override public T cols( int begin, int end ) { - return extractMatrix(0, SimpleMatrix.END, begin, end); - } - /** {@inheritDoc} */ @Override public MatrixType getType() { return mat.getType(); diff --git a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java index f1127e07..ee11aa98 100644 --- a/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java +++ b/main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java @@ -179,14 +179,14 @@ * Get the {@code i}th row. * {@link #getColumn(int)} * Get the {@code j}th column. + * {@link #getRows(int, int)} + * Extract the specified rows. + * {@link #getColumns(int, int)} + * Extract the specified columns. * {@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. * diff --git a/main/ejml-simple/test/org/ejml/simple/TestSimpleMatrix.java b/main/ejml-simple/test/org/ejml/simple/TestSimpleMatrix.java index ec0696cb..55a6c6ce 100644 --- a/main/ejml-simple/test/org/ejml/simple/TestSimpleMatrix.java +++ b/main/ejml-simple/test/org/ejml/simple/TestSimpleMatrix.java @@ -681,6 +681,28 @@ void setColumn_SimpleMatrix_real_complex( SimpleMatrix a, SimpleMatrix b ) { } } + @Test void getRows() { + SimpleMatrix A = SimpleMatrix.random_DDRM(5, 7, -1, 1, rand); + SimpleMatrix B = A.getRows(1, 3); + + for (int i = 1; i < 3; i++) { + for (int j = 0; j < 7; j++) { + assertEquals(A.get(i, j), B.get(i - 1, j), UtilEjml.TEST_F64); + } + } + } + + @Test void getColumns() { + SimpleMatrix A = SimpleMatrix.random_DDRM(5, 7, -1, 1, rand); + SimpleMatrix B = A.getColumns(2, 4); + + for (int i = 0; i < 5; i++) { + for (int j = 2; j < 4; j++) { + assertEquals(A.get(i, j), B.get(i, j - 2), UtilEjml.TEST_F64); + } + } + } + @Test void get_2d() { SimpleMatrix a = SimpleMatrix.random_DDRM(3, 3, 0, 1, rand); @@ -1246,28 +1268,6 @@ void setColumn_SimpleMatrix_real_complex( SimpleMatrix a, SimpleMatrix b ) { assertTrue(C.isIdentical(D, UtilEjml.TEST_F64)); } - @Test void rows() { - SimpleMatrix A = SimpleMatrix.random_DDRM(5, 7, -1, 1, rand); - SimpleMatrix B = A.rows(1, 3); - - for (int i = 1; i < 3; i++) { - for (int j = 0; j < 7; j++) { - assertEquals(A.get(i, j), B.get(i - 1, j), UtilEjml.TEST_F64); - } - } - } - - @Test void cols() { - SimpleMatrix A = SimpleMatrix.random_DDRM(5, 7, -1, 1, rand); - SimpleMatrix B = A.rows(1, 3); - - for (int i = 1; i < 3; i++) { - for (int j = 0; j < 7; j++) { - assertEquals(A.get(i, j), B.get(i - 1, j), UtilEjml.TEST_F64); - } - } - } - @Test void serialization() { List matrixTypes = new ArrayList<>(); matrixTypes.add(new DMatrixRMaj(2, 3));