Skip to content

Commit

Permalink
[SparseArrayInterface] [BlockSparseArrays] Rename nstored to stored_l…
Browse files Browse the repository at this point in the history
…ength (#1585)

* [SparseArrayInterface] [BlockSparseArrays] Rename nstored to stored_length

* [NDTensors] Bump to v0.3.67
  • Loading branch information
mtfishman authored Nov 14, 2024
1 parent f4aa481 commit 7faad33
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 147 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 <mfishman@flatironinstitute.org>"]
version = "0.3.66"
version = "0.3.67"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
8 changes: 4 additions & 4 deletions NDTensors/src/lib/BlockSparseArrays/examples/README.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# `BlockArrays` reinterprets the `SparseArray` as a blocked data structure.

using BlockArrays: BlockArrays, PseudoBlockVector, blockedrange
using NDTensors.BlockSparseArrays: BlockSparseArray, block_nstored
using NDTensors.BlockSparseArrays: BlockSparseArray, block_stored_length
using Test: @test, @test_broken

function main()
Expand Down Expand Up @@ -36,13 +36,13 @@ function main()
]
b = BlockSparseArray(nz_blocks, d_blocks, i_axes)

@test block_nstored(b) == 2
@test block_stored_length(b) == 2

## Blocks with discontiguous underlying data
d_blocks = randn.(nz_block_sizes)
b = BlockSparseArray(nz_blocks, d_blocks, i_axes)

@test block_nstored(b) == 2
@test block_stored_length(b) == 2

## Access a block
@test b[Block(1, 1)] == d_blocks[1]
Expand All @@ -65,7 +65,7 @@ function main()

@test b + b Array(b) + Array(b)
@test b + b isa BlockSparseArray
@test block_nstored(b + b) == 2
@test block_stored_length(b + b) == 2

scaled_b = 2b
@test scaled_b 2Array(b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Test: @test, @testset
using BlockArrays:
AbstractBlockArray, Block, BlockedOneTo, blockedrange, blocklengths, blocksize
using NDTensors.BlockSparseArrays: BlockSparseArray, block_nstored
using NDTensors.BlockSparseArrays: BlockSparseArray, block_stored_length
using NDTensors.GradedAxes:
GradedAxes,
GradedOneTo,
Expand All @@ -13,7 +13,7 @@ using NDTensors.GradedAxes:
gradedrange,
isdual
using NDTensors.LabelledNumbers: label
using NDTensors.SparseArrayInterface: nstored
using NDTensors.SparseArrayInterface: stored_length
using NDTensors.SymmetrySectors: U1
using NDTensors.TensorAlgebra: fusedims, splitdims
using LinearAlgebra: adjoint
Expand All @@ -40,8 +40,8 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
@test size(b) == (4, 4, 4, 4)
@test blocksize(b) == (2, 2, 2, 2)
@test blocklengths.(axes(b)) == ([2, 2], [2, 2], [2, 2], [2, 2])
@test nstored(b) == 32
@test block_nstored(b) == 2
@test stored_length(b) == 32
@test block_stored_length(b) == 2
for i in 1:ndims(a)
@test axes(b, i) isa GradedOneTo
end
Expand All @@ -58,8 +58,8 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
@test size(b) == (4, 4, 4, 4)
@test blocksize(b) == (2, 2, 2, 2)
@test blocklengths.(axes(b)) == ([2, 2], [2, 2], [2, 2], [2, 2])
@test nstored(b) == 256
@test block_nstored(b) == 16
@test stored_length(b) == 256
@test block_stored_length(b) == 16
for i in 1:ndims(a)
@test axes(b, i) isa BlockedOneTo{Int}
end
Expand All @@ -71,8 +71,8 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
b = a[2:3, 2:3, 2:3, 2:3]
@test size(b) == (2, 2, 2, 2)
@test blocksize(b) == (2, 2, 2, 2)
@test nstored(b) == 2
@test block_nstored(b) == 2
@test stored_length(b) == 2
@test block_stored_length(b) == 2
for i in 1:ndims(a)
@test axes(b, i) isa GradedOneTo
end
Expand Down Expand Up @@ -156,7 +156,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
a[i] = randn(elt, size(a[i]))
end
b = 2 * a
@test block_nstored(b) == 2
@test block_stored_length(b) == 2
@test Array(b) == 2 * Array(a)
for i in 1:2
@test axes(b, i) isa GradedOneTo
Expand All @@ -177,7 +177,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
a[i] = randn(elt, size(a[i]))
end
b = 2 * a
@test block_nstored(b) == 2
@test block_stored_length(b) == 2
@test Array(b) == 2 * Array(a)
for i in 1:2
@test axes(b, i) isa GradedUnitRange
Expand All @@ -204,7 +204,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
a[i] = randn(elt, size(a[i]))
end
b = 2 * a
@test block_nstored(b) == 2
@test block_stored_length(b) == 2
@test Array(b) == 2 * Array(a)
for i in 1:2
@test axes(b, i) isa GradedUnitRangeDual
Expand All @@ -229,7 +229,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
a[i] = randn(elt, size(a[i]))
end
b = 2 * a
@test block_nstored(b) == 2
@test block_stored_length(b) == 2
@test Array(b) == 2 * Array(a)
for i in 1:2
@test axes(b, i) isa GradedUnitRangeDual
Expand All @@ -255,7 +255,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
a[i] = randn(elt, size(a[i]))
end
b = 2 * a
@test block_nstored(b) == 2
@test block_stored_length(b) == 2
@test Array(b) == 2 * Array(a)
@test a[:, :] isa BlockSparseArray
for i in 1:2
Expand All @@ -280,7 +280,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
a[i] = randn(elt, size(a[i]))
end
b = 2 * a'
@test block_nstored(b) == 2
@test block_stored_length(b) == 2
@test Array(b) == 2 * Array(a)'
for ax in axes(b)
@test ax isa typeof(dual(r))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using BlockArrays:
using Compat: allequal
using Dictionaries: Dictionary, Indices
using ..GradedAxes: blockedunitrange_getindices, to_blockindices
using ..SparseArrayInterface: SparseArrayInterface, nstored, stored_indices
using ..SparseArrayInterface: SparseArrayInterface, stored_length, stored_indices

# A return type for `blocks(array)` when `array` isn't blocked.
# Represents a vector with just that single block.
Expand Down Expand Up @@ -534,13 +534,13 @@ function Base.setindex!(a::BlockView{<:Any,N}, value, index::Vararg{Int,N}) wher
return a
end

function SparseArrayInterface.nstored(a::BlockView)
function SparseArrayInterface.stored_length(a::BlockView)
# TODO: Store whether or not the block is stored already as
# a Bool in `BlockView`.
I = CartesianIndex(Int.(a.block))
# TODO: Use `block_stored_indices`.
if I stored_indices(blocks(a.array))
return nstored(blocks(a.array)[I])
return stored_length(blocks(a.array)[I])
end
return 0
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using BlockArrays: AbstractBlockArray, BlocksView
using ..SparseArrayInterface: SparseArrayInterface, nstored
using ..SparseArrayInterface: SparseArrayInterface, stored_length

function SparseArrayInterface.nstored(a::AbstractBlockArray)
return sum(b -> nstored(b), blocks(a); init=zero(Int))
function SparseArrayInterface.stored_length(a::AbstractBlockArray)
return sum(b -> stored_length(b), blocks(a); init=zero(Int))
end

# TODO: Handle `BlocksView` wrapping a sparse array?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using BlockArrays:
using ..SparseArrayInterface: sparse_getindex, sparse_setindex!

# TODO: Delete this. This function was replaced
# by `nstored` but is still used in `NDTensors`.
# by `stored_length` but is still used in `NDTensors`.
function nonzero_keys end

abstract type AbstractBlockSparseArray{T,N} <: AbstractBlockArray{T,N} end
Expand Down
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::AnyAbstractBlockSparseArray)
return sum(nstored, sparse_storage(blocks(a)); init=zero(Int))
function SparseArrayInterface.stored_length(a::AnyAbstractBlockSparseArray)
return sum(stored_length, sparse_storage(blocks(a)); init=zero(Int))
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using BlockArrays:
blocks,
findblockindex
using LinearAlgebra: Adjoint, Transpose
using ..SparseArrayInterface: perm, iperm, nstored, sparse_zero!
using ..SparseArrayInterface: perm, iperm, stored_length, sparse_zero!

