OjAlgo : Is there a way to add/subtract a double from all elements of a PrimitiveDenseStore in ojAlgo?

392 Views Asked by At

Looking for a function to add/subtract a double from all elements of a matrix or dense store.

1

There are 1 best solutions below

2
On BEST ANSWER

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.