Skip to content

Commit 7faad33

Browse files
authored
[SparseArrayInterface] [BlockSparseArrays] Rename nstored to stored_length (#1585)
* [SparseArrayInterface] [BlockSparseArrays] Rename nstored to stored_length * [NDTensors] Bump to v0.3.67
1 parent f4aa481 commit 7faad33

File tree

18 files changed

+149
-147
lines changed

18 files changed

+149
-147
lines changed

NDTensors/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "NDTensors"
22
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
33
authors = ["Matthew Fishman <[email protected]>"]
4-
version = "0.3.66"
4+
version = "0.3.67"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"

NDTensors/src/lib/BlockSparseArrays/examples/README.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# `BlockArrays` reinterprets the `SparseArray` as a blocked data structure.
88

99
using BlockArrays: BlockArrays, PseudoBlockVector, blockedrange
10-
using NDTensors.BlockSparseArrays: BlockSparseArray, block_nstored
10+
using NDTensors.BlockSparseArrays: BlockSparseArray, block_stored_length
1111
using Test: @test, @test_broken
1212

1313
function main()
@@ -36,13 +36,13 @@ function main()
3636
]
3737
b = BlockSparseArray(nz_blocks, d_blocks, i_axes)
3838

39-
@test block_nstored(b) == 2
39+
@test block_stored_length(b) == 2
4040

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

45-
@test block_nstored(b) == 2
45+
@test block_stored_length(b) == 2
4646

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

6666
@test b + b Array(b) + Array(b)
6767
@test b + b isa BlockSparseArray
68-
@test block_nstored(b + b) == 2
68+
@test block_stored_length(b + b) == 2
6969

7070
scaled_b = 2b
7171
@test scaled_b 2Array(b)

NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/test/runtests.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Test: @test, @testset
33
using BlockArrays:
44
AbstractBlockArray, Block, BlockedOneTo, blockedrange, blocklengths, blocksize
5-
using NDTensors.BlockSparseArrays: BlockSparseArray, block_nstored
5+
using NDTensors.BlockSparseArrays: BlockSparseArray, block_stored_length
66
using NDTensors.GradedAxes:
77
GradedAxes,
88
GradedOneTo,
@@ -13,7 +13,7 @@ using NDTensors.GradedAxes:
1313
gradedrange,
1414
isdual
1515
using NDTensors.LabelledNumbers: label
16-
using NDTensors.SparseArrayInterface: nstored
16+
using NDTensors.SparseArrayInterface: stored_length
1717
using NDTensors.SymmetrySectors: U1
1818
using NDTensors.TensorAlgebra: fusedims, splitdims
1919
using LinearAlgebra: adjoint
@@ -40,8 +40,8 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
4040
@test size(b) == (4, 4, 4, 4)
4141
@test blocksize(b) == (2, 2, 2, 2)
4242
@test blocklengths.(axes(b)) == ([2, 2], [2, 2], [2, 2], [2, 2])
43-
@test nstored(b) == 32
44-
@test block_nstored(b) == 2
43+
@test stored_length(b) == 32
44+
@test block_stored_length(b) == 2
4545
for i in 1:ndims(a)
4646
@test axes(b, i) isa GradedOneTo
4747
end
@@ -58,8 +58,8 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
5858
@test size(b) == (4, 4, 4, 4)
5959
@test blocksize(b) == (2, 2, 2, 2)
6060
@test blocklengths.(axes(b)) == ([2, 2], [2, 2], [2, 2], [2, 2])
61-
@test nstored(b) == 256
62-
@test block_nstored(b) == 16
61+
@test stored_length(b) == 256
62+
@test block_stored_length(b) == 16
6363
for i in 1:ndims(a)
6464
@test axes(b, i) isa BlockedOneTo{Int}
6565
end
@@ -71,8 +71,8 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
7171
b = a[2:3, 2:3, 2:3, 2:3]
7272
@test size(b) == (2, 2, 2, 2)
7373
@test blocksize(b) == (2, 2, 2, 2)
74-
@test nstored(b) == 2
75-
@test block_nstored(b) == 2
74+
@test stored_length(b) == 2
75+
@test block_stored_length(b) == 2
7676
for i in 1:ndims(a)
7777
@test axes(b, i) isa GradedOneTo
7878
end
@@ -156,7 +156,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
156156
a[i] = randn(elt, size(a[i]))
157157
end
158158
b = 2 * a
159-
@test block_nstored(b) == 2
159+
@test block_stored_length(b) == 2
160160
@test Array(b) == 2 * Array(a)
161161
for i in 1:2
162162
@test axes(b, i) isa GradedOneTo
@@ -177,7 +177,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
177177
a[i] = randn(elt, size(a[i]))
178178
end
179179
b = 2 * a
180-
@test block_nstored(b) == 2
180+
@test block_stored_length(b) == 2
181181
@test Array(b) == 2 * Array(a)
182182
for i in 1:2
183183
@test axes(b, i) isa GradedUnitRange
@@ -204,7 +204,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
204204
a[i] = randn(elt, size(a[i]))
205205
end
206206
b = 2 * a
207-
@test block_nstored(b) == 2
207+
@test block_stored_length(b) == 2
208208
@test Array(b) == 2 * Array(a)
209209
for i in 1:2
210210
@test axes(b, i) isa GradedUnitRangeDual
@@ -229,7 +229,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
229229
a[i] = randn(elt, size(a[i]))
230230
end
231231
b = 2 * a
232-
@test block_nstored(b) == 2
232+
@test block_stored_length(b) == 2
233233
@test Array(b) == 2 * Array(a)
234234
for i in 1:2
235235
@test axes(b, i) isa GradedUnitRangeDual
@@ -255,7 +255,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
255255
a[i] = randn(elt, size(a[i]))
256256
end
257257
b = 2 * a
258-
@test block_nstored(b) == 2
258+
@test block_stored_length(b) == 2
259259
@test Array(b) == 2 * Array(a)
260260
@test a[:, :] isa BlockSparseArray
261261
for i in 1:2
@@ -280,7 +280,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
280280
a[i] = randn(elt, size(a[i]))
281281
end
282282
b = 2 * a'
283-
@test block_nstored(b) == 2
283+
@test block_stored_length(b) == 2
284284
@test Array(b) == 2 * Array(a)'
285285
for ax in axes(b)
286286
@test ax isa typeof(dual(r))

NDTensors/src/lib/BlockSparseArrays/src/BlockArraysExtensions/BlockArraysExtensions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using BlockArrays:
2222
using Compat: allequal
2323
using Dictionaries: Dictionary, Indices
2424
using ..GradedAxes: blockedunitrange_getindices, to_blockindices
25-
using ..SparseArrayInterface: SparseArrayInterface, nstored, stored_indices
25+
using ..SparseArrayInterface: SparseArrayInterface, stored_length, stored_indices
2626

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

537-
function SparseArrayInterface.nstored(a::BlockView)
537+
function SparseArrayInterface.stored_length(a::BlockView)
538538
# TODO: Store whether or not the block is stored already as
539539
# a Bool in `BlockView`.
540540
I = CartesianIndex(Int.(a.block))
541541
# TODO: Use `block_stored_indices`.
542542
if I stored_indices(blocks(a.array))
543-
return nstored(blocks(a.array)[I])
543+
return stored_length(blocks(a.array)[I])
544544
end
545545
return 0
546546
end

NDTensors/src/lib/BlockSparseArrays/src/BlockArraysSparseArrayInterfaceExt/BlockArraysSparseArrayInterfaceExt.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using BlockArrays: AbstractBlockArray, BlocksView
2-
using ..SparseArrayInterface: SparseArrayInterface, nstored
2+
using ..SparseArrayInterface: SparseArrayInterface, stored_length
33

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

88
# TODO: Handle `BlocksView` wrapping a sparse array?

NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/abstractblocksparsearray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using BlockArrays:
33
using ..SparseArrayInterface: sparse_getindex, sparse_setindex!
44

