Skip to content

Commit

Permalink
Merge 6d57dce into 70eb783
Browse files Browse the repository at this point in the history
  • Loading branch information
kmp5VT committed Jul 20, 2023
2 parents 70eb783 + 6d57dce commit 7507112
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 11 additions & 3 deletions NDTensors/src/dense/tensoralgebra/contract.jl
Expand Up @@ -375,9 +375,17 @@ function _contract!(

# TODO: this logic may be wrong
if props.permuteC
# Need to copy here since we will be permuting
# into C later
CM = reshape(copy(CT), (props.dleft, props.dright))
# if we are computing C = α * A B + β * C
# we need to make sure C is permuted to the same
# ordering as A B
if β 0
pC = NTuple{NB,Int}(props.PC)
CM = reshape(permutedims(CT, pC), (props.dleft, props.dright))
else
# Need to copy here since we will be permuting
# into C later
CM = reshape(copy(CT), (props.dleft, props.dright))
end
else
if Ctrans(props)
CM = transpose(reshape(CT, (props.dright, props.dleft)))
Expand Down
10 changes: 10 additions & 0 deletions test/base/test_contract.jl
Expand Up @@ -241,6 +241,16 @@ digits(::Type{T}, i, j, k) where {T} = T(i * 10^2 + j * 10 + k)
@test CArray array(permute(C, α, i, j))
end
end
@testset "Test contract in-place ITensors (4-Tensor*Matrix -> 4-Tensor)" begin
A = randomITensor(T, (j, i))
B = randomITensor(T, (j, k, l, α))
C = ITensor(zero(T), (i, k, α, l))
ITensors.contract!(C, A, B, 1.0, 0.0)
ITensors.contract!(C, A, B, 1.0, 1.0)
D = A * B
D .+= A * B
@test C D
end
end # End contraction testset
end

Expand Down

0 comments on commit 7507112

Please sign in to comment.