From 3469f1cfa3e7c04d77cafaeda11150dd67a64dd5 Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Mon, 26 Apr 2021 15:46:13 +1200 Subject: [PATCH] Make <:AbstractOrbital behave like scalars under broadcasting --- src/orbitals.jl | 5 +++++ test/orbitals.jl | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/orbitals.jl b/src/orbitals.jl index d202c00..aa38989 100644 --- a/src/orbitals.jl +++ b/src/orbitals.jl @@ -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} diff --git a/test/orbitals.jl b/test/orbitals.jl index e70edb9..3919052 100644 --- a/test/orbitals.jl +++ b/test/orbitals.jl @@ -417,4 +417,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