Skip to content

Commit bbc6b20

Browse files
authored
Merge pull request #74 from scijava/scijava/scijava-ops-api/op-builder-refactor
Refactor OpBuilder to improve usability
2 parents 410b17a + 12e8d34 commit bbc6b20

155 files changed

Lines changed: 14676 additions & 5920 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

imagej/imagej-ops2/src/test/java/net/imagej/ops2/coloc/icq/LiICQTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void testICQ() {
5959
final Img<ByteType> img1 = TestImgGeneration.byteArray(true, 10, 15, 20);
6060
final Img<ByteType> img2 = TestImgGeneration.byteArray(true, 10, 15, 20);
6161

62-
final Double icqValue = ops.op("coloc.icq").input(img1, img2).outType(Double.class).apply();
62+
final Double icqValue = ops.op("coloc.icq").arity2().input(img1, img2).outType(Double.class).apply();
6363

6464
assertEquals(0.5, icqValue, 0.0);
6565
}
@@ -69,7 +69,7 @@ public void testICQ() {
6969
*/
7070
@Test
7171
public void liPositiveCorrTest() {
72-
final Double icqValue = ops.op("coloc.icq").input(getPositiveCorrelationImageCh1(), getPositiveCorrelationImageCh2())
72+
final Double icqValue = ops.op("coloc.icq").arity2().input(getPositiveCorrelationImageCh1(), getPositiveCorrelationImageCh2())
7373
.outType(Double.class).apply();
7474
assertTrue(icqValue > 0.34 && icqValue < 0.35);
7575
}
@@ -80,7 +80,7 @@ public void liPositiveCorrTest() {
8080
*/
8181
@Test
8282
public void liZeroCorrTest() {
83-
final Object icqValue = ops.op("coloc.icq").input(getZeroCorrelationImageCh1(), getZeroCorrelationImageCh2()).apply();
83+
final Object icqValue = ops.op("coloc.icq").arity2().input(getZeroCorrelationImageCh1(), getZeroCorrelationImageCh2()).apply();
8484

8585
assertTrue(icqValue instanceof Double);
8686
final double icq = (Double) icqValue;
@@ -103,7 +103,7 @@ public void testPValue() {
103103
BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double> op = OpBuilder.matchFunction(ops, "coloc.icq",
104104
new Nil<RandomAccessibleInterval<FloatType>>() {}, new Nil<RandomAccessibleInterval<FloatType>>() {}, new Nil<Double>() {});
105105
PValueResult value = new PValueResult();
106-
ops.op("coloc.pValue").input(ch1, ch2, op, es).output(value).compute();
106+
ops.op("coloc.pValue").arity4().input(ch1, ch2, op, es).output(value).compute();
107107
assertEquals(0.72, value.getPValue(), 0.0);
108108
}
109109

imagej/imagej-ops2/src/test/java/net/imagej/ops2/coloc/kendallTau/KendallTauBRankTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void exhaustiveKendallTauBRankTesting() {
104104
//final PairIterator<DoubleType> iter = pairIterator(values1, values2);
105105
final Iterable<Pair<IntType, IntType>> iter = new IterablePair<>(ArrayImgs.ints(values1, n), ArrayImgs.ints(values2, n));
106106
double kendallValue1 = calculateNaive(iter.iterator());
107-
double kendallValue2 = ops.op("coloc.kendallTau").input(values1, values2).outType(Double.class).apply();
107+
double kendallValue2 = ops.op("coloc.kendallTau").arity2().input(values1, values2).outType(Double.class).apply();
108108
if (Double.isNaN(kendallValue1)) {
109109
assertTrue(Double.isInfinite(kendallValue2) || Double.isNaN(
110110
kendallValue2), "i: " + i + ", value2: " + kendallValue2);
@@ -133,7 +133,7 @@ public void testPValue() {
133133
// new Nil<BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double>>() {})
134134
// .apply();
135135
PValueResult value = new PValueResult();
136-
ops.op("coloc.pValue").input(ch1, ch2, op, es).output(value).compute();
136+
ops.op("coloc.pValue").arity4().input(ch1, ch2, op, es).output(value).compute();
137137
assertEquals(0.75, value.getPValue(), 0.0);
138138
}
139139

@@ -145,7 +145,7 @@ private int pseudoRandom()
145145
}
146146

147147
private <T extends RealType<T>, U extends RealType<U>> void assertTau(final double expected, final Iterable<T> img1, final Iterable<U> img2) {
148-
final double kendallValue = (double) ops.op("coloc.kendallTau").input(img1, img2).apply();
148+
final double kendallValue = (double) ops.op("coloc.kendallTau").arity2().input(img1, img2).apply();
149149
assertEquals(expected, kendallValue, 1e-10);
150150
}
151151

imagej/imagej-ops2/src/test/java/net/imagej/ops2/coloc/maxTKendallTau/MTKTTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void testMTKTnone() {
145145
}
146146
Img<DoubleType> vImage1 = ArrayImgs.doubles(values1, values1.length);
147147
Img<DoubleType> vImage2 = ArrayImgs.doubles(values2, values2.length);
148-
double result = ops.op("coloc.maxTKendallTau").input(vImage1, vImage2).outType(Double.class).apply();
148+
double result = ops.op("coloc.maxTKendallTau").arity2().input(vImage1, vImage2).outType(Double.class).apply();
149149
assertEquals(4.9E-324, result, 0.0);
150150
}
151151

@@ -161,7 +161,7 @@ public void testMTKTall() {
161161
}
162162
Img<DoubleType> vImage1 = ArrayImgs.doubles(values1, values1.length);
163163
Img<DoubleType> vImage2 = ArrayImgs.doubles(values2, values2.length);
164-
double result = (Double) ops.op("coloc.maxTKendallTau").input(vImage1, vImage2).apply();
164+
double result = (Double) ops.op("coloc.maxTKendallTau").arity2().input(vImage1, vImage2).apply();
165165
assertEquals(1.0, result, 0.0);
166166
}
167167

@@ -175,7 +175,7 @@ public void testMTKTrandom() {
175175
0x01234567);
176176
Img<FloatType> ch2 = AbstractColocalisationTest.produceMeanBasedNoiseImage(new FloatType(), 24, 24, mean, spread, sigma,
177177
0x98765432);
178-
double result = (Double) ops.op("coloc.maxTKendallTau").input(ch1, ch2).apply();
178+
double result = (Double) ops.op("coloc.maxTKendallTau").arity2().input(ch1, ch2).apply();
179179
assertEquals(2.710687382741972, result, 0.0);
180180
}
181181

@@ -186,7 +186,7 @@ public void testMTKTimage() {
186186
new long[] { 0, 0, 0 }, new long[] { 20, 20, 0 });
187187
RandomAccessibleInterval<UnsignedByteType> cropCh2 = Views.interval(getZeroCorrelationImageCh2(),
188188
new long[] { 0, 0, 0 }, new long[] { 20, 20, 0 });
189-
double result = (Double) ops.op("coloc.maxTKendallTau").input(cropCh1, cropCh2).apply();
189+
double result = (Double) ops.op("coloc.maxTKendallTau").arity2().input(cropCh1, cropCh2).apply();
190190
assertEquals(2.562373279563565, result, 0.0);
191191
}
192192

