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 floating-point arrays using isapprox #318

Merged
merged 1 commit into from
Apr 3, 2024
Merged
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
12 changes: 6 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,22 @@ end
# type, and produce numerically correct results.
as_array(x::AbstractArray) = Array(x)
as_array(x::UniformScaling) = x
equal_or_undef(a::Number, b::Number) = (a == b) || isequal(a, b)
equal_or_undef(a, b) = all(equal_or_undef.(a, b))
isapprox_or_undef(a::Number, b::Number) = (a b) || isequal(a, b)
Copy link
Member

Choose a reason for hiding this comment

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

this is fine.
I had though might want to flip order because of types that mightt define isapprox but would define isequal.
But if you restrict to Number subtypes there is a fallback defintion for isapprox that does call == at least.
And I think that has you covered

isapprox_or_undef(a, b) = all(((x,y),) -> isapprox_or_undef(x,y), zip(a, b))
function test_addition_subtraction_dot(As, Bs, Tout::Type)
for A in As, B in Bs
@testset "$(typeof(A)) and $(typeof(B))" begin
@test @inferred(A + B) isa Tout{promote_type(eltype(A), eltype(B))}
@test equal_or_undef(as_array(A + B), as_array(A) + as_array(B))
@test isapprox_or_undef(as_array(A + B), as_array(A) + as_array(B))

@test @inferred(A - B) isa Tout{promote_type(eltype(A), eltype(B))}
@test equal_or_undef(as_array(A - B), as_array(A) - as_array(B))
@test isapprox_or_undef(as_array(A - B), as_array(A) - as_array(B))

@test @inferred(B + A) isa Tout{promote_type(eltype(B), eltype(A))}
@test equal_or_undef(as_array(B + A), as_array(B) + as_array(A))
@test isapprox_or_undef(as_array(B + A), as_array(B) + as_array(A))

@test @inferred(B - A) isa Tout{promote_type(eltype(B), eltype(A))}
@test equal_or_undef(as_array(B - A), as_array(B) - as_array(A))
@test isapprox_or_undef(as_array(B - A), as_array(B) - as_array(A))

# Julia 1.6 doesn't support dot(UniformScaling)
if VERSION < v"1.6.0" || VERSION >= v"1.8.0"
Expand Down