Skip to content

Commit cdc271f

Browse files
Merge pull request #325 from JuliaArrays/staticarrayscore
Create ArrayInterfaceStaticArraysCore
2 parents 9cc5804 + 691acbf commit cdc271f

File tree

9 files changed

+105
-47
lines changed

9 files changed

+105
-47
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- ArrayInterfaceCUDA
2222
- ArrayInterfaceOffsetArrays
2323
- ArrayInterfaceStaticArrays
24+
- ArrayInterfaceStaticArraysCore
2425
- ArrayInterfaceTracker
2526
version:
2627
- '1'

lib/ArrayInterfaceStaticArrays/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
name = "ArrayInterfaceStaticArrays"
22
uuid = "b0d46f97-bff5-4637-a19a-dd75974142cd"
3-
version = "0.1.3"
3+
version = "0.1.4"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
8+
ArrayInterfaceStaticArraysCore = "dd5226c6-a4d4-4bc7-8575-46859f9c95b9"
89
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
910
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1011
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1112

1213
[compat]
1314
Adapt = "3"
1415
ArrayInterface = "6"
16+
ArrayInterfaceStaticArraysCore = "0.1"
1517
Static = "0.7"
1618
StaticArrays = "1.2.5, 1.3, 1.4"
1719
julia = "1.6"

lib/ArrayInterfaceStaticArrays/src/ArrayInterfaceStaticArrays.jl

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,10 @@ using ArrayInterface
55
using LinearAlgebra
66
using StaticArrays
77
using Static
8+
import ArrayInterfaceStaticArraysCore
89

910
const CanonicalInt = Union{Int,StaticInt}
1011

11-
ArrayInterface.ismutable(::Type{<:StaticArrays.StaticArray}) = false
12-
ArrayInterface.ismutable(::Type{<:StaticArrays.MArray}) = true
13-
ArrayInterface.ismutable(::Type{<:StaticArrays.SizedArray}) = true
14-
15-
ArrayInterface.can_setindex(::Type{<:StaticArrays.StaticArray}) = false
16-
ArrayInterface.buffer(A::Union{StaticArrays.SArray,StaticArrays.MArray}) = getfield(A, :data)
17-
18-
function ArrayInterface.lu_instance(_A::StaticArrays.StaticMatrix{N,N}) where {N}
19-
A = StaticArrays.SArray(_A)
20-
L = LowerTriangular(A)
21-
U = UpperTriangular(A)
22-
p = StaticArrays.SVector{N,Int}(1:N)
23-
return StaticArrays.LU(L, U, p)
24-
end
25-
26-
function ArrayInterface.restructure(x::StaticArrays.SArray, y::StaticArrays.SArray)
27-
reshape(y, StaticArrays.Size(x))
28-
end
29-
ArrayInterface.restructure(x::StaticArrays.SArray{S}, y) where {S} = StaticArrays.SArray{S}(y)
30-
3112
ArrayInterface.known_first(::Type{<:StaticArrays.SOneTo}) = 1
3213
ArrayInterface.known_last(::Type{StaticArrays.SOneTo{N}}) where {N} = N
3314
ArrayInterface.known_length(::Type{StaticArrays.SOneTo{N}}) where {N} = N
@@ -76,6 +57,4 @@ else
7657
ArrayInterface.parent_type(::Type{<:StaticArrays.SizedArray{S,T,M,N}}) where {S,T,M,N} = Array{T,N}
7758
end
7859

79-
Adapt.adapt_storage(::Type{<:StaticArrays.SArray{S}}, xs::Array) where {S} = SArray{S}(xs)
80-
8160
end # module

lib/ArrayInterfaceStaticArrays/test/runtests.jl

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,11 @@ using Static
66
using Test
77

88
x = @SVector [1,2,3]
9-
@test ArrayInterface.ismutable(x) == false
10-
@test ArrayInterface.ismutable(view(x, 1:2)) == false
11-
@test ArrayInterface.can_setindex(typeof(x)) == false
12-
@test ArrayInterface.buffer(x) == x.data
139
@test @inferred(ArrayInterface.device(typeof(x))) === ArrayInterface.CPUTuple()
1410

1511
x = @MVector [1,2,3]
16-
@test ArrayInterface.ismutable(x) == true
17-
@test ArrayInterface.ismutable(view(x, 1:2)) == true
1812
@test @inferred(ArrayInterface.device(typeof(x))) === ArrayInterface.CPUPointer()
1913

20-
A = @SMatrix(randn(5, 5))
21-
@test ArrayInterface.lu_instance(A) isa typeof(lu(A))
22-
A = @MMatrix(randn(5, 5))
23-
@test ArrayInterface.lu_instance(A) isa typeof(lu(A))
24-
2514
@test isone(ArrayInterface.known_first(typeof(StaticArrays.SOneTo(7))))
2615
@test ArrayInterface.known_last(typeof(StaticArrays.SOneTo(7))) == 7
2716
@test ArrayInterface.known_length(typeof(StaticArrays.SOneTo(7))) == 7
@@ -40,18 +29,6 @@ T = SizedArray{Tuple{5,4,3}}(zeros(5,4,3));
4029
@test @inferred(ArrayInterface.length(A)) === StaticInt(42)
4130
@test @inferred(ArrayInterface.length(T)) === StaticInt(60)
4231

