Jutho / TensorKit.jl

A Julia package for large-scale tensor computations, with a hint of category theory
MIT License
242 stars 41 forks source link

convert to floating point in matrix factorisations #181

Open Jutho opened 5 hours ago

Jutho commented 5 hours ago
julia> t = TensorMap([1 0 ; 0 -1], ℂ^2, ℂ^2)
TensorMap(ℂ^2 ← ℂ^2):
 1   0
 0  -1

julia> tsvd(t)
ERROR: MethodError: no method matching svd!(::Base.ReshapedArray{Int64, 2, SubArray{Int64, 1, Vector{Int64}, Tuple{UnitRange{Int64}}, true}, Tuple{}}, ::SDD)
The function `svd!` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  svd!(::StridedMatrix{T}, ::Union{SDD, SVD}) where T<:Union{Float32, Float64, ComplexF64, ComplexF32}
   @ TensorKit ~/.julia/dev/TensorKit/src/auxiliary/linalg.jl:274
Jutho commented 5 hours ago

Solution: e.g. float(::TensorMap) and use that instead of copy in the lowering from tsvd to tsvd!.

lkdvos commented 5 hours ago

LinearAlgebra uses eigencopy_oftype(A, T) (also for the SVD) to catch these cases. It might be reasonable to also use that here, or at least something similar?

https://github.com/JuliaLang/julia/blob/5fab51a38cbb41da5d2619a6923619144725c437/stdlib/LinearAlgebra/src/eigen.jl#L534