Skip to content

Commit d6f7e4d

Browse files
author
oscarddssmith
committed
fix and test undef matrix for MArray
1 parent a260a8a commit d6f7e4d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/ArrayInterfaceStaticArraysCore/src/ArrayInterfaceStaticArraysCore.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import StaticArraysCore, ArrayInterfaceCore, Adapt
44
using LinearAlgebra
55

66
function ArrayInterfaceCore.undefmatrix(::StaticArraysCore.MArray{S, T, N, L}) where {S, T, N, L}
7-
return MMatrix{L, L, T, L*L}(undef)
7+
return StaticArraysCore.MMatrix{L, L, T, L*L}(undef)
88
end
99
# SArray doesn't have an undef constructor and is going to be small enough that this is fine.
1010
function ArrayInterfaceCore.undefmatrix(s::StaticArraysCore.SArray)

lib/ArrayInterfaceStaticArraysCore/test/runtests.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using StaticArrays, ArrayInterfaceCore, ArrayInterfaceStaticArraysCore, Test
22
using LinearAlgebra
3+
using ArrayInterfaceCore: undefmatrix, zeromatrix
34

45
x = @SVector [1,2,3]
56
@test ArrayInterfaceCore.ismutable(x) == false
@@ -26,4 +27,19 @@ z = rand(4)
2627
zr = ArrayInterfaceCore.restructure(x, z)
2728
@test zr isa SMatrix{2, 2}
2829
@test Base.size(zr) == (2,2)
29-
@test vec(zr) == vec(z)
30+
@test vec(zr) == vec(z)
31+
32+
33+
@testset "zeromatrix and unsafematrix" begin
34+
for T in (Int, Float32, Float64)
35+
for (vectype, mattype) in ((SVector{4,T}, SMatrix{4,4,T,16}),
36+
(MVector{4,T}, MMatrix{4,4,T,16}),
37+
(SMatrix{2,2,T,4}, SMatrix{4,4,T,16}),
38+
(MMatrix{2,2,T,4}, MMatrix{4,4,T,16}))
39+
v = vectype(rand(T, 4))
40+
um = undefmatrix(v)
41+
@test typeof(um) == mattype
42+
@test zeromatrix(v) == zeros(T,length(v),length(v))
43+
end
44+
end
45+
end

0 commit comments

Comments
 (0)