Skip to content

Commit d709776

Browse files
authored
Merge pull request #20 from theogf/patch-1
Add kwarg constructor for TupleVector
2 parents 4713518 + 8490cc7 commit d709776

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TupleVectors"
22
uuid = "615932cf-77b6-4358-adcd-5b7eba981d7e"
33
authors = ["Chad Scherrer <[email protected]> and contributors"]
4-
version = "0.1.3"
4+
version = "0.1.4"
55

66
[deps]
77
ArraysOfArrays = "65a8f2f4-9b39-5baf-92e2-a9cc46fdf018"

src/tuplevector.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ function TupleVector(::UndefInitializer, x::T, n::Int) where {T<:NamedTuple}
3636
return TupleVector{T, typeof(data)}(data)
3737
end
3838

39+
function TupleVector(; kwargs...)
40+
return TupleVector(NamedTuple(kwargs))
41+
end
42+
3943
# function TupleVector(x::Union{Tuple, NamedTuple})
4044
# flattened = flatten(x)
4145
# @assert allequal(size.(flattened)...)

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ using MeasureTheory
66
using LinearAlgebra
77

88
@testset "TupleVectors.jl" begin
9+
## Testing constructors
10+
w = randn(10)
11+
y = randn(10)
12+
nt = (w=w, y=y)
13+
A = TupleVector(nt)
14+
B = TupleVector(; w=w, y=y)
15+
@test A.w == B.w
16+
917
@test chainvec(3,5)[1] == 3
1018

1119

0 commit comments

Comments
 (0)