33import com .google .common .collect .Streams ;
44
55import java .math .BigInteger ;
6- import java .util .Arrays ;
76import java .util .function .BiFunction ;
7+ import java .util .function .Function ;
88import java .util .stream .Stream ;
9+ import java .util .stream .StreamSupport ;
910
1011import org .scijava .core .Priority ;
1112import org .scijava .ops .core .Op ;
1617import org .scijava .struct .ItemIO ;
1718
1819public class Add {
19-
20+
2021 public static final String NAMES = MathOps .ADD ;
21-
22+
2223 // --------- Functions ---------
23-
24+
2425 @ Plugin (type = Op .class , name = NAMES )
2526 @ Parameter (key = "number1" )
2627 @ Parameter (key = "number2" )
@@ -33,26 +34,26 @@ public Double apply(Double t, Double u) {
3334 }
3435
3536 // This Op is not needed anymore, can be handled via auto op transformation
36- // @Plugin(type = Op.class, priority = Priority.HIGH, name = NAMES)
37- // @Parameter(key = "array1")
38- // @Parameter(key = "array2")
39- // @Parameter(key = "resultArray", type = ItemIO.OUTPUT)
40- // public static class MathPointwiseAddDoubleArraysFunction
41- // implements BiFunction<double[], double[], double[]> {
42- // @Override
43- // public double[] apply(double[] arr1, double[] arr2) {
44- // Stream<Double> s1 = Arrays.stream(arr1).boxed();
45- // Stream<Double> s2 = Arrays.stream(arr2).boxed();
46- // return Streams.zip(s1, s2, (num1, num2) -> num1 + num2).mapToDouble(Double::doubleValue).toArray();
47- // }
48- // }
49-
37+ // @Plugin(type = Op.class, priority = Priority.HIGH, name = NAMES)
38+ // @Parameter(key = "array1")
39+ // @Parameter(key = "array2")
40+ // @Parameter(key = "resultArray", type = ItemIO.OUTPUT)
41+ // public static class MathPointwiseAddDoubleArraysFunction
42+ // implements BiFunction<double[], double[], double[]> {
43+ // @Override
44+ // public double[] apply(double[] arr1, double[] arr2) {
45+ // Stream<Double> s1 = Arrays.stream(arr1).boxed();
46+ // Stream<Double> s2 = Arrays.stream(arr2).boxed();
47+ // return Streams.zip(s1, s2, (num1, num2) -> num1 + num2).mapToDouble(Double::doubleValue).toArray();
48+ // }
49+ // }
50+
5051 @ Plugin (type = Op .class , priority = Priority .HIGH , name = NAMES )
5152 @ Parameter (key = "iter1" )
5253 @ Parameter (key = "iter2" )
5354 @ Parameter (key = "resultArray" , type = ItemIO .OUTPUT )
5455 public static class MathPointwiseAddIterablesFunction <M extends Number , I extends Iterable <M >>
55- implements BiFunction <I , I , Iterable <Double >> {
56+ implements BiFunction <I , I , Iterable <Double >> {
5657 @ Override
5758 public Iterable <Double > apply (I i1 , I i2 ) {
5859 Stream <? extends Number > s1 = Streams .stream ((Iterable <? extends Number >) i1 );
@@ -62,7 +63,7 @@ public Iterable<Double> apply(I i1, I i2) {
6263 }
6364
6465 // --------- Computers ---------
65-
66+
6667 @ Plugin (type = Op .class , name = NAMES )
6768 @ Parameter (key = "integer1" )
6869 @ Parameter (key = "integer2" )
@@ -86,9 +87,9 @@ public void compute(double[] in1, double[] in2, double[] out) {
8687 }
8788 }
8889 }
89-
90+
9091 // --------- Inplaces ---------
91-
92+
9293 @ Plugin (type = Op .class , name = NAMES )
9394 @ Parameter (key = "arrayIO" , type = ItemIO .BOTH )
9495 @ Parameter (key = "array1" )
@@ -100,7 +101,31 @@ public void mutate(double[] io, double[] in2) {
100101 }
101102 }
102103 }
103-
104+
105+ @ Plugin (type = Op .class , name = NAMES )
106+ @ Parameter (key = "val1" )
107+ @ Parameter (key = "val2" )
108+ @ Parameter (key = "output" , type = ItemIO .OUTPUT )
109+ public static class MathAddNumbersFunction <N extends Number > implements BiFunction <N , N , Double >{
110+
111+ @ Override
112+ public Double apply (N in1 , N in2 ) {
113+ return in1 .doubleValue () + in2 .doubleValue ();
114+ }
115+ }
116+
117+ @ Plugin (type = Op .class , name = NAMES )
118+ @ Parameter (key = "iterable" )
119+ @ Parameter (key = "result" , type = ItemIO .OUTPUT )
120+ public static class MathReductionAdd <N extends Number > implements Function <Iterable <N >, Double >{
121+
122+ @ Override
123+ public Double apply (Iterable <N > iterable ) {
124+ return StreamSupport .stream (iterable .spliterator (), false ).mapToDouble (Number ::doubleValue ).sum ();
125+ }
126+ }
127+
128+
104129 // @Op
105130 // @Parameter(key = "number1")
106131 // @Parameter(key = "number2")
0 commit comments