43-
x = @SMatrix rand(Float32, 2, 2)
44-
y = @SVector rand(4)
45-
yr = ArrayInterface.restructure(x, y)
46-
@test yr isa SMatrix{2, 2}
47-
@test Base.size(yr) == (2,2)
48-
@test vec(yr) == vec(y)
49-
z = rand(4)
50-
zr = ArrayInterface.restructure(x, z)
51-
@test zr isa SMatrix{2, 2}
52-
@test Base.size(zr) == (2,2)
53-
@test vec(zr) == vec(z)
54-
5532
Am = @MMatrix rand(2,10);
5633
@test @inferred(ArrayInterface.strides(view(Am,1,:))) === (StaticInt(2),)
5734

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 SciML
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name = "ArrayInterfaceStaticArraysCore"
2+
uuid = "dd5226c6-a4d4-4bc7-8575-46859f9c95b9"
3+
version = "0.1.0"
4+
5+
[deps]
6+
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
7+
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"
8+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
9+
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
10+
11+
[compat]
12+
Adapt = "3"
13+
ArrayInterfaceCore = "0.1.13"
14+
julia = "1.6"
15+
16+
[extras]
17+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
18+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
19+
20+
[targets]
21+
test = ["StaticArrays", "Test"]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module ArrayInterfaceStaticArraysCore
2+
3+
import StaticArraysCore, ArrayInterfaceCore, Adapt
4+
using LinearAlgebra
5+
6+
ArrayInterfaceCore.ismutable(::Type{<:StaticArraysCore.StaticArray}) = false
7+
ArrayInterfaceCore.ismutable(::Type{<:StaticArraysCore.MArray}) = true
8+
ArrayInterfaceCore.ismutable(::Type{<:StaticArraysCore.SizedArray}) = true
9+
10+
ArrayInterfaceCore.can_setindex(::Type{<:StaticArraysCore.StaticArray}) = false
11+
ArrayInterfaceCore.buffer(A::Union{StaticArraysCore.SArray,StaticArraysCore.MArray}) = getfield(A, :data)
12+
13+
function ArrayInterfaceCore.lu_instance(_A::StaticArraysCore.StaticMatrix{N,N}) where {N}
14+
lu(one(_A))
15+
end
16+
17+
function ArrayInterfaceCore.restructure(x::StaticArraysCore.SArray{S,T,N}, y::StaticArraysCore.SArray) where {S,T,N}
18+
StaticArraysCore.SArray{S,T,N}(y)
19+
end
20+
ArrayInterfaceCore.restructure(x::StaticArraysCore.SArray{S}, y) where {S} = StaticArraysCore.SArray{S}(y)
21+
22+
Adapt.adapt_storage(::Type{<:StaticArraysCore.SArray{S}}, xs::Array) where {S} = SArray{S}(xs)
23+
24+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using StaticArrays, ArrayInterfaceCore, ArrayInterfaceStaticArraysCore, Test
2+
using LinearAlgebra
3+
4+
x = @SVector [1,2,3]
5+
@test ArrayInterfaceCore.ismutable(x) == false
6+
@test ArrayInterfaceCore.ismutable(view(x, 1:2)) == false
7+
@test ArrayInterfaceCore.can_setindex(typeof(x)) == false
8+
@test ArrayInterfaceCore.buffer(x) == x.data
9+
10+
x = @MVector [1,2,3]
11+
@test ArrayInterfaceCore.ismutable(x) == true
12+
@test ArrayInterfaceCore.ismutable(view(x, 1:2)) == true
13+
14+
A = @SMatrix(randn(5, 5))
15+
@test ArrayInterfaceCore.lu_instance(A) isa typeof(lu(A))
16+
A = @MMatrix(randn(5, 5))
17+
@test ArrayInterfaceCore.lu_instance(A) isa typeof(lu(A))
18+
19+
x = @SMatrix rand(Float32, 2, 2)
20+
y = @SVector rand(4)
21+
yr = ArrayInterfaceCore.restructure(x, y)
22+
@test yr isa SMatrix{2, 2}
23+
@test Base.size(yr) == (2,2)
24+
@test vec(yr) == vec(Float32.(y))
25+
z = rand(4)
26+
zr = ArrayInterfaceCore.restructure(x, z)
27+
@test zr isa SMatrix{2, 2}
28+
@test Base.size(zr) == (2,2)
29+
@test vec(zr) == vec(z)

test/runtests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ if GROUP == "ArrayInterfaceBlockBandedMatrices"
1919
dev_subpkg("ArrayInterfaceBandedMatrices")
2020
end
2121

22+
if GROUP == "ArrayInterfaceStaticArrays"
23+
dev_subpkg("ArrayInterfaceStaticArraysCore")
24+
end
25+
2226
groups = if GROUP == "All"
2327
["ArrayInterfaceCore", "ArrayInterface", "ArrayInterfaceBandedMatrices", "ArrayInterfaceBlockBandedMatrices",
24-
"ArrayInterfaceOffsetArrays", "ArrayInterfaceStaticArrays",]
28+
"ArrayInterfaceOffsetArrays", "ArrayInterfaceStaticArrays", "ArrayInterfaceStaticArraysCore"]
2529
else
2630
[GROUP]
2731
end

0 commit comments

Comments
 (0)