1

Say I have an 2x2 matrix as PrimitiveDenseStore

pstore = [ 1 2 
           3 4 ]

Is there anyway to map all these values based on given anonymous function like

pstore.map(x -> x * x)

So the result is

pstore = [ 1 4
           9 16 ]
Siva
  • 7,780
  • 6
  • 47
  • 54

2 Answers2

1

Okay I was confused with java's UnaryOperator turns out ojAlgo expects its own Functional Interface PrimitiveFunction.Unary

PrimitiveFunction.Unary square = arg -> arg * arg;
pstore.modifyAll(square);
Siva
  • 7,780
  • 6
  • 47
  • 54
0

There are at least 3 alternatives for you to "investigate":

pstore.loopAll(...);
pstore.modifyAll(...);
pstore.operateOnAll(...);

and/or you could have a look at the answers to these questions:

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

Elementwise multiplication two matrices or PrimitiveDenseStores in ojAlgo

apete
  • 1,250
  • 1
  • 10
  • 16
  • @apte yes I did solid investigation with your source code and those answers and checkout those 3 methods as well. But still couldn't figure out how to pass a custom lambda function instead of given UnaryFunction to operateonall method. Couldn't figure out certain things with out examples. Docs are pretty vague. – Siva Jun 07 '17 at 07:29
  • I guess the main problem is that the interfaces in the org.ojalgo.function package are not java8-functional - they typically have 2 methods to implement. This design was chosen for ojAlgo long before Java8. No problem with anonymous classes but lamba expressions and functional references won't work in many cases. The pstore.loopAll(...) alternative works with lambda expressions. – apete Jun 07 '17 at 12:50