0

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

apete
  • 1,250
  • 1
  • 10
  • 16
Sree
  • 117
  • 1
  • 11
  • Looking for a block function. Will denseStore.add(0, addend) do it ? Would it mutate original store ? – Sree Jan 16 '17 at 11:16

1 Answers1

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
  • 1
    Yes sure, and for a ParameterFunction (like ROOT or POWER) you can lock the parameter... – apete Jan 16 '17 at 14:49