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

Add a few more convenience helpers, tweak code setting them up #125

Merged
merged 2 commits into from
Nov 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions LibGAP.jl/src/gap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,29 @@ RNamObj(f::Symbol) = GAP.GAPFuncs.RNamObj(MakeString(string(f)))
Base.getproperty(x::MPtr, f::Symbol) = GAP.GAPFuncs.ELM_REC(x, RNamObj(f))
Base.setproperty!(x::MPtr, f::Symbol, v) = GAP.GAPFuncs.ASS_REC(x, RNamObj(f), v)


import Base: *, +, -, /, ^, mod, <, ==

typecombinations = [[:GAPInputType_noint,:GAPInputType_noint],
[:GAPInputType_noint,:Int64],
[:Int64,:GAPInputType_noint]]
function_combinations = [[:(+),:SUM],
[:(-),:DIFF],
[:(*),:PROD],
[:(/),:QUO],
[:(^),:POW],
[:(mod),:MOD],
[:(<),:LT],
[:(==),:EQ]]

for types in typecombinations
for func in function_combinations
#
Base.zero(x::GAPInputType_noint) = GAP.GAPFuncs.ZERO(x)
Base.one(x::GAPInputType_noint) = GAP.GAPFuncs.ONE(x)
Base.:-(x::GAPInputType_noint) = GAP.GAPFuncs.AINV(x)

#
typecombinations = ((:GAPInputType_noint,:GAPInputType_noint),
(:GAPInputType_noint,:Int64),
(:Int64,:GAPInputType_noint))
function_combinations = ((:+,:SUM),
(:-,:DIFF),
(:*,:PROD),
(:/,:QUO),
(:\,:LQUO),
(:^,:POW),
(:mod,:MOD),
(:<,:LT),
(:(==),:EQ))

for (left, right) in typecombinations
for (funcJ, funcC) in function_combinations
@eval begin
$(func[1])(x::$(types[1]),y::$(types[2])) = GAP.GAPFuncs.$(func[2])(x,y)
Base.$(funcJ)(x::$left,y::$right) = GAP.GAPFuncs.$(funcC)(x,y)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I want to be super picky, it should be funcG I guess . . .

end
end
end
35 changes: 24 additions & 11 deletions LibGAP.jl/test/convenience.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@
large_int = GAP.EvalString( "2^100;" )[1][2]
large_int_p1 = GAP.EvalString( "2^100 + 1;" )[1][2]
large_int_m1 = GAP.EvalString( "2^100 - 1;" )[1][2]
large_int_double = GAP.EvalString( "2^200;" )[1][2]
large_int_squared = GAP.EvalString( "2^200;" )[1][2]
large_int_t2 = GAP.EvalString( "2^101;" )[1][2]

@test zero(large_int) == 0
@test one(large_int) == 1

@test large_int + 1 == large_int_p1
@test 1 + large_int == large_int_p1

@test large_int + (-large_int) == 0

@test large_int - 1 == large_int_m1

@test large_int * 2 == large_int_t2
@test 2 * large_int == large_int_t2

@test large_int * large_int == large_int_double
@test large_int * large_int == large_int_squared
@test large_int^2 == large_int_squared

@test large_int / large_int == 1
@test large_int / 2^50 == 2^50

@test large_int \ large_int == 1
@test 2^50 \ large_int == 2^50

@test large_int < large_int_p1
@test large_int <= large_int_p1
@test large_int > large_int_m1
Expand All @@ -33,17 +42,21 @@ end

@testset "ffe_arithmetics" begin

f3_gen = GAP.EvalString( "Z(3);" )[1][2]
f3_one = GAP.EvalString( "Z(3)^0;" )[1][2]
f3_zero = GAP.EvalString( "0 * Z(3);" )[1][2]
z3_gen = GAP.EvalString( "Z(3);" )[1][2]
z3_one = GAP.EvalString( "Z(3)^0;" )[1][2]
z3_zero = GAP.EvalString( "0 * Z(3);" )[1][2]

z3 = GAP.GAPFuncs.Z(3)

f3_call = GAP.GAPFuncs.Z(3)
@test z3_gen == z3
@test z3_one == one(z3)
@test z3_zero == zero(z3)

@test f3_call * 1 == f3_gen
@test f3_call + 1 == f3_zero
@test f3_call + 2 == f3_one
@test f3_call ^ 2 == f3_one
@test f3_call - 1 == f3_one
@test z3 * 1 == z3_gen
@test z3 + 1 == z3_zero
@test z3 + 2 == z3_one
@test z3 ^ 2 == z3_one
@test z3 - 1 == z3_one
end

@testset "object_access" begin
Expand Down