engine.wrap Ops by gselzer · Pull Request #283 · scijava/scijava
This PR, based on a branch that was designed simply to streamline the conversion of RandomAccessibleIntervals via wrapping, has been taken over to add a new feature to Op conversion. Namely:
Can we convert Computers without that annoying copy at the end??
Background
Suppose you want to convert a Computer<I, O> into a Computer<A, B>. Currently, you need (at a minimum):
- An
engine.convertOp that transforms yourAobject into anIobject. - An
engine.convertOp that transforms yourBobject into anOobject. - An
engine.copyOp that puts the data from anOobject into yourBobject or anengine.convertOp that transforms yourOobject into aBobject and anengine.copyOp to put the data from the intermediaryBobject into the one you gave it.
In many cases, however, those engine.convert Ops will be most performant when wrapping the object. If that wrapper is read/write (as is the case for ndarray -> RAI wrapping via imglyb, for example), when the Computer<I, O> backing your Computer<A, B> Op is called, the changes will be written through into the original B object, and the later engine.convert/engine.copy is unnecessary work.
A new Op name: engine.wrap
engine.wrap Ops are object conversions via a read/write wrapper. While not enforced, all engine.wrap Ops should be aliased engine.convert (and likely also convert.X).
When performing conversion, the Op conversion MatchingRoutine will watch for the usage of engine.wrap Ops. If used for a preallocated output, the matching routine will avoid matching the output engine.convert/engine.copy Ops.
- In practice, this is a very simple change, as it is equivalent to the existing behavior that watches out for the
engine.identityOp
TODO:
- The proof of correctness here will be with inter-
ComplexTypeimage conversion, and as of right now the tests fail 😦. These tests must be fixed. - Clean up PR (commits + code)
- Additional tests?
- Bump SciJava Ops Engine minor version, signifying new behavior.