This repository was archived by the owner on Oct 26, 2026. It is now read-only.
Repository navigation
Create simplification framework - #25
Merged
Merged
Conversation
gselzer
force-pushed
the
scijava/scijava-ops/simplification
branch
4 times, most recently
from
January 15, 2021 22:17
ab00995 to
8a94ee8
Compare
gselzer
marked this pull request as ready for review
January 19, 2021 15:19
The DefaultOpMatcher already has methods to return a single match from a list of OpRefs, which means that if we change the return of simplifyOp to a list of OpRefs, we can make use of this code.
Now the tests depend on an Op within the test itself, which prevents changes to external Ops from affecting the outcome of the test
This allows us to extensibly discover simplifiers
OpRefs with more types are: * More complicated * Never used in practice
These things (not sure what they will be yet) calculate the magnitude of the (worst-case) loss when converting between two types
These Ops are now called LossReporters
This commit does two things. Firstly, it provides a proof of concept for generic simplifiers. Secondly, it adds the logic necessary to simplify to/from types that are not directly related to each other (as illustrated in the test, where the simplification chain is Byte[] -> ObjectArray<Number> -> Integer[])
The startup time was greatly increased due to the simplification process. We can mitigate a lot of this time by lazily initializing elements of the SimplifiedOpInfos, such as their simplified type and their simplified Struct.
We now create the simplifiedOpInfos for Ops whose name matches the Op request. This lazy approach saves time and opens the possibility for us to refactor Simplifiers into Ops
Optional parameters are no longer allowed
In rare edge cases, functional interfaces don't declare their abstract
method. This might happen for a convenience interface like:
interface AllSameFunction<T> extends BiFunction<T, T, T> {}
such an interface does not have a declared abstract method, so we have
to find it via its superinterface BiFunction. The method we get out of
BiFunction, however, will not know of the mapping of the Ts in
AllSameFunction to the T, U, R of BiFunction; this is a bug in the
method.
This commit adds logic that determines the mappings of the type
variables of interfaces like AllSameFunction to the type variables of
BiFunction, so that Ops implementing AllSameFunction can be retyped.
This data strucutre held the Simplifiers, which we no longer use (since
we converted to an Ops-based simplification framework)
This better aligns with the results of simplification
SimplifiedOpCandidate was taking on too much work. I would rather this work be extracted to a helper class, so that the SimplifiedOpInfo can be called without needing the SimplifiedOpCandidate. Of course, SimplifiedOpCandidate can't go away, since some functionality (like determining loss) is probably better performed there.
When Op wrappers exist for both a class and one of its superclasses, Op wrapping would fail as multiple wrappers would be suitable. The Op wrapping logic was not smart enough to filter these matches in any way. This commit adds a method to filter superclasses out of the list of suitable wrappers. Since these wrappers also preserve the exact supertype of the Op w.r.t. the wrapper class, it is desirable to have subclasses declare their own wrappers, and this fix prevents multiple suitable wrappers from preventing a wrapper match (so long as all classes are related). This commit also fixes a bug in the error message when multiple wrappers would match. The error was designed to print the classes of each wrapper that matched, but would instead vomit out the classes of all known wrappers. This bug has also been fixed.
gselzer
force-pushed
the
scijava/scijava-ops/simplification
branch
from
January 19, 2021 15:34
e084881 to
5d3b11d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a matching extension dubbed "simplification" that allows "on the fly" argument type conversion. This type conversion is extensibly facilitated by three sets of Ops:
simplifyFunctions that produce a general type from a precise type.focusFunctions that produce a precise type from a general type.lossReporterLossReporters that describe the worst-case loss resulting from a conversion between two precise types.For example, to facilitate a conversion from
DoubletoIntegerOps would require:simplifyOp that produces a general type (e.g.Number) from aDoublefocusOp that produces anIntegerfrom the same general type output by thesimplifyOp (i.e.Number)lossReporterOp that describes the worst-case loss of a conversion from aDoubleto anInteger.During the matching process, simplification is performed after direct matching and after adaptation. This ordering was devised with two claims in mind:
The simplification process is currently performed as follows:
SimplifiedOpRefis created, knowing:simplifyOp that can simplify each of its inputsfocusOps that can focus its outputcopyOp that can be used to store the Op's result into a preallocated output (if applicable)SimplifiedOpInfos are created, knowing:focusOp that can focus each of its inputssimplifyOps that can simplify its outputSimplifiedInfo, we attempt to find a pathway from eachOpRefinput to its correspondingOpInfoinput using thesimplifyandfocusFunctions of theSimplifiedOpRefandSimplifiedOpInfo, respectively. If multiple pathways exist for a particular set of inputs, we sort by the number ofidentitysimplify/focusOps and choose the pathway with the mostidentityOps. Ties are broken by hashcode to ensure deterministic behavior. A pathway is also found for the output, however the pathway is found from theOpInfooutput to theOpRefoutput.SimplifiedOpCandidates are recorded for allSimplifiedOpRef/SimplifiedOpInfocombinations with a complete set of valid pathways. Of these valid candidates, the candidate with the smallest loss (as determined by a set ofLossReporters) is chosen.Classthat wraps the Op being simplified. ThisClassis responsible for:TODO:
Computers.Arity1<Integer, Integer[]>as a Function<Double, Double[]>`?) Should such a monstrosity be allowed?WIPcommits. These should probably all be squashed.