Siva
Siva

Reputation: 8058

OjAlgo How to map / update all the values in PrimitiveDenseStore?

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 ]

Upvotes: 1

Views: 209

Answers (2)

Siva
Siva

Reputation: 8058

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);

Upvotes: 1

apete
apete

Reputation: 1320

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

Upvotes: 0

Related Questions