Skip to content

Commit cabfea7

Browse files
authored
Merge branch 'main' into BlockSparseArrays_more_constructors
2 parents 8656a56 + 7faad33 commit cabfea7

File tree

33 files changed

+281
-272
lines changed

33 files changed

+281
-272
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.65"
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/arraylayouts.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using BlockArrays: BlockLayout
33
using ..SparseArrayInterface: SparseLayout
44
using ..TypeParameterAccessors: parenttype, similartype
55

6-
function ArrayLayouts.MemoryLayout(arraytype::Type{<:BlockSparseArrayLike})
6+
function ArrayLayouts.MemoryLayout(arraytype::Type{<:AnyAbstractBlockSparseArray})
77
outer_layout = typeof(MemoryLayout(blockstype(arraytype)))
88
inner_layout = typeof(MemoryLayout(blocktype(arraytype)))
99
return BlockLayout{outer_layout,inner_layout}()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using BlockArrays: AbstractBlockedUnitRange, BlockSlice
22
using Base.Broadcast: Broadcast
33

4-
function Broadcast.BroadcastStyle(arraytype::Type{<:BlockSparseArrayLike})
4+
function Broadcast.BroadcastStyle(arraytype::Type{<:AnyAbstractBlockSparseArray})
55
return BlockSparseArrayStyle{ndims(arraytype)}()
66
end
77

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# TODO: Change to `AnyAbstractBlockSparseArray`.
2-
function Base.cat(as::BlockSparseArrayLike...; dims)
2+
function Base.cat(as::AnyAbstractBlockSparseArray...; dims)
33
# TODO: Use `sparse_cat` instead, currently
44
# that erroneously allocates too many blocks that are
55
# zero and shouldn't be stored.

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,27 @@ end
9292
# function SparseArrayInterface.sparse_mapreduce(::BlockSparseArrayStyle, f, a_dest::AbstractArray, a_srcs::Vararg{AbstractArray})
9393
# end
9494

95-
function Base.map!(f, a_dest::AbstractArray, a_srcs::Vararg{BlockSparseArrayLike})
95+
function Base.map!(f, a_dest::AbstractArray, a_srcs::Vararg{AnyAbstractBlockSparseArray})
9696
sparse_map!(f, a_dest, a_srcs...)
9797
return a_dest
9898
end
9999

100-
function Base.map(f, as::Vararg{BlockSparseArrayLike})
100+
function Base.map(f, as::Vararg{AnyAbstractBlockSparseArray})
101101
return f.(as...)
102102
end
103103

104-
function Base.copy!(a_dest::AbstractArray, a_src::BlockSparseArrayLike)
104+
function Base.copy!(a_dest::AbstractArray, a_src::AnyAbstractBlockSparseArray)
105105
sparse_copy!(a_dest, a_src)
106106
return a_dest
107107
end
108108

109-
function Base.copyto!(a_dest::AbstractArray, a_src::BlockSparseArrayLike)
109+
function Base.copyto!(a_dest::AbstractArray, a_src::AnyAbstractBlockSparseArray)
110110
sparse_copyto!(a_dest, a_src)
111111
return a_dest
112112
end
113113

114114
# Fix ambiguity error
115-
function Base.copyto!(a_dest::LayoutArray, a_src::BlockSparseArrayLike)
115+
function Base.copyto!(a_dest::LayoutArray, a_src::AnyAbstractBlockSparseArray)
116116
sparse_copyto!(a_dest, a_src)
117117
return a_dest
118118
end
@@ -131,21 +131,21 @@ function Base.copyto!(
131131
return a_dest
132132
end
133133

134-
function Base.permutedims!(a_dest, a_src::BlockSparseArrayLike, perm)
134+
function Base.permutedims!(a_dest, a_src::AnyAbstractBlockSparseArray, perm)
135135
sparse_permutedims!(a_dest, a_src, perm)
136136
return a_dest
137137
end
138138

139-
function Base.mapreduce(f, op, as::Vararg{BlockSparseArrayLike}; kwargs...)
139+
function Base.mapreduce(f, op, as::Vararg{AnyAbstractBlockSparseArray}; kwargs...)
140140
return sparse_mapreduce(f, op, as...; kwargs...)
141141
end
142142

143143
# TODO: Why isn't this calling `mapreduce` already?
144-
function Base.iszero(a::BlockSparseArrayLike)
144+
function Base.iszero(a::AnyAbstractBlockSparseArray)
145145
return sparse_iszero(blocks(a))
146146
end
147147

148148
# TODO: Why isn't this calling `mapreduce` already?
149-
function Base.isreal(a::BlockSparseArrayLike)
149+
function Base.isreal(a::AnyAbstractBlockSparseArray)
150150
return sparse_isreal(blocks(a))
151151
end

0 commit comments

Comments
 (0)