Skip to content

Commit 16346bf

Browse files
Merge pull request #357 from oscardssmith/move-undefmatrix-to-staticarrays-core
move `undefmatrix` overload to `ArrayInterfaceStaticarraysCore`
2 parents dad11db + 7892c53 commit 16346bf

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/ArrayInterfaceStaticArrays/src/ArrayInterfaceStaticArrays.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ import ArrayInterfaceStaticArraysCore
99

1010
const CanonicalInt = Union{Int,StaticInt}
1111

12-
function ArrayInterface.undefmatrix(::MArray{S, T, N, L}) where {S, T, N, L}
13-
return MMatrix{L, L, T, L*L}(undef)
14-
end
15-
# SArray doesn't have an undef constructor and is going to be small enough that this is fine.
16-
function ArrayInterface.undefmatrix(s::SArray)
17-
v = vec(s)
18-
return v.*v'
19-
end
2012
ArrayInterface.known_first(::Type{<:StaticArrays.SOneTo}) = 1
2113
ArrayInterface.known_last(::Type{StaticArrays.SOneTo{N}}) where {N} = N
2214
ArrayInterface.known_length(::Type{StaticArrays.SOneTo{N}}) where {N} = N

lib/ArrayInterfaceStaticArraysCore/src/ArrayInterfaceStaticArraysCore.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ module ArrayInterfaceStaticArraysCore
33
import StaticArraysCore, ArrayInterfaceCore, Adapt
44
using LinearAlgebra
55

6+
function ArrayInterfaceCore.undefmatrix(::StaticArraysCore.MArray{S, T, N, L}) where {S, T, N, L}
7+
return MMatrix{L, L, T, L*L}(undef)
8+
end
9+
# SArray doesn't have an undef constructor and is going to be small enough that this is fine.
10+
function ArrayInterfaceCore.undefmatrix(s::StaticArraysCore.SArray)
11+
v = vec(s)
12+
return v.*v'
13+
end
14+
615
ArrayInterfaceCore.ismutable(::Type{<:StaticArraysCore.StaticArray}) = false
716
ArrayInterfaceCore.ismutable(::Type{<:StaticArraysCore.MArray}) = true
817
ArrayInterfaceCore.ismutable(::Type{<:StaticArraysCore.SizedArray}) = true
@@ -21,4 +30,4 @@ ArrayInterfaceCore.restructure(x::StaticArraysCore.SArray{S}, y) where {S} = Sta
2130

2231
Adapt.adapt_storage(::Type{<:StaticArraysCore.SArray{S}}, xs::Array) where {S} = SArray{S}(xs)
2332

24-
end
33+
end

0 commit comments

Comments
 (0)