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
109 changes: 109 additions & 0 deletions main/ejml-simple/src/org/ejml/simple/SimpleBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ public T plus( T B ) {
return ret;
}

public T plusi( T B ) {
convertType.specify(this, B);
T A = convertType.convert(this);
B = convertType.convert(B);

A.ops.plusi(A.mat, B.mat);

return A;
}

/**
* <p>
* Returns the result of matrix subtraction:<br>
Expand All @@ -262,6 +272,15 @@ public T minus( T B ) {
return ret;
}

public T minusi( T B ) {
convertType.specify(this, B);
T A = convertType.convert(this);
B = convertType.convert(B);

A.ops.minusi(A.mat, B.mat);
return A;
}

/**
* <p>
* Returns the result of matrix-double subtraction:<br>
Expand All @@ -281,6 +300,11 @@ public T minus( double b ) {
return ret;
}

public T minusi( double b ) {
ops.minus(mat, b, mat);
return (T) this;
}

/**
* <p>
* Returns the result of scalar addition:<br>
Expand All @@ -300,6 +324,11 @@ public T plus( double b ) {
return ret;
}

public T plusi( double b ) {
ops.plus(mat, b, mat);
return (T) this;
}

/**
* <p>
* Performs a matrix addition and scale operation.<br>
Expand All @@ -323,6 +352,15 @@ public T plus( double beta, T B ) {
return ret;
}

public T plusi( double beta, T B ) {
convertType.specify(this, B);
T A = convertType.convert(this);
B = convertType.convert(B);

A.ops.plusi(A.mat, beta, B.mat);
return A;
}

/**
* Computes the dot product (a.k.a. inner product) between this vector and vector 'v'.
*
Expand Down Expand Up @@ -369,6 +407,11 @@ public T scale( double val ) {
return ret;
}

public T scalei( double val ) {
ops.scale(mat, val, mat);
return (T) this;
}

/**
* <p>
* Returns the result of dividing each element by 'val':
Expand All @@ -385,6 +428,11 @@ public T divide( double val ) {
return ret;
}

public T dividei( double val ) {
ops.divide(mat, val, mat);
return (T) this;
}

/**
* <p>
* Returns the inverse of this matrix.<br>
Expand All @@ -411,6 +459,15 @@ public T invert() {
return ret;
}

public T inverti() {
if (!ops.invert(mat, mat))
throw new SingularMatrixException();
if (ops.hasUncountable(mat))
throw new SingularMatrixException("Solution contains uncountable numbers");

return (T) this;
}

/**
* <p>
* Computes the Moore-Penrose pseudo-inverse
Expand All @@ -424,6 +481,11 @@ public T pseudoInverse() {
return ret;
}

public T pseudoInversei() {
ops.pseudoInverse(mat, mat);
return (T) this;
}

/**
* <p>
* Solves for X in the following equation:<br>
Expand Down Expand Up @@ -1048,6 +1110,15 @@ public T elementMult( T b ) {
return c;
}

public T elementMulti( T b ) {
convertType.specify(this, b);
T A = convertType.convert(this);
b = convertType.convert(b);

A.ops.elementMult(A.mat, b.mat, A.mat);
return A;
}

/**
* <p>
* Returns a matrix which is the result of an element by element division of 'this' and 'b':
Expand All @@ -1067,6 +1138,15 @@ public T elementDiv( T b ) {
return c;
}

public T elementDivi( T b ) {
convertType.specify(this, b);
T A = convertType.convert(this);
b = convertType.convert(b);

A.ops.elementDiv(A.mat, b.mat, A.mat);
return A;
}

/**
* <p>
* Returns a matrix which is the result of an element by element power of 'this' and 'b':
Expand All @@ -1086,6 +1166,15 @@ public T elementPower( T b ) {
return c;
}

public T elementPoweri( T b ) {
convertType.specify(this, b);
T A = convertType.convert(this);
b = convertType.convert(b);

A.ops.elementPower(A.mat, b.mat, A.mat);
return A;
}

/**
* <p>
* Returns a matrix which is the result of an element by element power of 'this' and 'b':
Expand All @@ -1101,6 +1190,11 @@ public T elementPower( double b ) {
return c;
}

public T elementPoweri( double b ) {
ops.elementPower(mat, b, mat);
return (T) this;
}

/**
* <p>
* Returns a matrix which is the result of an element by element exp of 'this'
Expand All @@ -1115,6 +1209,11 @@ public T elementExp() {
return c;
}

public T elementExpi() {
ops.elementExp(mat, mat);
return (T) this;
}

/**
* <p>
* Returns a matrix which is the result of an element by element exp of 'this'
Expand All @@ -1129,6 +1228,11 @@ public T elementLog() {
return c;
}

public T elementLogi() {
ops.elementLog(mat, mat);
return (T) this;
}

/**
* <p>
* Returns a new matrix whose elements are the negative of 'this' matrix's elements.<br>
Expand All @@ -1144,6 +1248,11 @@ public T negative() {
return A;
}

public T negativei() {
ops.changeSign(mat);
return (T) this;
}

/**
* <p>Allows you to perform an equation in-place on this matrix by specifying the right hand side. For information on how to define an equation
* see {@link org.ejml.equation.Equation}. The variable sequence alternates between variable and it's label String.
Expand Down
6 changes: 6 additions & 0 deletions main/ejml-simple/src/org/ejml/simple/SimpleOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,20 @@ public interface SimpleOperations<T extends Matrix> extends Serializable {

void plus( T A, T B, T output );

void plusi( T A, T B );

void minus( T A, T B, T output );

void minusi( T A, T B );

void minus( T A, double b, T output );

void plus( T A, double b, T output );

void plus( T A, double beta, T b, T output );

void plusi( T A, double beta, T b );

void plus( double alpha, T A, double beta, T b, T output );

double dot( T A, T v );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,21 @@ public void plus( DMatrixRMaj A, DMatrixRMaj B, DMatrixRMaj output ) {
CommonOps_DDRM.add(A, B, output);
}

@Override
public void plusi( DMatrixRMaj A, DMatrixRMaj B) {
CommonOps_DDRM.addEquals(A, B);
}

@Override
public void minus( DMatrixRMaj A, DMatrixRMaj B, DMatrixRMaj output ) {
CommonOps_DDRM.subtract(A, B, output);
}

@Override
public void minusi( DMatrixRMaj A, DMatrixRMaj B ) {
CommonOps_DDRM.subtractEquals(A, B);
}

@Override
public void minus( DMatrixRMaj A, /**/double b, DMatrixRMaj output ) {
CommonOps_DDRM.subtract(A, (double)b, output);
Expand All @@ -124,6 +134,11 @@ public void plus( DMatrixRMaj A, /**/double beta, DMatrixRMaj b, DMatrixRMaj out
CommonOps_DDRM.add(A, (double)beta, b, output);
}

@Override
public void plusi( DMatrixRMaj A, /**/double beta, DMatrixRMaj b ) {
CommonOps_DDRM.addEquals(A, (double)beta, b);
}

@Override
public void plus( /**/double alpha, DMatrixRMaj A, /**/double beta, DMatrixRMaj b, DMatrixRMaj output ) {
CommonOps_DDRM.add((double)alpha, A, (double)beta, b, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,21 @@ public void plus( DMatrixSparseCSC A, DMatrixSparseCSC B, DMatrixSparseCSC outpu
CommonOps_DSCC.add(1, A, 1, B, output, null, null);
}

@Override
public void plusi( DMatrixSparseCSC A, DMatrixSparseCSC B) {
CommonOps_DSCC.add(1, A, 1, B, A, null, null);
}

@Override
public void minus( DMatrixSparseCSC A, DMatrixSparseCSC B, DMatrixSparseCSC output ) {
CommonOps_DSCC.add(1, A, -1, B, output, null, null);
}

@Override
public void minusi( DMatrixSparseCSC A, DMatrixSparseCSC B ) {
CommonOps_DSCC.add(1, A, -1, B, A, null, null);
}

@Override
public void minus( DMatrixSparseCSC A, /**/double b, DMatrixSparseCSC output ) {
throw new ConvertToDenseException();
Expand All @@ -161,6 +171,15 @@ public void plus( DMatrixSparseCSC A, /**/double beta, DMatrixSparseCSC b, DMatr
}
}

@Override
public void plusi( DMatrixSparseCSC A, /**/double beta, DMatrixSparseCSC b ) {
if (EjmlConcurrency.useConcurrent(A)) {
CommonOps_MT_DSCC.add(1, A, (double)beta, b, A, workspaceMT);
} else {
CommonOps_DSCC.add(1, A, (double)beta, b, A, gw, gx);
}
}

@Override
public void plus( /**/double alpha, DMatrixSparseCSC A, /**/double beta, DMatrixSparseCSC b, DMatrixSparseCSC output ) {
if (EjmlConcurrency.useConcurrent(A)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,21 @@ public void plus( ZMatrixRMaj A, ZMatrixRMaj B, ZMatrixRMaj output ) {
CommonOps_ZDRM.add(A, B, output);
}

@Override
public void plusi( ZMatrixRMaj A, ZMatrixRMaj B ) {
CommonOps_ZDRM.add(A, B, A);
}

@Override
public void minus( ZMatrixRMaj A, ZMatrixRMaj B, ZMatrixRMaj output ) {
CommonOps_ZDRM.subtract(A, B, output);
}

@Override
public void minusi( ZMatrixRMaj A, ZMatrixRMaj B ) {
CommonOps_ZDRM.subtract(A, B, A);
}

@Override
public void minus( ZMatrixRMaj A, /**/double b, ZMatrixRMaj output ) {
// CommonOps_ZDRM.subtract(A, (double)b, output);
Expand All @@ -113,6 +123,12 @@ public void plus( ZMatrixRMaj A, /**/double beta, ZMatrixRMaj b, ZMatrixRMaj out
throw new UnsupportedOperation();
}

@Override
public void plusi( ZMatrixRMaj A, /**/double beta, ZMatrixRMaj b ) {
// CommonOps_ZDRM.add(A, (double)beta, b, output);
throw new UnsupportedOperation();
}

@Override
public void plus( /**/double alpha, ZMatrixRMaj A, /**/double beta, ZMatrixRMaj b, ZMatrixRMaj output ) {
throw new UnsupportedOperation();
Expand Down
Loading