Skip to content

Commit

Permalink
Use values in iszero (#635)
Browse files Browse the repository at this point in the history
* Use values in iszero

* Special case empty coeff vectors

* Check for zero coefficients first

* Fix typo
  • Loading branch information
jishnub authored Feb 5, 2024
1 parent 9e06124 commit 77cd9f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ isapprox(g::Number, f::Fun; kw...) = isapprox(g*ones(space(f)), f; kw...)
isreal(f::Fun{<:RealSpace,<:Real}) = true
isreal(f::Fun) = false

iszero(f::Fun) = all(iszero,f.coefficients)
iszero(f::Fun) = all(iszero, coefficients(f)) || all(iszero, values(f))

# Deliberately not named isconst or isconstant to avoid conflicts with Base or DomainSets
isconstantfun(f::Fun) = iszero(f - first(f))
Expand Down
5 changes: 5 additions & 0 deletions test/SpacesTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ using Test
F = Fun{typeof(PointSpace(1:3)), Float32}
@test ApproxFunBase.cfstype(F) == Float32
end

@testset "isconstantfun" begin
f = Fun(PointSpace(1:4), ones(4))
@test ApproxFunBase.isconstantfun(f)
end
end

@testset "DiracSpace" begin
Expand Down

0 comments on commit 77cd9f1

Please sign in to comment.