Skip to content

Commit

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

* Fix tensormap constructor from matrix

* Fix tests
  • Loading branch information
lkdvos committed Aug 12, 2024
1 parent fc34907 commit 0a93955
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 @@ -400,9 +400,10 @@ function TensorMap(data::DenseArray, V::TensorMapSpace{S,N₁,N₂};
end

t = TensorMap{eltype(data)}(undef, 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 @@ -115,6 +115,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 0a93955

Please sign in to comment.