Skip to content

Commit d1958cc

Browse files
authored
Update for latest Derive, SparseArraysBase (#10)
1 parent 5bf6dab commit d1958cc

30 files changed

+500
-598
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
88
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
99
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
1010
BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2"
11+
Derive = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a"
1112
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
1213
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
1314
GradedUnitRanges = "e2de450a-8a67-46c7-b59c-01d5a3d041c5"
@@ -25,11 +26,14 @@ Adapt = "4.1.1"
2526
Aqua = "0.8.9"
2627
ArrayLayouts = "1.10.4"
2728
BlockArrays = "1.2.0"
29+
Derive = "0.3.1"
2830
Dictionaries = "0.4.3"
2931
GPUArraysCore = "0.1.0"
3032
LinearAlgebra = "1.10"
3133
MacroTools = "0.5.13"
34+
SparseArraysBase = "0.2"
3235
SplitApplyCombine = "1.2.3"
36+
TensorAlgebra = "0.1.0"
3337
Test = "1.10"
3438
julia = "1.10"
3539

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ julia> Pkg.add("BlockSparseArrays")
3535

3636
````julia
3737
using BlockArrays: BlockArrays, BlockedVector, Block, blockedrange
38-
using BlockSparseArrays: BlockSparseArray, block_stored_length
38+
using BlockSparseArrays: BlockSparseArray, blockstoredlength
3939
using Test: @test, @test_broken
4040

4141
function main()
@@ -62,13 +62,13 @@ function main()
6262
]
6363
b = BlockSparseArray(nz_blocks, d_blocks, i_axes)
6464

65-
@test block_stored_length(b) == 2
65+
@test blockstoredlength(b) == 2
6666

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

71-
@test block_stored_length(b) == 2
71+
@test blockstoredlength(b) == 2
7272

7373
# Access a block
7474
@test b[Block(1, 1)] == d_blocks[1]
@@ -92,7 +92,7 @@ function main()
9292
@test b + b Array(b) + Array(b)
9393
@test b + b isa BlockSparseArray
9494
# TODO: Fix this, broken.
95-
@test_broken block_stored_length(b + b) == 2
95+
@test_broken blockstoredlength(b + b) == 2
9696

9797
scaled_b = 2b
9898
@test scaled_b 2Array(b)

TODO.md

Lines changed: 0 additions & 68 deletions
This file was deleted.

examples/README.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ julia> Pkg.add("BlockSparseArrays")
4040
# ## Examples
4141

4242
using BlockArrays: BlockArrays, BlockedVector, Block, blockedrange
43-
using BlockSparseArrays: BlockSparseArray, block_stored_length
43+
using BlockSparseArrays: BlockSparseArray, blockstoredlength
4444
using Test: @test, @test_broken
4545

4646
function main()
@@ -67,13 +67,13 @@ function main()
6767
]
6868
b = BlockSparseArray(nz_blocks, d_blocks, i_axes)
6969

70-
@test block_stored_length(b) == 2
70+
@test blockstoredlength(b) == 2
7171

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

76-
@test block_stored_length(b) == 2
76+
@test blockstoredlength(b) == 2
7777

7878
## Access a block
7979
@test b[Block(1, 1)] == d_blocks[1]
@@ -97,7 +97,7 @@ function main()
9797
@test b + b Array(b) + Array(b)
9898
@test b + b isa BlockSparseArray
9999
## TODO: Fix this, broken.
100-
@test_broken block_stored_length(b + b) == 2
100+
@test_broken blockstoredlength(b + b) == 2
101101

102102
scaled_b = 2b
103103
@test scaled_b 2Array(b)

