Skip to content

Commit cb127c2

Browse files
committed
WIP: change ops.run() to OpBuilder
TODO: squash with other commits
1 parent 8cc6a44 commit cb127c2

22 files changed

Lines changed: 150 additions & 161 deletions

File tree

src/test/java/net/imagej/ops/coloc/icq/LiICQTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737

3838
import net.imagej.ops.coloc.ColocalisationTest;
3939
import net.imagej.ops.coloc.pValue.PValueResult;
40+
import net.imglib2.RandomAccessibleInterval;
4041
import net.imglib2.img.Img;
4142
import net.imglib2.type.numeric.integer.ByteType;
4243
import net.imglib2.type.numeric.real.FloatType;
4344

4445
import org.junit.Test;
45-
import org.scijava.ops.core.builder.OpBuilder;
4646
import org.scijava.ops.function.Functions;
4747
import org.scijava.ops.types.Nil;
4848
import org.scijava.thread.ThreadService;
@@ -69,7 +69,8 @@ public void testICQ() {
6969
*/
7070
@Test
7171
public void liPositiveCorrTest() {
72-
final Double icqValue = op("coloc.icq").input(positiveCorrelationImageCh1, positiveCorrelationImageCh2).outType(Double.class).apply();
72+
final Double icqValue = op("coloc.icq").input(positiveCorrelationImageCh1, positiveCorrelationImageCh2)
73+
.outType(Double.class).apply();
7374
assertTrue(icqValue > 0.34 && icqValue < 0.35);
7475
}
7576

@@ -101,8 +102,12 @@ public void testPValue() {
101102
0x98765432);
102103
BiFunction<Iterable<FloatType>, Iterable<FloatType>, Double> op = Functions.match(ops, "coloc.icq",
103104
new Nil<Iterable<FloatType>>() {}, new Nil<Iterable<FloatType>>() {}, new Nil<Double>() {});
105+
BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double> raiOp = op(
106+
"transform.raiToIterable").input(op).outType(
107+
new Nil<BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double>>() {})
108+
.apply();
104109
PValueResult value = new PValueResult();
105-
op("coloc.pValue").input(ch1, ch2, op, es).output(value).compute();
110+
op("coloc.pValue").input(ch1, ch2, raiOp, es).output(value).compute();
106111
assertEquals(0.72, value.getPValue(), 0.0);
107112
}
108113

src/test/java/net/imagej/ops/coloc/kendallTau/KendallTauBRankTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import net.imagej.ops.AbstractOpTest;
4141
import net.imagej.ops.coloc.ColocalisationTest;
4242
import net.imagej.ops.coloc.pValue.PValueResult;
43+
import net.imglib2.RandomAccessibleInterval;
4344
import net.imglib2.img.Img;
4445
import net.imglib2.img.array.ArrayImgs;
4546
import net.imglib2.type.numeric.RealType;
@@ -49,7 +50,6 @@
4950
import net.imglib2.util.Pair;
5051

5152
import org.junit.Test;
52-
import org.scijava.ops.core.builder.OpBuilder;
5353
import org.scijava.ops.function.Functions;
5454
import org.scijava.ops.types.Nil;
5555
import org.scijava.thread.ThreadService;
@@ -127,8 +127,12 @@ public void testPValue() {
127127
Nil<Iterable<FloatType>> nilI = new Nil<Iterable<FloatType>>() {};
128128
BiFunction<Iterable<FloatType>, Iterable<FloatType>, Double> op = Functions.match(ops,
129129
"coloc.kendallTau", nilI, nilI, new Nil<Double>() {});
130+
BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double> raiOp = op(
131+
"transform.raiToIterable").input(op).outType(
132+
new Nil<BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double>>() {})
133+
.apply();
130134
PValueResult value = new PValueResult();
131-
op("coloc.pValue").input(ch1, ch2, op, es).output(value).compute();
135+
op("coloc.pValue").input(ch1, ch2, raiOp, es).output(value).compute();
132136
assertEquals(0.75, value.getPValue(), 0.0);
133137
}
134138

src/test/java/net/imagej/ops/coloc/maxTKendallTau/MTKTTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public void testMTKTpValueNone() {
210210
BiFunction<RandomAccessibleInterval<DoubleType>, RandomAccessibleInterval<DoubleType>, Double> op =
211211
Functions.match(ops, "coloc.maxTKendallTau", new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<Double>() {});
212212
PValueResult value = new PValueResult();
213-
op("coloc.pValue").input(vImage1, vImage2, op, 5, es, value).apply();
213+
op("coloc.pValue").input(vImage1, vImage2, op, 5, es).output(value).compute();
214214
assertEquals(0.0, value.getPValue(), 0.0);
215215
}
216216

