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

fixed and extended GAP <-> Julia conversions #347

Merged
merged 1 commit into from
Mar 3, 2020

Conversation

ThomasBreuer
Copy link
Member

  • fixed the GAP -> Julia conversion for strings
  • added the GAP <-> Julia conversion for ranges
  • added the GAP -> Julia conversion for Blists (to BitArrays);
    note that the Julia -> GAP conversion to Blists happens automatically
  • changed the generic GAP -> Julia conversions for GAP strings, ranges, blists
  • added tests for all this

(Why is Cuchar and not Char the default type for the conversion of GAP characters to Julia?)

@fingolfin
Copy link
Member

Good question. I think the reasoning was that Julia's Char is a 32bit type and meant to store unicode code point. But in GAP, we don't specify any encoding, a gap char really is the same as a byte, w/o any particular encoding. Not sure why we mapped this to Cuchar instead of Cchar, but that doesn't matter for your question, of course...

For most "regular" text, this doesn't matter, because it is ASCII. It would matter for strings that represent binary data read from a file; but that's somewhat rare in GAP.

All in all, I am open to changing this. Pure GAP chars are rarely used anyway.

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@@ -135,6 +145,19 @@ function gap_to_julia( ::Type{Array{UInt8,1}}, obj :: GapObj )
end
end

## BitArrays
function gap_to_julia( ::Type{BitArray{1}}, obj :: GapObj )
if ! Globals.IsBlistRep( obj )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function doesn't use anything about the actual blist rep, could also do this:

Suggested change
if ! Globals.IsBlistRep( obj )
if ! Globals.IsBlist( obj )

Of course we could also write a more efficient conversion which does exploit the actual representation at some point in the future... But it's not important right now.

@@ -243,9 +301,18 @@ function gap_to_julia(x::GapObj)
elseif Globals.IsFloat(x)
return gap_to_julia(Float64,x)
elseif Globals.IsChar(x)
#T why Cuchar not Char?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with switching this to Char

@test GAP.julia_to_gap( 4:13 ) == r
@test GAP.julia_to_gap( 4:1:13 ) == r
r = GAP.EvalString( "[ 1, 4 .. 10 ]" )
@test GAP.julia_to_gap( 1:3:10 ) == r
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume trying to convert 1:2^62 will throw an error? Perhaps this should also be tested for?

- fixed the GAP -> Julia conversion for strings
- added the GAP <-> Julia conversion for ranges
- added the GAP -> Julia conversion for Blists (to BitArrays);
  note that the Julia -> GAP conversion to Blists happens automatically)
- changed the generic GAP -> Julia conversions for GAP strings, ranges, blists
- added tests for all this

(Why is Cuchar and not Char the default type for the conversion
of GAP characters to Julia?)
@ThomasBreuer
Copy link
Member Author

@fingolfin I have updated the pull request according to your suggestions

@fingolfin fingolfin merged commit 640702a into oscar-system:master Mar 3, 2020
@ThomasBreuer ThomasBreuer deleted the TB_conversions branch March 3, 2020 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants