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

make partial output container iterable (zero cost) #47

Merged
merged 2 commits into from
Nov 9, 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 = "SpectralKit"
uuid = "5c252ae7-b5b6-46ab-a016-b0e3d78320b7"
authors = ["Tamas K. Papp <[email protected]>"]
version = "0.14.0"
version = "0.14.1"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
6 changes: 4 additions & 2 deletions src/derivatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ end

"""
Container for output of evaluating partial derivatives. Each corresponds to an
specification in a [`∂Specification`](@ref). Can be indexed with integers, or converted
to a `Tuple`.
specification in a [`∂Specification`](@ref). Can be indexed with integers, iterated, or
converted to a `Tuple`.
"""
struct ∂Output{N,T}
values::NTuple{N,T}
Expand All @@ -303,6 +303,8 @@ end

@inline Base.getindex(∂output::∂Output, i) = ∂output.values[i]

@inline Base.iterate(∂output::∂Output, i...) = Base.iterate(∂output.values, i...)

function _product(∂specification::∂Specification, sources, indices)
(; lookups) = ∂specification
p = map(lookups) do lookup
Expand Down
14 changes: 14 additions & 0 deletions test/test_derivatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,17 @@ end
end
end
end

@testset "iteration for ∂Output" begin
o_src = (1.0, 2.0, 3.0)
∂o = SpectralKit.∂Output(o_src)
for (o1, o2) in zip(o_src, ∂o)
@test o1 ≡ o2
end
function f(o)
o1, o2, o3 = o
o1 + o2 + o3
end
@test @inferred(f(∂o)) == sum(o_src)
@test @ballocated($f($∂o)) == 0
end
Loading