Open mroodschild opened 6 years ago
If something like this was added how would you suggest it be incorporated?
CommonOps.bcAdd(A,B,C);
C = SimpleMatrix.bcAdd(A,B);
I don't like automatically broadcasting if the dimensions don't line up. That can easily lead to a difficult to detect bug. Which I have encountered in python/matlab before.
Actually for the broadcasting I have to do:
Z [n x m] = W [n x j] * A [j x m] + B [n x 1]
SimpleMatrix W = new SimpleMatrix(2, 3, true, 1.0, 5, 6, 3, 2, 1);
SimpleMatrix A = new SimpleMatrix(3, 1, true, 1.0, 2, 3);
SimpleMatrix B = new SimpleMatrix(2, 1, true, 0.5, 1);
SimpleMatrix Z = W.mult(A);
Z.print();
for (int i = 0; i < Z.numCols(); i++) {
Z.setColumn(i, 0, Z.extractVector(false, i).plus(B).getDDRM().getData());
}
Z.print();
but it would be easier if:
Z = W.mult(A).bcAdd(B, false)
where:
true - broadcasting in rows
false - broadcasting in columns
Did you end up implementing this on your own?
This seems close enough to my request that I'll bump this. I would also really like to be able to do arithmetic operations on two matrices, not just one scalar value.
Hi Peter,
I think it would be good, if ejml supports other matrix operations, such as adding or multiplying a vector to an entire matrix, for example:
https://jakevdp.github.io/PythonDataScienceHandbook/02.05-computation-on-arrays-broadcasting.html
Thanks Peter!