|
1 | 1 | package org.scijava.ops.math; |
2 | 2 |
|
3 | 3 | import java.util.function.Function; |
4 | | -import java.util.stream.IntStream; |
5 | 4 |
|
6 | | -import org.scijava.ops.core.Op; |
| 5 | +import org.scijava.ops.OpField; |
| 6 | +import org.scijava.ops.core.OpCollection; |
7 | 7 | import org.scijava.ops.core.computer.Computer; |
8 | 8 | import org.scijava.ops.core.inplace.Inplace; |
9 | 9 | import org.scijava.param.Parameter; |
10 | 10 | import org.scijava.plugin.Plugin; |
11 | 11 | import org.scijava.struct.ItemIO; |
12 | 12 |
|
| 13 | +@Plugin(type = OpCollection.class) |
13 | 14 | public class Sqrt { |
14 | 15 |
|
15 | 16 | public static final String NAMES = MathOps.SQRT; |
16 | | - |
| 17 | + |
17 | 18 | // --------- Functions --------- |
18 | 19 |
|
19 | | - @Plugin(type = Op.class, name = NAMES) |
| 20 | + @OpField(names = NAMES) |
20 | 21 | @Parameter(key = "number1") |
21 | 22 | @Parameter(key = "result", type = ItemIO.OUTPUT) |
22 | | - public static class MathSqrtDoubleFunction implements Function<Double, Double> { |
23 | | - @Override |
24 | | - public Double apply(Double t) { |
25 | | - return Math.sqrt(t); |
26 | | - } |
27 | | - } |
28 | | - |
| 23 | + public static final Function<Double, Double> MathSqrtDoubleFunction = (t) -> Math.sqrt(t); |
| 24 | + |
29 | 25 | // --------- Computers --------- |
30 | 26 |
|
31 | | - @Plugin(type = Op.class, name = NAMES) |
| 27 | + @OpField(names = NAMES) |
32 | 28 | @Parameter(key = "array1") |
33 | 29 | @Parameter(key = "resultArray", type = ItemIO.BOTH) |
34 | | - public static class MathPointwiseSqrtDoubleArrayComputer implements Computer<double[], double[]> { |
35 | | - @Override |
36 | | - public void compute(double[] in1, double[] out) { |
37 | | - for (int i = 0; i < out.length; i++) { |
38 | | - out[i] = Math.sqrt(in1[i]); |
39 | | - } |
40 | | - } |
41 | | - } |
42 | | - |
| 30 | + public static final Computer<double[], double[]> MathPointwiseSqrtDoubleArrayComputer = (arr1, arr2) -> { |
| 31 | + for (int i = 0; i < arr1.length; i++) |
| 32 | + arr2[i] = Math.sqrt(arr1[i]); |
| 33 | + }; |
| 34 | + |
43 | 35 | // --------- Inplaces --------- |
44 | | - |
45 | | - @Plugin(type = Op.class, name = NAMES) |
| 36 | + |
| 37 | + @OpField(names = NAMES) |
46 | 38 | @Parameter(key = "arrayIO", type = ItemIO.BOTH) |
47 | | - public static class MathPointwiseSqrtDoubleArrayInplace implements Inplace<double[]> { |
48 | | - @Override |
49 | | - public void mutate(double[] in1) { |
50 | | - IntStream.range(0, in1.length).forEach(index -> { |
51 | | - in1[index] = Math.sqrt(in1[index]); |
52 | | - }); |
53 | | - } |
54 | | - } |
| 39 | + public static final Inplace<double[]> MathPointwiseSqrtDoubleArrayInplace = (arr) -> { |
| 40 | + for(int i = 0; i < arr.length; i++) arr[i] = Math.sqrt(arr[i]); |
| 41 | + }; |
| 42 | + |
55 | 43 | } |
0 commit comments