Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Oct 4, 2023
1 parent d9b7d97 commit a8e13a7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
1 change: 1 addition & 0 deletions NDTensors/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ NDTensorsTBLISExt = "TBLIS"

[compat]
Adapt = "3.5"
BlockArrays = "0.16"
Compat = "4.9"
Dictionaries = "0.3.5"
FLoops = "0.2.1"
Expand Down
12 changes: 6 additions & 6 deletions NDTensors/src/BlockSparseArrays/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ to store non-zero values, specifically a `Dictionary` from `Dictionaries.jl`.

````julia
using NDTensors.BlockSparseArrays
using BlockArrays
using BlockArrays: BlockArrays, blockedrange

# Block dimensions
i1 = [2, 3]
Expand All @@ -17,11 +17,11 @@ i2 = [2, 3]
i_axes = (blockedrange(i1), blockedrange(i2))

function block_size(axes, block)
return length.(getindex.(axes, Block.(block.n)))
return length.(getindex.(axes, BlockArrays.Block.(block.n)))
end

# Data
nz_blocks = [Block(1, 1), Block(2, 2)]
nz_blocks = BlockArrays.Block.([(1, 1), (2, 2)])
nz_block_sizes = [block_size(i_axes, nz_block) for nz_block in nz_blocks]
nz_block_lengths = prod.(nz_block_sizes)

Expand All @@ -35,13 +35,13 @@ d_blocks = randn.(nz_block_sizes)
B = BlockSparseArray(nz_blocks, d_blocks, i_axes)

# Access a block
B[Block(1, 1)]
B[BlockArrays.Block(1, 1)]

# Access a non-zero block, returns a zero matrix
B[Block(1, 2)]
B[BlockArrays.Block(1, 2)]

# Set a zero block
B[Block(1, 2)] = randn(2, 3)
B[BlockArrays.Block(1, 2)] = randn(2, 3)

# Matrix multiplication (not optimized for sparsity yet)
B * B
Expand Down
12 changes: 6 additions & 6 deletions NDTensors/src/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 NDTensors.BlockSparseArrays
using BlockArrays
using BlockArrays: BlockArrays, blockedrange

## Block dimensions
i1 = [2, 3]
Expand All @@ -16,11 +16,11 @@ i2 = [2, 3]
i_axes = (blockedrange(i1), blockedrange(i2))

function block_size(axes, block)
return length.(getindex.(axes, Block.(block.n)))
return length.(getindex.(axes, BlockArrays.Block.(block.n)))
end

## Data
nz_blocks = [Block(1, 1), Block(2, 2)]
nz_blocks = BlockArrays.Block.([(1, 1), (2, 2)])
nz_block_sizes = [block_size(i_axes, nz_block) for nz_block in nz_blocks]
nz_block_lengths = prod.(nz_block_sizes)

Expand All @@ -34,13 +34,13 @@ d_blocks = randn.(nz_block_sizes)
B = BlockSparseArray(nz_blocks, d_blocks, i_axes)

## Access a block
B[Block(1, 1)]
B[BlockArrays.Block(1, 1)]

## Access a non-zero block, returns a zero matrix
B[Block(1, 2)]
B[BlockArrays.Block(1, 2)]

## Set a zero block
B[Block(1, 2)] = randn(2, 3)
B[BlockArrays.Block(1, 2)] = randn(2, 3)

## Matrix multiplication (not optimized for sparsity yet)
B * B
Expand Down
4 changes: 4 additions & 0 deletions NDTensors/test/BlockSparseArrays.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using Test
using NDTensors

include(joinpath(pkgdir(NDTensors), "src", "BlockSparseArrays", "test", "runtests.jl"))
1 change: 1 addition & 0 deletions NDTensors/test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
Expand Down
12 changes: 7 additions & 5 deletions NDTensors/test/arraytensor/blocksparsearray.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
using NDTensors
using NDTensors.BlockSparseArrays
using BlockArrays
using BlockArrays: BlockArrays
using LinearAlgebra
using Test

using BlockArrays: Block

using NDTensors: storage, storagetype

@testset "Tensor wrapping BlockSparseArray" begin
is1 = ([1, 1], [1, 2])
D1 = BlockSparseArray([Block(1, 1), Block(2, 2)], [randn(1, 1), randn(1, 2)], is1)
D1 = BlockSparseArray(
[BlockArrays.Block(1, 1), BlockArrays.Block(2, 2)], [randn(1, 1), randn(1, 2)], is1
)

is2 = ([1, 2], [2, 2])
D2 = BlockSparseArray([Block(1, 1), Block(2, 2)], [randn(1, 2), randn(2, 2)], is2)
D2 = BlockSparseArray(
[BlockArrays.Block(1, 1), BlockArrays.Block(2, 2)], [randn(1, 2), randn(2, 2)], is2
)

T1 = tensor(D1, is1)
T2 = tensor(D2, is2)
Expand Down
1 change: 1 addition & 0 deletions NDTensors/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ end

@safetestset "NDTensors" begin
@testset "$filename" for filename in [
"BlockSparseArrays.jl",
"SetParameters.jl",
"SmallVectors.jl",
"linearalgebra.jl",
Expand Down

0 comments on commit a8e13a7

Please sign in to comment.