@@ -208,7 +208,7 @@ public void testMTKTpValueNone() {
208208
BiFunction<RandomAccessibleInterval<DoubleType>, RandomAccessibleInterval<DoubleType>, Double> op =
209209
OpBuilder.matchFunction(ops, "coloc.maxTKendallTau", new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<Double>() {});
210210
PValueResult value = new PValueResult();
211-
ops.op("coloc.pValue").input(vImage1, vImage2, op, 5, es).output(value).compute();
211+
ops.op("coloc.pValue").arity5().input(vImage1, vImage2, op, 5, es).output(value).compute();
212212
assertEquals(0.0, value.getPValue(), 0.0);
213213
}
214214

@@ -228,7 +228,7 @@ public void testMTKTpValueAll() {
228228
BiFunction<RandomAccessibleInterval<DoubleType>, RandomAccessibleInterval<DoubleType>, Double> op =
229229
OpBuilder.matchFunction(ops, "coloc.maxTKendallTau", new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<Double>() {});
230230
PValueResult value = new PValueResult();
231-
ops.op("coloc.pValue").input(vImage1, vImage2, op, 5, es).output(value).compute();
231+
ops.op("coloc.pValue").arity5().input(vImage1, vImage2, op, 5, es).output(value).compute();
232232
assertEquals(0.0, value.getPValue(), 0.0);
233233
}
234234

