Skip to content

Commit 9e9462d

Browse files
Merge pull request #130 from SciML/multisize
Handle multisize undefs
2 parents b85d680 + fed81dc commit 9e9462d

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LabelledArrays"
22
uuid = "2ee39098-c373-598a-b85f-a56591580800"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "1.12.1"
4+
version = "1.12.2"
55

66
[deps]
77
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"

src/LabelledArrays.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ function ArrayInterfaceCore.ismutable(::Type{<:LArray{T, N, D, Syms}}) where {T,
6464
end
6565
ArrayInterfaceCore.can_setindex(::Type{<:SLArray}) = false
6666

67+
lenfun(x) = length(x)
68+
lenfun(::Symbol) = 1
6769
function ArrayInterfaceCore.undefmatrix(x::LArray{T, N, D, Syms}) where {T, N, D, Syms}
68-
similar(x.__x, length(Syms), length(Syms))
70+
n = sum(lenfun, Syms)
71+
similar(x.__x, n, n)
6972
end
7073

7174
function PreallocationTools.get_tmp(dc::PreallocationTools.DiffCache,

src/larray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct LArray{T, N, D <: AbstractArray{T, N}, Syms} <: DenseArray{T, N}
55
end
66

77
function LArray{T, N, D, Syms}(::UndefInitializer, n::Int64) where {T, N, D, Syms}
8-
@assert length(Syms) == n
8+
@assert sum(lenfun, Syms) == n
99
LArray{T, N, D, Syms}(similar(D, n))
1010
end
1111

test/larrays.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ using LabelledArrays, Test, InteractiveUtils
1616
syms = (:a, :b, :c)
1717
@test typeof(typeof(x)(undef, 3)) == typeof(x)
1818

19+
z = LabelledArrays.LArray{Float64, 1, Vector{Float64}, (x = 1:4, y = 5:8)}(undef, 8)
20+
@test length(z) == 8
21+
@test size(LabelledArrays.ArrayInterfaceCore.undefmatrix(z)) == (8, 8)
22+
1923
for (i, s) in enumerate(syms)
2024
@show i, s
2125
@test x[i] == x[s]

0 commit comments

Comments
 (0)