Skip to content

Commit

Permalink
Merge pull request #48
Browse files Browse the repository at this point in the history
Fix Overloading `iterate`
  • Loading branch information
ytdHuang committed Dec 27, 2023
2 parents ad09ffc + 41067ea commit 86965d6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HierarchicalEOM"
uuid = "a62dbcb7-80f5-4d31-9a88-8b19fd92b128"
authors = ["Yi-Te Huang <[email protected]>"]
version = "1.3.1"
version = "1.3.2"

[deps]
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Expand Down
12 changes: 1 addition & 11 deletions src/ADOs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,7 @@ function getindex(A::ADOs, r::UnitRange{Int})
end
getindex(A::ADOs, ::Colon) = getindex(A, 1:lastindex(A))

function iterate(A::ADOs)
return A[1], 2
end
function iterate(A::ADOs, state::Int)
if state < length(A)
return A[state], state + 1
else
return A[state], nothing
end
end
iterate(A::ADOs, ::Nothing) = nothing
iterate(A::ADOs, state::Int = 1) = state > length(A) ? nothing : (A[state], state + 1)

function show(io::IO, A::ADOs)
print(io,
Expand Down
10 changes: 1 addition & 9 deletions src/Bath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,7 @@ function getindex(B::AbstractBath, ::Colon)
return getindex(B, 1:B.Nterm)
end

iterate(B::AbstractBath) = B[1], 2
iterate(B::AbstractBath, ::Nothing) = nothing
function iterate(B::AbstractBath, state)
if state < length(B)
return B[state], state + 1
else
return B[state], nothing
end
end
iterate(B::AbstractBath, state::Int = 1) = state > length(B) ? nothing : (B[state], state + 1)

isclose(a::Number, b::Number, rtol=1e-05, atol=1e-08) = abs(a - b) <= (atol + rtol * abs(b))

Expand Down
12 changes: 1 addition & 11 deletions src/heom_matrices/Nvec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,7 @@ getindex(nvec::Nvec, i::T) where {T <: Any} = nvec.data[i]

keys(nvec::Nvec) = keys(nvec.data)

function iterate(nvec::Nvec)
return nvec[1], 2
end
function iterate(nvec::Nvec, state::Int)
if state < length(nvec)
return nvec[state], state + 1
else
return nvec[state], nothing
end
end
iterate(nvec::Nvec, ::Nothing) = nothing
iterate(nvec::Nvec, state::Int = 1) = state > length(nvec) ? nothing : (nvec[state], state + 1)

function show(io::IO, nvec::Nvec)
print(io, "Nvec($(nvec[:]))")
Expand Down
6 changes: 5 additions & 1 deletion test/bath.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# prepare coupling operator and coefficients of exponential-exponential-expansion terms
η0 = [1]
γ0 = [2]
η1 = [1, 3, 5, 7, 9]
η2 = [2, 4, 6, 8, 10]
γ1 = [0.1, 0.3, 0.5, 0.3, 0.7]
Expand All @@ -9,7 +11,7 @@ op = [0 0; 0 0]

################################################
# Boson bath
b = BosonBath(op, η1, η2, combine=false)
b = BosonBath(op, η1, γ1, combine=false)
@test length(b) == 5

## check for combine
Expand Down Expand Up @@ -126,6 +128,8 @@ end

################################################
# Exponent
@test C(BosonBath(op, η0, γ0), [0.123])[1] η0[1] * exp(-γ0[1] * 0.123)

## check exceptions
@test_throws ErrorException b[11]
@test_throws ErrorException b[1:11]
Expand Down

2 comments on commit 86965d6

@ytdHuang
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/97782

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.3.2 -m "<description of version>" 86965d610c5f49edfea0945997bf0bdc8a1b9e7e
git push origin v1.3.2

Please sign in to comment.