Skip to content
Open
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: 2 additions & 0 deletions Test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
NamedArrays = "86f7a689-2022-50b4-a561-43c23ac3c673"
24 changes: 24 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using StaticArrays
using OffsetArrays
using Test
using Unitful
using NamedArrays


## Test setup
Expand Down Expand Up @@ -598,6 +599,29 @@ end
@test convert(Cholesky{Float32,Matrix{Float32}}, chol).factors isa Matrix{Float32}
end


get_empty(cv::ComponentVector) = ComponentVector(similar(getdata(cv),0), (ComponentArrays.NullAxis(),))

@testset "KeepIndices" begin
cv = ComponentVector(a=(a1=100,a2=(a21=210, a22=reshape(1:4,(2,2))),a3=300), b=3, c=4)
# test whether underlying array type is preerved by using a NamedArray
cvn = ComponentVector(NamedArray(getdata(cv),(labels(cv),)), getaxes(cv))
@test_throws ArgumentError cv[(3,)] # only allow symbols
@test_broken @test == cv[Symbol[]] = get_empty(cv)
@test_broken @test == cvn[Symbol[]] = get_empty(cvn)
@test_broken @test cv[(:b,)] == cv[[:b]] == cv[KeepIndex(:b)]
cv_sub = cv[(:a,:b)]
cv_subt = vcat(cv[KeepIndex(:a)],cv[KeepIndex(:b)])
@test cv_sub == cv_subt
@test getdata(cvn[(:a,:b)]) isa NamedVector
@test_broken ca2[(:a,:b)] # PartitionedAyis
cv = ComponentArray(a=1, b=[1,2]) # array axis
@test cv[(:a,:b)] == vcat(cv[KeepIndex(:a)],cv[KeepIndex(:b)])
#
cvn_sub = cvn[KeepIndices(:a,:b, :c)] # 3 comp to test proper reduce rather than vcat
@test getdata(cvn_sub) isa NamedArray
end

@testset "Autodiff" begin
include("autodiff_tests.jl")
end