You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is an issue when one tries to construct a new tensor from the view of another tensor. It comes from the parameters of the new tensor being defined before the storage is copied, i.e. a type mismatch.
Minimal runnable code
using ITensors: Index
using NDTensors: randomTensor, Tensor
i,j =Index.((4,4))
t =randomTensor((i,j))
Tensor(storage(t[1:2, 1:2]), (2, 2))
Output of minimal runnable code
ERROR: MethodError: Cannot `convert` an object of type Vector{Float64} to an object of type Base.ReshapedArray{Float64, 1, SubArray{Float64, 2, Matrix{Float64}, Tuple{UnitRange{Int64}, UnitRange{Int64}}, false}, Tuple{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64}}}
Closest candidates are:convert(::Type{T}, ::T) where T
@ Base Base.jl:84convert(::Type{T}, ::LinearAlgebra.Factorization) where T<:AbstractArray
@ LinearAlgebra ~/.julia/juliaup/julia-1.10.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/LinearAlgebra/src/factorization.jl:108convert(::Type{T}, ::T) where T<:AbstractArray
@ Base abstractarray.jl:16...
Stacktrace:
[1] convert(::Type{NDTensors.Dense{Float64, Base.ReshapedArray{…}}}, D::NDTensors.Dense{Float64, Vector{Float64}})
@ NDTensors ~/.julia/dev/ITensors/NDTensors/src/dense/dense.jl:142
[2] NDTensors.DenseTensor{…}(::NDTensors.AllowAlias, storage::NDTensors.Dense{…}, inds::Tuple{…})
@ NDTensors ~/.julia/dev/ITensors/NDTensors/src/tensor/tensor.jl:27
[3] NDTensors.DenseTensor{…}(::NDTensors.NeverAlias, storage::NDTensors.Dense{…}, inds::Tuple{…})
@ NDTensors ~/.julia/dev/ITensors/NDTensors/src/tensor/tensor.jl:36
[4] Tensor(as::NDTensors.NeverAlias, storage::NDTensors.Dense{Float64, Base.ReshapedArray{…}}, inds::Tuple{Int64, Int64})
@ NDTensors ~/.julia/dev/ITensors/NDTensors/src/tensor/tensor.jl:67
[5] Tensor(storage::NDTensors.Dense{Float64, Base.ReshapedArray{…}}, inds::Tuple{Int64, Int64})
@ NDTensors ~/.julia/dev/ITensors/NDTensors/src/tensor/tensor.jl:81
[6] top-level scope
@ Untitled-1:16
Some type information was truncated. Use `show(err)` to see complete types.
Version information
Output from versioninfo():
julia>versioninfo()
Julia Version 1.10.2
Commit bd47eca2c8a (2024-03-0110:14 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: macOS (arm64-apple-darwin22.4.0)
CPU:10× Apple M1 Max
WORD_SIZE:64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads:1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
LD_LIBRARY_PATH =/Users/kpierce/Software/triqs/triqs_install/lib::/opt/intel/oneapi/mkl/latest/lib
JULIA_EDITOR = code
JULIA_NUM_THREADS =
Proposed solution
The code stack calls
functionTensor(as::AliasStyle, storage::TensorStorage, inds::Tuple)
returnTensor{eltype(storage),length(inds),typeof(storage),typeof(inds)}(
as, storage, inds
)
end
which calls
functionTensor{ElT,N,StoreT,IndsT}(
::NeverAlias, storage::TensorStorage, inds
) where {ElT,N,StoreT<:TensorStorage,IndsT}
returnTensor{ElT,N,StoreT,IndsT}(AllowAlias(), copy(storage), inds)
end
So my proposal is to modify the second tensor constructor to be
functionTensor{ElT,N,StoreT,IndsT}(
::NeverAlias, storage::TensorStorage, inds
) where {ElT,N,StoreT<:TensorStorage,IndsT}
store =copy(storage)
returnTensor{ElT,N,typeof(store),IndsT}(AllowAlias(), store, inds)
end
which returns the following output
julia>Tensor(storage(t[1:2, 1:2]), (2,2))
Dim 1:2
Dim 2:2
NDTensors.Dense{Float64, Vector{Float64}}
2×2-0.87369545095928260.309524833120003731.6882572502541735-0.7830143316102207
The text was updated successfully, but these errors were encountered:
Description of bug
There is an issue when one tries to construct a new tensor from the view of another tensor. It comes from the parameters of the new tensor being defined before the storage is copied, i.e. a type mismatch.
Minimal runnable code
Output of minimal runnable code
Version information
versioninfo()
:Proposed solution
The code stack calls
which calls
In the first call
and when the type of the copied storage is
So my proposal is to modify the second tensor constructor to be
which returns the following output
The text was updated successfully, but these errors were encountered: