File tree Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,7 @@ Base.merge(axs::Axis...) = Axis(merge(indexmap.(axs)...))
142
142
143
143
Base. firstindex (ax:: AbstractAxis ) = first (viewindex (first (indexmap (ax))))
144
144
Base. lastindex (ax:: AbstractAxis ) = last (viewindex (last (indexmap (ax))))
145
+ Base. length (ax:: AbstractAxis ) = lastindex (ax) - firstindex (ax) + 1
145
146
146
147
Base. keys (ax:: AbstractAxis ) = keys (indexmap (ax))
147
148
Original file line number Diff line number Diff line change @@ -235,6 +235,10 @@ last_index(x) = last(x)
235
235
last_index (x:: ViewAxis ) = last_index (viewindex (x))
236
236
last_index (x:: AbstractAxis ) = last_index (last (indexmap (x)))
237
237
238
+ # length information is in Axis, use it to make SVector creation type stable
239
+ Base. length (ca:: ComponentArray ) = prod (length .(getaxes (ca)))
240
+ Base. size (ca:: ComponentArray ) = map (length, getaxes (ca))
241
+
238
242
# Reduce singleton dimensions
239
243
remove_nulls () = ()
240
244
remove_nulls (x1, args... ) = (x1, remove_nulls (args... )... )
Original file line number Diff line number Diff line change 598
598
@test convert (Cholesky{Float32,Matrix{Float32}}, chol). factors isa Matrix{Float32}
599
599
end
600
600
601
+ @testset " length typestable" begin
602
+ # function boundary, so that cv is type-inferred
603
+ test_create_svector = (cv) -> SVector {length(cv)} (cv)
604
+ @inferred test_create_svector (ComponentVector (a= 1 : 3 ));
605
+ @inferred test_create_svector (cmat);
606
+ test_create_smatrix = (cmat) -> SMatrix {size(cmat)...} (cmat)
607
+ @test (@inferred test_create_smatrix (cmat)) isa SMatrix
608
+ end ;
609
+
601
610
@testset " Autodiff" begin
602
611
include (" autodiff_tests.jl" )
603
612
end
You can’t perform that action at this time.
0 commit comments