Skip to content

Commit

Permalink
Backport: Fix TensorMap constructor for symmetric tensor from dense…
Browse files Browse the repository at this point in the history
… matrix (#144)

* Fix tensormap constructor from matrix

* Fix tests
  • Loading branch information
lkdvos committed Aug 13, 2024
1 parent 6265c35 commit 8467bf8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/tensors/tensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,10 @@ function TensorMap(data::DenseArray, codom::ProductSpace{S,N₁}, dom::ProductSp
end

t = TensorMap(undef, eltype(data), codom, dom)
project_symmetric!(t, data)
data2 = reshape(data, (dims(codom)..., dims(dom)...))
project_symmetric!(t, data2)

if !isapprox(data, convert(Array, t); atol=tol)
if !isapprox(data2, convert(Array, t); atol=tol)
throw(ArgumentError("Data has non-zero elements at incompatible positions"))
end

Expand Down
3 changes: 3 additions & 0 deletions test/tensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ for V in spacelist
end
a = @constinferred convert(Array, t)
@test t @constinferred TensorMap(a, W)
# also test if input is matrix
a2 = reshape(a, prod(dim, codomain(t)), prod(dim, domain(t)))
@test t @constinferred TensorMap(a2, codomain(t), domain(t))
end
end
end
Expand Down

0 comments on commit 8467bf8

Please sign in to comment.