Skip to content

Commit

Permalink
adjusted JuliaExperimental to the new conversion rules
Browse files Browse the repository at this point in the history
- adjusted the function calls to the new rules (from pull request oscar-system#160),
  removed or simplified the relevant code
- removed `gap/record.g` since the code is now obsolete;
  moved the contents of `tst/record.tst` to `JuliaInterface/tst/convert.tst`
- changed the auxiliary dictionaries to use symbols as keys,
  in order to use the default conversions
- adjusted some Julia code which worked only in pre-1.0 versions

After these changes, the JuliaExperimental tests should work,
thus the automatic test runs can be reactivated.

(Currently I am rewriting the whole package JuliaExperimental,
a pull request for that will be available on Monday.)
  • Loading branch information
ThomasBreuer committed Nov 23, 2018
1 parent ace62c6 commit dd32629
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 378 deletions.
39 changes: 30 additions & 9 deletions JuliaExperimental/gap/gapperm.g
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,29 @@ BindGlobal( "ExtPermType",
NewType( PermutationsFamily, IsExtPerm and IsPositionalObjectRep ) );

BindGlobal( "PermutationInJulia",
gapperm -> Objectify( ExtPermType,
[ Julia.GAPPermutations.Permutation( ConvertedToJulia( ListPerm( gapperm ) ) ) ] ) );
function( gapperm, degree... )

if IsPerm( gapperm ) then
if Length( degree ) > 0 and IsInt( degree[1] ) then
gapperm:= ListPerm( gapperm, degree[1] );
else
gapperm:= ListPerm( gapperm );
fi;
elif IsPositionsList( gapperm ) then
if Length( degree ) > 0 and IsInt( degree[1] ) then
if degree[1] < Length( gapperm ) then
Error( "degree cannot be smaller than length of <gapperm>" );
fi;
gapperm:= Concatenation( gapperm,
[ Length( gapperm ) + 1 .. degree[1] ] );
fi;
else
Error( "<gapperm> must be a permutation or a list of positions" );
fi;

return Objectify( ExtPermType,
[ Julia.GAPPermutations.Permutation( GAPToJulia( gapperm ) ) ] );
end );

BindGlobal( "WrappedPermutationInJulia",
jperm -> Objectify( ExtPermType, [ jperm ] ) );
Expand All @@ -65,11 +86,11 @@ InstallMethod( ViewObj, [ IsExtPerm ], function( p )
end );

InstallMethod( \=, [ IsExtPerm, IsExtPerm ], function( p1, p2 )
return ConvertedFromJulia( Julia.Base.("==")( p1![1], p2![1] ) );
return Julia.Base.("==")( p1![1], p2![1] );
end );

InstallMethod( \<, [ IsExtPerm, IsExtPerm ], function( p1, p2 )
return ConvertedFromJulia( Julia.Base.isless( p1![1], p2![1] ) );
return Julia.Base.isless( p1![1], p2![1] );
end );

InstallMethod( \*, [ IsExtPerm, IsExtPerm ], function( p1, p2 )
Expand All @@ -79,23 +100,23 @@ InstallMethod( \*, [ IsExtPerm, IsExtPerm ], function( p1, p2 )

InstallMethod( \^, [ IsExtPerm, IsInt ], function( p1, n )
return WrappedPermutationInJulia( Julia.Base.("^")(
p1![1], ConvertedToJulia( n ) ) );
p1![1], GAPToJulia( n ) ) );
end );

InstallMethod( \^, [ IsInt, IsExtPerm ], function( i, p )
return ConvertedFromJulia( Julia.Base.("^")( ConvertedToJulia( i ), p![1] ) );
return JuliaToGAP( IsInt, Julia.Base.("^")( GAPToJulia( i ), p![1] ) );
end );

InstallMethod( \/, [ IsInt, IsExtPerm ], function( i, p )
return ConvertedFromJulia( Julia.Base.("/")( ConvertedToJulia( i ), p![1] ) );
return JuliaToGAP( IsInt, Julia.Base.("/")( GAPToJulia( i ), p![1] ) );
end );

InstallMethod( LargestMovedPoint, [ IsExtPerm ], function( p )
return ConvertedFromJulia( Julia.GAPPermutations.LargestMovedPointPerm( p![1] ) );
return JuliaToGAP( IsInt, Julia.GAPPermutations.LargestMovedPointPerm( p![1] ) );
end );

InstallMethod( Order, [ IsExtPerm ], function( p )
return ConvertedFromJulia( Julia.GAPPermutations.OrderPerm( p![1] ) );
return JuliaToGAP( IsInt, Julia.GAPPermutations.OrderPerm( p![1] ) );
end );

