Skip to content

Commit

Permalink
Merge pull request oscar-system#93 from ThomasBreuer/TB_adjust_numfield
Browse files Browse the repository at this point in the history
adjusted the `numfield*` code to Julia 1.0
  • Loading branch information
ThomasBreuer authored Oct 23, 2018
2 parents f6bb570 + 1834caf commit 4435356
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
15 changes: 8 additions & 7 deletions JuliaExperimental/gap/numfield.g
Original file line number Diff line number Diff line change
Expand Up @@ -165,27 +165,28 @@ end );
## whose columns are the exponent vectors of the monomials.
##
BindGlobal( "Nemo_Polynomial", function( R, descr )
local fmpq, div, aux, pol, coeffs, monoms;
local fmpq, aux, pol, coeffs, monoms;

if not IsNemoPolynomialRing( R ) then
Error( "<R> must be a Nemo polynomial ring" );
elif Length( descr ) = 0 then
return Zero( R );
elif R!.isUnivariatePolynomialRing = true then
# Create a univariate polynomial
if ForAll( descr, IsInt ) then
# Nothing is to do.
# Convert the coefficient list from "Array{Any,1}" to "Array{Int,1}".
descr:= Julia.Base.convert( JuliaEvalString( "Array{Int,1}" ),
ConvertedToJulia( descr ) );
elif ForAll( descr, IsRat ) then
# 'ConvertedToJulia' does not allow us to transfer rationals.
fmpq:= Julia.Nemo.fmpq;
div:= Julia.Base.("//");
descr:= JuliaArrayOfFmpq( descr );
else
Error( "<descr> must be a list of rationals (or integers)" );
fi;
aux:= Julia.GAPUtilsExperimental.MatrixFromNestedArray( descr );
aux:= Julia.Base.vec( aux );
pol:= JuliaPointer( R )( aux );
pol:= JuliaPointer( R )( descr );
else
# Create a multivariate polynomial
if IsList( descr ) and Length( descr ) = 2 then
coeffs:= JuliaArrayOfFmpq( descr[1] );
monoms:= Julia.Base.convert(
Expand Down Expand Up @@ -820,7 +821,7 @@ InstallMethod( TraceMat,
function( nemomat )
local trace, type;

trace:= Julia.Base.trace( JuliaPointer( nemomat ) );
trace:= Julia.LinearAlgebra.tr( JuliaPointer( nemomat ) );
type:= ElementsFamily( ElementsFamily( FamilyObj( nemomat ) ) )!.defaultType;
return ObjectifyWithAttributes( rec(), type, JuliaPointer, trace );
end );
Expand Down
20 changes: 10 additions & 10 deletions JuliaExperimental/julia/numfield.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Nemo_Matrix_over_NumberField( f, m::Int, n::Int, lst, denom::Int )
local pos, mat, d, i, j

pos = 1
mat = Array{Any}( m, n )
mat = Array{Any}( undef, m, n )
d = Nemo.fmpz( denom )
for i = 1:m
for j = 1:n
Expand All @@ -64,7 +64,7 @@ end
function CoefficientVectorOfNumberFieldElement( elm::Nemo.nf_elem, d::Int )
local arr, i

arr = Array{Nemo.fmpq,1}( d )
arr = Array{Nemo.fmpq,1}( undef, d )
for i = 1:d
arr[i] = Nemo.coeff( elm, i-1 )
end
Expand All @@ -83,8 +83,8 @@ end
function CoefficientVectorsNumDenOfNumberFieldElement( elm, d )
local num, den, i, onecoeff

num = Array{Nemo.fmpz,1}( d )
den = Array{Nemo.fmpz,1}( d )
num = Array{Nemo.fmpz,1}( undef, d )
den = Array{Nemo.fmpz,1}( undef, d )
for i = 1:d
onecoeff = Nemo.coeff( elm, i-1 )
num[i] = numerator( onecoeff )
Expand All @@ -105,8 +105,8 @@ function MatricesOfCoefficientVectorsNumDen( nemomat, d )
local m, n, num, den, i, j, resnum, resden

m, n = size( nemomat )
num = Array{Any,1}( 0 )
den = Array{Any,1}( 0 )
num = Array{Any,1}( undef, 0 )
den = Array{Any,1}( undef, 0 )
for i = 1:m
for j = 1:n
resnum, resden = CoefficientVectorsNumDenOfNumberFieldElement(
Expand All @@ -116,8 +116,8 @@ function MatricesOfCoefficientVectorsNumDen( nemomat, d )
end
end

return Nemo.matrix( Nemo.ZZ, hcat( num... )' ),
Nemo.matrix( Nemo.ZZ, hcat( den... )' )
return Nemo.matrix( Nemo.ZZ, copy( transpose( hcat( num... ) ) ) ),
Nemo.matrix( Nemo.ZZ, copy( transpose( hcat( den... ) ) ) )
end


Expand All @@ -136,9 +136,9 @@ end
# f, x = Nemo.CyclotomicField( N, "x" )
# n = length( lst )
# m = MatrixSpace( Nemo.ZZ, n, length( lst[1] ) )
# mat = m( hcat( lst... )' )
# mat = m( copy( transpose( hcat( lst... ) ) ) )
# d = Nemo.fmpz( denom )
# res = Array{Any}( n )
# res = Array{Any}( undef, n )
# for i = 1:n
# res[i] = QabElem( Nemo.elem_from_mat_row( f, mat, i, d ), N )
# end
Expand Down
2 changes: 1 addition & 1 deletion JuliaExperimental/julia/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module GAPUtilsExperimental
> Return a 2-dim array created from the 1-dim array of 1-dim arrays `lst`.
> (Note that GAP's `ConvertedToJulia` creates nested arrays.)
"""
function MatrixFromNestedArray( lst ) return hcat( lst... )' end
function MatrixFromNestedArray( lst ) return copy( hcat( lst... )' ) end


"""
Expand Down
6 changes: 5 additions & 1 deletion JuliaExperimental/read.g
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ ReadPackage( "JuliaExperimental", "gap/gapperm.g");


# Nemo's number fields.
if JuliaImportPackage( "Nemo" ) then
# 'Nemo' imports (some functions from) 'LinearAlgebra',
# see its 'Nemo.jl', but we have to tell GAP about 'LinearAlgebra',
# in order to use, e. g., 'Julia.LinearAlgebra.tr'.
if JuliaImportPackage( "LinearAlgebra" ) and
JuliaImportPackage( "Nemo" ) then
ReadPackage( "JuliaExperimental", "gap/gapnemo.g");
ReadPackage( "JuliaExperimental", "gap/numfield.g");
fi;
Expand Down
5 changes: 2 additions & 3 deletions JuliaExperimental/tst/numfield.tst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ gap> Nemo_Polynomial( R, [ [ 1, 2, 3/2 ], [ [ 4, 5, 6 ], [ 7, 8, 9 ] ] ] );
gap> x:= X( Rationals );;
gap> f:= AlgebraicExtension( Rationals, x^2+1 );;
gap> iso:= IsomorphismToNemoField( f );;
gap> ff:= Range( iso );
<field in characteristic 0>
gap> ff:= Range( iso );; # remove one semicolon when GAP has the right method
gap> one:= Image( iso, One( f ) );
<<Julia: 1>>
gap> PreImage( iso, one );
Expand Down Expand Up @@ -61,7 +60,7 @@ gap> mat:= [ [ o, a/2 ], [ z, o ] ];
gap> nmat:= NemoMatrix( ff, mat );
<<Julia: [1 1//2*a]
[0 1]>>
gap> PrintObj( nmat );
gap> PrintObj( nmat ); Print( "\n" );
[1 1//2*a]
[0 1]
gap> TraceMat( nmat );
Expand Down

0 comments on commit 4435356

Please sign in to comment.