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 Overloading iterate #48

Merged
merged 3 commits into from
Dec 27, 2023
Merged
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
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 <y.t.d.huang@phys.ncku.edu.tw>"]
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