Skip to content

Commit 9c5eddd

Browse files
committed
Add indices_do_not_alias closes #140
1 parent efd8cc6 commit 9c5eddd

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ComponentArrays"
22
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
33
authors = ["Jonnie Diegelman <47193959+jonniedie@users.noreply.github.com>"]
4-
version = "0.12.0"
4+
version = "0.12.1"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
@@ -10,7 +10,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1111

1212
[compat]
13-
ArrayInterface = "2, 3, 4, 5, 6"
1413
ChainRulesCore = "0.8, 0.9, 0.10, 1"
1514
Requires = "1"
1615
julia = "1"

src/ComponentArrays.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module ComponentArrays
22

33
import ChainRulesCore
4+
import ArrayInterface
5+
import ArrayInterface.ArrayInterfaceCore
46

5-
using ArrayInterface
67
using LinearAlgebra
78
using Requires
89

src/array_interface.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Base.reinterpret(::Type{T}, x::ComponentArray, args...) where T = ComponentArray
1212

1313
Base.reshape(A::AbstractArray, axs::NTuple{N,<:CombinedAxis}) where {N} = reshape(A, _array_axis.(axs))
1414

15+
ArrayInterfaceCore.indices_do_not_alias(::Type{ComponentArray{T,N,A,Axes}}) where {T,N,A,Axes} = ArrayInterfaceCore.indices_do_not_alias(A)
16+
ArrayInterfaceCore.instances_do_not_alias(::Type{ComponentArray{T,N,A,Axes}}) where {T,N,A,Axes} = ArrayInterfaceCore.instances_do_not_alias(A)
17+
1518
# Cats
1619
# TODO: Make this a little less copy-pastey
1720
function Base.hcat(x::AbstractComponentVecOrMat, y::AbstractComponentVecOrMat)
@@ -135,12 +138,12 @@ Base.pointer(x::ComponentArray{T,N,A,Axes}) where {T,N,A<:DenseArray,Axes} = poi
135138
Base.unsafe_convert(::Type{Ptr{T}}, x::ComponentArray{T,N,A,Axes}) where {T,N,A,Axes} = Base.unsafe_convert(Ptr{T}, getdata(x))
136139

137140
Base.strides(x::ComponentArray) = strides(getdata(x))
138-
ArrayInterface.strides(A::ComponentArray) = ArrayInterface.strides(parent(A))
141+
ArrayInterfaceCore.strides(A::ComponentArray) = ArrayInterfaceCore.strides(parent(A))
139142
for f in [:device, :stride_rank, :contiguous_axis, :contiguous_batch_size, :dense_dims]
140143
@eval ArrayInterface.$f(::Type{ComponentArray{T,N,A,Axes}}) where {T,N,A,Axes} = ArrayInterface.$f(A)
141144
end
142145

143146
Base.stride(x::ComponentArray, k) = stride(getdata(x), k)
144147
Base.stride(x::ComponentArray, k::Int64) = stride(getdata(x), k)
145148

146-
ArrayInterface.parent_type(::Type{ComponentArray{T,N,A,Axes}}) where {T,N,A,Axes} = A
149+
ArrayInterfaceCore.parent_type(::Type{ComponentArray{T,N,A,Axes}}) where {T,N,A,Axes} = A

src/linear_algebra.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## https://github.com/SciML/DifferentialEquations.jl/issues/849
2-
function ArrayInterface.lu_instance(x::ComponentMatrix)
2+
function ArrayInterfaceCore.lu_instance(x::ComponentMatrix)
33
T = eltype(x)
44
noUnitT = typeof(zero(T))
55
luT = LinearAlgebra.lutype(noUnitT)

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"
23
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
34
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
45
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

test/runtests.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ sq_mat = collect(reshape(1:9, 3, 3))
2222

2323
ca = ComponentArray(nt)
2424
ca_Float32 = ComponentArray{Float32}(nt)
25-
ca_MVector = ComponentArray{MVector{10}}(nt)
26-
ca_SVector = ComponentArray{SVector{10}}(nt)
25+
ca_MVector = ComponentArray{MVector{10, Float64}}(nt) # TODO: Deprecate these
26+
ca_SVector = ComponentArray{SVector{10, Float64}}(nt)
2727
ca_composed = ComponentArray(a = 1, b = ca)
2828

2929
ca2 = ComponentArray(nt2)
@@ -596,6 +596,10 @@ end
596596
# Issue #100
597597
chol = cholesky(cmat + I)
598598
@test convert(Cholesky{Float32,Matrix{Float32}}, chol).factors isa Matrix{Float32}
599+
600+
# Issue #140
601+
@test ComponentArrays.ArrayInterfaceCore.indices_do_not_alias(typeof(ca)) == true
602+
@test ComponentArrays.ArrayInterfaceCore.instances_do_not_alias(typeof(ca)) == false
599603
end
600604

601605
@testset "Autodiff" begin

0 commit comments

Comments
 (0)