diff --git a/NDTensors/src/backup/arraystorage/blocksparsearray/storage/contract.jl b/NDTensors/src/backup/arraystorage/blocksparsearray/storage/contract.jl index b733c37706..7a8bf5217c 100644 --- a/NDTensors/src/backup/arraystorage/blocksparsearray/storage/contract.jl +++ b/NDTensors/src/backup/arraystorage/blocksparsearray/storage/contract.jl @@ -1,4 +1,4 @@ -# TODO: Define in `SparseArrayInterface`. +# TODO: Define in `SparseArraysBase`. using ..SparseArrayDOKs: SparseArrayDOK # TODO: This is inefficient, need to optimize. diff --git a/NDTensors/src/backup/arraystorage/diagonalarray/storage/contract.jl b/NDTensors/src/backup/arraystorage/diagonalarray/storage/contract.jl index de1455d78a..5e53d2bd22 100644 --- a/NDTensors/src/backup/arraystorage/diagonalarray/storage/contract.jl +++ b/NDTensors/src/backup/arraystorage/diagonalarray/storage/contract.jl @@ -1,4 +1,4 @@ -using .SparseArrayInterface: densearray +using .SparseArraysBase: densearray using .DiagonalArrays: DiagIndex, diaglength using .TypeParameterAccessors: unwrap_array_type diff --git a/NDTensors/src/imports.jl b/NDTensors/src/imports.jl index 77d0d6c1d6..a78cc2736d 100644 --- a/NDTensors/src/imports.jl +++ b/NDTensors/src/imports.jl @@ -38,7 +38,7 @@ for lib in [ :SymmetrySectors, :TensorAlgebra, :NestedPermutedDimsArrays, - :SparseArrayInterface, + :SparseArraysBase, :SparseArrayDOKs, :DiagonalArrays, :BlockSparseArrays, diff --git a/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/test/runtests.jl b/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/test/runtests.jl index 9296f22f2d..2c2a504df5 100644 --- a/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/test/runtests.jl +++ b/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/test/runtests.jl @@ -13,7 +13,7 @@ using NDTensors.GradedAxes: gradedrange, isdual using NDTensors.LabelledNumbers: label -using NDTensors.SparseArrayInterface: stored_length +using NDTensors.SparseArraysBase: stored_length using NDTensors.SymmetrySectors: U1 using NDTensors.TensorAlgebra: fusedims, splitdims using LinearAlgebra: adjoint diff --git a/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysTensorAlgebraExt/test/runtests.jl b/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysTensorAlgebraExt/test/runtests.jl index 38914a22ae..e5c1e5069e 100644 --- a/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysTensorAlgebraExt/test/runtests.jl +++ b/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysTensorAlgebraExt/test/runtests.jl @@ -2,7 +2,7 @@ using Test: @test, @testset using NDTensors.BlockSparseArrays: BlockSparseArray using NDTensors.TensorAlgebra: contract -using NDTensors.SparseArrayInterface: densearray +using NDTensors.SparseArraysBase: densearray @testset "BlockSparseArraysTensorAlgebraExt (eltype=$elt)" for elt in ( Float32, Float64, Complex{Float32}, Complex{Float64} ) diff --git a/NDTensors/src/lib/BlockSparseArrays/src/BlockArraysExtensions/BlockArraysExtensions.jl b/NDTensors/src/lib/BlockSparseArrays/src/BlockArraysExtensions/BlockArraysExtensions.jl index 67d667353e..98d58c1050 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/BlockArraysExtensions/BlockArraysExtensions.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/BlockArraysExtensions/BlockArraysExtensions.jl @@ -22,7 +22,7 @@ using BlockArrays: using Compat: allequal using Dictionaries: Dictionary, Indices using ..GradedAxes: blockedunitrange_getindices, to_blockindices -using ..SparseArrayInterface: SparseArrayInterface, stored_length, stored_indices +using ..SparseArraysBase: SparseArraysBase, stored_length, stored_indices # A return type for `blocks(array)` when `array` isn't blocked. # Represents a vector with just that single block. @@ -534,7 +534,7 @@ function Base.setindex!(a::BlockView{<:Any,N}, value, index::Vararg{Int,N}) wher return a end -function SparseArrayInterface.stored_length(a::BlockView) +function SparseArraysBase.stored_length(a::BlockView) # TODO: Store whether or not the block is stored already as # a Bool in `BlockView`. I = CartesianIndex(Int.(a.block)) diff --git a/NDTensors/src/lib/BlockSparseArrays/src/BlockArraysSparseArrayInterfaceExt/BlockArraysSparseArrayInterfaceExt.jl b/NDTensors/src/lib/BlockSparseArrays/src/BlockArraysSparseArraysBaseExt/BlockArraysSparseArraysBaseExt.jl similarity index 51% rename from NDTensors/src/lib/BlockSparseArrays/src/BlockArraysSparseArrayInterfaceExt/BlockArraysSparseArrayInterfaceExt.jl rename to NDTensors/src/lib/BlockSparseArrays/src/BlockArraysSparseArraysBaseExt/BlockArraysSparseArraysBaseExt.jl index 335c37b0fb..56b0080d92 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/BlockArraysSparseArrayInterfaceExt/BlockArraysSparseArrayInterfaceExt.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/BlockArraysSparseArraysBaseExt/BlockArraysSparseArraysBaseExt.jl @@ -1,11 +1,11 @@ using BlockArrays: AbstractBlockArray, BlocksView -using ..SparseArrayInterface: SparseArrayInterface, stored_length +using ..SparseArraysBase: SparseArraysBase, stored_length -function SparseArrayInterface.stored_length(a::AbstractBlockArray) +function SparseArraysBase.stored_length(a::AbstractBlockArray) return sum(b -> stored_length(b), blocks(a); init=zero(Int)) end # TODO: Handle `BlocksView` wrapping a sparse array? -function SparseArrayInterface.storage_indices(a::BlocksView) +function SparseArraysBase.storage_indices(a::BlocksView) return CartesianIndices(a) end diff --git a/NDTensors/src/lib/BlockSparseArrays/src/BlockSparseArrays.jl b/NDTensors/src/lib/BlockSparseArrays/src/BlockSparseArrays.jl index dc43ba560a..576fe03ce6 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/BlockSparseArrays.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/BlockSparseArrays.jl @@ -21,7 +21,7 @@ include("abstractblocksparsearray/linearalgebra.jl") include("abstractblocksparsearray/cat.jl") include("blocksparsearray/defaults.jl") include("blocksparsearray/blocksparsearray.jl") -include("BlockArraysSparseArrayInterfaceExt/BlockArraysSparseArrayInterfaceExt.jl") +include("BlockArraysSparseArraysBaseExt/BlockArraysSparseArraysBaseExt.jl") include("../ext/BlockSparseArraysTensorAlgebraExt/src/BlockSparseArraysTensorAlgebraExt.jl") include("../ext/BlockSparseArraysGradedAxesExt/src/BlockSparseArraysGradedAxesExt.jl") include("../ext/BlockSparseArraysAdaptExt/src/BlockSparseArraysAdaptExt.jl") diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/abstractblocksparsearray.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/abstractblocksparsearray.jl index ca21af2136..cfe1ef5ab6 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/abstractblocksparsearray.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/abstractblocksparsearray.jl @@ -1,6 +1,6 @@ using BlockArrays: BlockArrays, AbstractBlockArray, Block, BlockIndex, BlockedUnitRange, blocks -using ..SparseArrayInterface: sparse_getindex, sparse_setindex! +using ..SparseArraysBase: sparse_getindex, sparse_setindex! # TODO: Delete this. This function was replaced # by `stored_length` but is still used in `NDTensors`. diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/arraylayouts.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/arraylayouts.jl index 7b8088ff2b..4e79b8fb81 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/arraylayouts.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/arraylayouts.jl @@ -1,6 +1,6 @@ using ArrayLayouts: ArrayLayouts, DualLayout, MemoryLayout, MulAdd using BlockArrays: BlockLayout -using ..SparseArrayInterface: SparseLayout +using ..SparseArraysBase: SparseLayout using ..TypeParameterAccessors: parenttype, similartype function ArrayLayouts.MemoryLayout(arraytype::Type{<:AnyAbstractBlockSparseArray}) diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl index d7ffe36487..30ca37c53b 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/map.jl @@ -1,8 +1,8 @@ using ArrayLayouts: LayoutArray using BlockArrays: blockisequal using LinearAlgebra: Adjoint, Transpose -using ..SparseArrayInterface: - SparseArrayInterface, +using ..SparseArraysBase: + SparseArraysBase, SparseArrayStyle, sparse_map!, sparse_copy!, @@ -62,7 +62,7 @@ end # is used to determine `union_stored_blocked_cartesianindices(...)`). # `reblock` is a partial solution to that, but a bit ad-hoc. # TODO: Move to `blocksparsearrayinterface/map.jl`. -function SparseArrayInterface.sparse_map!( +function SparseArraysBase.sparse_map!( ::BlockSparseArrayStyle, f, a_dest::AbstractArray, a_srcs::Vararg{AbstractArray} ) a_dest, a_srcs = reblock(a_dest), reblock.(a_srcs) @@ -89,7 +89,7 @@ function SparseArrayInterface.sparse_map!( end # TODO: Implement this. -# function SparseArrayInterface.sparse_mapreduce(::BlockSparseArrayStyle, f, a_dest::AbstractArray, a_srcs::Vararg{AbstractArray}) +# function SparseArraysBase.sparse_mapreduce(::BlockSparseArrayStyle, f, a_dest::AbstractArray, a_srcs::Vararg{AbstractArray}) # end function Base.map!(f, a_dest::AbstractArray, a_srcs::Vararg{AnyAbstractBlockSparseArray}) diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/sparsearrayinterface.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/sparsearrayinterface.jl index 691aad5f2b..31dbca27e7 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/sparsearrayinterface.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/sparsearrayinterface.jl @@ -1,5 +1,5 @@ using BlockArrays: Block -using ..SparseArrayInterface: SparseArrayInterface, sparse_storage, stored_indices +using ..SparseArraysBase: SparseArraysBase, sparse_storage, stored_indices # Structure storing the block sparse storage struct BlockSparseStorage{Arr<:AbstractBlockSparseArray} @@ -29,10 +29,10 @@ function Base.iterate(s::BlockSparseStorage, args...) return iterate(values(s), args...) end -function SparseArrayInterface.sparse_storage(a::AbstractBlockSparseArray) +function SparseArraysBase.sparse_storage(a::AbstractBlockSparseArray) return BlockSparseStorage(a) end -function SparseArrayInterface.stored_length(a::AnyAbstractBlockSparseArray) +function SparseArraysBase.stored_length(a::AnyAbstractBlockSparseArray) return sum(stored_length, sparse_storage(blocks(a)); init=zero(Int)) end diff --git a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/arraylayouts.jl b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/arraylayouts.jl index 483c53f835..f7d02ae554 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/arraylayouts.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/arraylayouts.jl @@ -1,6 +1,6 @@ using ArrayLayouts: ArrayLayouts, Dot, MatMulMatAdd, MatMulVecAdd, MulAdd using BlockArrays: BlockLayout -using ..SparseArrayInterface: SparseLayout +using ..SparseArraysBase: SparseLayout using LinearAlgebra: dot, mul! function blocksparse_muladd!( diff --git a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl index b6374671db..4e9b85a958 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl @@ -13,7 +13,7 @@ using BlockArrays: blocks, findblockindex using LinearAlgebra: Adjoint, Transpose -using ..SparseArrayInterface: perm, iperm, stored_length, sparse_zero! +using ..SparseArraysBase: perm, iperm, stored_length, sparse_zero! blocksparse_blocks(a::AbstractArray) = error("Not implemented") @@ -142,8 +142,7 @@ end # BlockArrays -using ..SparseArrayInterface: - SparseArrayInterface, AbstractSparseArray, AbstractSparseMatrix +using ..SparseArraysBase: SparseArraysBase, AbstractSparseArray, AbstractSparseMatrix _perm(::PermutedDimsArray{<:Any,<:Any,perm}) where {perm} = perm _invperm(::PermutedDimsArray{<:Any,<:Any,<:Any,invperm}) where {invperm} = invperm @@ -170,16 +169,16 @@ function Base.getindex( blocks(parent(a.array))[_getindices(index, _invperm(a.array))...], _perm(a.array) ) end -function SparseArrayInterface.stored_indices(a::SparsePermutedDimsArrayBlocks) +function SparseArraysBase.stored_indices(a::SparsePermutedDimsArrayBlocks) return map(I -> _getindices(I, _perm(a.array)), stored_indices(blocks(parent(a.array)))) end # TODO: Either make this the generic interface or define -# `SparseArrayInterface.sparse_storage`, which is used +# `SparseArraysBase.sparse_storage`, which is used # to defined this. -function SparseArrayInterface.stored_length(a::SparsePermutedDimsArrayBlocks) +function SparseArraysBase.stored_length(a::SparsePermutedDimsArrayBlocks) return length(stored_indices(a)) end -function SparseArrayInterface.sparse_storage(a::SparsePermutedDimsArrayBlocks) +function SparseArraysBase.sparse_storage(a::SparsePermutedDimsArrayBlocks) return error("Not implemented") end @@ -241,22 +240,22 @@ function Base.isassigned(a::SparseSubArrayBlocks{<:Any,N}, I::Vararg{Int,N}) whe # TODO: Implement this properly. return true end -function SparseArrayInterface.stored_indices(a::SparseSubArrayBlocks) +function SparseArraysBase.stored_indices(a::SparseSubArrayBlocks) return stored_indices(view(blocks(parent(a.array)), blockrange(a)...)) end # TODO: Either make this the generic interface or define -# `SparseArrayInterface.sparse_storage`, which is used +# `SparseArraysBase.sparse_storage`, which is used # to defined this. -SparseArrayInterface.stored_length(a::SparseSubArrayBlocks) = length(stored_indices(a)) +SparseArraysBase.stored_length(a::SparseSubArrayBlocks) = length(stored_indices(a)) ## struct SparseSubArrayBlocksStorage{Array<:SparseSubArrayBlocks} ## array::Array ## end -function SparseArrayInterface.sparse_storage(a::SparseSubArrayBlocks) +function SparseArraysBase.sparse_storage(a::SparseSubArrayBlocks) return map(I -> a[I], stored_indices(a)) end -function SparseArrayInterface.getindex_zero_function(a::SparseSubArrayBlocks) +function SparseArraysBase.getindex_zero_function(a::SparseSubArrayBlocks) # TODO: Base it off of `getindex_zero_function(blocks(parent(a.array))`, but replace the # axes with `axes(a.array)`. return BlockZero(axes(a.array)) @@ -272,4 +271,4 @@ function blocksparse_blocks( end using BlockArrays: BlocksView -SparseArrayInterface.stored_length(a::BlocksView) = length(a) +SparseArraysBase.stored_length(a::BlocksView) = length(a) diff --git a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/cat.jl b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/cat.jl index 22d1a24a02..b2d6596bd5 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/cat.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/cat.jl @@ -1,9 +1,9 @@ using BlockArrays: AbstractBlockedUnitRange, blockedrange, blocklengths -using NDTensors.SparseArrayInterface: SparseArrayInterface, allocate_cat_output, sparse_cat! +using NDTensors.SparseArraysBase: SparseArraysBase, allocate_cat_output, sparse_cat! -# TODO: Maybe move to `SparseArrayInterfaceBlockArraysExt`. -# TODO: Handle dual graded unit ranges, for example in a new `SparseArrayInterfaceGradedAxesExt`. -function SparseArrayInterface.axis_cat( +# TODO: Maybe move to `SparseArraysBaseBlockArraysExt`. +# TODO: Handle dual graded unit ranges, for example in a new `SparseArraysBaseGradedAxesExt`. +function SparseArraysBase.axis_cat( a1::AbstractBlockedUnitRange, a2::AbstractBlockedUnitRange ) return blockedrange(vcat(blocklengths(a1), blocklengths(a2))) diff --git a/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl b/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl index ddf0d46eb1..fe4ca22332 100644 --- a/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl +++ b/NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl @@ -30,7 +30,7 @@ using NDTensors.BlockSparseArrays: blocktype, view! using NDTensors.GPUArraysCoreExtensions: cpu -using NDTensors.SparseArrayInterface: stored_length +using NDTensors.SparseArraysBase: stored_length using NDTensors.SparseArrayDOKs: SparseArrayDOK, SparseMatrixDOK, SparseVectorDOK using NDTensors.TensorAlgebra: contract using Test: @test, @test_broken, @test_throws, @testset, @inferred diff --git a/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/abstractdiagonalarray.jl b/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/abstractdiagonalarray.jl index b6131450cf..8180a61472 100644 --- a/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/abstractdiagonalarray.jl +++ b/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/abstractdiagonalarray.jl @@ -1,3 +1,3 @@ -using ..SparseArrayInterface: AbstractSparseArray +using ..SparseArraysBase: AbstractSparseArray abstract type AbstractDiagonalArray{T,N} <: AbstractSparseArray{T,N} end diff --git a/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/arraylayouts.jl b/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/arraylayouts.jl index bae6f80e8f..d8f0b41dbe 100644 --- a/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/arraylayouts.jl +++ b/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/arraylayouts.jl @@ -1,5 +1,5 @@ using ArrayLayouts: ArrayLayouts -using ..SparseArrayInterface: AbstractSparseLayout +using ..SparseArraysBase: AbstractSparseLayout abstract type AbstractDiagonalLayout <: AbstractSparseLayout end struct DiagonalLayout <: AbstractDiagonalLayout end diff --git a/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/diagonalarraydiaginterface.jl b/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/diagonalarraydiaginterface.jl index 5f76a6abe0..bcc2c81cbd 100644 --- a/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/diagonalarraydiaginterface.jl +++ b/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/diagonalarraydiaginterface.jl @@ -1,6 +1,6 @@ -using ..SparseArrayInterface: SparseArrayInterface, StorageIndex, StorageIndices +using ..SparseArraysBase: SparseArraysBase, StorageIndex, StorageIndices -SparseArrayInterface.StorageIndex(i::DiagIndex) = StorageIndex(index(i)) +SparseArraysBase.StorageIndex(i::DiagIndex) = StorageIndex(index(i)) function Base.getindex(a::AbstractDiagonalArray, i::DiagIndex) return a[StorageIndex(i)] @@ -11,7 +11,7 @@ function Base.setindex!(a::AbstractDiagonalArray, value, i::DiagIndex) return a end -SparseArrayInterface.StorageIndices(i::DiagIndices) = StorageIndices(indices(i)) +SparseArraysBase.StorageIndices(i::DiagIndices) = StorageIndices(indices(i)) function Base.getindex(a::AbstractDiagonalArray, i::DiagIndices) return a[StorageIndices(i)] diff --git a/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/sparsearrayinterface.jl b/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/sparsearrayinterface.jl index 32036920a1..98762bbbca 100644 --- a/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/sparsearrayinterface.jl +++ b/NDTensors/src/lib/DiagonalArrays/src/abstractdiagonalarray/sparsearrayinterface.jl @@ -1,20 +1,20 @@ using Compat: Returns, allequal -using ..SparseArrayInterface: SparseArrayInterface +using ..SparseArraysBase: SparseArraysBase -# `SparseArrayInterface` interface -function SparseArrayInterface.index_to_storage_index( +# `SparseArraysBase` interface +function SparseArraysBase.index_to_storage_index( a::AbstractDiagonalArray{<:Any,N}, I::CartesianIndex{N} ) where {N} !allequal(Tuple(I)) && return nothing return first(Tuple(I)) end -function SparseArrayInterface.storage_index_to_index(a::AbstractDiagonalArray, I) +function SparseArraysBase.storage_index_to_index(a::AbstractDiagonalArray, I) return CartesianIndex(ntuple(Returns(I), ndims(a))) end ## # 1-dimensional case can be `AbstractDiagonalArray`. -## function SparseArrayInterface.sparse_similar( +## function SparseArraysBase.sparse_similar( ## a::AbstractDiagonalArray, elt::Type, dims::Tuple{Int} ## ) ## # TODO: Handle preserving zero element function. diff --git a/NDTensors/src/lib/DiagonalArrays/src/diagonalarray/diagonalarray.jl b/NDTensors/src/lib/DiagonalArrays/src/diagonalarray/diagonalarray.jl index cc1f0a0df2..c8ab3c1348 100644 --- a/NDTensors/src/lib/DiagonalArrays/src/diagonalarray/diagonalarray.jl +++ b/NDTensors/src/lib/DiagonalArrays/src/diagonalarray/diagonalarray.jl @@ -1,4 +1,4 @@ -using ..SparseArrayInterface: Zero, getindex_zero_function +using ..SparseArraysBase: Zero, getindex_zero_function # TODO: Put into `DiagonalArraysSparseArrayDOKsExt`? using ..SparseArrayDOKs: SparseArrayDOKs, SparseArrayDOK @@ -88,20 +88,20 @@ function Base.similar(a::DiagonalArray, elt::Type, dims::Tuple{Vararg{Int}}) return DiagonalArray{elt}(undef, dims, getindex_zero_function(a)) end -# Minimal `SparseArrayInterface` interface -SparseArrayInterface.sparse_storage(a::DiagonalArray) = a.diag +# Minimal `SparseArraysBase` interface +SparseArraysBase.sparse_storage(a::DiagonalArray) = a.diag -# `SparseArrayInterface` +# `SparseArraysBase` # Defines similar when the output can't be `DiagonalArray`, # such as in `reshape`. # TODO: Put into `DiagonalArraysSparseArrayDOKsExt`? # TODO: Special case 2D to output `SparseMatrixCSC`? -function SparseArrayInterface.sparse_similar( +function SparseArraysBase.sparse_similar( a::DiagonalArray, elt::Type, dims::Tuple{Vararg{Int}} ) return SparseArrayDOK{elt}(undef, dims, getindex_zero_function(a)) end -function SparseArrayInterface.getindex_zero_function(a::DiagonalArray) +function SparseArraysBase.getindex_zero_function(a::DiagonalArray) return a.zero end diff --git a/NDTensors/src/lib/DiagonalArrays/test/runtests.jl b/NDTensors/src/lib/DiagonalArrays/test/runtests.jl index 6b90974f81..ed6a0065d7 100644 --- a/NDTensors/src/lib/DiagonalArrays/test/runtests.jl +++ b/NDTensors/src/lib/DiagonalArrays/test/runtests.jl @@ -2,7 +2,7 @@ using Test: @test, @testset, @test_broken using NDTensors.DiagonalArrays: DiagonalArrays, DiagonalArray, DiagonalMatrix, diaglength using NDTensors.SparseArrayDOKs: SparseArrayDOK -using NDTensors.SparseArrayInterface: stored_length +using NDTensors.SparseArraysBase: stored_length @testset "Test NDTensors.DiagonalArrays" begin @testset "README" begin @test include( diff --git a/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArrayInterfaceExt/src/NamedDimsArraysSparseArrayInterfaceExt.jl b/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArrayInterfaceExt/src/NamedDimsArraysSparseArrayInterfaceExt.jl deleted file mode 100644 index 3816b9d470..0000000000 --- a/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArrayInterfaceExt/src/NamedDimsArraysSparseArrayInterfaceExt.jl +++ /dev/null @@ -1,3 +0,0 @@ -module NamedDimsArraysSparseArrayInterfaceExt -include("densearray.jl") -end diff --git a/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArraysBaseExt/src/NamedDimsArraysSparseArraysBaseExt.jl b/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArraysBaseExt/src/NamedDimsArraysSparseArraysBaseExt.jl new file mode 100644 index 0000000000..aef726d2dc --- /dev/null +++ b/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArraysBaseExt/src/NamedDimsArraysSparseArraysBaseExt.jl @@ -0,0 +1,3 @@ +module NamedDimsArraysSparseArraysBaseExt +include("densearray.jl") +end diff --git a/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArrayInterfaceExt/src/densearray.jl b/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArraysBaseExt/src/densearray.jl similarity index 67% rename from NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArrayInterfaceExt/src/densearray.jl rename to NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArraysBaseExt/src/densearray.jl index 059019a05a..db9da0c76c 100644 --- a/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArrayInterfaceExt/src/densearray.jl +++ b/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArraysBaseExt/src/densearray.jl @@ -1,8 +1,8 @@ using ..NamedDimsArrays: AbstractNamedDimsArray, dimnames, named, unname -using ...SparseArrayInterface: SparseArrayInterface, densearray +using ...SparseArraysBase: SparseArraysBase, densearray # TODO: Use `Adapt` or some kind of rewrap function like in # ArrayInterface.jl (https://github.com/JuliaArrays/ArrayInterface.jl/issues/136) -function SparseArrayInterface.densearray(na::AbstractNamedDimsArray) +function SparseArraysBase.densearray(na::AbstractNamedDimsArray) return named(densearray(unname(na)), dimnames(na)) end diff --git a/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArrayInterfaceExt/test/Project.toml b/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArraysBaseExt/test/Project.toml similarity index 100% rename from NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArrayInterfaceExt/test/Project.toml rename to NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArraysBaseExt/test/Project.toml diff --git a/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArrayInterfaceExt/test/runtests.jl b/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArraysBaseExt/test/runtests.jl similarity index 56% rename from NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArrayInterfaceExt/test/runtests.jl rename to NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArraysBaseExt/test/runtests.jl index 2355e42714..bc87d642fb 100644 --- a/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArrayInterfaceExt/test/runtests.jl +++ b/NDTensors/src/lib/NamedDimsArrays/ext/NamedDimsArraysSparseArraysBaseExt/test/runtests.jl @@ -1,10 +1,9 @@ @eval module $(gensym()) using LinearAlgebra: Diagonal using Test: @test, @testset -using NDTensors.SparseArrayInterface: densearray +using NDTensors.SparseArraysBase: densearray using NDTensors.NamedDimsArrays: named, unname -@testset "NamedDimsArraysSparseArrayInterfaceExt (eltype=$elt)" for elt in - (Float32, Float64) +@testset "NamedDimsArraysSparseArraysBaseExt (eltype=$elt)" for elt in (Float32, Float64) na = named(Diagonal(randn(2)), ("i", "j")) na_dense = densearray(na) @test na ≈ na_dense diff --git a/NDTensors/src/lib/NamedDimsArrays/src/NamedDimsArrays.jl b/NDTensors/src/lib/NamedDimsArrays/src/NamedDimsArrays.jl index f46ef6d910..71d1a78c95 100644 --- a/NDTensors/src/lib/NamedDimsArrays/src/NamedDimsArrays.jl +++ b/NDTensors/src/lib/NamedDimsArrays/src/NamedDimsArrays.jl @@ -21,7 +21,7 @@ include("broadcast.jl") # Extensions include("../ext/NamedDimsArraysAdaptExt/src/NamedDimsArraysAdaptExt.jl") include( - "../ext/NamedDimsArraysSparseArrayInterfaceExt/src/NamedDimsArraysSparseArrayInterfaceExt.jl", + "../ext/NamedDimsArraysSparseArraysBaseExt/src/NamedDimsArraysSparseArraysBaseExt.jl" ) include("../ext/NamedDimsArraysTensorAlgebraExt/src/NamedDimsArraysTensorAlgebraExt.jl") end diff --git a/NDTensors/src/lib/NamedDimsArrays/test/test_NamedDimsArraysSparseArrayInterfaceExt.jl b/NDTensors/src/lib/NamedDimsArrays/test/test_NamedDimsArraysSparseArrayInterfaceExt.jl index c358e1f9af..5cd5ef6498 100644 --- a/NDTensors/src/lib/NamedDimsArrays/test/test_NamedDimsArraysSparseArrayInterfaceExt.jl +++ b/NDTensors/src/lib/NamedDimsArrays/test/test_NamedDimsArraysSparseArrayInterfaceExt.jl @@ -1,5 +1,5 @@ using Test: @testset @testset "NamedDimsArrays $(@__FILE__)" begin - include("../ext/NamedDimsArraysSparseArrayInterfaceExt/test/runtests.jl") + include("../ext/NamedDimsArraysSparseArraysBaseExt/test/runtests.jl") end diff --git a/NDTensors/src/lib/SparseArrayDOKs/src/arraylayouts.jl b/NDTensors/src/lib/SparseArrayDOKs/src/arraylayouts.jl index 1e39fecc50..609220ac4f 100644 --- a/NDTensors/src/lib/SparseArrayDOKs/src/arraylayouts.jl +++ b/NDTensors/src/lib/SparseArrayDOKs/src/arraylayouts.jl @@ -1,5 +1,5 @@ using ArrayLayouts: ArrayLayouts, MemoryLayout, MulAdd -using ..SparseArrayInterface: AbstractSparseLayout, SparseLayout +using ..SparseArraysBase: AbstractSparseLayout, SparseLayout ArrayLayouts.MemoryLayout(::Type{<:SparseArrayDOK}) = SparseLayout() diff --git a/NDTensors/src/lib/SparseArrayDOKs/src/defaults.jl b/NDTensors/src/lib/SparseArrayDOKs/src/defaults.jl index 074f4c940f..0b4fce5e55 100644 --- a/NDTensors/src/lib/SparseArrayDOKs/src/defaults.jl +++ b/NDTensors/src/lib/SparseArrayDOKs/src/defaults.jl @@ -1,5 +1,5 @@ using Dictionaries: Dictionary -using ..SparseArrayInterface: Zero +using ..SparseArraysBase: Zero default_zero() = Zero() default_data(type::Type, ndims::Int) = Dictionary{default_keytype(ndims),type}() diff --git a/NDTensors/src/lib/SparseArrayDOKs/src/sparsearraydok.jl b/NDTensors/src/lib/SparseArrayDOKs/src/sparsearraydok.jl index d3b2e913ca..a5425212aa 100644 --- a/NDTensors/src/lib/SparseArrayDOKs/src/sparsearraydok.jl +++ b/NDTensors/src/lib/SparseArrayDOKs/src/sparsearraydok.jl @@ -1,8 +1,7 @@ using Accessors: @set using Dictionaries: Dictionary, set! using MacroTools: @capture -using ..SparseArrayInterface: - SparseArrayInterface, AbstractSparseArray, getindex_zero_function +using ..SparseArraysBase: SparseArraysBase, AbstractSparseArray, getindex_zero_function # TODO: Parametrize by `data`? struct SparseArrayDOK{T,N,Zero} <: AbstractSparseArray{T,N} @@ -82,15 +81,15 @@ end # Base `AbstractArray` interface Base.size(a::SparseArrayDOK) = a.dims[] -SparseArrayInterface.getindex_zero_function(a::SparseArrayDOK) = a.zero -function SparseArrayInterface.set_getindex_zero_function(a::SparseArrayDOK, f) +SparseArraysBase.getindex_zero_function(a::SparseArrayDOK) = a.zero +function SparseArraysBase.set_getindex_zero_function(a::SparseArrayDOK, f) return @set a.zero = f end -function SparseArrayInterface.setindex_notstored!( +function SparseArraysBase.setindex_notstored!( a::SparseArrayDOK{<:Any,N}, value, I::CartesianIndex{N} ) where {N} - set!(SparseArrayInterface.sparse_storage(a), I, value) + set!(SparseArraysBase.sparse_storage(a), I, value) return a end @@ -98,11 +97,11 @@ function Base.similar(a::SparseArrayDOK, elt::Type, dims::Tuple{Vararg{Int}}) return SparseArrayDOK{elt}(undef, dims, getindex_zero_function(a)) end -# `SparseArrayInterface` interface -SparseArrayInterface.sparse_storage(a::SparseArrayDOK) = a.data +# `SparseArraysBase` interface +SparseArraysBase.sparse_storage(a::SparseArrayDOK) = a.data -function SparseArrayInterface.dropall!(a::SparseArrayDOK) - return empty!(SparseArrayInterface.sparse_storage(a)) +function SparseArraysBase.dropall!(a::SparseArrayDOK) + return empty!(SparseArraysBase.sparse_storage(a)) end SparseArrayDOK(a::AbstractArray) = SparseArrayDOK{eltype(a)}(a) @@ -110,7 +109,7 @@ SparseArrayDOK(a::AbstractArray) = SparseArrayDOK{eltype(a)}(a) SparseArrayDOK{T}(a::AbstractArray) where {T} = SparseArrayDOK{T,ndims(a)}(a) function SparseArrayDOK{T,N}(a::AbstractArray) where {T,N} - return SparseArrayInterface.sparse_convert(SparseArrayDOK{T,N}, a) + return SparseArraysBase.sparse_convert(SparseArrayDOK{T,N}, a) end function Base.resize!(a::SparseArrayDOK{<:Any,N}, new_size::NTuple{N,Integer}) where {N} diff --git a/NDTensors/src/lib/SparseArrayDOKs/test/runtests.jl b/NDTensors/src/lib/SparseArrayDOKs/test/runtests.jl index 4bf44f99b8..25a48524bd 100644 --- a/NDTensors/src/lib/SparseArrayDOKs/test/runtests.jl +++ b/NDTensors/src/lib/SparseArrayDOKs/test/runtests.jl @@ -9,7 +9,7 @@ using Dictionaries: Dictionary using Test: @test, @testset, @test_broken using NDTensors.SparseArrayDOKs: SparseArrayDOKs, SparseArrayDOK, SparseMatrixDOK, @maybe_grow -using NDTensors.SparseArrayInterface: storage_indices, stored_length +using NDTensors.SparseArraysBase: storage_indices, stored_length using SparseArrays: SparseMatrixCSC, nnz @testset "SparseArrayDOK (eltype=$elt)" for elt in (Float32, ComplexF32, Float64, ComplexF64) diff --git a/NDTensors/src/lib/SparseArrayInterface/test/test_array.jl b/NDTensors/src/lib/SparseArrayInterface/test/test_array.jl deleted file mode 100644 index 9cc0381771..0000000000 --- a/NDTensors/src/lib/SparseArrayInterface/test/test_array.jl +++ /dev/null @@ -1,13 +0,0 @@ -@eval module $(gensym()) -using NDTensors.SparseArrayInterface: SparseArrayInterface -include("SparseArrayInterfaceTestUtils/SparseArrayInterfaceTestUtils.jl") -using Test: @test, @testset -@testset "Array (eltype=$elt)" for elt in (Float32, ComplexF32, Float64, ComplexF64) - a = randn(2, 3) - @test SparseArrayInterface.sparse_storage(a) == a - @test SparseArrayInterface.index_to_storage_index(a, CartesianIndex(1, 2)) == - CartesianIndex(1, 2) - @test SparseArrayInterface.storage_index_to_index(a, CartesianIndex(1, 2)) == - CartesianIndex(1, 2) -end -end diff --git a/NDTensors/src/lib/SparseArrayInterface/.JuliaFormatter.toml b/NDTensors/src/lib/SparseArraysBase/.JuliaFormatter.toml similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/.JuliaFormatter.toml rename to NDTensors/src/lib/SparseArraysBase/.JuliaFormatter.toml diff --git a/NDTensors/src/lib/SparseArrayInterface/README.md b/NDTensors/src/lib/SparseArraysBase/README.md similarity index 81% rename from NDTensors/src/lib/SparseArrayInterface/README.md rename to NDTensors/src/lib/SparseArraysBase/README.md index 917f5dfdfb..75712505b7 100644 --- a/NDTensors/src/lib/SparseArrayInterface/README.md +++ b/NDTensors/src/lib/SparseArraysBase/README.md @@ -1,4 +1,4 @@ -# SparseArrayInterface +# SparseArraysBase Defines a generic interface for sparse arrays in Julia. @@ -7,18 +7,18 @@ The minimal interface is: nonzeros(a::AbstractArray) = ... nonzero_index_to_index(a::AbstractArray, Inz) = ... index_to_nonzero_index(a::AbstractArray{<:Any,N}, I::CartesianIndex{N}) where {N} = ... -Broadcast.BroadcastStyle(arraytype::Type{<:AbstractArray}) = SparseArrayInterface.SparseArrayStyle{ndims(arraytype)}() +Broadcast.BroadcastStyle(arraytype::Type{<:AbstractArray}) = SparseArraysBase.SparseArrayStyle{ndims(arraytype)}() ``` Once these are defined, along with Julia AbstractArray interface functions like `Base.size` and `Base.similar`, functions like the following will take advantage of sparsity: ```julia -SparseArrayInterface.nonzero_length # SparseArrays.nnz -SparseArrayInterface.sparse_getindex -SparseArrayInterface.sparse_setindex! -SparseArrayInterface.sparse_map! -SparseArrayInterface.sparse_copy! -SparseArrayInterface.sparse_copyto! -SparseArrayInterface.sparse_permutedims! +SparseArraysBase.nonzero_length # SparseArrays.nnz +SparseArraysBase.sparse_getindex +SparseArraysBase.sparse_setindex! +SparseArraysBase.sparse_map! +SparseArraysBase.sparse_copy! +SparseArraysBase.sparse_copyto! +SparseArraysBase.sparse_permutedims! ``` which can be used to define the corresponding `Base` functions. diff --git a/NDTensors/src/lib/SparseArrayInterface/src/SparseArrayInterface.jl b/NDTensors/src/lib/SparseArraysBase/src/SparseArraysBase.jl similarity index 83% rename from NDTensors/src/lib/SparseArrayInterface/src/SparseArrayInterface.jl rename to NDTensors/src/lib/SparseArraysBase/src/SparseArraysBase.jl index f192225f27..b6bb1b4736 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/SparseArrayInterface.jl +++ b/NDTensors/src/lib/SparseArraysBase/src/SparseArraysBase.jl @@ -1,4 +1,4 @@ -module SparseArrayInterface +module SparseArraysBase include("sparsearrayinterface/arraylayouts.jl") include("sparsearrayinterface/densearray.jl") include("sparsearrayinterface/vectorinterface.jl") @@ -13,7 +13,7 @@ include("sparsearrayinterface/conversion.jl") include("sparsearrayinterface/wrappers.jl") include("sparsearrayinterface/zero.jl") include("sparsearrayinterface/cat.jl") -include("sparsearrayinterface/SparseArrayInterfaceLinearAlgebraExt.jl") +include("sparsearrayinterface/SparseArraysBaseLinearAlgebraExt.jl") include("abstractsparsearray/abstractsparsearray.jl") include("abstractsparsearray/abstractsparsematrix.jl") include("abstractsparsearray/abstractsparsevector.jl") @@ -26,6 +26,6 @@ include("abstractsparsearray/map.jl") include("abstractsparsearray/baseinterface.jl") include("abstractsparsearray/convert.jl") include("abstractsparsearray/cat.jl") -include("abstractsparsearray/SparseArrayInterfaceSparseArraysExt.jl") -include("abstractsparsearray/SparseArrayInterfaceLinearAlgebraExt.jl") +include("abstractsparsearray/SparseArraysBaseSparseArraysExt.jl") +include("abstractsparsearray/SparseArraysBaseLinearAlgebraExt.jl") end diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/SparseArrayInterfaceLinearAlgebraExt.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/SparseArraysBaseLinearAlgebraExt.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/SparseArrayInterfaceLinearAlgebraExt.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/SparseArraysBaseLinearAlgebraExt.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/SparseArrayInterfaceSparseArraysExt.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/SparseArraysBaseSparseArraysExt.jl similarity index 94% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/SparseArrayInterfaceSparseArraysExt.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/SparseArraysBaseSparseArraysExt.jl index 828a681cc0..492a0a37f7 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/SparseArrayInterfaceSparseArraysExt.jl +++ b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/SparseArraysBaseSparseArraysExt.jl @@ -1,6 +1,6 @@ using Base: Forward using SparseArrays: SparseArrays, SparseMatrixCSC, findnz, getcolptr, nonzeros, rowvals -using ..SparseArrayInterface: stored_length +using ..SparseArraysBase: stored_length # Julia Base `AbstractSparseArray` interface SparseArrays.nnz(a::AbstractSparseArray) = stored_length(a) diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/abstractsparsearray.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/abstractsparsearray.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/abstractsparsearray.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/abstractsparsearray.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/abstractsparsematrix.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/abstractsparsematrix.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/abstractsparsematrix.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/abstractsparsematrix.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/abstractsparsevector.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/abstractsparsevector.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/abstractsparsevector.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/abstractsparsevector.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/arraylayouts.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/arraylayouts.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/arraylayouts.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/arraylayouts.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/base.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/base.jl similarity index 52% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/base.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/base.jl index 5be8c9c1b3..eeedcf9518 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/base.jl +++ b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/base.jl @@ -1,18 +1,18 @@ -using ..SparseArrayInterface: SparseArrayInterface +using ..SparseArraysBase: SparseArraysBase # Base function Base.:(==)(a1::AnyAbstractSparseArray, a2::AnyAbstractSparseArray) - return SparseArrayInterface.sparse_isequal(a1, a2) + return SparseArraysBase.sparse_isequal(a1, a2) end function Base.reshape(a::AnyAbstractSparseArray, dims::Tuple{Vararg{Int}}) - return SparseArrayInterface.sparse_reshape(a, dims) + return SparseArraysBase.sparse_reshape(a, dims) end function Base.zero(a::AnyAbstractSparseArray) - return SparseArrayInterface.sparse_zero(a) + return SparseArraysBase.sparse_zero(a) end function Base.one(a::AnyAbstractSparseArray) - return SparseArrayInterface.sparse_one(a) + return SparseArraysBase.sparse_one(a) end diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/baseinterface.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/baseinterface.jl similarity index 64% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/baseinterface.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/baseinterface.jl index 323289246e..f4488f984e 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/baseinterface.jl +++ b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/baseinterface.jl @@ -1,4 +1,4 @@ -using ..SparseArrayInterface: SparseArrayInterface +using ..SparseArraysBase: SparseArraysBase Base.size(a::AbstractSparseArray) = error("Not implemented") @@ -7,29 +7,29 @@ function Base.similar(a::AbstractSparseArray, elt::Type, dims::Tuple{Vararg{Int} end function Base.getindex(a::AbstractSparseArray, I...) - return SparseArrayInterface.sparse_getindex(a, I...) + return SparseArraysBase.sparse_getindex(a, I...) end # Fixes ambiguity error with `ArrayLayouts`. function Base.getindex(a::AbstractSparseMatrix, I1::AbstractVector, I2::AbstractVector) - return SparseArrayInterface.sparse_getindex(a, I1, I2) + return SparseArraysBase.sparse_getindex(a, I1, I2) end # Fixes ambiguity error with `ArrayLayouts`. function Base.getindex( a::AbstractSparseMatrix, I1::AbstractUnitRange, I2::AbstractUnitRange ) - return SparseArrayInterface.sparse_getindex(a, I1, I2) + return SparseArraysBase.sparse_getindex(a, I1, I2) end function Base.isassigned(a::AbstractSparseArray, I::Integer...) - return SparseArrayInterface.sparse_isassigned(a, I...) + return SparseArraysBase.sparse_isassigned(a, I...) end function Base.setindex!(a::AbstractSparseArray, I...) - return SparseArrayInterface.sparse_setindex!(a, I...) + return SparseArraysBase.sparse_setindex!(a, I...) end function Base.fill!(a::AbstractSparseArray, value) - return SparseArrayInterface.sparse_fill!(a, value) + return SparseArraysBase.sparse_fill!(a, value) end diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/broadcast.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/broadcast.jl similarity index 58% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/broadcast.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/broadcast.jl index de67af5495..565fccb441 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/broadcast.jl +++ b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/broadcast.jl @@ -1,4 +1,4 @@ # Broadcasting function Broadcast.BroadcastStyle(arraytype::Type{<:AnyAbstractSparseArray}) - return SparseArrayInterface.SparseArrayStyle{ndims(arraytype)}() + return SparseArraysBase.SparseArrayStyle{ndims(arraytype)}() end diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/cat.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/cat.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/cat.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/cat.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/convert.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/convert.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/convert.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/convert.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/map.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/map.jl similarity index 65% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/map.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/map.jl index 4dd96f907b..106cfff579 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/map.jl +++ b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/map.jl @@ -2,41 +2,41 @@ using ArrayLayouts: LayoutArray # Map function Base.map!(f, a_dest::AbstractArray, a_srcs::Vararg{AnyAbstractSparseArray}) - SparseArrayInterface.sparse_map!(f, a_dest, a_srcs...) + SparseArraysBase.sparse_map!(f, a_dest, a_srcs...) return a_dest end function Base.copy!(a_dest::AbstractArray, a_src::AnyAbstractSparseArray) - SparseArrayInterface.sparse_copy!(a_dest, a_src) + SparseArraysBase.sparse_copy!(a_dest, a_src) return a_dest end function Base.copyto!(a_dest::AbstractArray, a_src::AnyAbstractSparseArray) - SparseArrayInterface.sparse_copyto!(a_dest, a_src) + SparseArraysBase.sparse_copyto!(a_dest, a_src) return a_dest end # Fix ambiguity error function Base.copyto!(a_dest::LayoutArray, a_src::AnyAbstractSparseArray) - SparseArrayInterface.sparse_copyto!(a_dest, a_src) + SparseArraysBase.sparse_copyto!(a_dest, a_src) return a_dest end function Base.permutedims!(a_dest::AbstractArray, a_src::AnyAbstractSparseArray, perm) - SparseArrayInterface.sparse_permutedims!(a_dest, a_src, perm) + SparseArraysBase.sparse_permutedims!(a_dest, a_src, perm) return a_dest end function Base.mapreduce(f, op, as::Vararg{AnyAbstractSparseArray}; kwargs...) - return SparseArrayInterface.sparse_mapreduce(f, op, as...; kwargs...) + return SparseArraysBase.sparse_mapreduce(f, op, as...; kwargs...) end # TODO: Why isn't this calling `mapreduce` already? function Base.iszero(a::AnyAbstractSparseArray) - return SparseArrayInterface.sparse_iszero(a) + return SparseArraysBase.sparse_iszero(a) end # TODO: Why isn't this calling `mapreduce` already? function Base.isreal(a::AnyAbstractSparseArray) - return SparseArrayInterface.sparse_isreal(a) + return SparseArraysBase.sparse_isreal(a) end diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/sparsearrayinterface.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/sparsearrayinterface.jl similarity index 72% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/sparsearrayinterface.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/sparsearrayinterface.jl index e4929b5e81..a628d4cec1 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/sparsearrayinterface.jl +++ b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/sparsearrayinterface.jl @@ -1,16 +1,16 @@ using Dictionaries: set! -using ..SparseArrayInterface: SparseArrayInterface +using ..SparseArraysBase: SparseArraysBase -SparseArrayInterface.sparse_storage(::AbstractSparseArray) = error("Not implemented") +SparseArraysBase.sparse_storage(::AbstractSparseArray) = error("Not implemented") -function SparseArrayInterface.index_to_storage_index( +function SparseArraysBase.index_to_storage_index( a::AbstractSparseArray{<:Any,N}, I::CartesianIndex{N} ) where {N} - !isassigned(SparseArrayInterface.sparse_storage(a), I) && return nothing + !isassigned(SparseArraysBase.sparse_storage(a), I) && return nothing return I end -function SparseArrayInterface.setindex_notstored!( +function SparseArraysBase.setindex_notstored!( a::AbstractSparseArray{<:Any,N}, value, I::CartesianIndex{N} ) where {N} iszero(value) && return a @@ -20,7 +20,7 @@ end # TODO: Make this into a generic definition of all `AbstractArray`? # TODO: Check if this is efficient, or determine if this mapping should # be performed in `storage_index_to_index` and/or `index_to_storage_index`. -function SparseArrayInterface.sparse_storage(a::SubArray{<:Any,<:Any,<:AbstractSparseArray}) +function SparseArraysBase.sparse_storage(a::SubArray{<:Any,<:Any,<:AbstractSparseArray}) parent_storage = sparse_storage(parent(a)) all_sliced_storage_indices = map(keys(parent_storage)) do I return map_index(a.indices, I) @@ -31,7 +31,7 @@ function SparseArrayInterface.sparse_storage(a::SubArray{<:Any,<:Any,<:AbstractS end # TODO: Make this into a generic definition of all `AbstractArray`? -function SparseArrayInterface.stored_indices( +function SparseArraysBase.stored_indices( a::AnyPermutedDimsArray{<:Any,<:Any,<:Any,<:Any,<:AbstractSparseArray} ) return Iterators.map( @@ -40,7 +40,7 @@ function SparseArrayInterface.stored_indices( end # TODO: Make this into a generic definition of all `AbstractArray`? -function SparseArrayInterface.sparse_storage( +function SparseArraysBase.sparse_storage( a::AnyPermutedDimsArray{<:Any,<:Any,<:Any,<:Any,<:AbstractSparseArray} ) return sparse_storage(parent(a)) diff --git a/NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/wrappedabstractsparsearray.jl b/NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/wrappedabstractsparsearray.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/abstractsparsearray/wrappedabstractsparsearray.jl rename to NDTensors/src/lib/SparseArraysBase/src/abstractsparsearray/wrappedabstractsparsearray.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/SparseArrayInterfaceLinearAlgebraExt.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/SparseArraysBaseLinearAlgebraExt.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/SparseArrayInterfaceLinearAlgebraExt.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/SparseArraysBaseLinearAlgebraExt.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/arraylayouts.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/arraylayouts.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/arraylayouts.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/arraylayouts.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/base.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/base.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/base.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/base.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/broadcast.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/broadcast.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/broadcast.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/broadcast.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/cat.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/cat.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/cat.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/cat.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/conversion.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/conversion.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/conversion.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/conversion.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/copyto.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/copyto.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/copyto.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/copyto.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/densearray.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/densearray.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/densearray.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/densearray.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/indexing.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/indexing.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/indexing.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/indexing.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/interface.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/interface.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/interface.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/interface.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/interface_optional.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/interface_optional.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/interface_optional.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/interface_optional.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/map.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/map.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/map.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/map.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/vectorinterface.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/vectorinterface.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/vectorinterface.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/vectorinterface.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/wrappers.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/wrappers.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/wrappers.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/wrappers.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/zero.jl b/NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/zero.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/zero.jl rename to NDTensors/src/lib/SparseArraysBase/src/sparsearrayinterface/zero.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/test/Project.toml b/NDTensors/src/lib/SparseArraysBase/test/Project.toml similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/test/Project.toml rename to NDTensors/src/lib/SparseArraysBase/test/Project.toml diff --git a/NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/AbstractSparseArrays.jl b/NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/AbstractSparseArrays.jl similarity index 79% rename from NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/AbstractSparseArrays.jl rename to NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/AbstractSparseArrays.jl index 1a81334397..5ae5f5c1ff 100644 --- a/NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/AbstractSparseArrays.jl +++ b/NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/AbstractSparseArrays.jl @@ -1,6 +1,6 @@ module AbstractSparseArrays using ArrayLayouts: ArrayLayouts, MatMulMatAdd, MemoryLayout, MulAdd -using NDTensors.SparseArrayInterface: SparseArrayInterface, AbstractSparseArray, Zero +using NDTensors.SparseArraysBase: SparseArraysBase, AbstractSparseArray, Zero struct SparseArray{T,N,Zero} <: AbstractSparseArray{T,N} data::Vector{T} @@ -35,7 +35,7 @@ function ArrayLayouts.materialize!( m::MatMulMatAdd{<:SparseLayout,<:SparseLayout,<:SparseLayout} ) α, a1, a2, β, a_dest = m.α, m.A, m.B, m.β, m.C - SparseArrayInterface.sparse_mul!(a_dest, a1, a2, α, β) + SparseArraysBase.sparse_mul!(a_dest, a1, a2, α, β) return a_dest end @@ -46,15 +46,15 @@ function Base.similar(a::SparseArray, elt::Type, dims::Tuple{Vararg{Int}}) end # Minimal interface -SparseArrayInterface.getindex_zero_function(a::SparseArray) = a.zero -SparseArrayInterface.sparse_storage(a::SparseArray) = a.data -function SparseArrayInterface.index_to_storage_index( +SparseArraysBase.getindex_zero_function(a::SparseArray) = a.zero +SparseArraysBase.sparse_storage(a::SparseArray) = a.data +function SparseArraysBase.index_to_storage_index( a::SparseArray{<:Any,N}, I::CartesianIndex{N} ) where {N} return get(a.index_to_dataindex, I, nothing) end -SparseArrayInterface.storage_index_to_index(a::SparseArray, I) = a.dataindex_to_index[I] -function SparseArrayInterface.setindex_notstored!( +SparseArraysBase.storage_index_to_index(a::SparseArray, I) = a.dataindex_to_index[I] +function SparseArraysBase.setindex_notstored!( a::SparseArray{<:Any,N}, value, I::CartesianIndex{N} ) where {N} push!(a.data, value) @@ -65,7 +65,7 @@ end # Empty the storage, helps with efficiency in `map!` to drop # zeros. -function SparseArrayInterface.dropall!(a::SparseArray) +function SparseArraysBase.dropall!(a::SparseArray) empty!(a.data) empty!(a.index_to_dataindex) empty!(a.dataindex_to_index) diff --git a/NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/DiagonalArrays.jl b/NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/DiagonalArrays.jl similarity index 65% rename from NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/DiagonalArrays.jl rename to NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/DiagonalArrays.jl index e3164fe675..394a622694 100644 --- a/NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/DiagonalArrays.jl +++ b/NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/DiagonalArrays.jl @@ -1,5 +1,5 @@ module DiagonalArrays -using NDTensors.SparseArrayInterface: SparseArrayInterface +using NDTensors.SparseArraysBase: SparseArraysBase struct DiagonalArray{T,N} <: AbstractArray{T,N} data::Vector{T} @@ -21,75 +21,75 @@ end # AbstractArray interface Base.size(a::DiagonalArray) = a.dims function Base.getindex(a::DiagonalArray, I...) - return SparseArrayInterface.sparse_getindex(a, I...) + return SparseArraysBase.sparse_getindex(a, I...) end function Base.setindex!(a::DiagonalArray, I...) - return SparseArrayInterface.sparse_setindex!(a, I...) + return SparseArraysBase.sparse_setindex!(a, I...) end function Base.similar(a::DiagonalArray, elt::Type, dims::Tuple{Vararg{Int}}) return DiagonalArray{elt}(undef, dims) end # Minimal interface -SparseArrayInterface.sparse_storage(a::DiagonalArray) = a.data -function SparseArrayInterface.index_to_storage_index( +SparseArraysBase.sparse_storage(a::DiagonalArray) = a.data +function SparseArraysBase.index_to_storage_index( a::DiagonalArray{<:Any,N}, I::CartesianIndex{N} ) where {N} !allequal(Tuple(I)) && return nothing return first(Tuple(I)) end -function SparseArrayInterface.storage_index_to_index(a::DiagonalArray, I) +function SparseArraysBase.storage_index_to_index(a::DiagonalArray, I) return CartesianIndex(ntuple(Returns(I), ndims(a))) end -function SparseArrayInterface.sparse_similar( +function SparseArraysBase.sparse_similar( a::DiagonalArray, elt::Type, dims::Tuple{Vararg{Int}} ) return Array{elt}(undef, dims) end -function SparseArrayInterface.sparse_similar(a::DiagonalArray, elt::Type, dims::Tuple{Int}) +function SparseArraysBase.sparse_similar(a::DiagonalArray, elt::Type, dims::Tuple{Int}) return similar(a, elt, dims) end # Broadcasting function Broadcast.BroadcastStyle(arraytype::Type{<:DiagonalArray}) - return SparseArrayInterface.SparseArrayStyle{ndims(arraytype)}() + return SparseArraysBase.SparseArrayStyle{ndims(arraytype)}() end # Base function Base.iszero(a::DiagonalArray) - return SparseArrayInterface.sparse_iszero(a) + return SparseArraysBase.sparse_iszero(a) end function Base.isreal(a::DiagonalArray) - return SparseArrayInterface.sparse_isreal(a) + return SparseArraysBase.sparse_isreal(a) end function Base.zero(a::DiagonalArray) - return SparseArrayInterface.sparse_zero(a) + return SparseArraysBase.sparse_zero(a) end function Base.one(a::DiagonalArray) - return SparseArrayInterface.sparse_one(a) + return SparseArraysBase.sparse_one(a) end function Base.:(==)(a1::DiagonalArray, a2::DiagonalArray) - return SparseArrayInterface.sparse_isequal(a1, a2) + return SparseArraysBase.sparse_isequal(a1, a2) end function Base.reshape(a::DiagonalArray, dims::Tuple{Vararg{Int}}) - return SparseArrayInterface.sparse_reshape(a, dims) + return SparseArraysBase.sparse_reshape(a, dims) end # Map function Base.map!(f, dest::AbstractArray, src::DiagonalArray) - SparseArrayInterface.sparse_map!(f, dest, src) + SparseArraysBase.sparse_map!(f, dest, src) return dest end function Base.copy!(dest::AbstractArray, src::DiagonalArray) - SparseArrayInterface.sparse_copy!(dest, src) + SparseArraysBase.sparse_copy!(dest, src) return dest end function Base.copyto!(dest::AbstractArray, src::DiagonalArray) - SparseArrayInterface.sparse_copyto!(dest, src) + SparseArraysBase.sparse_copyto!(dest, src) return dest end function Base.permutedims!(dest::AbstractArray, src::DiagonalArray, perm) - SparseArrayInterface.sparse_permutedims!(dest, src, perm) + SparseArraysBase.sparse_permutedims!(dest, src, perm) return dest end end diff --git a/NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/Project.toml b/NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/Project.toml similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/Project.toml rename to NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/Project.toml diff --git a/NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/SparseArrays.jl b/NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/SparseArrays.jl similarity index 69% rename from NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/SparseArrays.jl rename to NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/SparseArrays.jl index f74846e2c1..082adb173d 100644 --- a/NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/SparseArrays.jl +++ b/NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/SparseArrays.jl @@ -1,6 +1,6 @@ module SparseArrays using LinearAlgebra: LinearAlgebra -using NDTensors.SparseArrayInterface: SparseArrayInterface, Zero +using NDTensors.SparseArraysBase: SparseArraysBase, Zero struct SparseArray{T,N,Zero} <: AbstractArray{T,N} data::Vector{T} @@ -33,12 +33,12 @@ function LinearAlgebra.mul!( α::Number, β::Number, ) - SparseArrayInterface.sparse_mul!(a_dest, a1, a2, α, β) + SparseArraysBase.sparse_mul!(a_dest, a1, a2, α, β) return a_dest end function LinearAlgebra.dot(a1::SparseArray, a2::SparseArray) - return SparseArrayInterface.sparse_dot(a1, a2) + return SparseArraysBase.sparse_dot(a1, a2) end # AbstractArray interface @@ -48,25 +48,25 @@ function Base.similar(a::SparseArray, elt::Type, dims::Tuple{Vararg{Int}}) end function Base.getindex(a::SparseArray, I...) - return SparseArrayInterface.sparse_getindex(a, I...) + return SparseArraysBase.sparse_getindex(a, I...) end function Base.setindex!(a::SparseArray, value, I...) - return SparseArrayInterface.sparse_setindex!(a, value, I...) + return SparseArraysBase.sparse_setindex!(a, value, I...) end function Base.fill!(a::SparseArray, value) - return SparseArrayInterface.sparse_fill!(a, value) + return SparseArraysBase.sparse_fill!(a, value) end # Minimal interface -SparseArrayInterface.getindex_zero_function(a::SparseArray) = a.zero -SparseArrayInterface.sparse_storage(a::SparseArray) = a.data -function SparseArrayInterface.index_to_storage_index( +SparseArraysBase.getindex_zero_function(a::SparseArray) = a.zero +SparseArraysBase.sparse_storage(a::SparseArray) = a.data +function SparseArraysBase.index_to_storage_index( a::SparseArray{<:Any,N}, I::CartesianIndex{N} ) where {N} return get(a.index_to_dataindex, I, nothing) end -SparseArrayInterface.storage_index_to_index(a::SparseArray, I) = a.dataindex_to_index[I] -function SparseArrayInterface.setindex_notstored!( +SparseArraysBase.storage_index_to_index(a::SparseArray, I) = a.dataindex_to_index[I] +function SparseArraysBase.setindex_notstored!( a::SparseArray{<:Any,N}, value, I::CartesianIndex{N} ) where {N} push!(a.data, value) @@ -76,8 +76,8 @@ function SparseArrayInterface.setindex_notstored!( end # TODO: Make this into a generic definition of all `AbstractArray`? -using NDTensors.SparseArrayInterface: perm, stored_indices -function SparseArrayInterface.stored_indices( +using NDTensors.SparseArraysBase: perm, stored_indices +function SparseArraysBase.stored_indices( a::PermutedDimsArray{<:Any,<:Any,<:Any,<:Any,<:SparseArray} ) return Iterators.map( @@ -86,8 +86,8 @@ function SparseArrayInterface.stored_indices( end # TODO: Make this into a generic definition of all `AbstractArray`? -using NDTensors.SparseArrayInterface: sparse_storage -function SparseArrayInterface.sparse_storage( +using NDTensors.SparseArraysBase: sparse_storage +function SparseArraysBase.sparse_storage( a::PermutedDimsArray{<:Any,<:Any,<:Any,<:Any,<:SparseArray} ) return sparse_storage(parent(a)) @@ -95,7 +95,7 @@ end # TODO: Make this into a generic definition of all `AbstractArray`? using NDTensors.NestedPermutedDimsArrays: NestedPermutedDimsArray -function SparseArrayInterface.stored_indices( +function SparseArraysBase.stored_indices( a::NestedPermutedDimsArray{<:Any,<:Any,<:Any,<:Any,<:SparseArray} ) return Iterators.map( @@ -105,8 +105,8 @@ end # TODO: Make this into a generic definition of all `AbstractArray`? using NDTensors.NestedPermutedDimsArrays: NestedPermutedDimsArray -using NDTensors.SparseArrayInterface: sparse_storage -function SparseArrayInterface.sparse_storage( +using NDTensors.SparseArraysBase: sparse_storage +function SparseArraysBase.sparse_storage( a::NestedPermutedDimsArray{<:Any,<:Any,<:Any,<:Any,<:SparseArray} ) return sparse_storage(parent(a)) @@ -114,7 +114,7 @@ end # Empty the storage, helps with efficiency in `map!` to drop # zeros. -function SparseArrayInterface.dropall!(a::SparseArray) +function SparseArraysBase.dropall!(a::SparseArray) empty!(a.data) empty!(a.index_to_dataindex) empty!(a.dataindex_to_index) @@ -123,44 +123,44 @@ end # Broadcasting function Broadcast.BroadcastStyle(arraytype::Type{<:SparseArray}) - return SparseArrayInterface.SparseArrayStyle{ndims(arraytype)}() + return SparseArraysBase.SparseArrayStyle{ndims(arraytype)}() end # Map function Base.map!(f, dest::AbstractArray, src::SparseArray) - SparseArrayInterface.sparse_map!(f, dest, src) + SparseArraysBase.sparse_map!(f, dest, src) return dest end function Base.copy!(dest::AbstractArray, src::SparseArray) - SparseArrayInterface.sparse_copy!(dest, src) + SparseArraysBase.sparse_copy!(dest, src) return dest end function Base.copyto!(dest::AbstractArray, src::SparseArray) - SparseArrayInterface.sparse_copyto!(dest, src) + SparseArraysBase.sparse_copyto!(dest, src) return dest end function Base.permutedims!(dest::AbstractArray, src::SparseArray, perm) - SparseArrayInterface.sparse_permutedims!(dest, src, perm) + SparseArraysBase.sparse_permutedims!(dest, src, perm) return dest end # Base function Base.:(==)(a1::SparseArray, a2::SparseArray) - return SparseArrayInterface.sparse_isequal(a1, a2) + return SparseArraysBase.sparse_isequal(a1, a2) end function Base.reshape(a::SparseArray, dims::Tuple{Vararg{Int}}) - return SparseArrayInterface.sparse_reshape(a, dims) + return SparseArraysBase.sparse_reshape(a, dims) end function Base.iszero(a::SparseArray) - return SparseArrayInterface.sparse_iszero(a) + return SparseArraysBase.sparse_iszero(a) end function Base.isreal(a::SparseArray) - return SparseArrayInterface.sparse_isreal(a) + return SparseArraysBase.sparse_isreal(a) end function Base.zero(a::SparseArray) - return SparseArrayInterface.sparse_zero(a) + return SparseArraysBase.sparse_zero(a) end function Base.one(a::SparseArray) - return SparseArrayInterface.sparse_one(a) + return SparseArraysBase.sparse_one(a) end end diff --git a/NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/SparseArrayInterfaceTestUtils.jl b/NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/SparseArraysBaseTestUtils.jl similarity index 71% rename from NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/SparseArrayInterfaceTestUtils.jl rename to NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/SparseArraysBaseTestUtils.jl index 9c1b7b6d54..9067f9df96 100644 --- a/NDTensors/src/lib/SparseArrayInterface/test/SparseArrayInterfaceTestUtils/SparseArrayInterfaceTestUtils.jl +++ b/NDTensors/src/lib/SparseArraysBase/test/SparseArraysBaseTestUtils/SparseArraysBaseTestUtils.jl @@ -1,4 +1,4 @@ -module SparseArrayInterfaceTestUtils +module SparseArraysBaseTestUtils include("AbstractSparseArrays.jl") include("DiagonalArrays.jl") include("SparseArrays.jl") diff --git a/NDTensors/src/lib/SparseArrayInterface/test/runtests.jl b/NDTensors/src/lib/SparseArraysBase/test/runtests.jl similarity index 100% rename from NDTensors/src/lib/SparseArrayInterface/test/runtests.jl rename to NDTensors/src/lib/SparseArraysBase/test/runtests.jl diff --git a/NDTensors/src/lib/SparseArrayInterface/test/test_abstractsparsearray.jl b/NDTensors/src/lib/SparseArraysBase/test/test_abstractsparsearray.jl similarity index 76% rename from NDTensors/src/lib/SparseArrayInterface/test/test_abstractsparsearray.jl rename to NDTensors/src/lib/SparseArraysBase/test/test_abstractsparsearray.jl index 0c44c25f6d..b64955cb55 100644 --- a/NDTensors/src/lib/SparseArrayInterface/test/test_abstractsparsearray.jl +++ b/NDTensors/src/lib/SparseArraysBase/test/test_abstractsparsearray.jl @@ -1,10 +1,10 @@ @eval module $(gensym()) using LinearAlgebra: dot, mul!, norm -using NDTensors.SparseArrayInterface: SparseArrayInterface +using NDTensors.SparseArraysBase: SparseArraysBase using NDTensors.NestedPermutedDimsArrays: NestedPermutedDimsArray -include("SparseArrayInterfaceTestUtils/SparseArrayInterfaceTestUtils.jl") -using .SparseArrayInterfaceTestUtils.AbstractSparseArrays: AbstractSparseArrays -using .SparseArrayInterfaceTestUtils.SparseArrays: SparseArrays +include("SparseArraysBaseTestUtils/SparseArraysBaseTestUtils.jl") +using .SparseArraysBaseTestUtils.AbstractSparseArrays: AbstractSparseArrays +using .SparseArraysBaseTestUtils.SparseArrays: SparseArrays using Test: @test, @testset @testset "AbstractSparseArray (arraytype=$SparseArray, eltype=$elt)" for SparseArray in ( AbstractSparseArrays.SparseArray, SparseArrays.SparseArray @@ -14,9 +14,9 @@ using Test: @test, @testset a = SparseArray{elt}(2, 3) @test size(a) == (2, 3) @test axes(a) == (1:2, 1:3) - @test SparseArrayInterface.sparse_storage(a) == elt[] - @test iszero(SparseArrayInterface.stored_length(a)) - @test collect(SparseArrayInterface.stored_indices(a)) == CartesianIndex{2}[] + @test SparseArraysBase.sparse_storage(a) == elt[] + @test iszero(SparseArraysBase.stored_length(a)) + @test collect(SparseArraysBase.stored_indices(a)) == CartesianIndex{2}[] @test iszero(a) @test iszero(norm(a)) for I in eachindex(a) @@ -35,9 +35,9 @@ using Test: @test, @testset fill!(a, 0) @test size(a) == (2, 3) @test iszero(a) - @test iszero(SparseArrayInterface.stored_length(a)) + @test iszero(SparseArraysBase.stored_length(a)) - a_dense = SparseArrayInterface.densearray(a) + a_dense = SparseArraysBase.densearray(a) @test a_dense == a @test a_dense isa Array{elt,ndims(a)} @@ -45,7 +45,7 @@ using Test: @test, @testset fill!(a, 2) @test size(a) == (2, 3) @test !iszero(a) - @test SparseArrayInterface.stored_length(a) == length(a) + @test SparseArraysBase.stored_length(a) == length(a) for I in eachindex(a) @test a[I] == 2 end @@ -56,10 +56,10 @@ using Test: @test, @testset @test a[3] == 12 # linear indexing @test size(a) == (2, 3) @test axes(a) == (1:2, 1:3) - @test a[SparseArrayInterface.StorageIndex(1)] == 12 - @test SparseArrayInterface.sparse_storage(a) == elt[12] - @test isone(SparseArrayInterface.stored_length(a)) - @test collect(SparseArrayInterface.stored_indices(a)) == [CartesianIndex(1, 2)] + @test a[SparseArraysBase.StorageIndex(1)] == 12 + @test SparseArraysBase.sparse_storage(a) == elt[12] + @test isone(SparseArraysBase.stored_length(a)) + @test collect(SparseArraysBase.stored_indices(a)) == [CartesianIndex(1, 2)] @test !iszero(a) @test !iszero(norm(a)) for I in eachindex(a) @@ -98,7 +98,7 @@ using Test: @test, @testset a[1, 2] = 12 a = zero(a) @test size(a) == (2, 3) - @test iszero(SparseArrayInterface.stored_length(a)) + @test iszero(SparseArraysBase.stored_length(a)) a = SparseArray{elt}(2, 3) a[1, 2] = 12 @@ -145,17 +145,17 @@ using Test: @test, @testset a[1, 2] = 12 a = zero(a) @test size(a) == (2, 3) - @test iszero(SparseArrayInterface.stored_length(a)) + @test iszero(SparseArraysBase.stored_length(a)) a = SparseArray{elt}(2, 3) a[1, 2] = 12 a = copy(a) @test size(a) == (2, 3) @test axes(a) == (1:2, 1:3) - @test SparseArrayInterface.sparse_storage(a) == elt[12] - @test isone(SparseArrayInterface.stored_length(a)) - @test SparseArrayInterface.storage_indices(a) == 1:1 - @test collect(SparseArrayInterface.stored_indices(a)) == [CartesianIndex(1, 2)] + @test SparseArraysBase.sparse_storage(a) == elt[12] + @test isone(SparseArraysBase.stored_length(a)) + @test SparseArraysBase.storage_indices(a) == 1:1 + @test collect(SparseArraysBase.stored_indices(a)) == [CartesianIndex(1, 2)] @test !iszero(a) @test !iszero(norm(a)) for I in eachindex(a) @@ -171,9 +171,9 @@ using Test: @test, @testset a = 2 * a @test size(a) == (2, 3) @test axes(a) == (1:2, 1:3) - @test SparseArrayInterface.sparse_storage(a) == elt[24] - @test isone(SparseArrayInterface.stored_length(a)) - @test collect(SparseArrayInterface.stored_indices(a)) == [CartesianIndex(1, 2)] + @test SparseArraysBase.sparse_storage(a) == elt[24] + @test isone(SparseArraysBase.stored_length(a)) + @test collect(SparseArraysBase.stored_indices(a)) == [CartesianIndex(1, 2)] @test !iszero(a) @test !iszero(norm(a)) for I in eachindex(a) @@ -191,9 +191,9 @@ using Test: @test, @testset c = a + b @test size(c) == (2, 3) @test axes(c) == (1:2, 1:3) - @test SparseArrayInterface.sparse_storage(c) == elt[12, 21] - @test SparseArrayInterface.stored_length(c) == 2 - @test collect(SparseArrayInterface.stored_indices(c)) == + @test SparseArraysBase.sparse_storage(c) == elt[12, 21] + @test SparseArraysBase.stored_length(c) == 2 + @test collect(SparseArraysBase.stored_indices(c)) == [CartesianIndex(1, 2), CartesianIndex(2, 1)] @test !iszero(c) @test !iszero(norm(c)) @@ -212,9 +212,9 @@ using Test: @test, @testset b = permutedims(a, (2, 1)) @test size(b) == (3, 2) @test axes(b) == (1:3, 1:2) - @test SparseArrayInterface.sparse_storage(b) == elt[12] - @test SparseArrayInterface.stored_length(b) == 1 - @test collect(SparseArrayInterface.stored_indices(b)) == [CartesianIndex(2, 1)] + @test SparseArraysBase.sparse_storage(b) == elt[12] + @test SparseArraysBase.stored_length(b) == 1 + @test collect(SparseArraysBase.stored_indices(b)) == [CartesianIndex(2, 1)] @test !iszero(b) @test !iszero(norm(b)) for I in eachindex(b) @@ -230,9 +230,9 @@ using Test: @test, @testset b = PermutedDimsArray(a, (2, 1)) @test size(b) == (3, 2) @test axes(b) == (1:3, 1:2) - @test SparseArrayInterface.sparse_storage(b) == elt[12] - @test SparseArrayInterface.stored_length(b) == 1 - @test collect(SparseArrayInterface.stored_indices(b)) == [CartesianIndex(2, 1)] + @test SparseArraysBase.sparse_storage(b) == elt[12] + @test SparseArraysBase.stored_length(b) == 1 + @test collect(SparseArraysBase.stored_indices(b)) == [CartesianIndex(2, 1)] @test !iszero(b) @test !iszero(norm(b)) for I in eachindex(b) @@ -250,9 +250,9 @@ using Test: @test, @testset b = NestedPermutedDimsArray(a, (2, 1)) @test size(b) == (3, 2) @test axes(b) == (1:3, 1:2) - @test SparseArrayInterface.sparse_storage(b) == [a[1, 2]] - @test SparseArrayInterface.stored_length(b) == 1 - @test collect(SparseArrayInterface.stored_indices(b)) == [CartesianIndex(2, 1)] + @test SparseArraysBase.sparse_storage(b) == [a[1, 2]] + @test SparseArraysBase.stored_length(b) == 1 + @test collect(SparseArraysBase.stored_indices(b)) == [CartesianIndex(2, 1)] @test !iszero(b) @test !iszero(norm(b)) for I in eachindex(b) @@ -310,7 +310,7 @@ using Test: @test, @testset @test a .+ 2 .* b == Array(a) + 2b @test a + b isa Matrix{elt} @test b + a isa Matrix{elt} - @test SparseArrayInterface.stored_length(a + b) == length(a) + @test SparseArraysBase.stored_length(a + b) == length(a) a = SparseArray{elt}(2, 3) a[1, 2] = 12 @@ -321,10 +321,10 @@ using Test: @test, @testset @test a′ == a + b # TODO: Should this be: # ```julia - # @test SparseArrayInterface.stored_length(a′) == 2 + # @test SparseArraysBase.stored_length(a′) == 2 # ``` # ? I.e. should it only store the nonzero values? - @test SparseArrayInterface.stored_length(a′) == 6 + @test SparseArraysBase.stored_length(a′) == 6 # Matrix multiplication a1 = SparseArray{elt}(2, 3) @@ -336,7 +336,7 @@ using Test: @test, @testset a_dest = a1 * a2 @test Array(a_dest) ≈ Array(a1) * Array(a2) @test a_dest isa SparseArray{elt} - @test SparseArrayInterface.stored_length(a_dest) == 2 + @test SparseArraysBase.stored_length(a_dest) == 2 # Dot product a1 = SparseArray{elt}(4) @@ -361,7 +361,7 @@ using Test: @test, @testset mul!(a_dest, a1, a2) @test Array(a_dest) ≈ Array(a1) * Array(a2) @test a_dest isa SparseArray{elt} - @test SparseArrayInterface.stored_length(a_dest) == 2 + @test SparseArraysBase.stored_length(a_dest) == 2 # In-place matrix multiplication a1 = SparseArray{elt}(2, 3) @@ -379,7 +379,7 @@ using Test: @test, @testset mul!(a_dest, a1, a2, α, β) @test Array(a_dest) ≈ Array(a1) * Array(a2) * α + Array(a_dest′) * β @test a_dest isa SparseArray{elt} - @test SparseArrayInterface.stored_length(a_dest) == 2 + @test SparseArraysBase.stored_length(a_dest) == 2 # cat a1 = SparseArray{elt}(2, 3) @@ -391,7 +391,7 @@ using Test: @test, @testset a_dest = cat(a1, a2; dims=1) @test size(a_dest) == (4, 3) - @test SparseArrayInterface.stored_length(a_dest) == 4 + @test SparseArraysBase.stored_length(a_dest) == 4 @test a_dest[1, 2] == a1[1, 2] @test a_dest[2, 1] == a1[2, 1] @test a_dest[3, 1] == a2[1, 1] @@ -399,7 +399,7 @@ using Test: @test, @testset a_dest = cat(a1, a2; dims=2) @test size(a_dest) == (2, 6) - @test SparseArrayInterface.stored_length(a_dest) == 4 + @test SparseArraysBase.stored_length(a_dest) == 4 @test a_dest[1, 2] == a1[1, 2] @test a_dest[2, 1] == a1[2, 1] @test a_dest[1, 4] == a2[1, 1] @@ -407,7 +407,7 @@ using Test: @test, @testset a_dest = cat(a1, a2; dims=(1, 2)) @test size(a_dest) == (4, 6) - @test SparseArrayInterface.stored_length(a_dest) == 4 + @test SparseArraysBase.stored_length(a_dest) == 4 @test a_dest[1, 2] == a1[1, 2] @test a_dest[2, 1] == a1[2, 1] @test a_dest[3, 4] == a2[1, 1] @@ -434,6 +434,6 @@ using Test: @test, @testset ## mul!(a_dest, a1, a2) ## @test Array(a_dest) ≈ Array(a1) * Array(a2) ## @test a_dest isa SparseArray{Matrix{elt}} - ## @test SparseArrayInterface.stored_length(a_dest) == 2 + ## @test SparseArraysBase.stored_length(a_dest) == 2 end end diff --git a/NDTensors/src/lib/SparseArraysBase/test/test_array.jl b/NDTensors/src/lib/SparseArraysBase/test/test_array.jl new file mode 100644 index 0000000000..0037412edf --- /dev/null +++ b/NDTensors/src/lib/SparseArraysBase/test/test_array.jl @@ -0,0 +1,13 @@ +@eval module $(gensym()) +using NDTensors.SparseArraysBase: SparseArraysBase +include("SparseArraysBaseTestUtils/SparseArraysBaseTestUtils.jl") +using Test: @test, @testset +@testset "Array (eltype=$elt)" for elt in (Float32, ComplexF32, Float64, ComplexF64) + a = randn(2, 3) + @test SparseArraysBase.sparse_storage(a) == a + @test SparseArraysBase.index_to_storage_index(a, CartesianIndex(1, 2)) == + CartesianIndex(1, 2) + @test SparseArraysBase.storage_index_to_index(a, CartesianIndex(1, 2)) == + CartesianIndex(1, 2) +end +end diff --git a/NDTensors/src/lib/SparseArrayInterface/test/test_diagonalarray.jl b/NDTensors/src/lib/SparseArraysBase/test/test_diagonalarray.jl similarity index 73% rename from NDTensors/src/lib/SparseArrayInterface/test/test_diagonalarray.jl rename to NDTensors/src/lib/SparseArraysBase/test/test_diagonalarray.jl index 257ef385b4..18075e3d35 100644 --- a/NDTensors/src/lib/SparseArrayInterface/test/test_diagonalarray.jl +++ b/NDTensors/src/lib/SparseArraysBase/test/test_diagonalarray.jl @@ -1,8 +1,8 @@ @eval module $(gensym()) using LinearAlgebra: norm -using NDTensors.SparseArrayInterface: SparseArrayInterface -include("SparseArrayInterfaceTestUtils/SparseArrayInterfaceTestUtils.jl") -using .SparseArrayInterfaceTestUtils.DiagonalArrays: DiagonalArray +using NDTensors.SparseArraysBase: SparseArraysBase +include("SparseArraysBaseTestUtils/SparseArraysBaseTestUtils.jl") +using .SparseArraysBaseTestUtils.DiagonalArrays: DiagonalArray using Test: @test, @testset, @test_throws @testset "DiagonalArray (eltype=$elt)" for elt in (Float32, ComplexF32, Float64, ComplexF64) # TODO: Test `fill!`. @@ -15,14 +15,14 @@ using Test: @test, @testset, @test_throws @test a[1, 1] == 11 @test a[2, 2] == 22 @test_throws ArgumentError a[1, 2] = 12 - @test SparseArrayInterface.storage_indices(a) == 1:2 - @test collect(SparseArrayInterface.stored_indices(a)) == + @test SparseArraysBase.storage_indices(a) == 1:2 + @test collect(SparseArraysBase.stored_indices(a)) == [CartesianIndex(1, 1), CartesianIndex(2, 2)] a[1, 2] = 0 @test a[1, 1] == 11 @test a[2, 2] == 22 - a_dense = SparseArrayInterface.densearray(a) + a_dense = SparseArraysBase.densearray(a) @test a_dense == a @test a_dense isa Array{elt,ndims(a)} @@ -35,9 +35,9 @@ using Test: @test, @testset, @test_throws @test a[1, 1] == 1 @test a[2, 2] == 2 @test a[3, 3] == 3 - @test a[SparseArrayInterface.StorageIndex(1)] == 1 - @test a[SparseArrayInterface.StorageIndex(2)] == 2 - @test a[SparseArrayInterface.StorageIndex(3)] == 3 + @test a[SparseArraysBase.StorageIndex(1)] == 1 + @test a[SparseArraysBase.StorageIndex(2)] == 2 + @test a[SparseArraysBase.StorageIndex(3)] == 3 @test iszero(a[1, 2]) a = DiagonalArray(elt[1, 2, 3], (3, 3)) @@ -56,7 +56,7 @@ using Test: @test, @testset, @test_throws end # This needs `Base.reshape` with a custom destination - # calling `SparseArrayInterface.sparse_reshape!` + # calling `SparseArraysBase.sparse_reshape!` # in order to specify an appropriate output # type to work. a = DiagonalArray(elt[1, 2], (2, 2, 2)) diff --git a/NDTensors/src/lib/TensorAlgebra/ext/TensorAlgebraGradedAxesExt/test/test_contract.jl b/NDTensors/src/lib/TensorAlgebra/ext/TensorAlgebraGradedAxesExt/test/test_contract.jl index 1ada7d3393..636900303c 100644 --- a/NDTensors/src/lib/TensorAlgebra/ext/TensorAlgebraGradedAxesExt/test/test_contract.jl +++ b/NDTensors/src/lib/TensorAlgebra/ext/TensorAlgebraGradedAxesExt/test/test_contract.jl @@ -3,7 +3,7 @@ using BlockArrays: Block, blocksize using Compat: Returns using NDTensors.BlockSparseArrays: BlockSparseArray using NDTensors.GradedAxes: gradedrange -using NDTensors.SparseArrayInterface: densearray +using NDTensors.SparseArraysBase: densearray using NDTensors.SymmetrySectors: U1 using NDTensors.TensorAlgebra: contract using Random: randn! diff --git a/NDTensors/test/backup/arraytensor/diagonalarray.jl b/NDTensors/test/backup/arraytensor/diagonalarray.jl index d5d73b88db..1e80d30fd1 100644 --- a/NDTensors/test/backup/arraytensor/diagonalarray.jl +++ b/NDTensors/test/backup/arraytensor/diagonalarray.jl @@ -1,6 +1,6 @@ @eval module $(gensym()) using NDTensors: contract, tensor -using NDTensors.SparseArrayInterface: densearray +using NDTensors.SparseArraysBase: densearray using NDTensors.DiagonalArrays: DiagonalArray using Test: @test, @testset @testset "Tensor wrapping DiagonalArray" begin