Skip to content

Commit

Permalink
[SparseArraysBase] Delete unnecessary using statements
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Nov 19, 2024
1 parent f1f179b commit f95fd8a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 34 deletions.
2 changes: 1 addition & 1 deletion NDTensors/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NDTensors"
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
authors = ["Matthew Fishman <[email protected]>"]
version = "0.3.72"
version = "0.3.73"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using ..SparseArraysBase: SparseArraysBase

# Base
function Base.:(==)(a1::AnyAbstractSparseArray, a2::AnyAbstractSparseArray)
return SparseArraysBase.sparse_isequal(a1, a2)
return sparse_isequal(a1, a2)
end

function Base.reshape(a::AnyAbstractSparseArray, dims::Tuple{Vararg{Int}})
return SparseArraysBase.sparse_reshape(a, dims)
return sparse_reshape(a, dims)
end

function Base.zero(a::AnyAbstractSparseArray)
return SparseArraysBase.sparse_zero(a)
return sparse_zero(a)
end

function Base.one(a::AnyAbstractSparseArray)
return SparseArraysBase.sparse_one(a)
return sparse_one(a)
end
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
using ..SparseArraysBase: SparseArraysBase

Base.size(a::AbstractSparseArray) = error("Not implemented")

function Base.similar(a::AbstractSparseArray, elt::Type, dims::Tuple{Vararg{Int}})
return error("Not implemented")
end

function Base.getindex(a::AbstractSparseArray, I...)
return SparseArraysBase.sparse_getindex(a, I...)
return sparse_getindex(a, I...)
end

# Fixes ambiguity error with `ArrayLayouts`.
function Base.getindex(a::AbstractSparseMatrix, I1::AbstractVector, I2::AbstractVector)
return SparseArraysBase.sparse_getindex(a, I1, I2)
return sparse_getindex(a, I1, I2)
end

# Fixes ambiguity error with `ArrayLayouts`.
function Base.getindex(
a::AbstractSparseMatrix, I1::AbstractUnitRange, I2::AbstractUnitRange
)
return SparseArraysBase.sparse_getindex(a, I1, I2)
return sparse_getindex(a, I1, I2)
end

function Base.isassigned(a::AbstractSparseArray, I::Integer...)
return SparseArraysBase.sparse_isassigned(a, I...)
return sparse_isassigned(a, I...)
end

function Base.setindex!(a::AbstractSparseArray, I...)
return SparseArraysBase.sparse_setindex!(a, I...)
return sparse_setindex!(a, I...)
end

function Base.fill!(a::AbstractSparseArray, value)
return SparseArraysBase.sparse_fill!(a, value)
return sparse_fill!(a, value)
end
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using Dictionaries: set!
using ..SparseArraysBase: SparseArraysBase

SparseArraysBase.sparse_storage(::AbstractSparseArray) = error("Not implemented")
sparse_storage(::AbstractSparseArray) = error("Not implemented")

function SparseArraysBase.index_to_storage_index(
function index_to_storage_index(
a::AbstractSparseArray{<:Any,N}, I::CartesianIndex{N}
) where {N}
!isassigned(SparseArraysBase.sparse_storage(a), I) && return nothing
!isassigned(sparse_storage(a), I) && return nothing
return I
end

function SparseArraysBase.setindex_notstored!(
function setindex_notstored!(
a::AbstractSparseArray{<:Any,N}, value, I::CartesianIndex{N}
) where {N}
iszero(value) && return a
Expand All @@ -20,7 +19,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 SparseArraysBase.sparse_storage(a::SubArray{<:Any,<:Any,<:AbstractSparseArray})
function 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)
Expand All @@ -31,7 +30,7 @@ function SparseArraysBase.sparse_storage(a::SubArray{<:Any,<:Any,<:AbstractSpars
end

# TODO: Make this into a generic definition of all `AbstractArray`?
function SparseArraysBase.stored_indices(
function stored_indices(
a::AnyPermutedDimsArray{<:Any,<:Any,<:Any,<:Any,<:AbstractSparseArray}
)
return Iterators.map(
Expand All @@ -40,7 +39,7 @@ function SparseArraysBase.stored_indices(
end

# TODO: Make this into a generic definition of all `AbstractArray`?
function SparseArraysBase.sparse_storage(
function sparse_storage(
a::AnyPermutedDimsArray{<:Any,<:Any,<:Any,<:Any,<:AbstractSparseArray}
)
return sparse_storage(parent(a))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ArrayLayouts: ArrayLayouts, MemoryLayout, MulAdd
using ..SparseArraysBase: AbstractSparseLayout, SparseLayout

ArrayLayouts.MemoryLayout(::Type{<:SparseArrayDOK}) = SparseLayout()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Dictionaries: Dictionary
using ..SparseArraysBase: Zero

default_zero() = Zero()
default_data(type::Type, ndims::Int) = Dictionary{default_keytype(ndims),type}()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Accessors: @set
using Dictionaries: Dictionary, set!
using MacroTools: @capture
using ..SparseArraysBase: SparseArraysBase, AbstractSparseArray, getindex_zero_function

# TODO: Parametrize by `data`?
struct SparseArrayDOK{T,N,Zero} <: AbstractSparseArray{T,N}
Expand Down Expand Up @@ -81,15 +80,15 @@ end
# Base `AbstractArray` interface
Base.size(a::SparseArrayDOK) = a.dims[]

SparseArraysBase.getindex_zero_function(a::SparseArrayDOK) = a.zero
function SparseArraysBase.set_getindex_zero_function(a::SparseArrayDOK, f)
getindex_zero_function(a::SparseArrayDOK) = a.zero
function set_getindex_zero_function(a::SparseArrayDOK, f)
return @set a.zero = f
end

function SparseArraysBase.setindex_notstored!(
function setindex_notstored!(
a::SparseArrayDOK{<:Any,N}, value, I::CartesianIndex{N}
) where {N}
set!(SparseArraysBase.sparse_storage(a), I, value)
set!(sparse_storage(a), I, value)
return a
end

Expand All @@ -98,18 +97,18 @@ function Base.similar(a::SparseArrayDOK, elt::Type, dims::Tuple{Vararg{Int}})
end

# `SparseArraysBase` interface
SparseArraysBase.sparse_storage(a::SparseArrayDOK) = a.data
sparse_storage(a::SparseArrayDOK) = a.data

function SparseArraysBase.dropall!(a::SparseArrayDOK)
return empty!(SparseArraysBase.sparse_storage(a))
function dropall!(a::SparseArrayDOK)
return empty!(sparse_storage(a))
end

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 SparseArraysBase.sparse_convert(SparseArrayDOK{T,N}, a)
return sparse_convert(SparseArrayDOK{T,N}, a)
end

function Base.resize!(a::SparseArrayDOK{<:Any,N}, new_size::NTuple{N,Integer}) where {N}
Expand Down

0 comments on commit f95fd8a

Please sign in to comment.