Skip to content

Commit

Permalink
Make <:AbstractOrbital behave like scalars under broadcasting (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenpi authored Apr 26, 2021
1 parent 2b3e59a commit db0c019
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/orbitals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
abstract type AbstractOrbital
Abstract supertype of all orbital types.
!!! note "Broadcasting"
When broadcasting, orbital objects behave like scalars.
"""
abstract type AbstractOrbital end
Base.Broadcast.broadcastable(x::AbstractOrbital) = Ref(x)

"""
const MQ = Union{Int,Symbol}
Expand Down
7 changes: 7 additions & 0 deletions test/orbitals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,11 @@ using Random
@test ne == e
end
end

@testset "Broadcasting" begin
@test ([o"1s", o"2p"] .== o"1s") == [true, false]
@test ([ro"1s", ro"2p-"] .== ro"1s") == [true, false]
@test ([so"1s(0,α)", so"2p(0,α)"] .== so"1s(0,α)") == [true, false]
@test ([rso"1s(1/2)", rso"2p-(1/2)"] .== rso"1s(1/2)") == [true, false]
end
end

2 comments on commit db0c019

@mortenpi
Copy link
Member 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/35368

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 v0.1.3 -m "<description of version>" db0c019f84623c1e8f8ce16147c180d39f3a53f0
git push origin v0.1.3

Please sign in to comment.