-
Notifications
You must be signed in to change notification settings - Fork 67
Proof-of-concept: _implements trait #1957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1957 +/- ##
==========================================
- Coverage 88.37% 88.30% -0.08%
==========================================
Files 126 126
Lines 31639 31667 +28
==========================================
Hits 27962 27962
- Misses 3677 3705 +28 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/fundamental_interface.jl
Outdated
# TODO: deal with type parameters: if `T` is `FreeAssociativeAlgebraElem{ZZRingElem}` | ||
# and `f` has a method for `FreeAssociativeAlgebraElem` then we should still consider | ||
# this a match. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the case that there is some method for PolyRing
and we have a QQPolyRing
. Is this a match?
What about T = QQPolyRing
and f(::PolyRing{QQFieldElem})
?
I am not sure if there is a deterministic and consistent semantic of match that you want here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, a method for PolyRing
should not "match" QQPolyRing
within _implements_directly
. The idea is that this function is meant for methods that match a "concrete" type: you are not going to define e.g. a factor(::QQPolyRing)
just to also throw a NotImplementedError
.
I do think this is well-defined: The type T
is a concrete type here. What I can do (well, at least in theory) is to "remove parameters" from it, to e.g. turn Vector{Int}
into Vector
, and then compare to the methods in meth
(possibly after removing parameters there, too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess using typename(T).wrapper
might be one option...
I would be in favor of moving this to |
e9c28d5
to
1d4ae96
Compare
Should I move this to |
... to allow fine control over which things to test in the conformance tests and which not.
Proof of concept of a "trait" that allows checking for some unary functions whether they are implemented for a given type. See also oscar-system/Oscar.jl#4394 for background.
So e.g. one can write
_implements(ZZRingElem, factor)
to determine whetherfactor
is implemented.This is different from
applicable
andhasmethod
in that it allows dealing with "generic" methods that delegate to other functionality. For example, we have an implementation ofis_nilpotent
for arbitrary polynomials, but it delegates tois_nilpotent
for the coefficient ring. So we can only consider it as "implemented" if it is implemented for the coefficient ring.Right now the way this is implemented it requires manual work to "model" these relations explicitly, and so in general it won't be reliable for "arbitrary" unary functions. Thus I named it
_implements
to mark it as "internal sharp tool, use with caution".My personal main use for this is in the conformance test suite. But I think it might also be useful for some algorithms which may be able to do something "better" if e.g.
factor
is available. Though of course such algorithms could often work by wrapping thefactor
call(s) intotry/catch
blocks. But this approach is not useful for the conformance tests: trying to put them inside a@test
leads to ugliness like this. It also isn't sufficient to e.g. callfactor(zero(R))
insidetry/catch
to determine iffactor
is available for elements of the ringR
because there are some "generic methods" that work only on some arguments (e.g. zero...) and so this test may give misleading results.If we follow PR #1954 and turn the conformance tests into a package extension, this method could also be moved into the
ConformanceTest
module if nobody is interested in this functionality beyond the conformance tests.