@@ -230,7 +230,7 @@ public void testMTKTpValueAll() {
230230
BiFunction<RandomAccessibleInterval<DoubleType>, RandomAccessibleInterval<DoubleType>, Double> op =
231231
Functions.match(ops, "coloc.maxTKendallTau", new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<RandomAccessibleInterval<DoubleType>>() {}, new Nil<Double>() {});
232232
PValueResult value = new PValueResult();
233-
op("coloc.pValue").input(vImage1, vImage2, op, 5, es, value).apply();
233+
op("coloc.pValue").input(vImage1, vImage2, op, 5, es).output(value).compute();
234234
assertEquals(0.0, value.getPValue(), 0.0);
235235
}
236236

@@ -248,7 +248,7 @@ public void testMTKTpValueRandom() {
248248
BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double> op =
249249
Functions.match(ops, "coloc.maxTKendallTau", new Nil<RandomAccessibleInterval<FloatType>>() {}, new Nil<RandomAccessibleInterval<FloatType>>() {}, new Nil<Double>() {});
250250
PValueResult value = new PValueResult();
251-
op("coloc.pValue").input(ch1, ch2, op, 10, es, value).apply();
251+
op("coloc.pValue").input(ch1, ch2, op, 10, es).output(value).compute();
252252
assertEquals(0.2, value.getPValue(), 0.0);
253253
}
254254

src/test/java/net/imagej/ops/coloc/pearsons/DefaultPearsonsTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import net.imglib2.type.numeric.real.FloatType;
4141

4242
import org.junit.Test;
43-
import org.scijava.ops.core.builder.OpBuilder;
4443
import org.scijava.ops.function.Functions;
4544
import org.scijava.ops.types.Nil;
4645
import org.scijava.thread.ThreadService;
@@ -109,8 +108,12 @@ public void testPValue() {
109108
mean, spread, sigma, 0x98765432);
110109
BiFunction<Iterable<FloatType>, Iterable<FloatType>, Double> op =
111110
Functions.match(ops, "coloc.pearsons", new Nil<Iterable<FloatType>>() {}, new Nil<Iterable<FloatType>>() {}, new Nil<Double>() {});
111+
BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double> raiOp = op(
112+
"transform.raiToIterable").input(op).outType(
113+
new Nil<BiFunction<RandomAccessibleInterval<FloatType>, RandomAccessibleInterval<FloatType>, Double>>() {})
114+
.apply();
112115
PValueResult value = new PValueResult();
113-
op("coloc.pValue").input(ch1, ch2, op, es, value).apply();
116+
op("coloc.pValue").input(ch1, ch2, raiOp, es).output(value).compute();
114117
assertEquals(0.66, value.getPValue(), 0.0);
115118
}
116119

src/test/java/net/imagej/ops/convert/ConvertIIsTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
import org.junit.Before;
4545
import org.junit.Test;
46-
import org.scijava.ops.core.builder.OpBuilder;
46+
import org.scijava.ops.types.Nil;
4747

