Skip to content

Commit

Permalink
Fix ambiguities, add precompile.jl
Browse files Browse the repository at this point in the history
* Fix ambiguities found by Aqua
* Add precompile.jl. Some delays that I found could be as much as 1.5s. Not a lot,
  but why not fix them.
  • Loading branch information
jlapeyre committed Sep 15, 2024
1 parent 48da841 commit 61d5fab
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2020 John Lapeyre <[email protected]>
Copyright (c) 2020-2024 John Lapeyre <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 5 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ version = "1.0.0"
[deps]
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"

[compat]
Aqua = ">= 0.8"
Dictionaries = "0.2, 0.3, 0.4"
julia = "1"
# Aqua wants these bogus versions. WTF
# Pkg.status will not give me numbers to use
Test = ">= 0.0"
LinearAlgebra = ">= 0.0"
JET = ">= 0.0"
LinearAlgebra = ">= 0.0"
PrecompileTools = "1"
Test = ">= 0.0"
julia = "1"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Expand All @@ -24,4 +24,3 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Aqua", "JET"]
# test = ["Test", "Aqua"]
3 changes: 3 additions & 0 deletions src/IsApprox.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module IsApprox

using PrecompileTools: @setup_workload, @compile_workload

using Dictionaries: Dictionaries
export AbstractApprox, Equal, EachApprox, Approx, UpToPhase
export isposdef, ispossemidef, isunitary, isinvolution, isidempotent, isnormal, commutes, anticommutes
Expand All @@ -16,5 +18,6 @@ const _AbstractDict{T, V} = Union{AbstractDict{T,V}, Dictionaries.AbstractDictio
include("core.jl")
include("base_applications.jl")
include("other_applications.jl")
include("precompile.jl")

end # module
5 changes: 3 additions & 2 deletions src/base_applications.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ end

# This uses the isapprox interface, which compares using a norm
ishermitian(A::AbstractMatrix, approx_test::Approx) = isapprox(approx_test, A, adjoint(A))

ishermitian(x::Number, approx_test::AbstractApprox=Equal()) = isapprox(approx_test, x, conj(x))

ishermitian(A::Hermitian, ::AbstractApprox=Equal()) = true
ishermitian(A::Hermitian, ::Approx) = true
ishermitian(A::Symmetric{<:Real}, ::AbstractApprox=Equal()) = true
ishermitian(A::Symmetric{<:Real}, ::Approx) = true
ishermitian(A::Symmetric{<:Complex}, approx_test::AbstractApprox=Equal()) = isreal(A, approx_test)
ishermitian(A::Symmetric{<:Complex}, approx_test::Approx) = isreal(A, approx_test)
issymmetric(A::Hermitian{<:Real}, ::AbstractApprox=Equal()) = true
issymmetric(A::Hermitian{<:Complex}, approx_test::AbstractApprox=Equal()) = isreal(A, approx_test)
issymmetric(A::Symmetric, ::AbstractApprox=Equal()) = true
Expand Down
24 changes: 24 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@setup_workload begin
nothing
using IsApprox
import LinearAlgebra
@compile_workload begin
for T in (Float64, Float32)
for m in (rand(T, 4, 4), rand(Complex{T}, 2, 2))
for approx in (Equal(), Approx(), EachApprox())
IsApprox.isposdef(m, approx)
IsApprox.ispossemidef(m, approx)
IsApprox.ishermitian(m, approx)
IsApprox.issymmetric(m, approx)
IsApprox.iszero(m, approx)
IsApprox.isone(m, approx)
IsApprox.isreal(m, approx)
IsApprox.isdiag(m, approx=approx)
IsApprox.isunitary(m, approx)
IsApprox.isidempotent(m, approx)
IsApprox.isnormalized(m, approx)
end
end
end
end
end

2 comments on commit 61d5fab

@jlapeyre
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/115238

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.0 -m "<description of version>" 61d5fab6fb9439f8e60cb56b58a689279876fbb9
git push origin v1.0.0

Please sign in to comment.