From 4ac431579aae9b4a37978a44860839fdab58f1b2 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Thu, 14 Nov 2024 11:06:31 -0500 Subject: [PATCH] [SparseArrayInterface] [BlockSparseArrays] Rename wrapper type unions (#1584) * [SparseArrayInterface] [BlockSparseArrays] Rename wrapper type unions * [NDTensors] Bump to v0.3.66 --- NDTensors/Project.toml | 2 +- .../abstractblocksparsearray/arraylayouts.jl | 2 +- .../src/abstractblocksparsearray/broadcast.jl | 2 +- .../src/abstractblocksparsearray/cat.jl | 2 +- .../src/abstractblocksparsearray/map.jl | 18 ++-- .../sparsearrayinterface.jl | 2 +- .../src/abstractblocksparsearray/views.jl | 16 ++-- .../wrappedabstractblocksparsearray.jl | 83 ++++++++++--------- .../src/blocksparsearray/blocksparsearray.jl | 2 +- .../src/abstractsparsearray/arraylayouts.jl | 2 +- .../src/abstractsparsearray/base.jl | 8 +- .../src/abstractsparsearray/broadcast.jl | 2 +- .../src/abstractsparsearray/cat.jl | 2 +- .../src/abstractsparsearray/map.jl | 16 ++-- .../wrappedabstractsparsearray.jl | 2 +- 15 files changed, 86 insertions(+), 75 deletions(-) diff --git a/NDTensors/Project.toml b/NDTensors/Project.toml index 7a42286b83..6886c23460 100644 --- a/NDTensors/Project.toml +++ b/NDTensors/Project.toml @@ -1,7 +1,7 @@ name = "NDTensors" uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" authors = ["Matthew Fishman "] -version = "0.3.65" +version = "0.3.66" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/arraylayouts.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/arraylayouts.jl index 069d367cf6..7b8088ff2b 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/arraylayouts.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/arraylayouts.jl @@ -3,7 +3,7 @@ using BlockArrays: BlockLayout using ..SparseArrayInterface: SparseLayout using ..TypeParameterAccessors: parenttype, similartype -function ArrayLayouts.MemoryLayout(arraytype::Type{<:BlockSparseArrayLike}) +function ArrayLayouts.MemoryLayout(arraytype::Type{<:AnyAbstractBlockSparseArray}) outer_layout = typeof(MemoryLayout(blockstype(arraytype))) inner_layout = typeof(MemoryLayout(blocktype(arraytype))) return BlockLayout{outer_layout,inner_layout}() diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/broadcast.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/broadcast.jl index 5887673036..96841be6f1 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/broadcast.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/broadcast.jl @@ -1,7 +1,7 @@ using BlockArrays: AbstractBlockedUnitRange, BlockSlice using Base.Broadcast: Broadcast -function Broadcast.BroadcastStyle(arraytype::Type{<:BlockSparseArrayLike}) +function Broadcast.BroadcastStyle(arraytype::Type{<:AnyAbstractBlockSparseArray}) return BlockSparseArrayStyle{ndims(arraytype)}() end diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/cat.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/cat.jl index eac4ea1b02..3023037113 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/cat.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/cat.jl @@ -1,5 +1,5 @@ # TODO: Change to `AnyAbstractBlockSparseArray`. -function Base.cat(as::BlockSparseArrayLike...; dims) +function Base.cat(as::AnyAbstractBlockSparseArray...; dims) # TODO: Use `sparse_cat` instead, currently # that erroneously allocates too many blocks that are # zero and shouldn't be stored. diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl index b9ab510566..d7ffe36487 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl @@ -92,27 +92,27 @@ end # function SparseArrayInterface.sparse_mapreduce(::BlockSparseArrayStyle, f, a_dest::AbstractArray, a_srcs::Vararg{AbstractArray}) # end -function Base.map!(f, a_dest::AbstractArray, a_srcs::Vararg{BlockSparseArrayLike}) +function Base.map!(f, a_dest::AbstractArray, a_srcs::Vararg{AnyAbstractBlockSparseArray}) sparse_map!(f, a_dest, a_srcs...) return a_dest end -function Base.map(f, as::Vararg{BlockSparseArrayLike}) +function Base.map(f, as::Vararg{AnyAbstractBlockSparseArray}) return f.(as...) end -function Base.copy!(a_dest::AbstractArray, a_src::BlockSparseArrayLike) +function Base.copy!(a_dest::AbstractArray, a_src::AnyAbstractBlockSparseArray) sparse_copy!(a_dest, a_src) return a_dest end -function Base.copyto!(a_dest::AbstractArray, a_src::BlockSparseArrayLike) +function Base.copyto!(a_dest::AbstractArray, a_src::AnyAbstractBlockSparseArray) sparse_copyto!(a_dest, a_src) return a_dest end # Fix ambiguity error -function Base.copyto!(a_dest::LayoutArray, a_src::BlockSparseArrayLike) +function Base.copyto!(a_dest::LayoutArray, a_src::AnyAbstractBlockSparseArray) sparse_copyto!(a_dest, a_src) return a_dest end @@ -131,21 +131,21 @@ function Base.copyto!( return a_dest end -function Base.permutedims!(a_dest, a_src::BlockSparseArrayLike, perm) +function Base.permutedims!(a_dest, a_src::AnyAbstractBlockSparseArray, perm) sparse_permutedims!(a_dest, a_src, perm) return a_dest end -function Base.mapreduce(f, op, as::Vararg{BlockSparseArrayLike}; kwargs...) +function Base.mapreduce(f, op, as::Vararg{AnyAbstractBlockSparseArray}; kwargs...) return sparse_mapreduce(f, op, as...; kwargs...) end # TODO: Why isn't this calling `mapreduce` already? -function Base.iszero(a::BlockSparseArrayLike) +function Base.iszero(a::AnyAbstractBlockSparseArray) return sparse_iszero(blocks(a)) end # TODO: Why isn't this calling `mapreduce` already? -function Base.isreal(a::BlockSparseArrayLike) +function Base.isreal(a::AnyAbstractBlockSparseArray) return sparse_isreal(blocks(a)) end diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/sparsearrayinterface.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/sparsearrayinterface.jl index ac866afc9a..96fc72a49a 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/sparsearrayinterface.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/sparsearrayinterface.jl @@ -33,6 +33,6 @@ function SparseArrayInterface.sparse_storage(a::AbstractBlockSparseArray) return BlockSparseStorage(a) end -function SparseArrayInterface.nstored(a::BlockSparseArrayLike) +function SparseArrayInterface.nstored(a::AnyAbstractBlockSparseArray) return sum(nstored, sparse_storage(blocks(a)); init=zero(Int)) end diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/views.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/views.jl index aa3c7711c6..4742f7b781 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/views.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/views.jl @@ -20,10 +20,12 @@ end # Override the default definition of `BlockArrays.blocksize`, # which is incorrect for certain slices. -function BlockArrays.blocksize(a::SubArray{<:Any,<:Any,<:BlockSparseArrayLike}) +function BlockArrays.blocksize(a::SubArray{<:Any,<:Any,<:AnyAbstractBlockSparseArray}) return blocklength.(axes(a)) end -function BlockArrays.blocksize(a::SubArray{<:Any,<:Any,<:BlockSparseArrayLike}, i::Int) +function BlockArrays.blocksize( + a::SubArray{<:Any,<:Any,<:AnyAbstractBlockSparseArray}, i::Int +) # TODO: Maybe use `blocklength(axes(a, i))` which would be a bit faster. return blocksize(a)[i] end @@ -33,7 +35,7 @@ end # which don't handle subslices of blocks properly. function Base.view( a::SubArray{ - <:Any,N,<:BlockSparseArrayLike,<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}} + <:Any,N,<:AnyAbstractBlockSparseArray,<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}} }, I::Block{N}, ) where {N} @@ -41,14 +43,14 @@ function Base.view( end function Base.view( a::SubArray{ - <:Any,N,<:BlockSparseArrayLike,<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}} + <:Any,N,<:AnyAbstractBlockSparseArray,<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}} }, I::Vararg{Block{1},N}, ) where {N} return blocksparse_view(a, I...) end function Base.view( - V::SubArray{<:Any,1,<:BlockSparseArrayLike,<:Tuple{BlockSlice{<:BlockRange{1}}}}, + V::SubArray{<:Any,1,<:AnyAbstractBlockSparseArray,<:Tuple{BlockSlice{<:BlockRange{1}}}}, I::Block{1}, ) return blocksparse_view(a, I) @@ -154,7 +156,7 @@ function BlockArrays.viewblock( return viewblock(a, to_tuple(block)...) end -# Fixes ambiguity error with `BlockSparseArrayLike` definition. +# Fixes ambiguity error with `AnyAbstractBlockSparseArray` definition. function Base.view( a::SubArray{ T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}} @@ -163,7 +165,7 @@ function Base.view( ) where {T,N} return viewblock(a, block) end -# Fixes ambiguity error with `BlockSparseArrayLike` definition. +# Fixes ambiguity error with `AnyAbstractBlockSparseArray` definition. function Base.view( a::SubArray{ T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}} diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl index e8d1e5e15b..c961f67e5a 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl @@ -16,20 +16,20 @@ const WrappedAbstractBlockSparseArray{T,N} = WrappedArray{ } # TODO: Rename `AnyBlockSparseArray`. -const BlockSparseArrayLike{T,N} = Union{ +const AnyAbstractBlockSparseArray{T,N} = Union{ <:AbstractBlockSparseArray{T,N},<:WrappedAbstractBlockSparseArray{T,N} } # a[1:2, 1:2] function Base.to_indices( - a::BlockSparseArrayLike, inds, I::Tuple{UnitRange{<:Integer},Vararg{Any}} + a::AnyAbstractBlockSparseArray, inds, I::Tuple{UnitRange{<:Integer},Vararg{Any}} ) return blocksparse_to_indices(a, inds, I) end # a[[Block(2), Block(1)], [Block(2), Block(1)]] function Base.to_indices( - a::BlockSparseArrayLike, inds, I::Tuple{Vector{<:Block{1}},Vararg{Any}} + a::AnyAbstractBlockSparseArray, inds, I::Tuple{Vector{<:Block{1}},Vararg{Any}} ) return blocksparse_to_indices(a, inds, I) end @@ -37,14 +37,16 @@ end # a[BlockVector([Block(2), Block(1)], [2]), BlockVector([Block(2), Block(1)], [2])] # a[BlockedVector([Block(2), Block(1)], [2]), BlockedVector([Block(2), Block(1)], [2])] function Base.to_indices( - a::BlockSparseArrayLike, inds, I::Tuple{AbstractBlockVector{<:Block{1}},Vararg{Any}} + a::AnyAbstractBlockSparseArray, + inds, + I::Tuple{AbstractBlockVector{<:Block{1}},Vararg{Any}}, ) return blocksparse_to_indices(a, inds, I) end # a[mortar([Block(1)[1:2], Block(2)[1:3]])] function Base.to_indices( - a::BlockSparseArrayLike, + a::AnyAbstractBlockSparseArray, inds, I::Tuple{BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}},Vararg{Any}}, ) @@ -53,13 +55,13 @@ end # a[[Block(1)[1:2], Block(2)[1:2]], [Block(1)[1:2], Block(2)[1:2]]] function Base.to_indices( - a::BlockSparseArrayLike, inds, I::Tuple{Vector{<:BlockIndexRange{1}},Vararg{Any}} + a::AnyAbstractBlockSparseArray, inds, I::Tuple{Vector{<:BlockIndexRange{1}},Vararg{Any}} ) return to_indices(a, inds, (mortar(I[1]), Base.tail(I)...)) end # BlockArrays `AbstractBlockArray` interface -BlockArrays.blocks(a::BlockSparseArrayLike) = blocksparse_blocks(a) +BlockArrays.blocks(a::AnyAbstractBlockSparseArray) = blocksparse_blocks(a) # Fix ambiguity error with `BlockArrays` using BlockArrays: BlockSlice @@ -74,59 +76,63 @@ function blockstype(arraytype::Type{<:WrappedAbstractBlockSparseArray}) return blockstype(parenttype(arraytype)) end -blocktype(a::BlockSparseArrayLike) = eltype(blocks(a)) -blocktype(arraytype::Type{<:BlockSparseArrayLike}) = eltype(blockstype(arraytype)) +blocktype(a::AnyAbstractBlockSparseArray) = eltype(blocks(a)) +blocktype(arraytype::Type{<:AnyAbstractBlockSparseArray}) = eltype(blockstype(arraytype)) using ArrayLayouts: ArrayLayouts -function Base.getindex(a::BlockSparseArrayLike{<:Any,N}, I::CartesianIndices{N}) where {N} +function Base.getindex( + a::AnyAbstractBlockSparseArray{<:Any,N}, I::CartesianIndices{N} +) where {N} return ArrayLayouts.layout_getindex(a, I) end function Base.getindex( - a::BlockSparseArrayLike{<:Any,N}, I::Vararg{AbstractUnitRange{<:Integer},N} + a::AnyAbstractBlockSparseArray{<:Any,N}, I::Vararg{AbstractUnitRange{<:Integer},N} ) where {N} return ArrayLayouts.layout_getindex(a, I...) end # TODO: Define `AnyBlockSparseMatrix`. function Base.getindex( - a::BlockSparseArrayLike{<:Any,2}, I::Vararg{AbstractUnitRange{<:Integer},2} + a::AnyAbstractBlockSparseArray{<:Any,2}, I::Vararg{AbstractUnitRange{<:Integer},2} ) return ArrayLayouts.layout_getindex(a, I...) end # Fixes ambiguity error. -function Base.getindex(a::BlockSparseArrayLike{<:Any,0}) +function Base.getindex(a::AnyAbstractBlockSparseArray{<:Any,0}) return ArrayLayouts.layout_getindex(a) end # TODO: Define `blocksparse_isassigned`. function Base.isassigned( - a::BlockSparseArrayLike{<:Any,N}, index::Vararg{Block{1},N} + a::AnyAbstractBlockSparseArray{<:Any,N}, index::Vararg{Block{1},N} ) where {N} return isassigned(blocks(a), Int.(index)...) end # Fix ambiguity error. -function Base.isassigned(a::BlockSparseArrayLike{<:Any,0}) +function Base.isassigned(a::AnyAbstractBlockSparseArray{<:Any,0}) return isassigned(blocks(a)) end -function Base.isassigned(a::BlockSparseArrayLike{<:Any,N}, index::Block{N}) where {N} +function Base.isassigned(a::AnyAbstractBlockSparseArray{<:Any,N}, index::Block{N}) where {N} return isassigned(a, Tuple(index)...) end # TODO: Define `blocksparse_isassigned`. function Base.isassigned( - a::BlockSparseArrayLike{<:Any,N}, index::Vararg{BlockIndex{1},N} + a::AnyAbstractBlockSparseArray{<:Any,N}, index::Vararg{BlockIndex{1},N} ) where {N} b = block.(index) return isassigned(a, b...) && isassigned(@view(a[b...]), blockindex.(index)...) end -function Base.setindex!(a::BlockSparseArrayLike{<:Any,N}, value, I::BlockIndex{N}) where {N} +function Base.setindex!( + a::AnyAbstractBlockSparseArray{<:Any,N}, value, I::BlockIndex{N} +) where {N} blocksparse_setindex!(a, value, I) return a end # Fixes ambiguity error with BlockArrays.jl -function Base.setindex!(a::BlockSparseArrayLike{<:Any,1}, value, I::BlockIndex{1}) +function Base.setindex!(a::AnyAbstractBlockSparseArray{<:Any,1}, value, I::BlockIndex{1}) blocksparse_setindex!(a, value, I) return a end @@ -141,7 +147,7 @@ function Base.fill!(a::AbstractBlockSparseArray, value) return a end -function Base.fill!(a::BlockSparseArrayLike, value) +function Base.fill!(a::AnyAbstractBlockSparseArray, value) # TODO: Even if `iszero(value)`, this doesn't drop # blocks from `a`, and additionally allocates # new blocks filled with zeros, unlike @@ -153,14 +159,15 @@ end # Needed by `BlockArrays` matrix multiplication interface function Base.similar( - arraytype::Type{<:BlockSparseArrayLike}, axes::Tuple{Vararg{AbstractUnitRange{<:Integer}}} + arraytype::Type{<:AnyAbstractBlockSparseArray}, + axes::Tuple{Vararg{AbstractUnitRange{<:Integer}}}, ) return similar(arraytype, eltype(arraytype), axes) end # Fixes ambiguity error. function Base.similar( - arraytype::Type{<:BlockSparseArrayLike}, axes::Tuple{Base.OneTo,Vararg{Base.OneTo}} + arraytype::Type{<:AnyAbstractBlockSparseArray}, axes::Tuple{Base.OneTo,Vararg{Base.OneTo}} ) return similar(arraytype, eltype(arraytype), axes) end @@ -170,7 +177,7 @@ end # is only appears to be needed in older versions of Julia like v1.6. # Delete once we drop support for older versions of Julia. function Base.similar( - arraytype::Type{<:BlockSparseArrayLike}, + arraytype::Type{<:AnyAbstractBlockSparseArray}, axes::Tuple{AbstractUnitRange{<:Integer},Vararg{AbstractUnitRange{<:Integer}}}, ) return similar(arraytype, eltype(arraytype), axes) @@ -178,7 +185,7 @@ end # Fixes ambiguity error with `BlockArrays`. function Base.similar( - arraytype::Type{<:BlockSparseArrayLike}, + arraytype::Type{<:AnyAbstractBlockSparseArray}, axes::Tuple{AbstractBlockedUnitRange{<:Integer},Vararg{AbstractUnitRange{<:Integer}}}, ) return similar(arraytype, eltype(arraytype), axes) @@ -186,7 +193,7 @@ end # Fixes ambiguity error with `BlockArrays`. function Base.similar( - arraytype::Type{<:BlockSparseArrayLike}, + arraytype::Type{<:AnyAbstractBlockSparseArray}, axes::Tuple{ AbstractUnitRange{<:Integer}, AbstractBlockedUnitRange{<:Integer}, @@ -198,7 +205,7 @@ end # Needed for disambiguation function Base.similar( - arraytype::Type{<:BlockSparseArrayLike}, + arraytype::Type{<:AnyAbstractBlockSparseArray}, axes::Tuple{Vararg{AbstractBlockedUnitRange{<:Integer}}}, ) return similar(arraytype, eltype(arraytype), axes) @@ -213,7 +220,7 @@ end # Needed by `BlockArrays` matrix multiplication interface # TODO: Define a `blocksparse_similar` function. function Base.similar( - arraytype::Type{<:BlockSparseArrayLike}, + arraytype::Type{<:AnyAbstractBlockSparseArray}, elt::Type, axes::Tuple{Vararg{AbstractUnitRange{<:Integer}}}, ) @@ -222,19 +229,21 @@ end # TODO: Define a `blocksparse_similar` function. function Base.similar( - a::BlockSparseArrayLike, elt::Type, axes::Tuple{Vararg{AbstractUnitRange{<:Integer}}} + a::AnyAbstractBlockSparseArray, + elt::Type, + axes::Tuple{Vararg{AbstractUnitRange{<:Integer}}}, ) return blocksparse_similar(a, elt, axes) end # Fixes ambiguity error. -function Base.similar(a::BlockSparseArrayLike, elt::Type, axes::Tuple{}) +function Base.similar(a::AnyAbstractBlockSparseArray, elt::Type, axes::Tuple{}) return blocksparse_similar(a, elt, axes) end # Fixes ambiguity error with `BlockArrays`. function Base.similar( - a::BlockSparseArrayLike, + a::AnyAbstractBlockSparseArray, elt::Type, axes::Tuple{ AbstractBlockedUnitRange{<:Integer},Vararg{AbstractBlockedUnitRange{<:Integer}} @@ -245,7 +254,7 @@ end # Fixes ambiguity error with `OffsetArrays`. function Base.similar( - a::BlockSparseArrayLike, + a::AnyAbstractBlockSparseArray, elt::Type, axes::Tuple{AbstractUnitRange{<:Integer},Vararg{AbstractUnitRange{<:Integer}}}, ) @@ -254,7 +263,7 @@ end # Fixes ambiguity error with `BlockArrays`. function Base.similar( - a::BlockSparseArrayLike, + a::AnyAbstractBlockSparseArray, elt::Type, axes::Tuple{AbstractBlockedUnitRange{<:Integer},Vararg{AbstractUnitRange{<:Integer}}}, ) @@ -263,7 +272,7 @@ end # Fixes ambiguity errors with BlockArrays. function Base.similar( - a::BlockSparseArrayLike, + a::AnyAbstractBlockSparseArray, elt::Type, axes::Tuple{ AbstractUnitRange{<:Integer}, @@ -276,7 +285,7 @@ end # Fixes ambiguity error with `StaticArrays`. function Base.similar( - a::BlockSparseArrayLike, elt::Type, axes::Tuple{Base.OneTo,Vararg{Base.OneTo}} + a::AnyAbstractBlockSparseArray, elt::Type, axes::Tuple{Base.OneTo,Vararg{Base.OneTo}} ) return blocksparse_similar(a, elt, axes) end @@ -285,7 +294,7 @@ end # which is ultimately what `Array{T,N}(::AbstractArray{<:Any,N})` calls. # These are defined for now to avoid scalar indexing issues when there # are blocks on GPU. -function Base.Array{T,N}(a::BlockSparseArrayLike{<:Any,N}) where {T,N} +function Base.Array{T,N}(a::AnyAbstractBlockSparseArray{<:Any,N}) where {T,N} # First make it dense, then move to CPU. # Directly copying to CPU causes some issues with # scalar indexing on GPU which we have to investigate. @@ -293,9 +302,9 @@ function Base.Array{T,N}(a::BlockSparseArrayLike{<:Any,N}) where {T,N} a_dest .= a return Array{T,N}(a_dest) end -function Base.Array{T}(a::BlockSparseArrayLike) where {T} +function Base.Array{T}(a::AnyAbstractBlockSparseArray) where {T} return Array{T,ndims(a)}(a) end -function Base.Array(a::BlockSparseArrayLike) +function Base.Array(a::AnyAbstractBlockSparseArray) return Array{eltype(a)}(a) end diff --git a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearray/blocksparsearray.jl b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearray/blocksparsearray.jl index 50d52a59ca..8c5d60b65f 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearray/blocksparsearray.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearray/blocksparsearray.jl @@ -141,7 +141,7 @@ end Base.axes(a::BlockSparseArray) = a.axes # BlockArrays `AbstractBlockArray` interface. -# This is used by `blocks(::BlockSparseArrayLike)`. +# This is used by `blocks(::AnyAbstractBlockSparseArray)`. blocksparse_blocks(a::BlockSparseArray) = a.blocks # TODO: Use `TypeParameterAccessors`. diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/arraylayouts.jl b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/arraylayouts.jl index 58176846ca..293d58f3ce 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/arraylayouts.jl +++ b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/arraylayouts.jl @@ -2,7 +2,7 @@ using ArrayLayouts: ArrayLayouts, Dot, DualLayout, MatMulMatAdd, MatMulVecAdd, M using LinearAlgebra: Adjoint, Transpose using ..TypeParameterAccessors: parenttype -function ArrayLayouts.MemoryLayout(arraytype::Type{<:SparseArrayLike}) +function ArrayLayouts.MemoryLayout(arraytype::Type{<:AnyAbstractSparseArray}) return SparseLayout() end diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/base.jl b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/base.jl index 8480b2fd88..5be8c9c1b3 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/base.jl +++ b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/base.jl @@ -1,18 +1,18 @@ using ..SparseArrayInterface: SparseArrayInterface # Base -function Base.:(==)(a1::SparseArrayLike, a2::SparseArrayLike) +function Base.:(==)(a1::AnyAbstractSparseArray, a2::AnyAbstractSparseArray) return SparseArrayInterface.sparse_isequal(a1, a2) end -function Base.reshape(a::SparseArrayLike, dims::Tuple{Vararg{Int}}) +function Base.reshape(a::AnyAbstractSparseArray, dims::Tuple{Vararg{Int}}) return SparseArrayInterface.sparse_reshape(a, dims) end -function Base.zero(a::SparseArrayLike) +function Base.zero(a::AnyAbstractSparseArray) return SparseArrayInterface.sparse_zero(a) end -function Base.one(a::SparseArrayLike) +function Base.one(a::AnyAbstractSparseArray) return SparseArrayInterface.sparse_one(a) end diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/broadcast.jl b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/broadcast.jl index fdade0f775..de67af5495 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/broadcast.jl +++ b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/broadcast.jl @@ -1,4 +1,4 @@ # Broadcasting -function Broadcast.BroadcastStyle(arraytype::Type{<:SparseArrayLike}) +function Broadcast.BroadcastStyle(arraytype::Type{<:AnyAbstractSparseArray}) return SparseArrayInterface.SparseArrayStyle{ndims(arraytype)}() end diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/cat.jl b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/cat.jl index a9db504e38..3d0475159c 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/cat.jl +++ b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/cat.jl @@ -1,4 +1,4 @@ # TODO: Change to `AnyAbstractSparseArray`. -function Base.cat(as::SparseArrayLike...; dims) +function Base.cat(as::AnyAbstractSparseArray...; dims) return sparse_cat(as...; dims) end diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/map.jl b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/map.jl index bc85aa1099..4dd96f907b 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/map.jl +++ b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/map.jl @@ -1,42 +1,42 @@ using ArrayLayouts: LayoutArray # Map -function Base.map!(f, a_dest::AbstractArray, a_srcs::Vararg{SparseArrayLike}) +function Base.map!(f, a_dest::AbstractArray, a_srcs::Vararg{AnyAbstractSparseArray}) SparseArrayInterface.sparse_map!(f, a_dest, a_srcs...) return a_dest end -function Base.copy!(a_dest::AbstractArray, a_src::SparseArrayLike) +function Base.copy!(a_dest::AbstractArray, a_src::AnyAbstractSparseArray) SparseArrayInterface.sparse_copy!(a_dest, a_src) return a_dest end -function Base.copyto!(a_dest::AbstractArray, a_src::SparseArrayLike) +function Base.copyto!(a_dest::AbstractArray, a_src::AnyAbstractSparseArray) SparseArrayInterface.sparse_copyto!(a_dest, a_src) return a_dest end # Fix ambiguity error -function Base.copyto!(a_dest::LayoutArray, a_src::SparseArrayLike) +function Base.copyto!(a_dest::LayoutArray, a_src::AnyAbstractSparseArray) SparseArrayInterface.sparse_copyto!(a_dest, a_src) return a_dest end -function Base.permutedims!(a_dest::AbstractArray, a_src::SparseArrayLike, perm) +function Base.permutedims!(a_dest::AbstractArray, a_src::AnyAbstractSparseArray, perm) SparseArrayInterface.sparse_permutedims!(a_dest, a_src, perm) return a_dest end -function Base.mapreduce(f, op, as::Vararg{SparseArrayLike}; kwargs...) +function Base.mapreduce(f, op, as::Vararg{AnyAbstractSparseArray}; kwargs...) return SparseArrayInterface.sparse_mapreduce(f, op, as...; kwargs...) end # TODO: Why isn't this calling `mapreduce` already? -function Base.iszero(a::SparseArrayLike) +function Base.iszero(a::AnyAbstractSparseArray) return SparseArrayInterface.sparse_iszero(a) end # TODO: Why isn't this calling `mapreduce` already? -function Base.isreal(a::SparseArrayLike) +function Base.isreal(a::AnyAbstractSparseArray) return SparseArrayInterface.sparse_isreal(a) end diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/wrappedabstractsparsearray.jl b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/wrappedabstractsparsearray.jl index e42ac91e8b..f9ec08acb7 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/wrappedabstractsparsearray.jl +++ b/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/wrappedabstractsparsearray.jl @@ -4,6 +4,6 @@ const WrappedAbstractSparseArray{T,N,A} = WrappedArray{ T,N,<:AbstractSparseArray,<:AbstractSparseArray{T,N} } -const SparseArrayLike{T,N} = Union{ +const AnyAbstractSparseArray{T,N} = Union{ <:AbstractSparseArray{T,N},<:WrappedAbstractSparseArray{T,N} }