Skip to content

Commit

Permalink
[SparseArrayInterface] [BlockSparseArrays] Rename wrapper type unions (
Browse files Browse the repository at this point in the history
…#1584)

* [SparseArrayInterface] [BlockSparseArrays] Rename wrapper type unions

* [NDTensors] Bump to v0.3.66
  • Loading branch information
mtfishman authored Nov 14, 2024
1 parent 2e5da07 commit 4ac4315
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 75 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.65"
version = "0.3.66"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using BlockArrays: BlockLayout
using ..SparseArrayInterface: SparseLayout
using ..TypeParameterAccessors: parenttype, similartype

function ArrayLayouts.MemoryLayout(arraytype::Type{<:BlockSparseArrayLike})
function ArrayLayouts.MemoryLayout(arraytype::Type{<:AnyAbstractBlockSparseArray})
outer_layout = typeof(MemoryLayout(blockstype(arraytype)))
inner_layout = typeof(MemoryLayout(blocktype(arraytype)))
return BlockLayout{outer_layout,inner_layout}()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using BlockArrays: AbstractBlockedUnitRange, BlockSlice
using Base.Broadcast: Broadcast

function Broadcast.BroadcastStyle(arraytype::Type{<:BlockSparseArrayLike})
function Broadcast.BroadcastStyle(arraytype::Type{<:AnyAbstractBlockSparseArray})
return BlockSparseArrayStyle{ndims(arraytype)}()
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# TODO: Change to `AnyAbstractBlockSparseArray`.
function Base.cat(as::BlockSparseArrayLike...; dims)
function Base.cat(as::AnyAbstractBlockSparseArray...; dims)
# TODO: Use `sparse_cat` instead, currently
# that erroneously allocates too many blocks that are
# zero and shouldn't be stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,27 @@ end
# function SparseArrayInterface.sparse_mapreduce(::BlockSparseArrayStyle, f, a_dest::AbstractArray, a_srcs::Vararg{AbstractArray})
# end

function Base.map!(f, a_dest::AbstractArray, a_srcs::Vararg{BlockSparseArrayLike})
function Base.map!(f, a_dest::AbstractArray, a_srcs::Vararg{AnyAbstractBlockSparseArray})
sparse_map!(f, a_dest, a_srcs...)
return a_dest
end

function Base.map(f, as::Vararg{BlockSparseArrayLike})
function Base.map(f, as::Vararg{AnyAbstractBlockSparseArray})
return f.(as...)
end

function Base.copy!(a_dest::AbstractArray, a_src::BlockSparseArrayLike)
function Base.copy!(a_dest::AbstractArray, a_src::AnyAbstractBlockSparseArray)
sparse_copy!(a_dest, a_src)
return a_dest
end

function Base.copyto!(a_dest::AbstractArray, a_src::BlockSparseArrayLike)
function Base.copyto!(a_dest::AbstractArray, a_src::AnyAbstractBlockSparseArray)
sparse_copyto!(a_dest, a_src)
return a_dest
end

# Fix ambiguity error
function Base.copyto!(a_dest::LayoutArray, a_src::BlockSparseArrayLike)
function Base.copyto!(a_dest::LayoutArray, a_src::AnyAbstractBlockSparseArray)
sparse_copyto!(a_dest, a_src)
return a_dest
end
Expand All @@ -131,21 +131,21 @@ function Base.copyto!(
return a_dest
end

function Base.permutedims!(a_dest, a_src::BlockSparseArrayLike, perm)
function Base.permutedims!(a_dest, a_src::AnyAbstractBlockSparseArray, perm)
sparse_permutedims!(a_dest, a_src, perm)
return a_dest
end

function Base.mapreduce(f, op, as::Vararg{BlockSparseArrayLike}; kwargs...)
function Base.mapreduce(f, op, as::Vararg{AnyAbstractBlockSparseArray}; kwargs...)
return sparse_mapreduce(f, op, as...; kwargs...)
end

# TODO: Why isn't this calling `mapreduce` already?
function Base.iszero(a::BlockSparseArrayLike)
function Base.iszero(a::AnyAbstractBlockSparseArray)
return sparse_iszero(blocks(a))
end

# TODO: Why isn't this calling `mapreduce` already?
function Base.isreal(a::BlockSparseArrayLike)
function Base.isreal(a::AnyAbstractBlockSparseArray)
return sparse_isreal(blocks(a))
end
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ function SparseArrayInterface.sparse_storage(a::AbstractBlockSparseArray)
return BlockSparseStorage(a)
end

function SparseArrayInterface.nstored(a::BlockSparseArrayLike)
function SparseArrayInterface.nstored(a::AnyAbstractBlockSparseArray)
return sum(nstored, sparse_storage(blocks(a)); init=zero(Int))
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ end

# Override the default definition of `BlockArrays.blocksize`,
# which is incorrect for certain slices.
function BlockArrays.blocksize(a::SubArray{<:Any,<:Any,<:BlockSparseArrayLike})
function BlockArrays.blocksize(a::SubArray{<:Any,<:Any,<:AnyAbstractBlockSparseArray})
return blocklength.(axes(a))
end
function BlockArrays.blocksize(a::SubArray{<:Any,<:Any,<:BlockSparseArrayLike}, i::Int)
function BlockArrays.blocksize(
a::SubArray{<:Any,<:Any,<:AnyAbstractBlockSparseArray}, i::Int
)
# TODO: Maybe use `blocklength(axes(a, i))` which would be a bit faster.
return blocksize(a)[i]
end
Expand All @@ -33,22 +35,22 @@ end
# which don't handle subslices of blocks properly.
function Base.view(
a::SubArray{
<:Any,N,<:BlockSparseArrayLike,<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}}
<:Any,N,<:AnyAbstractBlockSparseArray,<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}}
},
I::Block{N},
) where {N}
return blocksparse_view(a, I)
end
function Base.view(
a::SubArray{
<:Any,N,<:BlockSparseArrayLike,<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}}
<:Any,N,<:AnyAbstractBlockSparseArray,<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}}
},
I::Vararg{Block{1},N},
) where {N}
return blocksparse_view(a, I...)
end
function Base.view(
V::SubArray{<:Any,1,<:BlockSparseArrayLike,<:Tuple{BlockSlice{<:BlockRange{1}}}},
V::SubArray{<:Any,1,<:AnyAbstractBlockSparseArray,<:Tuple{BlockSlice{<:BlockRange{1}}}},
I::Block{1},
)
return blocksparse_view(a, I)
Expand Down Expand Up @@ -154,7 +156,7 @@ function BlockArrays.viewblock(
return viewblock(a, to_tuple(block)...)
end

# Fixes ambiguity error with `BlockSparseArrayLike` definition.
# Fixes ambiguity error with `AnyAbstractBlockSparseArray` definition.
function Base.view(
a::SubArray{
T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}}
Expand All @@ -163,7 +165,7 @@ function Base.view(
) where {T,N}
return viewblock(a, block)
end
# Fixes ambiguity error with `BlockSparseArrayLike` definition.
# Fixes ambiguity error with `AnyAbstractBlockSparseArray` definition.
function Base.view(
a::SubArray{
T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{BlockSlice{<:BlockRange{1}},N}}
Expand Down
Loading

2 comments on commit 4ac4315

@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/119406

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.66 -m "<description of version>" 4ac431579aae9b4a37978a44860839fdab58f1b2
git push origin NDTensors-v0.3.66

Please sign in to comment.