4848
/**
4949
* Tests {@link ConvertIIs} + {@link RealTypeConverter} ops.
@@ -58,14 +58,14 @@ public class ConvertIIsTest extends AbstractOpTest {
5858
@Before
5959
public void createImages() {
6060
final FinalDimensions dims = FinalDimensions.wrap(new long[] {10, 10});
61-
in = (IterableInterval<ShortType>) op("create.img").input(dims, new ShortType()).apply();
61+
in = op("create.img").input(dims, new ShortType()).outType(new Nil<IterableInterval<ShortType>>() {}).apply();
6262
addNoise(in);
63-
out = (Img<ByteType>) op("create.img").input(dims, new ByteType()).apply();
63+
out = op("create.img").input(dims, new ByteType()).outType(new Nil<Img<ByteType>>() {}).apply();
6464
}
6565

6666
@Test
6767
public void testClip() {
68-
op("convert.clip").input(in, out).apply();
68+
op("convert.clip").input(in).output(out).compute();
6969

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

7979
@Test
8080
public void testCopy() {
81-
op("convert.copy").input(in, out).apply();
81+
op("convert.copy").input(in).output(out).compute();
8282

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

9494
private void addNoise(final IterableInterval<ShortType> image) {
95-
IterableInterval<ShortType> copy = (IterableInterval<ShortType>) op("copy.img").input(image).apply();
96-
op("filter.addNoise").input(copy, -32768., 32767., 10000., image).apply();
95+
IterableInterval<ShortType> copy = op("copy").input(image).outType(new Nil<IterableInterval<ShortType>>() {}).apply();
96+
op("filter.addNoise").input(copy, -32768., 32767., 10000.).output(image).compute();
9797
}
9898

9999
private byte clip(final short value) {

src/test/java/net/imagej/ops/copy/CopyIITest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333

3434
import net.imagej.ops.AbstractOpTest;
3535
import net.imglib2.Cursor;
36-
import net.imglib2.RandomAccess;
37-
import net.imglib2.RandomAccessibleInterval;
36+
import net.imglib2.IterableInterval;
3837
import net.imglib2.img.Img;
3938
import net.imglib2.img.array.ArrayImgFactory;
4039
import net.imglib2.img.planar.PlanarImgFactory;
@@ -43,7 +42,6 @@
4342

4443
import org.junit.Before;
4544
import org.junit.Test;
46-
import org.scijava.ops.core.builder.OpBuilder;
4745
import org.scijava.ops.types.Nil;
4846
import org.scijava.util.MersenneTwisterFast;
4947

@@ -71,16 +69,16 @@ public void createData() {
7169

7270
@Test
7371
public void copyRAINoOutputTest() {
74-
RandomAccessibleInterval<DoubleType> output = op("copy.iterableInterval").input(input)
75-
.outType(new Nil<RandomAccessibleInterval<DoubleType>>() {}).apply();
72+
IterableInterval<DoubleType> output = op("copy.iterableInterval").input(input)
73+
.outType(new Nil<IterableInterval<DoubleType>>() {}).apply();
7674

7775
Cursor<DoubleType> inc = input.localizingCursor();
78-
RandomAccess<DoubleType> outRA = output.randomAccess();
76+
Cursor<DoubleType> out = output.cursor();
7977

8078
while (inc.hasNext()) {
8179
inc.fwd();
82-
outRA.setPosition(inc);
83-
assertEquals(inc.get().get(), outRA.get().get(), 0.0);
80+
out.fwd();
81+
assertEquals(inc.get().get(), out.get().get(), 0.0);
8482
}
8583
}
8684

src/test/java/net/imagej/ops/copy/CopyImgLabelingTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
import org.junit.Before;
4242
import org.junit.Test;
43-
import org.scijava.ops.core.builder.OpBuilder;
43+
import org.scijava.ops.types.Nil;
4444

4545
/**
4646
* Test {@link CopyImgLabeling}
@@ -52,13 +52,12 @@ public class CopyImgLabelingTest extends AbstractOpTest {
5252
private ImgLabeling<String, IntType> input;
5353
private ImgLabeling<String, IntType> copy;
5454

55-
@SuppressWarnings("unchecked")
5655
@Before
5756
public void createData() {
58-
input = (ImgLabeling<String, IntType>) ops.run(
59-
"create.imgLabeling", new FinalDimensions( 10, 10 ), new IntType());
60-
copy = (ImgLabeling<String, IntType>) ops.run(
61-
"create.imgLabeling", new FinalDimensions( 10, 10 ), new IntType());
57+
input = op("create.imgLabeling").input(new FinalDimensions(10, 10), new IntType())
58+
.outType(new Nil<ImgLabeling<String, IntType>>() {}).apply();
59+
copy = op("create.imgLabeling").input(new FinalDimensions(10, 10), new IntType())
60+
.outType(new Nil<ImgLabeling<String, IntType>>() {}).apply();
6261

6362
final Cursor<LabelingType<String>> inc = input.cursor();
6463

src/test/java/net/imagej/ops/copy/CopyLabelingMappingTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
import org.junit.Before;
4444
import org.junit.Test;
45-
import org.scijava.ops.core.builder.OpBuilder;
4645
import org.scijava.ops.types.Nil;
4746

4847
/**
@@ -92,9 +91,9 @@ public void copyLabelingWithoutOutputTest() {
9291
@Test
9392
public void copyLabelingWithOutputTest() {
9493

95-
LabelingMapping<String> out = (LabelingMapping<String>) ops.run("create.labelingMapping");
94+
LabelingMapping<String> out = op("create.labelingMapping").input().outType(new Nil<LabelingMapping<String>>() {}).create();
9695

97-
op("copy.labelingMapping").input(input, out).apply();
96+
op("copy.labelingMapping").input(input).output(out).compute();
9897

9998
Iterator<String> outIt = out.getLabels().iterator();
10099

src/test/java/net/imagej/ops/copy/CopyRAITest.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@
3232
import static org.junit.Assert.assertEquals;
3333
import static org.junit.Assert.assertNotNull;
3434

35-
import java.util.function.BiFunction;
36-
3735
import net.imagej.ops.AbstractOpTest;
3836
import net.imglib2.Cursor;
39-
import net.imglib2.Dimensions;
4037
import net.imglib2.FinalDimensions;
4138
import net.imglib2.FinalInterval;
4239
import net.imglib2.RandomAccess;
@@ -51,9 +48,7 @@
5148

5249
import org.junit.Before;
5350
import org.junit.Test;
54-
import org.scijava.ops.core.builder.OpBuilder;
5551
import org.scijava.ops.function.Computers;
56-
import org.scijava.ops.function.Functions;
5752
import org.scijava.ops.types.Nil;
5853
import org.scijava.util.MersenneTwisterFast;
5954

@@ -92,10 +87,8 @@ public void createData() {
9287
final long[] start = new long[] { 16, 16, 16 };
9388
final long[] end = new long[] { 47, 47, 47 };
9489

95-
// create an input with a cube at the center TODO can we use ops.run() here?
96-
BiFunction<Dimensions, UnsignedByteType, Img<UnsignedByteType>> imgOp = Functions.match(ops, "create.img",
97-
new Nil<Dimensions>() {}, new Nil<UnsignedByteType>() {}, new Nil<Img<UnsignedByteType>>() {});
98-
input2 = imgOp.apply(new FinalDimensions(size1), new UnsignedByteType());
90+
input2 = op("create.img").input(new FinalDimensions(size1), new UnsignedByteType())
91+
.outType(new Nil<Img<UnsignedByteType>>() {}).apply();
9992

10093
// create the same input but force it to be a planar image
10194
inputPlanar = op("create.img")
@@ -140,7 +133,7 @@ public void copyRAINoOutputTest() {
140133
public void copyRAIWithOutputTest() {
141134
final Img<UnsignedByteType> output = input.factory().create(input, input.firstElement());
142135

143-
op("copy.rai").input(input, output).apply();
136+
op("copy.rai").input(input).output(output).compute();
144137

145138
final Cursor<UnsignedByteType> inc = input.cursor();
146139
final Cursor<UnsignedByteType> outc = output.cursor();
@@ -151,7 +144,6 @@ public void copyRAIWithOutputTest() {
151144
}
152145

153146
@Test
154-
@SuppressWarnings({ "unchecked", "rawtypes" })
155147
public void copyRAIDifferentSizeTest() {
156148

157149
// create a copy op
@@ -161,8 +153,7 @@ public void copyRAIDifferentSizeTest() {
161153

162154
assertNotNull(copy);
163155

164-
final Img<UnsignedByteType> out = op("create.img")
165-
.input(new FinalDimensions(size2), new UnsignedByteType()) //
156+
final Img<UnsignedByteType> out = op("create.img").input(new FinalDimensions(size2), new UnsignedByteType()) //
166157
.outType(new Nil<Img<UnsignedByteType>>() {}) //
167158
.apply();
168159

@@ -173,8 +164,9 @@ public void copyRAIDifferentSizeTest() {
173164
assertEquals(sum.getRealDouble(), 100.0, delta);
174165

175166
// also try with a planar image
176-
final Img<UnsignedByteType> outFromPlanar = (Img<UnsignedByteType>) ops.run("create.img",
177-
new FinalDimensions(size2), new UnsignedByteType());
167+
final Img<UnsignedByteType> outFromPlanar = op("create.img")
168+
.input(new FinalDimensions(size2), new UnsignedByteType()).outType(new Nil<Img<UnsignedByteType>>() {})
169+
.apply();
178170

179171
copy.compute(viewPlanar, outFromPlanar);
180172
DoubleType sumFromPlanar = new DoubleType();

src/test/java/net/imagej/ops/copy/CopyTypeTest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@
2929
package net.imagej.ops.copy;
3030

3131
import static org.junit.Assert.assertEquals;
32-
import static org.junit.Assert.assertTrue;
3332

3433
import net.imagej.ops.AbstractOpTest;
3534
import net.imglib2.type.numeric.real.DoubleType;
3635

3736
import org.junit.Before;
3837
import org.junit.Test;
39-
import org.scijava.ops.core.builder.OpBuilder;
4038

4139
/**
4240
* Test {@link CopyType}.
@@ -55,14 +53,9 @@ public void createData() {
5553

5654
@Test
5755
public void copyTypeNoOutputTest() {
58-
Object out = op("copy.type").input(dt).apply();
59-
60-
if (out instanceof DoubleType) {
61-
assertEquals(dt.get(), ((DoubleType) out).get(), 0.0);
62-
} else {
63-
assertTrue("Copy is not instance of DoubleType.", false);
64-
}
56+
DoubleType out = op("copy.type").input(dt).outType(DoubleType.class).apply();
6557

58+
assertEquals(dt.get(), out.get(), 0.0);
6659
}
6760

6861
@Test

0 commit comments

Comments
 (0)