55
# TODO: Delete this. This function was replaced
6-
# by `nstored` but is still used in `NDTensors`.
6+
# by `stored_length` but is still used in `NDTensors`.
77
function nonzero_keys end
88

99
abstract type AbstractBlockSparseArray{T,N} <: AbstractBlockArray{T,N} end

NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/sparsearrayinterface.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ function SparseArrayInterface.sparse_storage(a::AbstractBlockSparseArray)
3333
return BlockSparseStorage(a)
3434
end
3535

36-
function SparseArrayInterface.nstored(a::AnyAbstractBlockSparseArray)
37-
return sum(nstored, sparse_storage(blocks(a)); init=zero(Int))
36+
function SparseArrayInterface.stored_length(a::AnyAbstractBlockSparseArray)
37+
return sum(stored_length, sparse_storage(blocks(a)); init=zero(Int))
3838
end

NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using BlockArrays:
1313
blocks,
1414
findblockindex
1515
using LinearAlgebra: Adjoint, Transpose
16-
using ..SparseArrayInterface: perm, iperm, nstored, sparse_zero!
16+
using ..SparseArrayInterface: perm, iperm, stored_length, sparse_zero!
1717

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

@@ -134,8 +134,8 @@ function blocksparse_fill!(a::AbstractArray, value)
134134
return a
135135
end
136136

137-
function block_nstored(a::AbstractArray)
138-
return nstored(blocks(a))
137+
function block_stored_length(a::AbstractArray)
138+
return stored_length(blocks(a))
139139
end
140140

141141
# BlockArrays
@@ -174,7 +174,9 @@ end
174174
# TODO: Either make this the generic interface or define
175175
# `SparseArrayInterface.sparse_storage`, which is used
176176
# to defined this.
177-
SparseArrayInterface.nstored(a::SparsePermutedDimsArrayBlocks) = length(stored_indices(a))
177+
function SparseArrayInterface.stored_length(a::SparsePermutedDimsArrayBlocks)
178+
return length(stored_indices(a))
179+
end
178180
function SparseArrayInterface.sparse_storage(a::SparsePermutedDimsArrayBlocks)
179181
return error("Not implemented")
180182
end
@@ -212,7 +214,7 @@ end
212214
# TODO: Either make this the generic interface or define
213215
# `SparseArrayInterface.sparse_storage`, which is used
214216
# to defined this.
215-
SparseArrayInterface.nstored(a::SparseTransposeBlocks) = length(stored_indices(a))
217+
SparseArrayInterface.stored_length(a::SparseTransposeBlocks) = length(stored_indices(a))
216218
function SparseArrayInterface.sparse_storage(a::SparseTransposeBlocks)
217219
return error("Not implemented")
218220
end
@@ -251,7 +253,7 @@ end
251253
# TODO: Either make this the generic interface or define
252254
# `SparseArrayInterface.sparse_storage`, which is used
253255
# to defined this.
254-
SparseArrayInterface.nstored(a::SparseAdjointBlocks) = length(stored_indices(a))
256+
SparseArrayInterface.stored_length(a::SparseAdjointBlocks) = length(stored_indices(a))
255257
function SparseArrayInterface.sparse_storage(a::SparseAdjointBlocks)
256258
return error("Not implemented")
257259
end
@@ -314,7 +316,7 @@ end
314316
# TODO: Either make this the generic interface or define
315317
# `SparseArrayInterface.sparse_storage`, which is used
316318
# to defined this.
317-
SparseArrayInterface.nstored(a::SparseSubArrayBlocks) = length(stored_indices(a))
319+
SparseArrayInterface.stored_length(a::SparseSubArrayBlocks) = length(stored_indices(a))
318320

319321
## struct SparseSubArrayBlocksStorage{Array<:SparseSubArrayBlocks}
320322
## array::Array
@@ -339,4 +341,4 @@ function blocksparse_blocks(
339341
end
340342

341343
using BlockArrays: BlocksView
342-
SparseArrayInterface.nstored(a::BlocksView) = length(a)
344+
SparseArrayInterface.stored_length(a::BlocksView) = length(a)

0 commit comments

Comments
 (0)