imagej / imagej/imagej-ops

OpSearcher reduces OpListings too eagerly

Open
#649 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
94
Forks
44
PR merge metrics
No merged PRs in 30d

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...

```java
@Plugin(type = Op.class, name = "realType.test.search")
public static class TooMuchReductionOp extends
AbstractUnaryComputerOp, DoubleType>
{

@Override
public void compute(final Img adsflkjsfdjlk,
final DoubleType d)
{
d.set(5.0);
}
}

@Test
public void testRealTypeSearching() throws ModuleException {
final List results = searcher.search("realType.test.search", false);
Assert.assertEquals(1, results.size());

Img testImg = ArrayImgs.doubles(10, 10);
DoubleType testRealType = new DoubleType(10.);
final ModuleInfo info = ((OpSearchResult) results.get(0)).info();
Iterator> 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);
}

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with OpSearcherTest.java and the failing test for realType.test.search. Trace OpSearcher and its OpListings reduction of RealType parameters, then verify the search result preserves the concrete input types. Done means the type assertions pass and the test completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.