Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a stackoverflow in CSF constructors #100

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/csfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct CSF{O<:AbstractOrbital, T<:Union{Term,HalfInteger}, S}
function CSF(config::Configuration{O},
subshell_terms::Vector{IntermediateTerm{T,S}},
terms::Vector{T}) where {O<:Union{<:Orbital,<:RelativisticOrbital},
T<:Union{Term,HalfInt}, S}
T<:Union{Term,HalfInteger}, S}
length(subshell_terms) == length(peel(config)) ||
throw(ArgumentError("Need to provide $(length(peel(config))) subshell terms for $(config)"))
length(terms) == length(peel(config)) ||
Expand All @@ -53,7 +53,7 @@ struct CSF{O<:AbstractOrbital, T<:Union{Term,HalfInteger}, S}
end

CSF(config, subshell_terms::Vector{<:IntermediateTerm}, terms::Vector{<:Real}) =
CSF(config, subshell_terms, convert.(HalfInt, terms))
CSF(config, subshell_terms, convert.(HalfInteger, terms))
end

"""
Expand Down
7 changes: 7 additions & 0 deletions test/csfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ using .ATSPParser
@test num_electrons(csf) == 4

@test CSF(c"1s2 2p", [IntermediateTerm(T"1S",Seniority(0)), IntermediateTerm(T"2Po", Seniority(1))], [T"1S", T"2Po"]) isa NonRelativisticCSF

# Test for a potential stackoverflow in CSF constructors (see #100).
@test CSF(
rc"1s 2s 2p2",
[IntermediateTerm(HalfUInt(j), Seniority(2j)) for j in [1//2, 1//2, 0]],
HalfUInt[1//2, 0, 0]
) isa CSF
end

@testset "CSF list generation" begin
Expand Down