Skip to content

Commit

Permalink
Update for latest Derive, SparseArraysBase (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Dec 16, 2024
1 parent 5bf6dab commit d1958cc
Show file tree
Hide file tree
Showing 30 changed files with 500 additions and 598 deletions.
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2"
Derive = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a"
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
GradedUnitRanges = "e2de450a-8a67-46c7-b59c-01d5a3d041c5"
Expand All @@ -25,11 +26,14 @@ Adapt = "4.1.1"
Aqua = "0.8.9"
ArrayLayouts = "1.10.4"
BlockArrays = "1.2.0"
Derive = "0.3.1"
Dictionaries = "0.4.3"
GPUArraysCore = "0.1.0"
LinearAlgebra = "1.10"
MacroTools = "0.5.13"
SparseArraysBase = "0.2"
SplitApplyCombine = "1.2.3"
TensorAlgebra = "0.1.0"
Test = "1.10"
julia = "1.10"

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ julia> Pkg.add("BlockSparseArrays")

````julia
using BlockArrays: BlockArrays, BlockedVector, Block, blockedrange
using BlockSparseArrays: BlockSparseArray, block_stored_length
using BlockSparseArrays: BlockSparseArray, blockstoredlength
using Test: @test, @test_broken

function main()
Expand All @@ -62,13 +62,13 @@ function main()
]
b = BlockSparseArray(nz_blocks, d_blocks, i_axes)

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

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

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

# Access a block
@test b[Block(1, 1)] == d_blocks[1]
Expand All @@ -92,7 +92,7 @@ function main()
@test b + b Array(b) + Array(b)
@test b + b isa BlockSparseArray
# TODO: Fix this, broken.
@test_broken block_stored_length(b + b) == 2
@test_broken blockstoredlength(b + b) == 2

scaled_b = 2b
@test scaled_b 2Array(b)
Expand Down
68 changes: 0 additions & 68 deletions TODO.md

This file was deleted.

8 changes: 4 additions & 4 deletions examples/README.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ julia> Pkg.add("BlockSparseArrays")
# ## Examples

using BlockArrays: BlockArrays, BlockedVector, Block, blockedrange
using BlockSparseArrays: BlockSparseArray, block_stored_length
using BlockSparseArrays: BlockSparseArray, blockstoredlength
using Test: @test, @test_broken

function main()
Expand All @@ -67,13 +67,13 @@ function main()
]
b = BlockSparseArray(nz_blocks, d_blocks, i_axes)

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

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

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

## Access a block
@test b[Block(1, 1)] == d_blocks[1]
Expand All @@ -97,7 +97,7 @@ function main()
@test b + b Array(b) + Array(b)
@test b + b isa BlockSparseArray
## TODO: Fix this, broken.
@test_broken block_stored_length(b + b) == 2
@test_broken blockstoredlength(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 @@ -9,11 +9,14 @@ using BlockArrays:
using ..BlockSparseArrays:
BlockSparseArrays,
AbstractBlockSparseArray,
AbstractBlockSparseArrayInterface,
AbstractBlockSparseMatrix,
BlockSparseArray,
BlockSparseArrayInterface,
BlockSparseMatrix,
BlockSparseVector,
block_merge
using Derive: @interface
using GradedUnitRanges:
GradedUnitRanges,
AbstractGradedUnitRange,
Expand Down Expand Up @@ -109,7 +112,7 @@ end
# with mixed dual and non-dual axes. This shouldn't be needed once
# GradedUnitRanges is rewritten using BlockArrays v1.
# TODO: Delete this once GradedUnitRanges is rewritten.
function blocksparse_show(
@interface ::AbstractBlockSparseArrayInterface function Base.show(
io::IO, mime::MIME"text/plain", a::AbstractArray, axes_a::Tuple; kwargs...
)
println(io, "typeof(axes) = ", typeof(axes_a), "\n")
Expand All @@ -127,7 +130,7 @@ end
function Base.show(io::IO, mime::MIME"text/plain", a::BlockSparseArray; kwargs...)
axes_a = axes(a)
a_nondual = BlockSparseArray(blocks(a), nondual.(axes(a)))
return blocksparse_show(io, mime, a_nondual, axes_a; kwargs...)
return @interface BlockSparseArrayInterface() show(io, mime, a_nondual, axes_a; kwargs...)
end

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

# This is a temporary fix for `show` being broken for BlockSparseArrays
Expand All @@ -151,6 +154,6 @@ function Base.show(
)
axes_a = axes(a)
a_nondual = tranpose(BlockSparseArray(transpose(blocks(a)), nondual.(axes(a))))
return blocksparse_show(io, mime, a_nondual, axes_a; kwargs...)
return @interface BlockSparseArrayInterface() show(io, mime, a_nondual, axes_a; kwargs...)
end
end
1 change: 0 additions & 1 deletion ext/BlockSparseArraysGradedUnitRangesExt/test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[deps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
28 changes: 14 additions & 14 deletions ext/BlockSparseArraysGradedUnitRangesExt/test/runtests.jl
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 BlockSparseArrays: BlockSparseArray, block_stored_length
using BlockSparseArrays: BlockSparseArray, blockstoredlength
using GradedUnitRanges:
GradedUnitRanges,
GradedOneTo,
Expand All @@ -13,7 +13,7 @@ using GradedUnitRanges:
gradedrange,
isdual
using LabelledNumbers: label
using SparseArraysBase: stored_length
using SparseArraysBase: storedlength
using SymmetrySectors: U1
using 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 stored_length(b) == 32
@test block_stored_length(b) == 2
@test storedlength(b) == 32
@test blockstoredlength(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 stored_length(b) == 256
@test block_stored_length(b) == 16
@test storedlength(b) == 256
@test blockstoredlength(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 stored_length(b) == 2
@test block_stored_length(b) == 2
@test storedlength(b) == 2
@test blockstoredlength(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_stored_length(b) == 2
@test blockstoredlength(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_stored_length(b) == 2
@test blockstoredlength(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_stored_length(b) == 2
@test blockstoredlength(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_stored_length(b) == 2
@test blockstoredlength(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_stored_length(b) == 2
@test blockstoredlength(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_stored_length(b) == 2
@test blockstoredlength(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
@@ -1,6 +1,6 @@
module BlockSparseArraysTensorAlgebraExt
using BlockArrays: AbstractBlockedUnitRange
using ..BlockSparseArrays: AbstractBlockSparseArray, block_reshape
using ..BlockSparseArrays: AbstractBlockSparseArray, blockreshape
using GradedUnitRanges: tensor_product
using TensorAlgebra: TensorAlgebra, FusionStyle, BlockReshapeFusion

Expand All @@ -13,12 +13,12 @@ TensorAlgebra.FusionStyle(::AbstractBlockedUnitRange) = BlockReshapeFusion()
function TensorAlgebra.fusedims(
::BlockReshapeFusion, a::AbstractArray, axes::AbstractUnitRange...
)
return block_reshape(a, axes)
return blockreshape(a, axes)
end

function TensorAlgebra.splitdims(
::BlockReshapeFusion, a::AbstractArray, axes::AbstractUnitRange...
)
return block_reshape(a, axes)
return blockreshape(a, axes)
end
end
1 change: 0 additions & 1 deletion ext/BlockSparseArraysTensorAlgebraExt/test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[deps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Loading

0 comments on commit d1958cc

Please sign in to comment.