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

Test field interface conformance for arb types #1886

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion src/arb/Complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ function canonical_unit(x::ComplexFieldElem)
return x
end

# TODO: implement hash
# TODO: implement better hash
function hash(a::ComplexFieldElem, h::UInt)
return h
end

characteristic(::ComplexField) = 0

Expand Down
3 changes: 3 additions & 0 deletions src/arb/Real.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ zero(R::RealField) = R(0)
one(R::RealField) = R(1)

# TODO: Add hash (and document under ArbFieldElem basic functionality)
function hash(a::RealFieldElem, h::UInt)
return h
end

@doc raw"""
accuracy_bits(x::RealFieldElem)
Expand Down
3 changes: 3 additions & 0 deletions src/arb/acb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ function canonical_unit(x::AcbFieldElem)
end

# TODO: implement hash
function hash(a::AcbFieldElem, h::UInt)
return h
end

characteristic(::AcbField) = 0

Expand Down
3 changes: 3 additions & 0 deletions src/arb/arb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ zero(R::ArbField) = R(0)
one(R::ArbField) = R(1)

# TODO: Add hash (and document under ArbFieldElem basic functionality)
function hash(a::ArbFieldElem, h::UInt)
return h
end

@doc raw"""
accuracy_bits(x::ArbFieldElem)
Expand Down
17 changes: 17 additions & 0 deletions test/arb/Complex-test.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
RR = RealField()
CC = ComplexField()

function test_elem(R::ComplexField)
randtype = rand((
:urandom,
:randtest,
:randtest_exact,
:randtest_precise,
:randtest_wide,
:randtest_special,
))
return rand(R; randtype)
end

@testset "ComplexFieldElem.conformance_tests" begin
test_Field_interface(CC)
#test_Field_interface_recursive(CC)
end

@testset "ComplexFieldElem.constructors" begin
@test isa(CC, ComplexField)
@test isa(CC(2), FieldElem)
Expand Down
17 changes: 17 additions & 0 deletions test/arb/Real-test.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
RR = RealField()

function test_elem(R::RealField)
randtype = rand((
:urandom,
:randtest,
:randtest_exact,
:randtest_precise,
:randtest_wide,
:randtest_special,
))
return rand(R; randtype)
end

@testset "RealFieldElem.conformance_tests" begin
test_Field_interface(RR)
#test_Field_interface_recursive(RR)
end

@testset "RealFieldElem.precision" begin
old_prec = precision(RealField)

Expand Down
17 changes: 17 additions & 0 deletions test/arb/acb-test.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
RR = ArbField(64)
CC = AcbField(64)

function test_elem(R::AcbField)
randtype = rand((
:urandom,
:randtest,
:randtest_exact,
:randtest_precise,
:randtest_wide,
:randtest_special,
))
return rand(R; randtype)
end

@testset "AcbFieldElem.conformance_tests" begin
test_Field_interface(CC)
#test_Field_interface_recursive(CC)
end

@testset "AcbFieldElem.constructors" begin
@test isa(CC, AcbField)
@test isa(CC(2), FieldElem)
Expand Down
21 changes: 21 additions & 0 deletions test/arb/arb-test.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
RR = ArbField(64)

function test_elem(R::ArbField)
randtype = rand((
:urandom,
:randtest,
:randtest_exact,
:randtest_precise,
:randtest_wide,
:randtest_special,
))
return rand(R; randtype)
end

function equality(a::T, b::T) where T <: Union{ArbFieldElem,RealFieldElem,AcbFieldElem,ComplexFieldElem}
return isequal(a, b)
end
Comment on lines +15 to +17
Copy link
Member Author

@fingolfin fingolfin Oct 8, 2024

Choose a reason for hiding this comment

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

this is a gross hack that I used to pass some tests (so that equality(a, deepcopy(a)) holds -- or for that matter, equality(a, a)).

But what we really need is a working isapprox method, see issue #1877

Copy link
Collaborator

Choose a reason for hiding this comment

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

could you split this up into the four files? In the way this is currently, one cannot just run "Complex-test.jl" on its own as it needs this definition.

And I noticed that there is == and isequal for these types, and they call different flint functions. What is the difference and why did you choose isequal for this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry my comment was confusing written (I've edited it now). The point is that equality by default is implemented using ==. But for arb types, in general a == a is not satisfied.

Hence this hack of using isequal which at least ensures equality(a, deepcopy(a)) and equality(a, a) both return true. But it doesn't really solve the problem, we need isapprox.


@testset "ArbFieldElem.conformance_tests" begin
test_Field_interface(RR)
#test_Field_interface_recursive(RR)
end

@testset "ArbFieldElem.constructors" begin
@test isa(RR, ArbField)
@test isa(RR(2), FieldElem)
Expand Down
Loading