-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Milestone
Description
Currently scijava-ops has support for the following adaptations:
Computers toFunctionsFunctions toComputersInplaces toFunctions
@ctrueden and I have discussed (several times) why the other three conversions have not been implemented. I think it a good idea to put the discussion here for posterity (and because I found myself again asking why we do not have these):
ComputertoInplace: Suppose we have adouble[]and want to mutate this array withmath.sqrt. Such a converter might look like
@Plugin(type = Op.class, name = "adapt")
public class CompToInplaceAdaptor implements Function<Computers.Arity1<IO, IO>, Inplaces.Arity1<IO>> {
@OpDependency(name = "copy")
private Function<IO, IO> copyOp;
public Inplaces.Arity1<IO> apply (final Computers.Arity1<IO, IO> computer) {
return (io) -> {
IO copy = copyOp.apply(io);
computer.compute(copy, io);
};
}
};InplacetoFunction: I cannot really think of a use case for this, but the general idea is that the user expects an output to be generated for them, and that their input will not be modified:
@Plugin(type = Op.class, name = "adapt")
public class InplaceToFunctionAdaptor implements Function<Inplaces.Arity1<IO>, Function<IO, IO>> {
@OpDependency(name = "copy")
private Function<IO, IO> copyOp;
public Function<IO, IO> apply (final Inplaces.Arity1<IO> inplace) {
return (in ) -> {
IO copy = copyOp.apply(io);
inplace.mutate(copy);
return copy;
};
}
};InplacetoComputer: I cannot really think of a use case for this, but the general idea is that the user expects the output of the Op to be placed in their preallocated output, and that their input will not be modified:
@Plugin(type = Op.class, name = "adapt")
public class InplaceToComputerAdaptor implements Function<Inplaces.Arity1<IO>, Computers.Arity1<IO, IO>> {
@OpDependency(name = "copy")
private Computers.Arity1<IO, IO> copyOp;
public Computers.Arity1<IO, IO> apply (final Inplaces.Arity1<IO> inplace) {
return (in, out) -> {
copyOp.compute(in, out);
inplace.mutate(out);
};
}
};Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
No status