Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion main/ejml-simple/src/org/ejml/simple/ConstMatrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public interface ConstMatrix<T extends ConstMatrix<T>> {
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
Expand Down Expand Up @@ -237,6 +237,16 @@ public interface ConstMatrix<T extends ConstMatrix<T>> {
*/
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 );

/**
* <p>
* Returns the inverse of this matrix.<br>
Expand Down
64 changes: 63 additions & 1 deletion main/ejml-simple/src/org/ejml/simple/SimpleBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,80 @@ protected T createComplexMatrix( int numRows, int numCols ) {
* when an operation is needed that is not provided by this class.
* </p>
*
* @return Reference to the internal DMatrixRMaj.
* @return Reference to the internal matrix.
*/
public <InnerType extends Matrix> InnerType getMatrix() {
return (InnerType)mat;
}

/**
* <p>
* 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}.
* </p>
*
* @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);
}

/**
* <p>
* 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}.
* </p>
*
* @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);
}

/**
* <p>
* 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}.
* </p>
*
* @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);
}

/**
* <p>
* 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}.
* </p>
*
* @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);
}

/**
* <p>
* 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}.
* </p>
*
* @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);
}

/**
* <p>
* 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}.
* </p>
*
* @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);
}
Expand Down Expand Up @@ -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();
Expand Down
Loading