问题
Looking for a function to add/subtract a double from all elements of a matrix or dense store.
回答1:
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.
来源:https://stackoverflow.com/questions/41675095/ojalgo-is-there-a-way-to-add-subtract-a-double-from-all-elements-of-a-primitiv