InstallMethod( One, [ IsExtPerm ], p -> JuliaIdentityPerm );
Expand Down
98 changes: 21 additions & 77 deletions JuliaExperimental/gap/hnf.g
Original file line number Diff line number Diff line change
Expand Up @@ -20,122 +20,66 @@ JuliaIncludeFile(
JuliaImportPackage( "Nemo" );


#! @Arguments intmat
#! @Returns a Julia object
#! @Description
#! For a matrix <A>intmat</A> of integers,
#! this function creates the matrix of <C>Nemo.fmpz</C> integers in Julia
#! that has the same entries.
BindGlobal( "NemoIntegerMatrix_Eval", function( mat )
local str, row;

# Turn the integers into strings, and use 'JuliaEvalString'.
str:= "Nemo.ZZ[";
for row in mat do
Append( str, JoinStringsWithSeparator( List( row, String ), " " ) );
Append( str, ";" );
od;
str[ Length( str ) ]:= ']';
return JuliaEvalString( str );
end );


##
## <mat> is assumed to be a list of lists of rationals.
##
BindGlobal( "NemoMatrix_fmpq", function( mat )
local arr, i, fmpz, fmpq, div, parse, map, alp, row, entry, num, den, s;
local arr, i, fmpz, div, row, entry;

# Convert the entries to 'Nemo.fmpq' objects,
# and use 'MatrixSpace' for creating the matrix in Julia.
arr:= [];
i:= 1;
fmpz:= Julia.Nemo.fmpz;
fmpq:= Julia.Nemo.fmpq;
div:= Julia.Base.( "//" );
parse:= Julia.Base.parse;
map:= Julia.Base.map;
alp:= ConvertedToJulia( 16 );
for row in mat do
for entry in row do
if IsSmallIntRep( entry ) then
if IsInt( entry ) then
arr[i]:= entry;
elif IsInt( entry ) then
arr[i]:= parse( fmpz, HexStringInt( entry ), alp );
else
num:= parse( fmpz, HexStringInt( NumeratorRat( entry ) ), alp );
den:= parse( fmpz, HexStringInt( DenominatorRat( entry ) ), alp );
arr[i]:= div( num, den );
arr[i]:= div( fmpz( NumeratorRat( entry ) ),
fmpz( DenominatorRat( entry ) ) );
fi;
i:= i + 1;
od;
od;
arr:= map( fmpq, ConvertedToJulia( arr ) );
s:= JuliaFunction( "MatrixSpace", "Nemo" );
s:= s( Julia.Nemo.QQ, NumberRows( mat ), NumberColumns( mat ) );

return s( arr );
return Julia.Nemo.matrix( Julia.Nemo.QQ,
NumberRows( mat ), NumberColumns( mat ),
Julia.Base.map( Julia.Nemo.fmpq, GAPToJulia( arr ) ) );
end );


##
## <mat> is assumed to be a list of lists of integers.
##
BindGlobal( "NemoMatrix_fmpz", function( mat )
local arr, i, fmpz, parse, alp, row, entry, map, s;

# Convert the entries to 'Nemo.fmpz' objects,
# and use 'MatrixSpace' for creating the matrix in Julia.
arr:= [];
i:= 1;
fmpz:= JuliaFunction( "fmpz", "Nemo" );
parse:= JuliaFunction( "parse", "Base" );
alp:= ConvertedToJulia( 16 );
for row in mat do
for entry in row do
if IsSmallIntRep( entry ) then
arr[i]:= entry;
else
arr[i]:= parse( fmpz, HexStringInt( entry ), alp );
fi;
i:= i + 1;
od;
od;
map:= JuliaFunction( "map", "Base" );
arr:= map( fmpz, ConvertedToJulia( arr ) );
s:= JuliaFunction( "MatrixSpace", "Nemo" );
s:= s( Julia.Nemo.ZZ, NumberRows( mat ), NumberColumns( mat ) );

return s( arr );
end );
#! @Arguments intmat
#! @Returns a Julia object
#! @Description
#! For a matrix <A>intmat</A> of integers,
#! this function creates the matrix of <C>Nemo.fmpz</C> integers in Julia
#! that has the same entries.
BindGlobal( "NemoMatrix_fmpz",
mat -> Julia.Nemo.matrix( Julia.Nemo.ZZ,
NumberRows( mat ), NumberColumns( mat ),
Julia.Base.map( Julia.Nemo.fmpz,
GAPToJulia( Concatenation( mat ) ) ) ) );


## ...
BindGlobal( "GAPMatrix_fmpz_mat", function( nemomat )
local result, getindex;
local result;

# Reformat in Julia s. t. the result can be translated back to GAP.
result:= Julia.GAPHNFModule.unpackedNemoMatrixFmpz( nemomat );

# Translate the Julia object to GAP.
getindex:= Julia.Base.getindex;
if ConvertedFromJulia( getindex( result, 1 ) ) = "int" then
# The entries are small integers.
return StructuralConvertedFromJulia( getindex( result, 2 ) );
else
# The entries are hex strings encoding integers.
return List( ConvertedFromJulia( getindex( result, 2 ) ),
row -> List( ConvertedFromJulia( row ),
x -> IntHexString( ConvertedFromJulia( x ) ) ) );
fi;
return JuliaToGAP( IsList, result, true );
end );


##
## The argument can be created with different methods.
##
BindGlobal( "HermiteNormalFormIntegerMatUsingNemo", function( juliamat )
local juliahnf, result, getindex;
local juliahnf;

# Compute the HNF in Julia.
juliahnf:= Julia.Nemo.hnf( juliamat );
Expand Down
Loading

0 comments on commit dd32629

Please sign in to comment.