-
Notifications
You must be signed in to change notification settings - Fork 2
Test BlockSparseArrays #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aaac9c7
include BlockSparseArrays tests
ogauthe 66aae60
add Random
ogauthe 408dda1
weaker Rand compat
ogauthe a52f668
decrease Rand compat
ogauthe d0123f3
use dual
ogauthe 0c3ea2f
fix labels
ogauthe 26f582b
Merge branch 'main' into BlockSparseArrays
ogauthe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "TensorAlgebra" | ||
uuid = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a" | ||
authors = ["ITensor developers <[email protected]> and contributors"] | ||
version = "0.1.9" | ||
version = "0.1.10" | ||
|
||
[deps] | ||
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,33 @@ | ||
using Test: @test_skip | ||
# TODO: Add this back once `BlockSparseArrays` is set up. | ||
@test_skip begin | ||
using BlockArrays: Block, blocksize | ||
using BlockSparseArrays: BlockSparseArray | ||
using GradedUnitRanges: gradedrange | ||
using SparseArraysBase: densearray | ||
using SymmetrySectors: U1 | ||
using TensorAlgebra: contract | ||
using Random: randn! | ||
using Test: @test, @testset | ||
using BlockArrays: Block, blocksize | ||
using BlockSparseArrays: BlockSparseArray | ||
using GradedUnitRanges: dual, gradedrange | ||
using SparseArraysBase: densearray | ||
using SymmetrySectors: U1 | ||
using TensorAlgebra: contract | ||
using Random: randn! | ||
using Test: @test, @testset | ||
|
||
function randn_blockdiagonal(elt::Type, axes::Tuple) | ||
a = BlockSparseArray{elt}(axes) | ||
blockdiaglength = minimum(blocksize(a)) | ||
for i in 1:blockdiaglength | ||
b = Block(ntuple(Returns(i), ndims(a))) | ||
a[b] = randn!(a[b]) | ||
end | ||
return a | ||
function randn_blockdiagonal(elt::Type, axes::Tuple) | ||
a = BlockSparseArray{elt}(axes) | ||
blockdiaglength = minimum(blocksize(a)) | ||
for i in 1:blockdiaglength | ||
b = Block(ntuple(Returns(i), ndims(a))) | ||
a[b] = randn!(a[b]) | ||
end | ||
return a | ||
end | ||
|
||
const elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) | ||
@testset "`contract` `BlockSparseArray` (eltype=$elt)" for elt in elts | ||
d = gradedrange([U1(0) => 2, U1(1) => 3]) | ||
a1 = randn_blockdiagonal(elt, (d, d, d)) | ||
a2 = randn_blockdiagonal(elt, (d, d, d)) | ||
a_dest, dimnames_dest = contract(a1, (-1, 1, -2), a2, (-1, -2, 2)) | ||
a1_dense = densearray(a1) | ||
a2_dense = densearray(a2) | ||
a_dest_dense, dimnames_dest_dense = contract( | ||
a1_dense, (-1, 1, -2), a2_dense, (-1, -2, 2) | ||
) | ||
@test dimnames_dest == dimnames_dest_dense | ||
@test a_dest ≈ a_dest_dense | ||
end | ||
const elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) | ||
@testset "`contract` `BlockSparseArray` (eltype=$elt)" for elt in elts | ||
d = gradedrange([U1(0) => 2, U1(1) => 3]) | ||
a1 = randn_blockdiagonal(elt, (d, d, dual(d), dual(d))) | ||
a2 = randn_blockdiagonal(elt, (d, d, dual(d), dual(d))) | ||
a_dest, dimnames_dest = contract(a1, (1, -1, 2, -3), a2, (2, -1, 1, -2)) | ||
a1_dense = densearray(a1) | ||
a2_dense = densearray(a2) | ||
a_dest_dense, dimnames_dest_dense = contract( | ||
a1_dense, (1, -1, 2, -3), a2_dense, (2, -1, 1, -2) | ||
) | ||
@test dimnames_dest == dimnames_dest_dense | ||
@test a_dest ≈ a_dest_dense | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.