Skip to content

Commit 2e96f31

Browse files
Merge pull request #213 from JuliaDiff/arrayinterface
Update to ArrayInterface v7
2 parents de885bc + a78c705 commit 2e96f31

File tree

5 files changed

+17
-30
lines changed

5 files changed

+17
-30
lines changed

Project.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ version = "1.30.0"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
8-
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"
9-
ArrayInterfaceStaticArrays = "b0d46f97-bff5-4637-a19a-dd75974142cd"
8+
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
109
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
1110
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
1211
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
@@ -20,8 +19,7 @@ VertexSafeGraphs = "19fa3120-7c27-5ec5-8db8-b0b0aa330d6f"
2019

2120
[compat]
2221
Adapt = "1, 2.0, 3.0"
23-
ArrayInterfaceCore = "0.1.1"
24-
ArrayInterfaceStaticArrays = "0.1"
22+
ArrayInterface = "7"
2523
Compat = "2.2, 3, 4"
2624
DataStructures = "0.17, 0.18"
2725
FiniteDiff = "2.8.1"

README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,4 @@ HesVecGrad(g,x::AbstractArray;autodiff=false)
350350
These all have the same interface, where `J*v` utilizes the out-of-place
351351
Jacobian-vector or Hessian-vector function, whereas `mul!(res,J,v)` utilizes
352352
the appropriate in-place versions. To update the location of differentiation
353-
in the operator, simply mutate the vector `u`: `J.u .= ...`.
354-
355-
# Note about sparse differentiation of GPUArrays, BandedMatrices, and BlockBandedMatrices
356-
357-
These two matrix types need the dependencies ArrayInterfaceBandedMatrices.jl and
358-
ArrayInterfaceBlockBandedMatrices.jl to basically work with any functionality
359-
(anywhere). For now, the right thing to do is to add these libraries and do
360-
`import` on them if you are using BandedMatrices.jl or BlockBandedMatrices.jl
361-
for sparsity patterns. In the future, those two packages should just depend on
362-
ArrayInterface.jl and remove this issue entirely from the user space.
363-
364-
Additionally, GPUs need ArrayInterfaceGPUArrays for proper determination of the indexing.
353+
in the operator, simply mutate the vector `u`: `J.u .= ...`.

src/SparseDiffTools.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ using VertexSafeGraphs
1010
using Adapt
1111

1212
using LinearAlgebra
13-
using SparseArrays, ArrayInterfaceCore
13+
using SparseArrays, ArrayInterface
1414

15-
import StaticArrays, ArrayInterfaceStaticArrays
15+
import StaticArrays
1616

1717
using ForwardDiff: Dual, jacobian, partials, DEFAULT_CHUNK_THRESHOLD
1818
using DataStructures: DisjointSets, find_root!, union!
1919

20-
using ArrayInterfaceCore: matrix_colors
20+
using ArrayInterface: matrix_colors
2121

2222
export contract_color,
2323
greedy_d1,

