OpMethod support#23
Conversation
Signed by: Gabriel Selzer
Signed off by: Gabriel Selzer
Signed off by: Gabriel Selzer
Signed off by: Gabriel Selzer
TODO: Consider moving
It's alive!!! Muahahaha
This allows us to be flexible on where we place our OpDependencies in our OpMethods
|
@hinerm no, it is not urgent. I only pinged you to:
|
|
@gselzer for me, this seems unfortunately long: If there was a way to do something like I think I might find that more pleasant, although I assume there's not a nice way to inject the parameters then. Side note: what are the advantages of Another side note: am I correct that in |
|
Thanks for the feedback @hinerm. I will try to address each of your points:
I agree that it is long, but it is also specific. We obviously cannot get shorter than Furthermore, we need to be able to determine whether a given parameter is an Op. We cannot assume to know that if a parameter is of type X, Y, or Z then it must be an If you agree with what I said above (and I would be thrilled if you found a way around this), we must also include the
The main benefit is that it provides independence from scijava-ops. If we wrote something along the lines of what you wrote above, we would then require anyone wanting to use our
You are correct in that the op name is not used until |
This PR introduces support for writing ops as methods. Ops written as methods are discovered using the
@OpMethodannotation, which declares both thenameof the Op as well as thetypeof the Op (this allows for extensibility). Method ops allow the declaration ofOpDependencies, which are included within the parameters accepted by the method.Method ops might look as follows:
This Op calculates the mean (hence the name
stats.mean), and is aFunction<Iterable<Number>, Double>(as declared bytypeand the set of parameters in the method). This Op also has twoOpDependencies: oneFunction<Iterable<Number>, Double> sumOpand oneFunction<Iterable<Number>, Double> sizeOp. There are (should be 😁) no restrictions on the position of theOpDependencieswithin the method signature.The op would be called as follows:
Both
OpDependencieswill automagically be injected by theOpServiceusing Javassist. It is important to note that this PR does introduce a dependency on Javassist, which does not yet have a module. When a method op has noOpDependencies, it will be constructed instead usingLambdaMetaFactory; this method is faster than using Javassist since we do not have to incur the compilation process during runtime.This PR also introduces a suite of tests, ensuring that method Ops can be written for all of our supported Op types (
Computer,Inplace,Function) both with and withoutOpDependencies.TODO:
Closes scijava/scijava#23.
Thanks to @MarcelWiedenmann for starting this work.