blocksparse_blocks(a::AbstractArray) = error("Not implemented")

Expand Down Expand Up @@ -134,8 +134,8 @@ function blocksparse_fill!(a::AbstractArray, value)
return a
end

function block_nstored(a::AbstractArray)
return nstored(blocks(a))
function block_stored_length(a::AbstractArray)
return stored_length(blocks(a))
end

# BlockArrays
Expand Down Expand Up @@ -174,7 +174,9 @@ end
# TODO: Either make this the generic interface or define
# `SparseArrayInterface.sparse_storage`, which is used
# to defined this.
SparseArrayInterface.nstored(a::SparsePermutedDimsArrayBlocks) = length(stored_indices(a))
function SparseArrayInterface.stored_length(a::SparsePermutedDimsArrayBlocks)
return length(stored_indices(a))
end
function SparseArrayInterface.sparse_storage(a::SparsePermutedDimsArrayBlocks)
return error("Not implemented")
end
Expand Down Expand Up @@ -212,7 +214,7 @@ end
# TODO: Either make this the generic interface or define
# `SparseArrayInterface.sparse_storage`, which is used
# to defined this.
SparseArrayInterface.nstored(a::SparseTransposeBlocks) = length(stored_indices(a))
SparseArrayInterface.stored_length(a::SparseTransposeBlocks) = length(stored_indices(a))
function SparseArrayInterface.sparse_storage(a::SparseTransposeBlocks)
return error("Not implemented")
end
Expand Down Expand Up @@ -251,7 +253,7 @@ end
# TODO: Either make this the generic interface or define
# `SparseArrayInterface.sparse_storage`, which is used
# to defined this.
SparseArrayInterface.nstored(a::SparseAdjointBlocks) = length(stored_indices(a))
SparseArrayInterface.stored_length(a::SparseAdjointBlocks) = length(stored_indices(a))
function SparseArrayInterface.sparse_storage(a::SparseAdjointBlocks)
return error("Not implemented")
end
Expand Down Expand Up @@ -314,7 +316,7 @@ end
# TODO: Either make this the generic interface or define
# `SparseArrayInterface.sparse_storage`, which is used
# to defined this.
SparseArrayInterface.nstored(a::SparseSubArrayBlocks) = length(stored_indices(a))
SparseArrayInterface.stored_length(a::SparseSubArrayBlocks) = length(stored_indices(a))

## struct SparseSubArrayBlocksStorage{Array<:SparseSubArrayBlocks}
## array::Array
Expand All @@ -339,4 +341,4 @@ function blocksparse_blocks(
end

using BlockArrays: BlocksView
SparseArrayInterface.nstored(a::BlocksView) = length(a)
SparseArrayInterface.stored_length(a::BlocksView) = length(a)
Loading

2 comments on commit 7faad33

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

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.67 -m "<description of version>" 7faad33645512dd68909dc6060e3920a076d4778
git push origin NDTensors-v0.3.67

Please sign in to comment.