Skip to content

Commit

Permalink
document the gap_to_julia conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBreuer authored and fingolfin committed Oct 10, 2022
1 parent 5b7d30d commit 7fec87d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
21 changes: 20 additions & 1 deletion src/gap_to_julia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ julia> GAP.gap_to_julia( Matrix{Int}, val )
1 2
3 4
```
The following `gap_to_julia` conversions are supported by GAP.jl.
(Other Julia packages may provide conversions for more GAP objects.)
| GAP filter | default Julia type | other Julia types |
|---------------|--------------------------|-----------------------|
| `IsInt` | `BigInt` | `T <: Integer |
| `IsFFE` | `GapFFE` | |
| `IsBool` | `Bool` | |
| `IsRat` | `Rational{BigInt}` | `Rational{T} |
| `IsFloat` | `Float64` | `T <: AbstractFloat |
| `IsChar` | `Cuchar` | `Char` |
| `IsStringRep` | `String` | `Symbol`, `Vector{T}` |
| `IsRangeRep` | `StepRange{Int64,Int64}` | `Vector{T}` |
| `IsBListRep` | `BitVector` | `Vector{T}` |
| `IsList` | `Vector{Any}` | `Vector{T}` |
| `IsVectorObj` | `Vector{Any}` | `Vector{T}` |
| `IsMatrixObj` | `Matrix{Any}` | `Matrix{T}` |
| `IsRecord` | `Dict{Symbol, Any}` | `Dict{Symbol, T}` |
"""
function gap_to_julia(t::T, x::Any) where {T<:Type}
## Default for conversion:
Expand Down Expand Up @@ -127,7 +146,7 @@ gap_to_julia(::Type{T}, obj::GapObj) where {T<:AbstractString} = T(obj)
## Symbols
gap_to_julia(::Type{Symbol}, obj::GapObj) = Symbol(obj)

## Convert GAP string to Vector{UInt8} (==Vector{UInt8})
## Convert GAP string to Vector{UInt8}
function gap_to_julia(::Type{Vector{UInt8}}, obj::GapObj)
Wrappers.IsStringRep(obj) && return CSTR_STRING_AS_ARRAY(obj)
Wrappers.IsList(obj) && return UInt8[gap_to_julia(UInt8, obj[i]) for i = 1:length(obj)]
Expand Down
31 changes: 17 additions & 14 deletions src/julia_to_gap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ GAP: [ [ 1, 2 ], [ 3, 4 ] ]
The following `julia_to_gap` conversions are supported by GAP.jl.
(Other Julia packages may provide conversions for more Julia objects.)
| Julia type | GAP filter |
|--------------------------------------|------------|
| `Int8`, `Int16`, ..., `BigInt` | `IsInt` |
| `GapFFE` | `IsFFE` |
| `Bool` | `IsBool` |
| `Rational{T}` | `IsRat` |
| `Float16`, `Float32`, `Float64` | `IsFloat` |
| `AbstractString` | `IsString` |
| `Symbol` | `IsString` |
| `Vector{T}` | `IsList` |
| `Vector{Bool}`, `BitVector` | `IsBList` |
| `Tuple{T}` | `IsList` |
| `Dict{String, T}`, `Dict{Symbol, T}` | `IsRecord` |
| `UnitRange{T}`, `StepRange{T}` | `IsRange` |
| Julia type | GAP filter |
|--------------------------------------|--------------|
| `Int8`, `Int16`, ..., `BigInt` | `IsInt` |
| `GapFFE` | `IsFFE` |
| `Bool` | `IsBool` |
| `Rational{T}` | `IsRat` |
| `Float16`, `Float32`, `Float64` | `IsFloat` |
| `AbstractString` | `IsString` |
| `Symbol` | `IsString` |
| `Char` | `IsChar` |
| `Vector{T}` | `IsList` |
| `Vector{Bool}`, `BitVector` | `IsBList` |
| `Tuple{T}` | `IsList` |
| `Matrix{T}` | `IsList` |
| `Dict{String, T}`, `Dict{Symbol, T}` | `IsRecord` |
| `UnitRange{T}`, `StepRange{T, S}` | `IsRange` |
| `Function` | `IsFunction` |
"""
julia_to_gap(x::FFE) = x # Default for actual GAP objects is to do nothing
julia_to_gap(x::Bool) = x # Default for actual GAP objects is to do nothing
Expand Down

0 comments on commit 7fec87d

Please sign in to comment.