Skip to content
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

Conversions between GAP and Julia: What do we really want? #740

Open
ThomasBreuer opened this issue Oct 19, 2021 · 0 comments
Open

Conversions between GAP and Julia: What do we really want? #740

ThomasBreuer opened this issue Oct 19, 2021 · 0 comments
Labels
topic: conversion Issue related to conversion

Comments

@ThomasBreuer
Copy link
Member

After some experiments that were inspired by issue #736, I think that the relation between Julia's constructors and gap_to_julia is more complicated than what we have at the moment.
Consider the following object L.

julia> using Oscar;  using GAP;  x = fmpz(10)^20;  L = GAP.evalstr("List([1..10], i -> Julia.Main.x + i)");

This is a GAP list containing Julia objects. Now we want to convert this to a Julia array of GAP objects. The following works.

julia> [GapObj(x) for x in L]
10-element Vector{GapObj}:
 GAP: 100000000000000000001
 GAP: 100000000000000000002
[...]

The corresponding constructor does not work.

julia> Vector{GapObj}(L)
ERROR: Don't know how to convert value of type fmpz to type GapObj
Stacktrace:
 [1] gap_to_julia(t::Type{GapObj}, x::fmpz)
[...]

The error message looks irritating: Oscar installs a method for converting fmpz to GapObj, see above.

The reason for the problem is that the constructor delegates to gap_to_julia with first argument Vector{GapObj} and with the wish to convert recursively; the method in question creates a Vector{GapObj} and wants to fill it with the results of gap_to_julia(GapObj, x) calls --but of course julia_to_gap would be the correct direction.
(And note that calling julia_to_gap(L) would not do what we want.)

My interpretation is that currently gap_to_julia promises a conversion in the direction from GAP to Julia, perhaps recursive (and then in this direction also for the subobjects), and if a Julia type is given as the first argument then this serves as a hint which conversion is intended but not as information about the direction of the conversion.
On the other hand, the constructor Vector{GapObj} promises a conversion to a Vector of GapObjs, which is impossible by delegation to the current gap_to_julia.

So what do we want:
change the recursions in gap_to_julia methods such that examples like the above one work,
separate the implementation of gap_to_julia from constructors where necessary, or
"reverse" the implementation such that gap_to_julia calls constructors, and not the other way round?

ThomasBreuer added a commit to ThomasBreuer/GAP.jl that referenced this issue Nov 30, 2022
This addresses issue oscar-system#740, but I am sill not sure what would be a good solution.
@fingolfin fingolfin added the topic: conversion Issue related to conversion label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: conversion Issue related to conversion
Projects
None yet
Development

No branches or pull requests

2 participants