From 02c79078436ea2a9d2db4c6c2a183c8d099d21c8 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 9 Jan 2025 20:39:17 -0500 Subject: [PATCH 1/2] Use MapBroadcast and DerivableInterfaces --- Project.toml | 8 ++++---- TODO.md | 2 +- src/abstractsparsearray.jl | 10 +++++----- src/abstractsparsearrayinterface.jl | 12 ++++++------ src/sparsearraydok.jl | 8 ++++---- src/sparsearrayinterface.jl | 12 +++++++----- test/Project.toml | 2 +- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/Project.toml b/Project.toml index fbe9358..c9de97d 100644 --- a/Project.toml +++ b/Project.toml @@ -5,18 +5,18 @@ version = "0.2.2" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" -BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2" -Derive = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a" +DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f" Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +MapBroadcast = "ebd9b9da-f48d-417c-9660-449667d60261" [compat] Aqua = "0.8.9" ArrayLayouts = "1.11.0" -BroadcastMapConversion = "0.1.0" -Derive = "0.3.6" +DerivableInterfaces = "0.3.7" Dictionaries = "0.4.3" LinearAlgebra = "1.10" +MapBroadcast = "0.1.5" SafeTestsets = "0.1" Suppressor = "0.2" Test = "1.10" diff --git a/TODO.md b/TODO.md index 97b0318..9f3e627 100644 --- a/TODO.md +++ b/TODO.md @@ -1 +1 @@ -- Updates for latest Derive. +- Updates for latest DerivableInterfaces. diff --git a/src/abstractsparsearray.jl b/src/abstractsparsearray.jl index b803e82..5144239 100644 --- a/src/abstractsparsearray.jl +++ b/src/abstractsparsearray.jl @@ -1,15 +1,15 @@ abstract type AbstractSparseArray{T,N} <: AbstractArray{T,N} end -using Derive: @array_aliases +using DerivableInterfaces: @array_aliases # Define AbstractSparseVector, AnyAbstractSparseArray, etc. @array_aliases AbstractSparseArray -using Derive: Derive -function Derive.interface(::Type{<:AbstractSparseArray}) +using DerivableInterfaces: DerivableInterfaces +function DerivableInterfaces.interface(::Type{<:AbstractSparseArray}) return SparseArrayInterface() end -using Derive: @derive +using DerivableInterfaces: @derive # TODO: These need to be loaded since `AbstractArrayOps` # includes overloads of functions from these modules. @@ -18,7 +18,7 @@ using Derive: @derive using ArrayLayouts: ArrayLayouts using LinearAlgebra: LinearAlgebra -# Derive `Base.getindex`, `Base.setindex!`, etc. +# DerivableInterfaces `Base.getindex`, `Base.setindex!`, etc. # TODO: Define `AbstractMatrixOps` and overload for # `AnyAbstractSparseMatrix` and `AnyAbstractSparseVector`, # which is where matrix multiplication and factorizations diff --git a/src/abstractsparsearrayinterface.jl b/src/abstractsparsearrayinterface.jl index 1dc18c6..b7e4ccd 100644 --- a/src/abstractsparsearrayinterface.jl +++ b/src/abstractsparsearrayinterface.jl @@ -1,4 +1,4 @@ -using Derive: Derive, @derive, @interface, AbstractArrayInterface +using DerivableInterfaces: DerivableInterfaces, @derive, @interface, AbstractArrayInterface # This is to bring `ArrayLayouts.zero!` into the namespace # since it is considered part of the sparse array interface. @@ -71,7 +71,7 @@ end @interface ::AbstractArrayInterface getunstoredindex(a::AbstractArray, I::Int...) = zero(eltype(a)) -# Derived interface. +# DerivableInterfacesd interface. @interface ::AbstractArrayInterface storedlength(a::AbstractArray) = length(storedvalues(a)) @interface ::AbstractArrayInterface storedpairs(a::AbstractArray) = map(I -> I => getstoredindex(a, I), eachstoredindex(a)) @@ -104,22 +104,22 @@ end # type instead so fallback functions can use abstract types. abstract type AbstractSparseArrayInterface <: AbstractArrayInterface end -function Derive.combine_interface_rule( +function DerivableInterfaces.combine_interface_rule( interface1::AbstractSparseArrayInterface, interface2::AbstractSparseArrayInterface ) return error("Rule not defined.") end -function Derive.combine_interface_rule( +function DerivableInterfaces.combine_interface_rule( interface1::Interface, interface2::Interface ) where {Interface<:AbstractSparseArrayInterface} return interface1 end -function Derive.combine_interface_rule( +function DerivableInterfaces.combine_interface_rule( interface1::AbstractSparseArrayInterface, interface2::AbstractArrayInterface ) return interface1 end -function Derive.combine_interface_rule( +function DerivableInterfaces.combine_interface_rule( interface1::AbstractArrayInterface, interface2::AbstractSparseArrayInterface ) return interface2 diff --git a/src/sparsearraydok.jl b/src/sparsearraydok.jl index 9249008..f878a6c 100644 --- a/src/sparsearraydok.jl +++ b/src/sparsearraydok.jl @@ -10,9 +10,9 @@ struct SparseArrayDOK{T,N,F} <: AbstractSparseArray{T,N} getunstoredindex::F end -using Derive: Derive -# This defines the destination type of various operations in Derive.jl. -Derive.arraytype(::AbstractSparseArrayInterface, T::Type) = SparseArrayDOK{T} +using DerivableInterfaces: DerivableInterfaces +# This defines the destination type of various operations in DerivableInterfaces.jl. +DerivableInterfaces.arraytype(::AbstractSparseArrayInterface, T::Type) = SparseArrayDOK{T} function SparseArrayDOK{T,N}(size::Vararg{Int,N}) where {T,N} getunstoredindex = default_getunstoredindex @@ -28,7 +28,7 @@ function SparseArrayDOK{T}(size::Int...) where {T} return SparseArrayDOK{T,length(size)}(size...) end -using Derive: @array_aliases +using DerivableInterfaces: @array_aliases # Define `SparseMatrixDOK`, `AnySparseArrayDOK`, etc. @array_aliases SparseArrayDOK diff --git a/src/sparsearrayinterface.jl b/src/sparsearrayinterface.jl index 505ff0e..61fb6b8 100644 --- a/src/sparsearrayinterface.jl +++ b/src/sparsearrayinterface.jl @@ -1,17 +1,19 @@ -using Derive: Derive +using DerivableInterfaces: DerivableInterfaces struct SparseArrayInterface <: AbstractSparseArrayInterface end # Fix ambiguity error. -function Derive.combine_interface_rule(::SparseArrayInterface, ::SparseArrayInterface) +function DerivableInterfaces.combine_interface_rule( + ::SparseArrayInterface, ::SparseArrayInterface +) return SparseArrayInterface() end -function Derive.combine_interface_rule( +function DerivableInterfaces.combine_interface_rule( interface1::SparseArrayInterface, interface2::AbstractSparseArrayInterface ) return interface1 end -function Derive.combine_interface_rule( +function DerivableInterfaces.combine_interface_rule( interface1::AbstractSparseArrayInterface, interface2::SparseArrayInterface ) return interface2 @@ -23,4 +25,4 @@ end # version of `map`. # const sparse = SparseArrayInterface() -Derive.interface(::Type{<:AbstractSparseArrayStyle}) = SparseArrayInterface() +DerivableInterfaces.interface(::Type{<:AbstractSparseArrayStyle}) = SparseArrayInterface() diff --git a/test/Project.toml b/test/Project.toml index 9a4e6ac..4e5feb3 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -2,7 +2,7 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" -Derive = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a" +DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f" Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4" JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" From 70415ddc40317defe8fc9160832e1a32f3e1c3a1 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 9 Jan 2025 20:45:53 -0500 Subject: [PATCH 2/2] Bump to v0.2.3 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index c9de97d..ae3fd5b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SparseArraysBase" uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208" authors = ["ITensor developers and contributors"] -version = "0.2.2" +version = "0.2.3" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"