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

for backward compatibility, reintroduce julia_to_gap #1056

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/JuliaInterface/gap/convert.gd
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
#! immediate integer to <C>Int64</C>,
#! </Item>
#! <Item>
#! immediate FFE to the <C>GapFFE</C> &Julia; type,
#! immediate FFE to the <C>FFE</C> &Julia; type,
#! </Item>
#! <Item>
#! &GAP; <K>true</K> to &Julia; <C>true</C>,
Expand All @@ -147,7 +147,7 @@
#! otherwise to a &GAP; large integer,
#! </Item>
#! <Item>
#! <C>GapFFE</C> to immediate FFE,
#! <C>FFE</C> to immediate FFE,
#! </Item>
#! <Item>
#! &Julia; <C>true</C> to &GAP; <K>true</K>,
Expand Down Expand Up @@ -190,7 +190,7 @@
#! </Item>
#! <Item>
#! <C>IsFFE and IsInternalRep</C> to
#! <C>GapFFE</C>,
#! <C>FFE</C>,
#! </Item>
#! <Item>
#! <C>IsInt and IsSmallIntRep</C> to
Expand Down Expand Up @@ -308,7 +308,7 @@
#! </Row>
#! <HorLine/>
#! <Row>
#! <Item><C>Int64</C>, <C>GapObj</C>, <C>GapFFE</C>, and <C>Bool</C></Item>
#! <Item><C>Int64</C>, <C>GapObj</C>, <C>FFE</C>, and <C>Bool</C></Item>
#! <Item></Item>
#! <Item>automatic conversion</Item>
#! </Row>
Expand Down
2 changes: 1 addition & 1 deletion src/gap_to_julia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The following `gap_to_julia` conversions are supported by GAP.jl.
| GAP filter | default Julia type | other Julia types |
|---------------|--------------------------|-----------------------|
| `IsInt` | `BigInt` | `T <: Integer |
| `IsFFE` | `GapFFE` | |
| `IsFFE` | `FFE` | |
| `IsBool` | `Bool` | |
| `IsRat` | `Rational{BigInt}` | `Rational{T} |
| `IsFloat` | `Float64` | `T <: AbstractFloat |
Expand Down
14 changes: 10 additions & 4 deletions src/julia_to_gap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The following `GapObj` conversions are supported by GAP.jl.
| Julia type | GAP filter |
|--------------------------------------|--------------|
| `Int8`, `Int16`, ..., `BigInt` | `IsInt` |
| `GapFFE` | `IsFFE` |
| `FFE` | `IsFFE` |
| `Bool` | `IsBool` |
| `Rational{T}` | `IsRat` |
| `Float16`, `Float32`, `Float64` | `IsFloat` |
Expand Down Expand Up @@ -248,9 +248,7 @@ function GapObj_internal(
recursion_dict = handle_recursion(obj, ret_val, rec, rec_dict)

for i = 1:rows
# We need not distinguish between recursive or not
# because we are just now creating the "row objects" in Julia.
ret_val[i] = GapObj_internal(obj[i, :], recursion_dict, Val(true))
ret_val[i] = GapObj_internal(obj[i, :], recursion_dict, Val(recursive))
end
return ret_val
end
Expand Down Expand Up @@ -347,3 +345,11 @@ function GapObj_internal(
end

GAP.@install GapObj(func::Function) = WrapJuliaFunc(func)

# For backwards compatibility,
# provide methods for `julia_to_gap` that cover the conversions promised
# in the documentation.
# (Installing other methods for `julia_to_gap` will not work in recursive
# situations, only `GapObj_internal` methods can be used for that.)
julia_to_gap(obj::Any; recursive::Bool = false) = GapObj_internal(obj, nothing, Val(recursive))
julia_to_gap(obj::Any, recursion_dict::IdDict{Any,Any}; recursive::Bool = false) = GapObj_internal(obj, nothing, Val(recursive))
73 changes: 71 additions & 2 deletions test/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,10 @@
yy = GAP.gap_to_julia(Vector{Tuple{Int64}}, xx)
@test [(1,)] == yy
@test typeof(yy) == Vector{Tuple{Int64}}

end
end

@testset "conversion to GAP" begin
end

@testset "Defaults" begin
@test GapObj(true)
Expand Down Expand Up @@ -555,6 +554,76 @@ end
@test GAP.Globals.List(list, return_first_gap) == list
end

@testset "Test julia_to_gap (backwards compatibility)" begin
# integers
@test GAP.julia_to_gap(Int8(27)) == 27
@test GAP.julia_to_gap(27) == 27
@test GAP.julia_to_gap(BigInt(27)) == 27
# FFE
x = GAP.evalstr("Z(3)")
@test GAP.julia_to_gap(x) == x
# Bool
@test GAP.julia_to_gap(true) == true
# Rat
@test GAP.julia_to_gap(1//2) == GAP.evalstr("1/2")
# Float64
@test GAP.julia_to_gap(.1) == GAP.evalstr(".1")
# String
@test GAP.julia_to_gap("a") == GAP.evalstr("\"a\"")
# Symbol
@test GAP.julia_to_gap(:a) == GAP.evalstr("\"a\"")
# Char
@test GAP.julia_to_gap('a') == GAP.evalstr("'a'")
# UnitRange
@test GAP.julia_to_gap(1:5) == GAP.evalstr("[ 1 .. 5 ]")
# StepRange
@test GAP.julia_to_gap(1:2:5) == GAP.evalstr("[ 1, 3 .. 5 ]")
# Tuple
l = GAP.julia_to_gap((1,"a"))
@test GAP.Globals.IsList(l)
@test l[2] == "a" # default conversion is non-recursive
l = GAP.julia_to_gap((1,"a"), recursive = true)
@test l[2] == GAP.evalstr("\"a\"")
# Vector{Bool}
v = GAP.julia_to_gap([true, false, true])
@test GAP.Globals.IsBlistRep(v)
# BitVector
v = GAP.julia_to_gap(BitVector((true, false, true)))
@test GAP.Globals.IsBlistRep(v)
# Vector
@test GAP.julia_to_gap([1, 2, 3, 4]) == GAP.evalstr("[ 1, 2, 3, 4 ]")
l = GAP.julia_to_gap([[1, 2], [3, 4]])
@test l isa GapObj
@test l[1] == [1, 2] # default conversion is non-recursive
l = GAP.julia_to_gap([[1, 2], [3, 4]], recursive = true)
@test l isa GapObj
@test l[1] isa GapObj
v = [1, 2]
l = GAP.julia_to_gap([v, v])
@test l[1] === l[2]
l = GAP.julia_to_gap([v, v], recursive = true)
@test l[1] === l[2]
@test GAP.julia_to_gap([v, v], IdDict(), recursive = true) isa GapObj
# Matrix
m = GAP.julia_to_gap([1//2 2//3; 3//4 4//5])
@test GAP.Globals.IsTable(m)
@test m[1, 1] == 1//2 # default conversion is non-recursive
m = GAP.julia_to_gap([1//2 2//3; 3//4 4//5], recursive = true)
@test GAP.Globals.IsMatrix(m)
@test m[1, 1] isa GapObj
# Dict
d = GAP.julia_to_gap(Dict("a" => v, "b" => v))
@test d isa GapObj
@test d.a == v # default conversion is non-recursive
d = GAP.julia_to_gap(Dict("a" => v, "b" => v), recursive = true)
@test d isa GapObj
@test d.a isa GapObj
@test d.a === d.b
@test GAP.julia_to_gap(Dict("a" => v, "b" => v), IdDict(), recursive = true) isa GapObj
# Function
@test GAP.Globals.IsFunction(GAP.julia_to_gap(sqrt))
@test !(GAP.julia_to_gap(sqrt) isa Function)
end
end

@testset "(Un)WrapJuliaFunc" begin
Expand Down
Loading