Skip to content

Commit b9f5c9b

Browse files
mtfishmanclaude
andauthored
Drop FunctionImplementations, TypeParameterAccessors, and NamedDimsArrays dependencies (#182)
## Summary Drops the `FunctionImplementations`, `TypeParameterAccessors`, and `NamedDimsArrays` dependencies and narrows the `TensorAlgebra` extension to `TensorAlgebra` 0.10. The `Concatenate` module is vendored from `FunctionImplementations` for now. --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0d4879e commit b9f5c9b

16 files changed

Lines changed: 314 additions & 277 deletions

Project.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SparseArraysBase"
22
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
3-
version = "0.9.23"
3+
version = "0.10.0"
44
authors = ["ITensor developers <support@itensor.org> and contributors"]
55

66
[workspace]
@@ -12,20 +12,16 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
1212
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
1313
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
1414
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
15-
FunctionImplementations = "7c7cc465-9c6a-495f-bdd1-f42428e86d0c"
1615
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
1716
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1817
MapBroadcast = "ebd9b9da-f48d-417c-9660-449667d60261"
1918
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2019
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
21-
TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138"
2220

2321
[weakdeps]
24-
NamedDimsArrays = "60cbd0c0-df58-4cb7-918c-6f5607b73fde"
2522
TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
2623

2724
[extensions]
28-
SparseArraysBaseNamedDimsArraysExt = "NamedDimsArrays"
2925
SparseArraysBaseTensorAlgebraExt = ["TensorAlgebra", "SparseArrays"]
3026

3127
[compat]
@@ -34,13 +30,10 @@ Adapt = "4.3"
3430
ArrayLayouts = "1.11"
3531
Dictionaries = "0.4.3"
3632
FillArrays = "1.13"
37-
FunctionImplementations = "0.4"
3833
GPUArraysCore = "0.2"
3934
LinearAlgebra = "1.10"
4035
MapBroadcast = "0.1.5"
41-
NamedDimsArrays = "0.13, 0.14, 0.15"
4236
Random = "1.10"
4337
SparseArrays = "1.10"
44-
TensorAlgebra = "0.6.2, 0.7, 0.8, 0.9"
45-
TypeParameterAccessors = "0.4.3"
38+
TensorAlgebra = "0.10"
4639
julia = "1.10"

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Dictionaries = "0.4.4"
1313
Documenter = "1.8.1"
1414
ITensorFormatter = "0.2.27"
1515
Literate = "2.20.1"
16-
SparseArraysBase = "0.9"
16+
SparseArraysBase = "0.10"

examples/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ path = ".."
88

99
[compat]
1010
Dictionaries = "0.4.4"
11-
SparseArraysBase = "0.9"
11+
SparseArraysBase = "0.10"
1212
Test = "<0.0.1, 1"

ext/SparseArraysBaseNamedDimsArraysExt/SparseArraysBaseNamedDimsArraysExt.jl

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/SparseArraysBase.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export SparseArrayDOK,
1717
storedpairs,
1818
storedvalues
1919

20+
# `zero!` isn't defined in `Base`, but it is defined in `ArrayLayouts`
21+
# and is useful for sparse array logic, since it can be used to empty
22+
# the sparse array storage. SparseArraysBase owns its own `zero!` rather
23+
# than relying on an external definition.
24+
function zero! end
25+
26+
include("concatenate.jl")
2027
include("abstractsparsearraystyle.jl")
2128
include("sparsearraystyle.jl")
2229
include("indexing.jl")

src/abstractsparsearray.jl

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ const AnyAbstractSparseVecOrMat{T} = Union{
2323

2424
Base.convert(T::Type{<:AbstractSparseArray}, a::AbstractArray) = a isa T ? a : T(a)
2525

26-
using FunctionImplementations: FunctionImplementations
27-
function FunctionImplementations.ImplementationStyle(::Type{<:AnyAbstractSparseArray})
28-
return SparseArrayImplementationStyle()
29-
end
30-
3126
function Base.copy(a::AnyAbstractSparseArray)
3227
return copyto!(similar(a), a)
3328
end
@@ -66,40 +61,66 @@ end
6661
using ArrayLayouts: ArrayLayouts
6762
using LinearAlgebra: LinearAlgebra
6863

69-
Base.getindex(a::AnyAbstractSparseArray, I::Any...) = style(a)(getindex)(a, I...)
70-
Base.getindex(a::AnyAbstractSparseArray, I::Int...) = style(a)(getindex)(a, I...)
71-
Base.setindex!(a::AnyAbstractSparseArray, x, I::Any...) = style(a)(setindex!)(a, x, I...)
72-
Base.setindex!(a::AnyAbstractSparseArray, x, I::Int...) = style(a)(setindex!)(a, x, I...)
73-
Base.copy!(dst::AbstractArray, src::AnyAbstractSparseArray) = style(src)(copy!)(dst, src)
64+
# `copy!` and `real` are routed to sparse implementations that are not (yet)
65+
# defined, matching the prior behavior where these threw a `MethodError`.
66+
function copy!_sparse end
67+
function real_sparse end
68+
69+
Base.getindex(a::AnyAbstractSparseArray, I::Any...) = getindex_sparse(a, I...)
70+
Base.getindex(a::AnyAbstractSparseArray, I::Int...) = getindex_sparse(a, I...)
71+
Base.setindex!(a::AnyAbstractSparseArray, x, I::Any...) = setindex!_sparse(a, x, I...)
72+
Base.setindex!(a::AnyAbstractSparseArray, x, I::Int...) = setindex!_sparse(a, x, I...)
73+
Base.copy!(dst::AbstractArray, src::AnyAbstractSparseArray) = copy!_sparse(dst, src)
7474
function Base.copyto!(dst::AbstractArray, src::AnyAbstractSparseArray)
75-
return style(src)(copyto!)(dst, src)
75+
return copyto!_sparse(dst, src)
7676
end
77-
Base.map(f, as::AnyAbstractSparseArray...) = style(as...)(map)(f, as...)
77+
Base.map(f, as::AnyAbstractSparseArray...) = map_sparse(f, as...)
7878
function Base.map!(f, dst::AbstractArray, as::AnyAbstractSparseArray...)
79-
return style(as...)(map!)(f, dst, as...)
79+
return map!_sparse(f, dst, as...)
8080
end
8181
function Base.mapreduce(f, op, as::AnyAbstractSparseArray...; kwargs...)
82-
return style(as...)(mapreduce)(f, op, as...; kwargs...)
82+
return mapreduce_sparse(f, op, as...; kwargs...)
8383
end
8484
function Base.reduce(f, as::AnyAbstractSparseArray...; kwargs...)
85-
return style(as...)(reduce)(f, as...; kwargs...)
86-
end
87-
Base.all(f::Function, a::AnyAbstractSparseArray) = style(a)(all)(f, a)
88-
Base.all(a::AnyAbstractSparseArray) = style(a)(all)(a)
89-
Base.iszero(a::AnyAbstractSparseArray) = style(a)(iszero)(a)
90-
Base.isreal(a::AnyAbstractSparseArray) = style(a)(isreal)(a)
91-
Base.real(a::AnyAbstractSparseArray) = style(a)(real)(a)
92-
Base.fill!(a::AnyAbstractSparseArray, x) = style(a)(fill!)(a, x)
93-
FunctionImplementations.zero!(a::AnyAbstractSparseArray) = style(a)(zero!)(a)
94-
Base.zero(a::AnyAbstractSparseArray) = style(a)(zero)(a)
85+
return reduce_sparse(f, as...; kwargs...)
86+
end
87+
Base.all(f::Function, a::AnyAbstractSparseArray) = all_sparse(f, a)
88+
Base.all(a::AnyAbstractSparseArray) = all_sparse(a)
89+
Base.iszero(a::AnyAbstractSparseArray) = iszero_sparse(a)
90+
Base.isreal(a::AnyAbstractSparseArray) = isreal_sparse(a)
91+
Base.real(a::AnyAbstractSparseArray) = real_sparse(a)
92+
Base.fill!(a::AnyAbstractSparseArray, x) = fill!_sparse(a, x)
93+
zero!(a::AnyAbstractSparseArray) = zero!_sparse(a)
94+
Base.zero(a::AnyAbstractSparseArray) = zero_sparse(a)
9595
function Base.permutedims!(dst, a::AnyAbstractSparseArray, perm)
96-
return style(a)(permutedims!)(dst, a, perm)
96+
return permutedims!_sparse(dst, a, perm)
9797
end
9898
function LinearAlgebra.mul!(
9999
dst::AbstractMatrix, a1::AnyAbstractSparseArray, a2::AnyAbstractSparseArray,
100100
α::Number, β::Number
101101
)
102-
return style(a1, a2)(mul!)(dst, a1, a2, α, β)
102+
return mul!_sparse(dst, a1, a2, α, β)
103+
end
104+
105+
# Wire the sparse stored-entry implementations (defined in `indexing.jl`) to the
106+
# generic interface functions for sparse array types. Concrete sparse types and
107+
# wrappers may override the canonical methods directly.
108+
@inline getstoredindex(a::AnyAbstractSparseArray, I::Int...) =
109+
getstoredindex_sparse(a, I...)
110+
@inline function getunstoredindex(a::AnyAbstractSparseArray, I::Int...)
111+
return getunstoredindex_sparse(a, I...)
112+
end
113+
@inline isstored(a::AbstractSparseArray, i::Int, I::Int...) = isstored_sparse(a, i, I...)
114+
@inline function setstoredindex!(a::AnyAbstractSparseArray, v, I::Int...)
115+
return setstoredindex!_sparse(a, v, I...)
116+
end
117+
@inline function setunstoredindex!(a::AnyAbstractSparseArray, v, I::Int...)
118+
return setunstoredindex!_sparse(a, v, I...)
119+
end
120+
storedvalues(a::AnyAbstractSparseArray) = storedvalues_sparse(a)
121+
storedpairs(a::AnyAbstractSparseArray) = storedpairs_sparse(a)
122+
function eachstoredindex(style::IndexStyle, a::AnyAbstractSparseArray, bs::AbstractArray...)
123+
return eachstoredindex_sparse(style, a, bs...)
103124
end
104125

105126
function Base.Broadcast.BroadcastStyle(type::Type{<:AnyAbstractSparseArray})
@@ -109,7 +130,7 @@ end
109130
using ArrayLayouts: ArrayLayouts
110131
ArrayLayouts.MemoryLayout(type::Type{<:AnyAbstractSparseArray}) = SparseLayout()
111132

112-
using FunctionImplementations.Concatenate: concatenate
133+
using .Concatenate: concatenate
113134
# We overload `Base._cat` instead of `Base.cat` since it
114135
# is friendlier for invalidations/compile times, see:
115136
# https://github.com/ITensor/SparseArraysBase.jl/issues/25

src/abstractsparsearraystyle.jl

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Base: @_propagate_inbounds_meta
22
using FillArrays: Zeros
3-
using FunctionImplementations: FunctionImplementations
43

54
function unstored end
65
function eachstoredindex end
@@ -38,7 +37,28 @@ unstoredsimilar(a::AbstractArray) = a
3837
# Generic functionality for converting to a
3938
# dense array, trying to preserve information
4039
# about the array (such as which device it is on).
41-
using TypeParameterAccessors: unspecify_type_parameters, unwrap_array, unwrap_array_type
40+
# Local equivalents of the `TypeParameterAccessors` helpers; usage is
41+
# limited to `densetype`/`dense`.
42+
unspecify_type_parameters(::Type{T}) where {T} = Base.typename(T).wrapper
43+
function unwrap_array(a::AbstractArray)
44+
p = parent(a)
45+
p isa typeof(a) && return a
46+
return unwrap_array(p)
47+
end
48+
using LinearAlgebra: Adjoint, Transpose
49+
unwrap_array_type(arraytype::Type{<:AbstractArray}) = arraytype
50+
unwrap_array_type(a::AbstractArray) = unwrap_array_type(typeof(a))
51+
unwrap_array_type(::Type{<:Adjoint{<:Any, P}}) where {P} = unwrap_array_type(P)
52+
unwrap_array_type(::Type{<:Transpose{<:Any, P}}) where {P} = unwrap_array_type(P)
53+
function unwrap_array_type(
54+
::Type{<:PermutedDimsArray{<:Any, <:Any, <:Any, <:Any, P}}
55+
) where {P}
56+
return unwrap_array_type(P)
57+
end
58+
function unwrap_array_type(::Type{<:Base.ReshapedArray{<:Any, <:Any, P}}) where {P}
59+
return unwrap_array_type(P)
60+
end
61+
unwrap_array_type(::Type{<:SubArray{<:Any, <:Any, P}}) where {P} = unwrap_array_type(P)
4262
function densetype(arraytype::Type{<:AbstractArray})
4363
return unspecify_type_parameters(unwrap_array_type(arraytype))
4464
end
@@ -51,34 +71,6 @@ function dense(a::AbstractArray)
5171
return @allowscalar convert(densetype(a), a)
5272
end
5373

54-
# Minimal interface for `SparseArrayImplementationStyle`.
55-
# Fallbacks for dense/non-sparse arrays.
56-
57-
using FunctionImplementations: AbstractArrayImplementationStyle
58-
abstract type AbstractSparseArrayImplementationStyle <: AbstractArrayImplementationStyle end
59-
60-
function FunctionImplementations.ImplementationStyle(
61-
style1::AbstractSparseArrayImplementationStyle,
62-
style2::AbstractSparseArrayImplementationStyle
63-
)
64-
return SparseArrayImplementationStyle()
65-
end
66-
function FunctionImplementations.ImplementationStyle(
67-
style1::AbstractSparseArrayImplementationStyle,
68-
style2::AbstractArrayImplementationStyle
69-
)
70-
return style1
71-
end
72-
# Fix ambiguity error with
73-
# `ImplementationStyle(::AbstractSparseArrayImplementationStyle, ::AbstractArrayImplementationStyle)`.
74-
using FunctionImplementations: DefaultArrayImplementationStyle
75-
function FunctionImplementations.ImplementationStyle(
76-
style1::AbstractSparseArrayImplementationStyle,
77-
style2::DefaultArrayImplementationStyle
78-
)
79-
return style1
80-
end
81-
8274
to_vec(x) = vec(collect(x))
8375
to_vec(x::AbstractArray) = vec(x)
8476

0 commit comments

Comments
 (0)