ext/BlockSparseArraysGradedUnitRangesExt/src/BlockSparseArraysGradedUnitRangesExt.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ using BlockArrays:
99
using ..BlockSparseArrays:
1010
BlockSparseArrays,
1111
AbstractBlockSparseArray,
12+
AbstractBlockSparseArrayInterface,
1213
AbstractBlockSparseMatrix,
1314
BlockSparseArray,
15+
BlockSparseArrayInterface,
1416
BlockSparseMatrix,
1517
BlockSparseVector,
1618
block_merge
19+
using Derive: @interface
1720
using GradedUnitRanges:
1821
GradedUnitRanges,
1922
AbstractGradedUnitRange,
@@ -109,7 +112,7 @@ end
109112
# with mixed dual and non-dual axes. This shouldn't be needed once
110113
# GradedUnitRanges is rewritten using BlockArrays v1.
111114
# TODO: Delete this once GradedUnitRanges is rewritten.
112-
function blocksparse_show(
115+
@interface ::AbstractBlockSparseArrayInterface function Base.show(
113116
io::IO, mime::MIME"text/plain", a::AbstractArray, axes_a::Tuple; kwargs...
114117
)
115118
println(io, "typeof(axes) = ", typeof(axes_a), "\n")
@@ -127,7 +130,7 @@ end
127130
function Base.show(io::IO, mime::MIME"text/plain", a::BlockSparseArray; kwargs...)
128131
axes_a = axes(a)
129132
a_nondual = BlockSparseArray(blocks(a), nondual.(axes(a)))
130-
return blocksparse_show(io, mime, a_nondual, axes_a; kwargs...)
133+
return @interface BlockSparseArrayInterface() show(io, mime, a_nondual, axes_a; kwargs...)
131134
end
132135

133136
# This is a temporary fix for `show` being broken for BlockSparseArrays
@@ -139,7 +142,7 @@ function Base.show(
139142
)
140143
axes_a = axes(a)
141144
a_nondual = BlockSparseArray(blocks(a'), dual.(nondual.(axes(a'))))'
142-
return blocksparse_show(io, mime, a_nondual, axes_a; kwargs...)
145+
return @interface BlockSparseArrayInterface() show(io, mime, a_nondual, axes_a; kwargs...)
143146
end
144147

145148
# This is a temporary fix for `show` being broken for BlockSparseArrays
@@ -151,6 +154,6 @@ function Base.show(
151154
)
152155
axes_a = axes(a)
153156
a_nondual = tranpose(BlockSparseArray(transpose(blocks(a)), nondual.(axes(a))))
154-
return blocksparse_show(io, mime, a_nondual, axes_a; kwargs...)
157+
return @interface BlockSparseArrayInterface() show(io, mime, a_nondual, axes_a; kwargs...)
155158
end
156159
end
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[deps]
22
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
43
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

ext/BlockSparseArraysGradedUnitRangesExt/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 BlockSparseArrays: BlockSparseArray, block_stored_length
5+
using BlockSparseArrays: BlockSparseArray, blockstoredlength
66
using GradedUnitRanges:
77
GradedUnitRanges,
88
GradedOneTo,
@@ -13,7 +13,7 @@ using GradedUnitRanges:
1313
gradedrange,
1414
isdual
1515
using LabelledNumbers: label
16-
using SparseArraysBase: stored_length
16+
using SparseArraysBase: storedlength
1717
using SymmetrySectors: U1
1818
using 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 stored_length(b) == 32
44-
@test block_stored_length(b) == 2
43+
@test storedlength(b) == 32
44+
@test blockstoredlength(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 stored_length(b) == 256
62-
@test block_stored_length(b) == 16
61+
@test storedlength(b) == 256
62+
@test blockstoredlength(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 stored_length(b) == 2
75-
@test block_stored_length(b) == 2
74+
@test storedlength(b) == 2
75+
@test blockstoredlength(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_stored_length(b) == 2
159+
@test blockstoredlength(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_stored_length(b) == 2
180+
@test blockstoredlength(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_stored_length(b) == 2
207+
@test blockstoredlength(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_stored_length(b) == 2
232+
@test blockstoredlength(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_stored_length(b) == 2
258+
@test blockstoredlength(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_stored_length(b) == 2
283+
@test blockstoredlength(b) == 2
284284
@test Array(b) == 2 * Array(a)'
285285
for ax in axes(b)
286286
@test ax isa typeof(dual(r))

ext/BlockSparseArraysTensorAlgebraExt/src/BlockSparseArraysTensorAlgebraExt.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module BlockSparseArraysTensorAlgebraExt
22
using BlockArrays: AbstractBlockedUnitRange
3-
using ..BlockSparseArrays: AbstractBlockSparseArray, block_reshape
3+
using ..BlockSparseArrays: AbstractBlockSparseArray, blockreshape
44
using GradedUnitRanges: tensor_product
55
using TensorAlgebra: TensorAlgebra, FusionStyle, BlockReshapeFusion
66

@@ -13,12 +13,12 @@ TensorAlgebra.FusionStyle(::AbstractBlockedUnitRange) = BlockReshapeFusion()
1313
function TensorAlgebra.fusedims(
1414
::BlockReshapeFusion, a::AbstractArray, axes::AbstractUnitRange...
1515
)
16-
return block_reshape(a, axes)
16+
return blockreshape(a, axes)
1717
end
1818

1919
function TensorAlgebra.splitdims(
2020
::BlockReshapeFusion, a::AbstractArray, axes::AbstractUnitRange...
2121
)
22-
return block_reshape(a, axes)
22+
return blockreshape(a, axes)
2323
end
2424
end
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[deps]
22
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
43
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

0 commit comments

Comments
 (0)