-
Notifications
You must be signed in to change notification settings - Fork 21
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
Work on conversion #160
Work on conversion #160
Conversation
Codecov Report
@@ Coverage Diff @@
## master #160 +/- ##
==========================================
- Coverage 65.59% 54.39% -11.2%
==========================================
Files 39 37 -2
Lines 2334 1682 -652
==========================================
- Hits 1531 915 -616
+ Misses 803 767 -36
|
e2605b8
to
a1eb8fc
Compare
Due to unwrapping of wrapped Julia objects, the Array we create in this method may contain arbitrary Julia objects, and thus needs to be of type Array{Any,1} instead of Array{GAPObj,1}
removed remaining code from JuliaInterface
@fingolfin @ThomasBreuer @frankluebeck I think this is finished for now. Sorry for the mess. Please have a look and review it. @ThomasBreuer JuliaExperimental is not completely adjusted yet. |
Also remove the old documentation comments, and the comment suggesting to reuse them: the new functions are sufficiently different that one is better off rewriting this from scratch.
LibGAP.jl/src/julia_to_gap.jl
Outdated
## Converters | ||
|
||
## Default | ||
julia_to_gap(x::GAPInputType, ::Val{Recursive}=Val(false), recursion_dict = nothing) where Recursive = x |
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.
Please add a longer comment to this file which explains what is going on. Like: What is this Val{Recursive}
bit doing; but also the general idea of what kind of methods, with what signature, one has to achieve what.
I actually need that explanation, as I don't understand right now why this complicated setup is better than this simpler one: For all "basic" types (= not containing subobjects that need to be converted), have methods like this:
julia_to_gap(x::Int32, recursion_dict) = Int64(x)
Then, have one generic redispatch function which handles all these primitive ones at once; and for all data types with subobjects, have both 1 and 2 arg methods:
julia_to_gap(x::Any) = julia_to_gap(x, nothing)
function julia_to_gap(obj::Array{T,1}, recursion_dict = IdDict()) where T
...
end
Perhaps the code the above produces is suboptimal? Well, I wouldn't ask this question if there was a comment explaining the design of the current approach :-)
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 am not sure about the code being less optimal that way. I will try to implement the changes you propose.
LibGAP.jl/src/gap_to_julia.jl
Outdated
return numerator // T(1) | ||
end | ||
|
||
function gap_to_julia(::Type{Rational{T}}, x::MPtr, recusive_dict = nothing) where T <: Integer |
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.
According to Codecov, there are no tests for this function at all, it is never called :-( Same for the other rationals conversion above, and the float conversion below, and more -- see also https://codecov.io/gh/oscar-system/GAPJulia/pull/160/diff
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.
(side remark: is recusive_dict
a typo?)
numer_julia = numerator(x) | ||
if denom_julia == 0 | ||
if numer_julia >= 0 | ||
return GAP.Globals.infinity |
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.
Should there perhaps also be a reverse conversion for this? But of course that's difficult, as on the GAP side, infinity
and -infinity
are objects, and "only" in the filter IsCyc
, not in IsRat
. Huh :/
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.
@fingolfin As far as I remember,
the object infinity
had originally been designed just for having a natural object
that is larger than any integer, and that can be compared with integers via =
and <
.
In particular, there were no arithmetic operations for infinity
,
and also -infinity
did not yet exist.
Because of the wish to compare the new object infinity
with integers,
the family CyclotomicsFamily
was a natural choice for it,
and thus infinity
is in the filter IsCyclotomic
--but not in IsCyc
, IsRat
, or IsInt
.
Before the introduction of infinity
, other GAP objects of different types had been used
for this kind of comparison, for example E(3)
,
assuming that GAP regards them as larger than integers.
Using infinity
in such situations is nicer because it is self-explanatory;
besides that, I do not think that infinity
is useful.
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 am not sure how this is relevant for the discussion at hand, though?
BTW, I added -infinity
, and I find it and infinity
quite useful for all kinds of things, e.g. for polynomial degree functions, or arbitrary valuations; as default values for minimum / maximum operations; etc.. But whether one finds them useful or not is kind of irrelevant for this discussion. What we have to deal with is issue #162. We can either throw an error if we encounter the Julia rationals 1//0 and -1//0; or convert them to infinity and -infinity (as this PR does). In the latter case, the question arises whether we want to make the conversion roundtrip or not. While in general, I am in favor for clean roundtrip conversions, but is of course not always possible; but then perhaps there should be a comment here pointing that out.
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 think it is sensible to convert to infinity
here.
Remember, we are talking about a very specific corner-case here, Julia rationals with 0
as denominator. I do not think it is that important anyway.
aa3bb4e
to
70e916b
Compare
In the moment I cannot try the code from this pull request (I get an error when trying to load the package). So, here are some general comments based on this description (which I have edited slightly).
|
@frankluebeck "I get an error when trying to load the package" -> could you perhaps tell us what that error is? |
I was loading "JuliaExperimental" which is maybe not expected to work with this pull request. Loading "JuliaInterface" only does work. So, now I get:
|
|
Yes, |
removed unused recursion arguments from non-recursive functions.
made default caller without recursion_dict, removed recursion dict from non-recursive conversions
|
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.
From my POV, these are great changes into the right direction. Of course there are still things we can improve, but let's merge this first, then iterate -- e.g., fix JuliaExperimental, merging PR #158 (after it gets rebased and improved bit), add some more tests, start writing some docs that explain how JuliaInterface and LibGAP.jl fit together, etc. But best to do that in many short lived feature branches, instead of growing this big bad branch even more.
- adjusted the function calls to the new rules (from pull request oscar-system#160), removed or simplified the relevant code - removed `gap/record.g` since the code is now obsolete; moved the contents of `tst/record.tst` to `JuliaInterface/tst/convert.tst` - changed the auxiliary dictionaries to use symbols as keys, in order to use the default conversions - adjusted some Julia code which worked only in pre-1.0 versions After these changes, the JuliaExperimental tests should work, thus the automatic test runs can be reactivated. (Currently I am rewriting the whole package JuliaExperimental, a pull request for that will be available on Monday.)
For a detailed description on this work, see https://hackmd.io/-xkD8BtORfCcgi-TQsb8Eg?both
Resolves #162
Resolves #146
Resolves #116