Skip to content

Commit de3e01d

Browse files
committed
WIP: Refactor ops.run calls to OpBuilder calls
1 parent a068418 commit de3e01d

37 files changed

Lines changed: 483 additions & 419 deletions

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import net.imglib2.util.Pair;
5050

5151
import org.junit.Test;
52+
import org.scijava.ops.core.builder.OpBuilder;
5253
import org.scijava.ops.function.Functions;
5354
import org.scijava.ops.types.Nil;
5455
import org.scijava.thread.ThreadService;
@@ -104,7 +105,7 @@ public void exhaustiveKendallTauBRankTesting() {
104105
//final PairIterator<DoubleType> iter = pairIterator(values1, values2);
105106
final Iterable<Pair<IntType, IntType>> iter = new IterablePair<>(ArrayImgs.ints(values1, n), ArrayImgs.ints(values2, n));
106107
double kendallValue1 = calculateNaive(iter.iterator());
107-
double kendallValue2 = (Double) new OpBuilder(ops, "coloc.kendallTau").input(values1, values2).apply();
108+
double kendallValue2 = new OpBuilder(ops, "coloc.kendallTau").input(values1, values2).outType(Double.class).apply();
108109
if (Double.isNaN(kendallValue1)) {
109110
assertTrue("i: " + i + ", value2: " + kendallValue2, Double.isInfinite(kendallValue2) || Double.isNaN(kendallValue2));
110111
} else {
@@ -127,7 +128,7 @@ public void testPValue() {
127128
BiFunction<Iterable<FloatType>, Iterable<FloatType>, Double> op = Functions.match(ops,
128129
"coloc.kendallTau", nilI, nilI, new Nil<Double>() {});
129130
PValueResult value = new PValueResult();
130-
new OpBuilder(ops, "coloc.pValue").input(ch1, ch2, op, es, value).apply();
131+
new OpBuilder(ops, "coloc.pValue").input(ch1, ch2, op, es).output(value).compute();
131132
assertEquals(0.75, value.getPValue(), 0.0);
132133
}
133134

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import net.imglib2.view.Views;
4848

4949
import org.junit.Test;
50+
import org.scijava.ops.core.builder.OpBuilder;
5051
import org.scijava.ops.function.Functions;
5152
import org.scijava.ops.types.Nil;
5253
import org.scijava.thread.ThreadService;
@@ -147,7 +148,7 @@ public void testMTKTnone() {
147148
}
148149
Img<DoubleType> vImage1 = ArrayImgs.doubles(values1, values1.length);
149150
Img<DoubleType> vImage2 = ArrayImgs.doubles(values2, values2.length);
150-
double result = (Double) new OpBuilder(ops, "coloc.maxTKendallTau").input(vImage1, vImage2).apply();
151+
double result = new OpBuilder(ops, "coloc.maxTKendallTau").input(vImage1, vImage2).outType(Double.class).apply();
151152
assertEquals(4.9E-324, result, 0.0);
152153
}
153154

src/test/java/net/imagej/ops/coloc/pValue/DefaultPValueTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import net.imglib2.type.numeric.real.FloatType;
4242

4343
import org.junit.Test;
44+
import org.scijava.ops.core.builder.OpBuilder;
4445
import org.scijava.thread.ThreadService;
4546

4647
/**
@@ -99,7 +100,7 @@ private void assertColoc(double expectedPValue, double expectedColocValue, doubl
99100
// new Nil<BiFunction<Iterable<FloatType>, Iterable<FloatType>, Double>>() {}.getType());
100101

101102
PValueResult output = new PValueResult();
102-
new OpBuilder(ops, "coloc.pValue").input(ch1, ch2, op, result.length - 1, es, output).apply();
103+
new OpBuilder(ops, "coloc.pValue").input(ch1, ch2, op, result.length - 1, es).output(output).compute();
103104
Double actualPValue = output.getPValue();
104105
Double actualColocValue = output.getColocValue();
105106
double[] actualColocValuesArray = output.getColocValuesArray();

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

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

4242
import org.junit.Test;
43+
import org.scijava.ops.core.builder.OpBuilder;
4344
import org.scijava.ops.function.Functions;
4445
import org.scijava.ops.types.Nil;
4546
import org.scijava.thread.ThreadService;
@@ -57,7 +58,7 @@ public class DefaultPearsonsTest extends ColocalisationTest {
5758
*/
5859
@Test
5960
public void fastPearsonsZeroCorrTest(){
60-
double result = (Double) new OpBuilder(ops, "coloc.pearsons").input(zeroCorrelationImageCh1, zeroCorrelationImageCh2).apply();
61+
double result = new OpBuilder(ops, "coloc.pearsons").input(zeroCorrelationImageCh1, zeroCorrelationImageCh2).outType(Double.class).apply();
6162
assertEquals(0.0, result, 0.05);
6263
}
6364

@@ -67,7 +68,7 @@ public void fastPearsonsZeroCorrTest(){
6768
*/
6869
@Test
6970
public void fastPearsonsPositiveCorrTest() {
70-
double result = (Double) new OpBuilder(ops, "coloc.pearsons").input(positiveCorrelationImageCh1, positiveCorrelationImageCh2).apply();
71+
double result = new OpBuilder(ops, "coloc.pearsons").input(positiveCorrelationImageCh1, positiveCorrelationImageCh2).outType(Double.class).apply();
7172
assertEquals(0.75, result, 0.01);
7273
}
7374

@@ -86,7 +87,7 @@ public void differentMeansTest() {
8687
512, 512, mean, spread, sigma, 0x01234567);
8788
RandomAccessibleInterval<FloatType> ch2 = produceMeanBasedNoiseImage(new FloatType(),
8889
512, 512, mean, spread, sigma, 0x98765432);
89-
double resultFast = (Double) new OpBuilder(ops, "coloc.pearsons").input(ch1, ch2).apply();
90+
double resultFast = new OpBuilder(ops, "coloc.pearsons").input(ch1, ch2).outType(Double.class).apply();
9091
assertEquals(0.0, resultFast, 0.1);
9192

9293
/* If the means are the same, it causes a numerical problem in the classic implementation of Pearson's

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import org.junit.Before;
4545
import org.junit.Test;
46+
import org.scijava.ops.core.builder.OpBuilder;
4647

4748
/**
4849
* Tests {@link ConvertIIs} + {@link RealTypeConverter} ops.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import net.imglib2.util.Intervals;
4343

4444
import org.junit.Test;
45+
import org.scijava.ops.core.builder.OpBuilder;
4546

4647
/**
4748
* Tests that the {@code convert} ops work on {@link Img} objects via
@@ -72,7 +73,7 @@ public void testLossless() {
7273
outC1.next().getRealDouble(), 0d);
7374
}
7475

75-
new OpBuilder(ops, "convert.float32").input(in, out).apply();
76+
new OpBuilder(ops, "convert.float32").input(in).output(out).compute();
7677

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

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

98-
new OpBuilder(ops, "convert.uint8").input(in, out).apply();
99+
new OpBuilder(ops, "convert.uint8").input(in).output(out).compute();
99100
// ops.run(Ops.Map.class, out, in, new ComplexToUint8<FloatType>());
100101

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

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

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

4242
import org.junit.Before;
4343
import org.junit.Test;
44+
import org.scijava.ops.core.builder.OpBuilder;
4445
import org.scijava.util.MersenneTwisterFast;
4546

4647
/**
@@ -68,8 +69,8 @@ public void createData() {
6869
@Test
6970
public void copyArrayImgNoOutputTest() {
7071
@SuppressWarnings("unchecked")
71-
final RandomAccessibleInterval<UnsignedByteType> output = (RandomAccessibleInterval<UnsignedByteType>) ops
72-
.run("copy.img", input);
72+
final RandomAccessibleInterval<UnsignedByteType> output = (RandomAccessibleInterval<UnsignedByteType>) new OpBuilder(
73+
ops, "copy.img").input(input).apply();
7374

7475
final Cursor<UnsignedByteType> inc = input.localizingCursor();
7576
final RandomAccess<UnsignedByteType> outRA = output.randomAccess();
@@ -83,10 +84,9 @@ public void copyArrayImgNoOutputTest() {
8384

8485
@Test
8586
public void copyArrayImgWithOutputTest() {
86-
final Img<UnsignedByteType> output = input.factory().create(input,
87-
input.firstElement());
87+
final Img<UnsignedByteType> output = input.factory().create(input, input.firstElement());
8888

89-
new OpBuilder(ops, "copy.img").input(input, output).apply();
89+
new OpBuilder(ops, "copy.img").input(input).output(output).compute();
9090

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

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

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

4444
import org.junit.Before;
4545
import org.junit.Test;
46+
import org.scijava.ops.core.builder.OpBuilder;
47+
import org.scijava.ops.types.Nil;
4648
import org.scijava.util.MersenneTwisterFast;
4749

4850
/**
@@ -69,9 +71,8 @@ public void createData() {
6971

7072
@Test
7173
public void copyRAINoOutputTest() {
72-
@SuppressWarnings("unchecked")
73-
RandomAccessibleInterval<DoubleType> output = (RandomAccessibleInterval<DoubleType>) ops
74-
.run("copy.iterableInterval", input);
74+
RandomAccessibleInterval<DoubleType> output = new OpBuilder(ops, "copy.iterableInterval").input(input)
75+
.outType(new Nil<RandomAccessibleInterval<DoubleType>>() {}).apply();
7576

7677
Cursor<DoubleType> inc = input.localizingCursor();
7778
RandomAccess<DoubleType> outRA = output.randomAccess();
@@ -87,8 +88,8 @@ public void copyRAINoOutputTest() {
8788
public void copyTypeTest() {
8889
Img<FloatType> inputFloat = new ArrayImgFactory<>(new FloatType()).create(new int[] { 120, 100 });
8990

90-
@SuppressWarnings("unchecked")
91-
Img<FloatType> output = (Img<FloatType>) new OpBuilder(ops, "copy.iterableInterval").input(inputFloat).apply();
91+
Img<FloatType> output = new OpBuilder(ops, "copy.iterableInterval").input(inputFloat)
92+
.outType(new Nil<Img<FloatType>>() {}).apply();
9293

9394
assertTrue("Should be FloatType.", output.firstElement() instanceof FloatType);
9495
}
@@ -97,7 +98,7 @@ public void copyTypeTest() {
9798
public void copyRAIWithOutputTest() {
9899
Img<DoubleType> output = input.factory().create(input, input.firstElement());
99100

100-
new OpBuilder(ops, "copy.iterableInterval").input(output, input).apply();
101+
new OpBuilder(ops, "copy.iterableInterval").input(input).output(output).compute();
101102

102103
final Cursor<DoubleType> inc = input.cursor();
103104
final Cursor<DoubleType> outc = output.cursor();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import org.junit.Before;
4242
import org.junit.Test;
43+
import org.scijava.ops.core.builder.OpBuilder;
4344

4445
/**
4546
* Test {@link CopyImgLabeling}
@@ -74,7 +75,7 @@ public void createData() {
7475

7576
@Test
7677
public void copyImgLabeling() {
77-
new OpBuilder(ops, "copy.imgLabeling").input(input, copy).apply();
78+
new OpBuilder(ops, "copy.imgLabeling").input(input).output(copy).compute();
7879
assertNotNull(copy);
7980

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

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
import org.junit.Before;
4343
import org.junit.Test;
44+
import org.scijava.ops.core.builder.OpBuilder;
45+
import org.scijava.ops.types.Nil;
4446
import org.scijava.util.MersenneTwisterFast;
4547

4648
/**
@@ -71,9 +73,8 @@ public void copyImgNoOutputTest() {
7173
.firstElement());
7274
copy(input, inputCopy);
7375

74-
@SuppressWarnings("unchecked")
7576
final RandomAccessibleInterval<DoubleType> output =
76-
(RandomAccessibleInterval<DoubleType>) new OpBuilder(ops, "copy.img").input(input).apply();
77+
new OpBuilder(ops, "copy.img").input(input).outType(new Nil<RandomAccessibleInterval<DoubleType>>() {}).apply();
7778

7879
final Cursor<DoubleType> inc = input.localizingCursor();
7980
final RandomAccess<DoubleType> inCopyRA = inputCopy.randomAccess();
@@ -97,7 +98,7 @@ public void copyImgWithOutputTest() {
9798
final Img<DoubleType> output = input.factory().create(input, input
9899
.firstElement());
99100

100-
new OpBuilder(ops, "copy.img").input(input, output).apply();
101+
new OpBuilder(ops, "copy.img").input(input).output(output).compute();
101102

102103
final Cursor<DoubleType> inc = input.cursor();
103104
final Cursor<DoubleType> inCopyc = inputCopy.cursor();

0 commit comments

Comments
 (0)