Skip to content

Commit db0c019

Browse files
authored
Make <:AbstractOrbital behave like scalars under broadcasting (#97)
1 parent 2b3e59a commit db0c019

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/orbitals.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
abstract type AbstractOrbital
33
44
Abstract supertype of all orbital types.
5+
6+
!!! note "Broadcasting"
7+
8+
When broadcasting, orbital objects behave like scalars.
59
"""
610
abstract type AbstractOrbital end
11+
Base.Broadcast.broadcastable(x::AbstractOrbital) = Ref(x)
712

813
"""
914
const MQ = Union{Int,Symbol}

test/orbitals.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,11 @@ using Random
424424
@test ne == e
425425
end
426426
end
427+
428+
@testset "Broadcasting" begin
429+
@test ([o"1s", o"2p"] .== o"1s") == [true, false]
430+
@test ([ro"1s", ro"2p-"] .== ro"1s") == [true, false]
431+
@test ([so"1s(0,α)", so"2p(0,α)"] .== so"1s(0,α)") == [true, false]
432+
@test ([rso"1s(1/2)", rso"2p-(1/2)"] .== rso"1s(1/2)") == [true, false]
433+
end
427434
end

0 commit comments

Comments
 (0)