Skip to content

Commit b2dcdef

Browse files
authored
Remove FillArrays dependency by implementing custom OneElement (#453)
* Remove FillArrays dep by implementing custom `OneElement` * Clean up * Fixes
1 parent e89793f commit b2dcdef

17 files changed

Lines changed: 110 additions & 47 deletions

File tree

DifferentiationInterface/Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ version = "0.6.0"
66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
88
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
9-
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
109
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1110
PackageExtensionCompat = "65ce6f38-6b18-4e1d-a461-8949797d7930"
1211

@@ -51,7 +50,6 @@ Compat = "3.46,4.2"
5150
Diffractor = "=0.2.6"
5251
Enzyme = "0.12.35"
5352
FastDifferentiation = "0.3.9, 0.4"
54-
FillArrays = "1.7.0"
5553
FiniteDiff = "2.23.1"
5654
FiniteDifferences = "0.12.31"
5755
ForwardDiff = "0.10.36"

DifferentiationInterface/docs/Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ DocumenterInterLinks = "d12716ef-a0f6-4df4-a9f1-a5a34e75c656"
99
DocumenterMermaid = "a078cd44-4d9c-4618-b545-3ab9d77f9177"
1010
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
1111
FastDifferentiation = "eb9bf01b-bf85-4b60-bf87-ee5de06c00be"
12-
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
1312
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
1413
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
1514
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

DifferentiationInterface/ext/DifferentiationInterfaceFastDifferentiationExt/DifferentiationInterfaceFastDifferentiationExt.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ using FastDifferentiation:
2424
make_variables,
2525
sparse_hessian,
2626
sparse_jacobian
27-
using FillArrays: Fill
2827
using LinearAlgebra: dot
2928
using FastDifferentiation.RuntimeGeneratedFunctions: RuntimeGeneratedFunction
3029

3130
DI.check_available(::AutoFastDifferentiation) = true
3231

33-
monovec(x::Number) = Fill(x, 1)
32+
monovec(x::Number) = [x]
3433

3534
myvec(x::Number) = monovec(x)
3635
myvec(x::AbstractArray) = vec(x)

DifferentiationInterface/ext/DifferentiationInterfaceFiniteDifferencesExt/DifferentiationInterfaceFiniteDifferencesExt.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ using ADTypes: AutoFiniteDifferences
44
import DifferentiationInterface as DI
55
using DifferentiationInterface:
66
NoGradientExtras, NoJacobianExtras, NoPullbackExtras, NoPushforwardExtras, Tangents
7-
using FillArrays: OneElement
87
using FiniteDifferences: FiniteDifferences, grad, jacobian, jvp, j′vp
98
using LinearAlgebra: dot
109

DifferentiationInterface/ext/DifferentiationInterfaceReverseDiffExt/DifferentiationInterfaceReverseDiffExt.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ using DifferentiationInterface:
99
JacobianExtras,
1010
NoPullbackExtras,
1111
Tangents
12-
using FillArrays: OneElement
1312
using ReverseDiff.DiffResults: DiffResults, DiffResult, GradientResult, MutableDiffResult
1413
using LinearAlgebra: dot, mul!
1514
using ReverseDiff:
@@ -32,10 +31,8 @@ using ReverseDiff:
3231

3332
DI.check_available(::AutoReverseDiff) = true
3433

35-
function DI.basis(
36-
::AutoReverseDiff, a::AbstractArray{T,N}, i::CartesianIndex{N}
37-
) where {T,N}
38-
return OneElement(one(T), Tuple(i), axes(a))
34+
function DI.basis(::AutoReverseDiff, a::AbstractArray{T}, i) where {T}
35+
return DI.OneElement(i, one(T), a)
3936
end
4037

4138
include("onearg.jl")

DifferentiationInterface/ext/DifferentiationInterfaceSparseArraysExt/sparsity_detector.jl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ function ADTypes.jacobian_sparsity(f, x, detector::DenseSparsityDetector{:iterat
2828
if pushforward_performance(backend) isa PushforwardFast
2929
p = similar(y)
3030
extras = prepare_pushforward_same_point(
31-
f, backend, x, basis(backend, x, first(CartesianIndices(x)))
31+
f, backend, x, basis(backend, x, first(eachindex(x)))
3232
)
33-
for (kj, j) in enumerate(CartesianIndices(x))
33+
for (kj, j) in enumerate(eachindex(x))
3434
pushforward!(f, p, extras, backend, x, basis(backend, x, j))
3535
for ki in LinearIndices(p)
3636
if abs(p[ki]) > atol
@@ -42,9 +42,9 @@ function ADTypes.jacobian_sparsity(f, x, detector::DenseSparsityDetector{:iterat
4242
else
4343
p = similar(x)
4444
extras = prepare_pullback_same_point(
45-
f, backend, x, basis(backend, y, first(CartesianIndices(y)))
45+
f, backend, x, basis(backend, y, first(eachindex(y)))
4646
)
47-
for (ki, i) in enumerate(CartesianIndices(y))
47+
for (ki, i) in enumerate(eachindex(y))
4848
pullback!(f, p, extras, backend, x, basis(backend, y, i))
4949
for kj in LinearIndices(p)
5050
if abs(p[kj]) > atol
@@ -64,9 +64,9 @@ function ADTypes.jacobian_sparsity(f!, y, x, detector::DenseSparsityDetector{:it
6464
if pushforward_performance(backend) isa PushforwardFast
6565
p = similar(y)
6666
extras = prepare_pushforward_same_point(
67-
f!, y, backend, x, basis(backend, x, first(CartesianIndices(x)))
67+
f!, y, backend, x, basis(backend, x, first(eachindex(x)))
6868
)
69-
for (kj, j) in enumerate(CartesianIndices(x))
69+
for (kj, j) in enumerate(eachindex(x))
7070
pushforward!(f!, y, p, extras, backend, x, basis(backend, x, j))
7171
for ki in LinearIndices(p)
7272
if abs(p[ki]) > atol
@@ -78,9 +78,9 @@ function ADTypes.jacobian_sparsity(f!, y, x, detector::DenseSparsityDetector{:it
7878
else
7979
p = similar(x)
8080
extras = prepare_pullback_same_point(
81-
f!, y, backend, x, basis(backend, y, first(CartesianIndices(y)))
81+
f!, y, backend, x, basis(backend, y, first(eachindex(y)))
8282
)
83-
for (ki, i) in enumerate(CartesianIndices(y))
83+
for (ki, i) in enumerate(eachindex(y))
8484
pullback!(f!, y, p, extras, backend, x, basis(backend, y, i))
8585
for kj in LinearIndices(p)
8686
if abs(p[kj]) > atol
@@ -98,10 +98,8 @@ function ADTypes.hessian_sparsity(f, x, detector::DenseSparsityDetector{:iterati
9898
n = length(x)
9999
I, J = Int[], Int[]
100100
p = similar(x)
101-
extras = prepare_hvp_same_point(
102-
f, backend, x, basis(backend, x, first(CartesianIndices(x)))
103-
)
104-
for (kj, j) in enumerate(CartesianIndices(x))
101+
extras = prepare_hvp_same_point(f, backend, x, basis(backend, x, first(eachindex(x))))
102+
for (kj, j) in enumerate(eachindex(x))
105103
hvp!(f, p, extras, backend, x, basis(backend, x, j))
106104
for ki in LinearIndices(p)
107105
if abs(p[ki]) > atol

DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/hessian.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function DI.prepare_hessian(f::F, backend::AutoSparse, x) where {F}
4545
groups = column_groups(coloring_result)
4646
Ng = length(groups)
4747
B = pick_batchsize(maybe_outer(dense_backend), Ng)
48-
seeds = [multibasis(backend, x, CartesianIndices(x)[group]) for group in groups]
48+
seeds = [multibasis(backend, x, eachindex(x)[group]) for group in groups]
4949
compressed_matrix = stack(_ -> vec(similar(x)), groups; dims=2)
5050
batched_seeds = [
5151
Tangents(ntuple(b -> seeds[1 + ((a - 1) * B + (b - 1)) % Ng], Val(B))) for

DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function _prepare_sparse_jacobian_aux(
8888
groups = column_groups(coloring_result)
8989
Ng = length(groups)
9090
B = pick_batchsize(dense_backend, Ng)
91-
seeds = [multibasis(backend, x, CartesianIndices(x)[group]) for group in groups]
91+
seeds = [multibasis(backend, x, eachindex(x)[group]) for group in groups]
9292
compressed_matrix = stack(_ -> vec(similar(y)), groups; dims=2)
9393
batched_seeds = [
9494
Tangents(ntuple(b -> seeds[1 + ((a - 1) * B + (b - 1)) % Ng], Val(B))) for
@@ -122,7 +122,7 @@ function _prepare_sparse_jacobian_aux(
122122
groups = row_groups(coloring_result)
123123
Ng = length(groups)
124124
B = pick_batchsize(dense_backend, Ng)
125-
seeds = [multibasis(backend, y, CartesianIndices(y)[group]) for group in groups]
125+
seeds = [multibasis(backend, y, eachindex(y)[group]) for group in groups]
126126
compressed_matrix = stack(_ -> vec(similar(x)), groups; dims=1)
127127
batched_seeds = [
128128
Tangents(ntuple(b -> seeds[1 + ((a - 1) * B + (b - 1)) % Ng], Val(B))) for

DifferentiationInterface/ext/DifferentiationInterfaceSymbolicsExt/DifferentiationInterfaceSymbolicsExt.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ using DifferentiationInterface:
1313
SecondDerivativeExtras,
1414
Tangents,
1515
maybe_dense_ad
16-
using FillArrays: Fill
1716
using LinearAlgebra: dot
1817
using Symbolics:
1918
build_function,
@@ -33,7 +32,7 @@ using Symbolics.RuntimeGeneratedFunctions: RuntimeGeneratedFunction
3332
DI.check_available(::AutoSymbolics) = true
3433
DI.pullback_performance(::AutoSymbolics) = DI.PullbackSlow()
3534

36-
monovec(x::Number) = Fill(x, 1)
35+
monovec(x::Number) = [x]
3736

3837
myvec(x::Number) = monovec(x)
3938
myvec(x::AbstractArray) = vec(x)

DifferentiationInterface/src/DifferentiationInterface.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ using ADTypes:
3030
AutoTracker,
3131
AutoZygote
3232
using Compat
33-
using FillArrays: OneElement
3433
using LinearAlgebra: Symmetric, Transpose, dot, parent, transpose
3534
using PackageExtensionCompat: @require_extensions
3635

0 commit comments

Comments
 (0)