-
Notifications
You must be signed in to change notification settings - Fork 42
Description
Here's a test (below) that fails. I placed it in OpSearcherTest.java
.
This test creates an Op TooMuchReductionOp
, a UnaryComputerOp
that takes an image and a RealType
, and places its output in the RealType
.
The test itself gets the OpSearchResult
wrapping the Op, and tries to ensure that its arguments are the same type as the Op. It fails on the line Assert.assertEquals(testRealType.getClass(), itr.next().getType());
The funny thing is that if you removed the type assertions, the test will pass, because OpListings
are super lenient in the types they accept. But this means that GUIs like Fiji and napari-imagej will fail when trying to run Ops like this, because they are providing incorrect inputs due to the type hints.
The crux of this issue is the OpSearcher
s eagerness to reduce RealType
parameters to Number
s. Thus Ops like image.invert
, imagemoments.__
, etc. are affected. The question is, what to do about it...
@Plugin(type = Op.class, name = "realType.test.search")
public static class TooMuchReductionOp extends
AbstractUnaryComputerOp<Img<DoubleType>, DoubleType>
{
@Override
public void compute(final Img<DoubleType> adsflkjsfdjlk,
final DoubleType d)
{
d.set(5.0);
}
}
@Test
public void testRealTypeSearching() throws ModuleException {
final List<SearchResult> results = searcher.search("realType.test.search", false);
Assert.assertEquals(1, results.size());
Img<DoubleType> testImg = ArrayImgs.doubles(10, 10);
DoubleType testRealType = new DoubleType(10.);
final ModuleInfo info = ((OpSearchResult) results.get(0)).info();
Iterator<ModuleItem<?>> itr = info.inputs().iterator();
Assert.assertEquals(testRealType.getClass(), itr.next().getType());
Assert.assertEquals(testImg.getClass(), itr.next().getType());
final Module module = info.createModule();
// run the Op with unsigned bytes
module.setInput("in", testImg);
module.resolveInput("in");
module.setInput("out", testRealType);
module.resolveInput("out");
module.run();
Assert.assertEquals(testRealType.get(), 5.0, 1e-6);
}