src/coloring/high_level.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
abstract type SparseDiffToolsColoringAlgorithm <: ArrayInterfaceCore.ColoringAlgorithm end
1+
abstract type SparseDiffToolsColoringAlgorithm <: ArrayInterface.ColoringAlgorithm end
22
struct GreedyD1Color <: SparseDiffToolsColoringAlgorithm end
33
struct BacktrackingColor <: SparseDiffToolsColoringAlgorithm end
44
struct ContractionColor <: SparseDiffToolsColoringAlgorithm end
@@ -16,7 +16,7 @@ The coloring defaults to a greedy distance-1 coloring.
1616
Note that if A isa SparseMatrixCSC, the sparsity pattern is defined by structural nonzeroes,
1717
ie includes explicitly stored zeros.
1818
"""
19-
function ArrayInterfaceCore.matrix_colors(A::AbstractMatrix,
19+
function ArrayInterface.matrix_colors(A::AbstractMatrix,
2020
alg::SparseDiffToolsColoringAlgorithm = GreedyD1Color();
2121
partition_by_rows::Bool = false)
2222
_A = A isa SparseMatrixCSC ? A : sparse(A) # Avoid the copy

src/differentiation/compute_jacobian_ad.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ function ForwardColorJacCache(f::F, x, _chunksize = nothing;
4444
p = adapt.(parameterless_type(x), generate_chunked_partials(x, colorvec, chunksize))
4545
_t = Dual{T, eltype(x), getsize(chunksize)
4646
}.(vec(x), ForwardDiff.Partials.(first(p)))
47-
t = ArrayInterfaceCore.restructure(x, _t)
47+
t = ArrayInterface.restructure(x, _t)
4848
end
4949

5050
if dx isa Nothing
5151
fx = similar(t)
5252
_dx = similar(x)
5353
else
54-
tup = ArrayInterfaceCore.allowed_getindex(ArrayInterfaceCore.allowed_getindex(p, 1),
54+
tup = ArrayInterface.allowed_getindex(ArrayInterface.allowed_getindex(p, 1),
5555
1) .* false
5656
_pi = adapt(parameterless_type(dx), [tup for i in 1:length(dx)])
5757
fx = reshape(Dual{T, eltype(dx), length(tup)}.(vec(dx), ForwardDiff.Partials.(_pi)),
@@ -156,8 +156,8 @@ end
156156
function forwarddiff_color_jacobian(f::F, x::AbstractArray{<:Number},
157157
jac_cache::ForwardColorJacCache,
158158
jac_prototype = nothing) where {F}
159-
if jac_prototype isa Nothing ? ArrayInterfaceCore.ismutable(x) :
160-
ArrayInterfaceCore.ismutable(jac_prototype)
159+
if jac_prototype isa Nothing ? ArrayInterface.ismutable(x) :
160+
ArrayInterface.ismutable(jac_prototype)
161161
# Whenever J is mutable, we mutate it to avoid allocations
162162
dx = jac_cache.dx
163163
vecx = vec(x)
@@ -190,7 +190,7 @@ function forwarddiff_color_jacobian(J::AbstractMatrix{<:Number}, f::F,
190190
nrows, ncols = size(J)
191191

192192
if !(sparsity isa Nothing)
193-
rows_index, cols_index = ArrayInterfaceCore.findstructralnz(sparsity)
193+
rows_index, cols_index = ArrayInterface.findstructralnz(sparsity)
194194
rows_index = [rows_index[i] for i in 1:length(rows_index)]
195195
cols_index = [cols_index[i] for i in 1:length(cols_index)]
196196
end
@@ -267,7 +267,7 @@ function forwarddiff_color_jacobian_immutable(f, x::AbstractArray{<:Number},
267267
nrows, ncols = size(J)
268268

269269
if !(sparsity isa Nothing)
270-
rows_index, cols_index = ArrayInterfaceCore.findstructralnz(sparsity)
270+
rows_index, cols_index = ArrayInterface.findstructralnz(sparsity)
271271
rows_index = [rows_index[i] for i in 1:length(rows_index)]
272272
cols_index = [cols_index[i] for i in 1:length(cols_index)]
273273
end
@@ -317,7 +317,7 @@ function forwarddiff_color_jacobian!(J::AbstractMatrix{<:Number},
317317
x::AbstractArray{<:Number};
318318
dx = similar(x, size(J, 1)),
319319
colorvec = 1:length(x),
320-
sparsity = ArrayInterfaceCore.has_sparsestruct(J) ? J :
320+
sparsity = ArrayInterface.has_sparsestruct(J) ? J :
321321
nothing)
322322
forwarddiff_color_jacobian!(J, f, x,
323323
ForwardColorJacCache(f, x, dx = dx, colorvec = colorvec,
@@ -347,7 +347,7 @@ function forwarddiff_color_jacobian!(J::AbstractMatrix{<:Number},
347347
end
348348

349349
if FiniteDiff._use_findstructralnz(sparsity)
350-
rows_index, cols_index = ArrayInterfaceCore.findstructralnz(sparsity)
350+
rows_index, cols_index = ArrayInterface.findstructralnz(sparsity)
351351
else
352352
rows_index = 1:size(J, 1)
353353
cols_index = 1:size(J, 2)
@@ -385,7 +385,7 @@ function forwarddiff_color_jacobian!(J::AbstractMatrix{<:Number},
385385
dx .= partials.(fx, j)
386386
end
387387

388-
if ArrayInterfaceCore.fast_scalar_indexing(dx)
388+
if ArrayInterface.fast_scalar_indexing(dx)
389389
#dx is implicitly used in vecdx
390390
if sparseCSC_common_sparsity
391391
FiniteDiff._colorediteration!(J, vecdx, colorvec, color_i, ncols)

0 commit comments

Comments
 (0)