-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
126 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# TODO: Implement. | ||
function contraction_output( | ||
tensor1::BlockSparseArray, tensor2::BlockSparseArray, indsR | ||
) | ||
return error("Not implemented") | ||
end | ||
|
||
# TODO: Implement. | ||
function contract!( | ||
tensorR::BlockSparseArray, | ||
labelsR, | ||
tensor1::BlockSparseArray, | ||
labels1, | ||
tensor2::BlockSparseArray, | ||
labels2, | ||
) | ||
return error("Not implemented") | ||
end |
This file contains 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using NDTensors | ||
using LinearAlgebra | ||
using Test | ||
|
||
using NDTensors: storage, storagetype | ||
|
||
@testset "Tensor wrapping Array" begin | ||
is1 = (2, 3) | ||
D1 = randn(is1) | ||
|
||
is2 = (3, 4) | ||
D2 = randn(is2) | ||
|
||
T1 = tensor(D1, is1) | ||
T2 = tensor(D2, is2) | ||
|
||
@test T1[1, 1] == D1[1, 1] | ||
|
||
x = rand() | ||
T1[1, 1] = x | ||
|
||
@test T1[1, 1] == x | ||
@test array(T1) == D1 | ||
@test storagetype(T1) <: Matrix{Float64} | ||
@test storage(T1) == D1 | ||
@test eltype(T1) == eltype(D1) | ||
@test inds(T1) == is1 | ||
|
||
R = T1 * T2 | ||
@test storagetype(R) <: Matrix{Float64} | ||
@test Array(R) ≈ Array(T1) * Array(T2) | ||
|
||
T1r = randn!(similar(T1)) | ||
@test Array(T1r + T1) ≈ Array(T1r) + Array(T1) | ||
@test Array(permutedims(T1, (2, 1))) ≈ permutedims(Array(T1), (2, 1)) | ||
|
||
U, S, V = svd(T1) | ||
@test U * S * V ≈ T1 | ||
|
||
T12 = contract(T1, (1, -1), T2, (-1, 2)) | ||
@test T12 ≈ T1 * T2 | ||
|
||
D12 = contract(D1, (1, -1), D2, (-1, 2)) | ||
@test D12 ≈ Array(T12) | ||
end |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using NDTensors | ||
using NDTensors.BlockSparseArrays | ||
using 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) | ||
|
||
is2 = ([1, 2], [2, 2]) | ||
D2 = BlockSparseArray([Block(1, 1), Block(2, 2)], [randn(1, 2), randn(2, 2)], is2) | ||
|
||
T1 = tensor(D1, is1) | ||
T2 = tensor(D2, is2) | ||
|
||
@test T1[1, 1] == D1[1, 1] | ||
|
||
x = rand() | ||
T1[1, 1] = x | ||
|
||
@test T1[1, 1] == x | ||
@test array(T1) == D1 | ||
@test storagetype(T1) <: BlockSparseArray{Float64,2} | ||
@test storage(T1) == D1 | ||
@test eltype(T1) == eltype(D1) | ||
@test inds(T1) == is1 | ||
|
||
@test_broken R = T1 * T2 | ||
@test_broken storagetype(R) <: Matrix{Float64} | ||
@test_broken Array(R) ≈ Array(T1) * Array(T2) | ||
|
||
@test_broken T1r = randn!(similar(T1)) | ||
@test_broken Array(T1r + T1) ≈ Array(T1r) + Array(T1) | ||
@test_broken Array(permutedims(T1, (2, 1))) ≈ permutedims(Array(T1), (2, 1)) | ||
|
||
U, S, V = svd(T1) | ||
@test U * S * V ≈ T1 | ||
|
||
@test_broken T12 = contract(T1, (1, -1), T2, (-1, 2)) | ||
@test_broken T12 ≈ T1 * T2 | ||
|
||
@test_broken D12 = contract(D1, (1, -1), D2, (-1, 2)) | ||
@test_broken D12 ≈ Array(T12) | ||
end |