11# TODO : Define this properly.
22dag (i:: Index ) = i
3+ dag (a:: ITensor ) = a
34# TODO : Deprecate.
45dim (i:: Index ) = dename (length (i))
6+ dim (a:: AbstractITensor ) = unname (length (a))
57# TODO : Define this properly.
68hasqns (i:: Index ) = false
79# TODO : Deprecate.
810itensor (parent:: AbstractArray , nameddimsindices) = ITensor (parent, nameddimsindices)
911function itensor (parent:: AbstractArray , i1:: Index , i_rest:: Index... )
1012 return ITensor (parent, (i1, i_rest... ))
1113end
14+ # TODO : Deprecate.
15+ order (a:: AbstractArray ) = ndims (a)
1216
1317# This seems to be needed to get broadcasting working.
1418# TODO : Investigate this and see if we can get rid of it.
@@ -23,9 +27,25 @@ function onehot(iv::Pair{<:Index,<:Int})
2327 return a
2428end
2529
26- using LinearAlgebra: svd
30+ using LinearAlgebra: qr, svd
2731# TODO : Define this in `MatrixAlgebra.jl`/`TensorAlgebra.jl`.
28- function factorize (a:: AbstractITensor , args... ; kwargs... )
29- U, S, V = svd (a, args... ; kwargs... )
30- return U, S * V
32+ function factorize (a:: AbstractITensor , args... ; tags= TagSet (), maxdim= nothing )
33+ if isnothing (maxdim)
34+ # `tags` are ignored right now.
35+ Q, R = qr (a, args... )
36+ return Q, R
37+ else
38+ error (" Truncation in `factorize` not implemented yet." )
39+ U, S, V = svd (a, args... ; kwargs... )
40+ return U, S * V
41+ end
3142end
43+
44+ # TODO : Used in `ITensorMPS.jl`, decide where or if to define it.
45+ # Ideally this would just be a zero-dimensional `ITensor` wrapping
46+ # a special type, like `Zeros{UnspecifiedZero()}()`.
47+ struct OneITensor <: AbstractITensor end
48+ Base. size (:: OneITensor ) = ()
49+ Base.:* (:: OneITensor , :: OneITensor ) = OneITensor ()
50+ Base.:* (:: OneITensor , a:: ITensor ) = a
51+ Base.:* (a:: ITensor , :: OneITensor ) = a
0 commit comments