Skip to content

Commit 0ca5afa

Browse files
committed
Overload DerivableInterfaces.zero!
1 parent d227c87 commit 0ca5afa

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SparseArraysBase"
22
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.5.1"
4+
version = "0.5.2"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"

src/abstractsparsearrayinterface.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using Base: @_propagate_inbounds_meta
2-
using DerivableInterfaces: DerivableInterfaces, @derive, @interface, AbstractArrayInterface
3-
4-
# This is to bring `ArrayLayouts.zero!` into the namespace
5-
# since it is considered part of the sparse array interface.
6-
using ArrayLayouts: zero!
2+
using DerivableInterfaces:
3+
DerivableInterfaces, @derive, @interface, AbstractArrayInterface, zero!
74

85
function eachstoredindex end
96
function getstoredindex end
@@ -256,13 +253,13 @@ function map_all! end
256253
return a_dest
257254
end
258255

259-
using ArrayLayouts: ArrayLayouts, zero!
256+
using DerivableInterfaces: DerivableInterfaces, zero!
260257

261258
# `zero!` isn't defined in `Base`, but it is defined in `ArrayLayouts`
262259
# and is useful for sparse array logic, since it can be used to empty
263260
# the sparse array storage.
264261
# We use a single function definition to minimize method ambiguities.
265-
@interface interface::AbstractSparseArrayInterface function ArrayLayouts.zero!(
262+
@interface interface::AbstractSparseArrayInterface function DerivableInterfaces.zero!(
266263
a::AbstractArray
267264
)
268265
# More generally, this codepath could be taking if `zero(eltype(a))`

src/sparsearraydok.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Accessors: @set
2-
using DerivableInterfaces: @interface, interface
2+
using DerivableInterfaces: DerivableInterfaces, @interface, interface, zero!
33
using Dictionaries: Dictionary, IndexError, set!
44

55
function getzero(a::AbstractArray{<:Any,N}, I::Vararg{Int,N}) where {N}
@@ -102,7 +102,11 @@ end
102102
# Optional, but faster than the default.
103103
storedpairs(a::SparseArrayDOK) = pairs(storage(a))
104104

105-
function ArrayLayouts.zero!(a::SparseArrayDOK)
105+
# TODO: Also handle wrappers.
106+
function DerivableInterfaces.zero!(a::SparseArrayDOK)
106107
empty!(storage(a))
107108
return a
108109
end
110+
function ArrayLayouts.zero!(a::SparseArrayDOK)
111+
return zero!(a)
112+
end

0 commit comments

Comments
 (0)