@@ -246,7 +246,7 @@ public void testMTKTpValueRandom() {
246246
BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double> op =
247247
OpBuilder.matchFunction(ops, "coloc.maxTKendallTau", new Nil<RandomAccessibleInterval<FloatType>>() {}, new Nil<RandomAccessibleInterval<FloatType>>() {}, new Nil<Double>() {});
248248
PValueResult value = new PValueResult();
249-
ops.op("coloc.pValue").input(ch1, ch2, op, 10, es).output(value).compute();
249+
ops.op("coloc.pValue").arity5().input(ch1, ch2, op, 10, es).output(value).compute();
250250
assertEquals(0.2, value.getPValue(), 0.0);
251251
}
252252

@@ -268,7 +268,7 @@ public void testMTKTpValueImage() {
268268
RandomAccessibleInterval<UnsignedByteType> ch1 = ShuffledView.cropAtMin(cropCh1, blockSize);
269269
RandomAccessibleInterval<UnsignedByteType> ch2 = ShuffledView.cropAtMin(cropCh2, blockSize);
270270
PValueResult value = new PValueResult();
271-
ops.op("coloc.pValue").input(ch1, ch2, op, 5, es).output(value).compute();
271+
ops.op("coloc.pValue").arity5().input(ch1, ch2, op, 5, es).output(value).compute();
272272
assertEquals(0.2, value.getPValue(), 0.0);
273273
}
274274
}

imagej/imagej-ops2/src/test/java/net/imagej/ops2/coloc/pValue/DefaultPValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private void assertColoc(double expectedPValue, double expectedColocValue, doubl
102102
{}.getType());
103103

104104
PValueResult output = new PValueResult();
105-
ops.op("coloc.pValue").input(ch1, ch2, wrapped, result.length - 1, es).output(output).compute();
105+
ops.op("coloc.pValue").arity5().input(ch1, ch2, wrapped, result.length - 1, es).output(output).compute();
106106
Double actualPValue = output.getPValue();
107107
Double actualColocValue = output.getColocValue();
108108
double[] actualColocValuesArray = output.getColocValuesArray();

