Skip to content

Commit

Permalink
Merge pull request #20 from theogf/patch-1
Browse files Browse the repository at this point in the history
Add kwarg constructor for TupleVector
  • Loading branch information
cscherrer authored Dec 15, 2021
2 parents 4713518 + 8490cc7 commit d709776
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TupleVectors"
uuid = "615932cf-77b6-4358-adcd-5b7eba981d7e"
authors = ["Chad Scherrer <[email protected]> and contributors"]
version = "0.1.3"
version = "0.1.4"

[deps]
ArraysOfArrays = "65a8f2f4-9b39-5baf-92e2-a9cc46fdf018"
Expand Down
4 changes: 4 additions & 0 deletions src/tuplevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function TupleVector(::UndefInitializer, x::T, n::Int) where {T<:NamedTuple}
return TupleVector{T, typeof(data)}(data)
end

function TupleVector(; kwargs...)
return TupleVector(NamedTuple(kwargs))
end

# function TupleVector(x::Union{Tuple, NamedTuple})
# flattened = flatten(x)
# @assert allequal(size.(flattened)...)
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ using MeasureTheory
using LinearAlgebra

@testset "TupleVectors.jl" begin
## Testing constructors
w = randn(10)
y = randn(10)
nt = (w=w, y=y)
A = TupleVector(nt)
B = TupleVector(; w=w, y=y)
@test A.w == B.w

@test chainvec(3,5)[1] == 3


Expand Down

2 comments on commit d709776

@cscherrer
Copy link
Owner 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/50626

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 v0.1.4 -m "<description of version>" d709776eceaf58d08d121c45a66056d312b1a1b3
git push origin v0.1.4

Please sign in to comment.