From c1a70b929b55d468bd8cac430048548d45ef0674 Mon Sep 17 00:00:00 2001 From: ThomasBreuer Date: Mon, 13 May 2024 14:34:17 +0200 Subject: [PATCH 1/3] support `gap_to_julia(::BitVector)` This had been claimed already before the change, but it was not tested. --- src/julia_to_gap.jl | 2 +- test/conversion.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/julia_to_gap.jl b/src/julia_to_gap.jl index 59214046a..6903d7ce6 100644 --- a/src/julia_to_gap.jl +++ b/src/julia_to_gap.jl @@ -116,7 +116,7 @@ julia_to_gap(obj::Any, recursion_dict::IdDict{Any,Any}; recursive::Bool = true) ## Arrays (including BitVector) function julia_to_gap( - obj::Vector{T}, + obj::AbstractVector{T}, recursion_dict::IdDict{Any,Any} = IdDict(); recursive::Bool = false, ) where {T} diff --git a/test/conversion.jl b/test/conversion.jl index e48b63a05..08c92f2b9 100644 --- a/test/conversion.jl +++ b/test/conversion.jl @@ -387,6 +387,11 @@ end y = GAP.julia_to_gap([true, false]) @test y == x @test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(y)) == "list (boolean)" + + v = BitVector([true, false]) + gap_v = GAP.julia_to_gap(v) + @test gap_v == x + @test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(gap_v)) == "list (boolean)" end @testset "Tuples" begin From 83b029a1cee830413980f7cba32643f53ceac513 Mon Sep 17 00:00:00 2001 From: ThomasBreuer Date: Mon, 13 May 2024 15:31:54 +0200 Subject: [PATCH 2/3] adjust the conversion of ranges After generalizing the three-argument method of `julia_to_gap` from `Vector` to `AbstractVector`, the default method that discards the last two arguments is no longer applicable to `AbstractRange{<:Integer}`, hence the special one-argument method does not get called. For the moment, install a three-argument method for `AbstractRange{<:Integer}`. (And add tests that check whether we really get a GAP `IsRange` object in the end.) --- src/julia_to_gap.jl | 10 +++++++++- test/conversion.jl | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/julia_to_gap.jl b/src/julia_to_gap.jl index 6903d7ce6..d9d3e0b12 100644 --- a/src/julia_to_gap.jl +++ b/src/julia_to_gap.jl @@ -172,12 +172,20 @@ function julia_to_gap( end ## Ranges -function julia_to_gap(r::AbstractRange{<:Integer}) +function julia_to_gap(r::AbstractRange{<:Integer}, recursive::Bool = false) res = NewRange(length(r), first(r), step(r)) Wrappers.IsRange(res) || throw(ConversionError(r, GapObj)) return res end +function julia_to_gap( + r::AbstractRange{<:Integer}, + recursion_dict::IdDict{Any,Any}; + recursive::Bool = false) + + return julia_to_gap(r) +end + ## Dictionaries function julia_to_gap( obj::Dict{T,S}, diff --git a/test/conversion.jl b/test/conversion.jl index 08c92f2b9..a1706ba46 100644 --- a/test/conversion.jl +++ b/test/conversion.jl @@ -414,6 +414,11 @@ end r = GAP.evalstr("[ 1, 4 .. 10 ]") @test GAP.julia_to_gap(1:3:10) == r @test_throws GAP.ConversionError GAP.julia_to_gap(1:2^62) + + r = GAP.julia_to_gap(1:2:11, IdDict(), recursive = false) + @test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(r)) == "list (range,ssort)" + r = GAP.Obj(1:10) + @test GAP.gap_to_julia(GAP.Globals.TNAM_OBJ(r)) == "list (range,ssort)" end @testset "Dictionaries" begin From edbdb197d22f8bb37e5586acafdd0b0c0fa4a92d Mon Sep 17 00:00:00 2001 From: ThomasBreuer Date: Tue, 14 May 2024 10:11:21 +0200 Subject: [PATCH 3/3] polish - do not show `C_NULL` but just its type (since printing has changed in Julia) - fix a typo --- pkg/JuliaInterface/tst/calls.tst | 6 +++--- pkg/JuliaInterface/tst/import.tst | 6 +++--- src/types.jl | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/JuliaInterface/tst/calls.tst b/pkg/JuliaInterface/tst/calls.tst index af61e84bc..d68ec83b3 100644 --- a/pkg/JuliaInterface/tst/calls.tst +++ b/pkg/JuliaInterface/tst/calls.tst @@ -178,8 +178,8 @@ gap> g6 := JuliaEvalString("function g6(a,b,c,d,e,f) return f end");; gap> g7 := JuliaEvalString("function g7(a,b,c,d,e,f,g) return g end");; # -gap> g0(); - +gap> Julia.typeof( g0() ); + gap> g1(true); true gap> g2(true,2); @@ -237,4 +237,4 @@ gap> _JuliaFunctionByModule("parse", "Base"); # -gap> STOP_TEST( "calls.tst", 1 ); +gap> STOP_TEST( "calls.tst" ); diff --git a/pkg/JuliaInterface/tst/import.tst b/pkg/JuliaInterface/tst/import.tst index ec62fae03..0bbe6248d 100644 --- a/pkg/JuliaInterface/tst/import.tst +++ b/pkg/JuliaInterface/tst/import.tst @@ -35,12 +35,12 @@ gap> Julia.Base.foo_bar_quux_not_defined; # gap> IsBound( Julia.Base.C_NULL ); true -gap> Julia.Base.C_NULL; - +gap> Julia.typeof( Julia.Base.C_NULL ); + gap> IsBound( Julia.Base.C_NULL ); true gap> Unbind( Julia.Base.C_NULL ); Error, cannot unbind Julia variables ## -gap> STOP_TEST( "import.tst", 1 ); +gap> STOP_TEST( "import.tst" ); diff --git a/src/types.jl b/src/types.jl index 6a06d37b7..9c7cee2bf 100644 --- a/src/types.jl +++ b/src/types.jl @@ -92,7 +92,7 @@ To also deal with GAP integers, finite field elements and booleans, use [`GAP.Obj`](@ref) instead. Recursive conversion of nested Julia objects (arrays, tuples, dictionaries) -can be forced either by a second agument `true` +can be forced either by a second argument `true` or by the keyword argument `recursive` with value `true`. # Examples @@ -129,7 +129,7 @@ in order to convert Julia objects to GAP objects, whenever a suitable conversion has been defined. Recursive conversion of nested Julia objects (arrays, tuples, dictionaries) -can be forced either by a second agument `true` +can be forced either by a second argument `true` or by the keyword argument `recursive` with value `true`. # Examples