imagej/imagej-ops2/src/test/java/net/imagej/ops2/coloc/pearsons/DefaultPearsonsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class DefaultPearsonsTest extends AbstractColocalisationTest {
5656
*/
5757
@Test
5858
public void fastPearsonsZeroCorrTest(){
59-
double result = ops.op("coloc.pearsons").input(getZeroCorrelationImageCh1(), getZeroCorrelationImageCh2()).outType(Double.class).apply();
59+
double result = ops.op("coloc.pearsons").arity2().input(getZeroCorrelationImageCh1(), getZeroCorrelationImageCh2()).outType(Double.class).apply();
6060
assertEquals(0.0, result, 0.05);
6161
}
6262

@@ -66,7 +66,7 @@ public void fastPearsonsZeroCorrTest(){
6666
*/
6767
@Test
6868
public void fastPearsonsPositiveCorrTest() {
69-
double result = ops.op("coloc.pearsons").input(getPositiveCorrelationImageCh1(), getPositiveCorrelationImageCh2()).outType(Double.class).apply();
69+
double result = ops.op("coloc.pearsons").arity2().input(getPositiveCorrelationImageCh1(), getPositiveCorrelationImageCh2()).outType(Double.class).apply();
7070
assertEquals(0.75, result, 0.01);
7171
}
7272

@@ -85,7 +85,7 @@ public void differentMeansTest() {
8585
512, 512, mean, spread, sigma, 0x01234567);
8686
RandomAccessibleInterval<FloatType> ch2 = produceMeanBasedNoiseImage(new FloatType(),
8787
512, 512, mean, spread, sigma, 0x98765432);
88-
double resultFast = ops.op("coloc.pearsons").input(ch1, ch2).outType(Double.class).apply();
88+
double resultFast = ops.op("coloc.pearsons").arity2().input(ch1, ch2).outType(Double.class).apply();
8989
assertEquals(0.0, resultFast, 0.1);
9090

9191
/* If the means are the same, it causes a numerical problem in the classic implementation of Pearson's
@@ -108,7 +108,7 @@ public void testPValue() {
108108
BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double> op =
109109
OpBuilder.matchFunction(ops, "coloc.pearsons", new Nil<RandomAccessibleInterval<FloatType>>() {}, new Nil<RandomAccessibleInterval<FloatType>>() {}, new Nil<Double>() {});
110110
PValueResult value = new PValueResult();
111-
ops.op("coloc.pValue").input(ch1, ch2, op, es).output(value).compute();
111+
ops.op("coloc.pValue").arity4().input(ch1, ch2, op, es).output(value).compute();
112112
assertEquals(0.66, value.getPValue(), 0.0);
113113
}
114114

imagej/imagej-ops2/src/test/java/net/imagej/ops2/convert/ConvertIIsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public class ConvertIIsTest extends AbstractOpTest {
5757
@BeforeEach
5858
public void createImages() {
5959
final FinalDimensions dims = FinalDimensions.wrap(new long[] {10, 10});
60-
in = ops.op("create.img").input(dims, new ShortType()).outType(new Nil<IterableInterval<ShortType>>() {}).apply();
60+
in = ops.op("create.img").arity2().input(dims, new ShortType()).outType(new Nil<IterableInterval<ShortType>>() {}).apply();
6161
addNoise(in);
62-
out = ops.op("create.img").input(dims, new ByteType()).outType(new Nil<Img<ByteType>>() {}).apply();
62+
out = ops.op("create.img").arity2().input(dims, new ByteType()).outType(new Nil<Img<ByteType>>() {}).apply();
6363
}
6464

6565
@Test
6666
public void testClip() {
67-
ops.op("convert.clip").input(in).output(out).compute();
67+
ops.op("convert.clip").arity1().input(in).output(out).compute();
6868

6969
final Cursor<ShortType> c = in.localizingCursor();
7070
final RandomAccess<ByteType> ra = out.randomAccess();
@@ -77,7 +77,7 @@ public void testClip() {
7777

7878
@Test
7979
public void testCopy() {
80-
ops.op("convert.copy").input(in).output(out).compute();
80+
ops.op("convert.copy").arity1().input(in).output(out).compute();
8181

8282
final Cursor<ShortType> c = in.localizingCursor();
8383
final RandomAccess<ByteType> ra = out.randomAccess();
@@ -91,8 +91,8 @@ public void testCopy() {
9191
// -- Helper methods --
9292

9393
private void addNoise(final IterableInterval<ShortType> image) {
94-
IterableInterval<ShortType> copy = ops.op("copy").input(image).outType(new Nil<IterableInterval<ShortType>>() {}).apply();
95-
ops.op("filter.addNoise").input(copy, -32768., 32767., 10000.).output(image).compute();
94+
IterableInterval<ShortType> copy = ops.op("copy").arity1().input(image).outType(new Nil<IterableInterval<ShortType>>() {}).apply();
95+
ops.op("filter.addNoise").arity4().input(copy, -32768., 32767., 10000.).output(image).compute();
9696
}
9797

9898
private byte clip(final short value) {

imagej/imagej-ops2/src/test/java/net/imagej/ops2/convert/ConvertMapTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void testLossless() {
7272
outC1.next().getRealDouble(), 0d);
7373
}
7474

75-
ops.op("convert.float32").input(in).output(out).compute();
75+
ops.op("convert.float32").arity1().input(in).output(out).compute();
7676

7777
// ops.run(Ops.Map.class, out, in, new ComplexToFloat32<UnsignedByteType>());
7878

@@ -95,7 +95,7 @@ public void testLossy() {
9595
final byte[] outArray = { 4, 123, 18, 64, 90, 120, 12, 17, 73 };
9696
final Img<UnsignedByteType> out = generateUnsignedByteImg(outArray);
9797

98-
ops.op("convert.uint8").input(in).output(out).compute();
98+
ops.op("convert.uint8").arity1().input(in).output(out).compute();
9999
// ops.run(Ops.Map.class, out, in, new ComplexToUint8<FloatType>());
100100

101101
final Cursor<FloatType> inC = in.cursor();

imagej/imagej-ops2/src/test/java/net/imagej/ops2/copy/CopyArrayImgTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void createData() {
6969
public void copyArrayImgNoOutputTest() {
7070
@SuppressWarnings("unchecked")
7171
final RandomAccessibleInterval<UnsignedByteType> output =
72-
(RandomAccessibleInterval<UnsignedByteType>) ops.op("copy.img").input(
72+
(RandomAccessibleInterval<UnsignedByteType>) ops.op("copy.img").arity1().input(
7373
input).apply();
7474

7575
final Cursor<UnsignedByteType> inc = input.localizingCursor();
@@ -86,7 +86,7 @@ public void copyArrayImgNoOutputTest() {
8686
public void copyArrayImgWithOutputTest() {
8787
final Img<UnsignedByteType> output = input.factory().create(input, input.firstElement());
8888

89-
ops.op("copy.img").input(input).output(output).compute();
89+
ops.op("copy.img").arity1().input(input).output(output).compute();
9090

9191
final Cursor<UnsignedByteType> inc = input.cursor();
9292
final Cursor<UnsignedByteType> outc = output.cursor();

imagej/imagej-ops2/src/test/java/net/imagej/ops2/copy/CopyIITest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void createData() {
6969

7070
@Test
7171
public void copyRAINoOutputTest() {
72-
IterableInterval<DoubleType> output = ops.op("copy.iterableInterval").input(input)
72+
IterableInterval<DoubleType> output = ops.op("copy.iterableInterval").arity1().input(input)
7373
.outType(new Nil<IterableInterval<DoubleType>>() {}).apply();
7474

7575
Cursor<DoubleType> inc = input.localizingCursor();
@@ -86,7 +86,7 @@ public void copyRAINoOutputTest() {
8686
public void copyTypeTest() {
8787
Img<FloatType> inputFloat = new ArrayImgFactory<>(new FloatType()).create(new int[] { 120, 100 });
8888

89-
Img<FloatType> output = ops.op("copy.iterableInterval").input(inputFloat)
89+
Img<FloatType> output = ops.op("copy.iterableInterval").arity1().input(inputFloat)
9090
.outType(new Nil<Img<FloatType>>() {}).apply();
9191

9292
assertTrue(output.firstElement() instanceof FloatType,
@@ -97,7 +97,7 @@ public void copyTypeTest() {
9797
public void copyRAIWithOutputTest() {
9898
Img<DoubleType> output = input.factory().create(input, input.firstElement());
9999

100-
ops.op("copy.iterableInterval").input(input).output(output).compute();
100+
ops.op("copy.iterableInterval").arity1().input(input).output(output).compute();
101101

102102
final Cursor<DoubleType> inc = input.cursor();
103103
final Cursor<DoubleType> outc = output.cursor();

imagej/imagej-ops2/src/test/java/net/imagej/ops2/copy/CopyImgLabelingTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public class CopyImgLabelingTest extends AbstractOpTest {
5454

5555
@BeforeEach
5656
public void createData() {
57-
input = ops.op("create.imgLabeling").input(new FinalDimensions(10, 10), new IntType())
57+
input = ops.op("create.imgLabeling").arity2().input(new FinalDimensions(10, 10), new IntType())
5858
.outType(new Nil<ImgLabeling<String, IntType>>() {}).apply();
59-
copy = ops.op("create.imgLabeling").input(new FinalDimensions(10, 10), new IntType())
59+
copy = ops.op("create.imgLabeling").arity2().input(new FinalDimensions(10, 10), new IntType())
6060
.outType(new Nil<ImgLabeling<String, IntType>>() {}).apply();
6161

6262
final Cursor<LabelingType<String>> inc = input.cursor();
@@ -74,7 +74,7 @@ public void createData() {
7474

7575
@Test
7676
public void copyImgLabeling() {
77-
ops.op("copy.imgLabeling").input(input).output(copy).compute();
77+
ops.op("copy.imgLabeling").arity1().input(input).output(copy).compute();
7878
assertNotNull(copy);
7979

8080
Cursor<LabelingType<String>> inCursor = input.cursor();

0 commit comments

Comments
 (0)