Looking for a function to add/subtract a double from all elements of a matrix or dense store.
Asked
Active
Viewed 370 times
1 Answers
3
Some alternatives:
matrixA.operateOnAll(ADD.second(scalarB)).supplyTo(matrixC);
matrixC.fillMatching(matrixA, ADD, scalarB);
matrixC.modifyAll(ADD.second(scalarB));
matrixA.passMatching((from, i, j, to) -> {
to.set(i, j, from.doubleValue(i, j) + scalarB);
}, matrixC);
Where ADD comes from a static import (org.ojalgo.function.PrimitiveFunction) and the call to the second(...) method set/locks the second argument of the binary "add" function turning it into a unary function that you can pass to the operateOnAll(...) or modifyAll(...) methods.

apete
- 1,250
- 1
- 10
- 16
-
This is awesome ! Can I also lock first operand - like SUBTRACT.first(1) for getting (1-X) ? – Sree Jan 16 '17 at 14:28
-
1Yes sure, and for a ParameterFunction (like ROOT or POWER) you can lock the parameter... – apete Jan 16 '17 at 14:49