commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ole Ersoy <ole.er...@gmail.com>
Subject [math] Java 8 RealVector Functional Design
Date Tue, 05 Jan 2016 16:35:26 GMT
Hi,

I'm attempting a more minimalistic array vector design and just thought I'd float a partial
API to see what you think.  The below methods are both 'mapToSelf' by default.  If the user
wants a new vector, she should first clone the vector and then call the map method (vector.clone().map(...)).

     public void map(BiFunction<Double, Double, Double> function, Vector v) {
         Arrays.setAll(data, i -> function.apply(data[i], v.getEntry(i)));
     }

     public void parallelMap(BiFunction<Double, Double, Double> function, Vector v)
{
         Arrays.parallelSetAll(data, i -> function.apply(data[i], v.getEntry(i)));
     }

The above two functions (Left the dimension check out) allow you to "Plug in" a lambda function
to perform the mapping.  For example if you want to perform addition, you would use the addition
BiFunction like this:

     public static BiFunction<Double, Double, Double> add = (x, y) -> {
         return x
                 + y;
     };

RUNTIME:
vector2.map(add, vector1);


Then the same for subtraction, multiplication, etc.  I'm thinking the static BiFunction instances
can go in the Arithmetic module. That way the map methods can use both checked and unchecked
arithmetic operations.  I hoping that this will also make the FieldVector and RealVector implementations
more efficient from a code sharing viewpoint and symmetric from an API perspective.

Thoughts?

Cheers,
Ole





---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message