Skip to content

Commit

Permalink
[SparseArraysBase] Delete unnecessary using statements (#1598)
Browse files Browse the repository at this point in the history
* [SparseArraysBase] Delete unnecessary using statements

* [NDTensors] Bump to v0.3.74
  • Loading branch information
mtfishman authored Nov 19, 2024
1 parent a84bb65 commit 795042b
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.73"
version = "0.3.74"

[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

2 comments on commit 795042b

@mtfishman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register subdir=NDTensors

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/119761

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a NDTensors-v0.3.74 -m "<description of version>" 795042b976729ed79768482e01f2c4d31b6325ff
git push origin NDTensors-v0.3.74

Please sign in to comment.