Skip to content

Commit

Permalink
Reorganize constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Oct 27, 2023
1 parent f241cc2 commit 2531031
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
8 changes: 8 additions & 0 deletions src/itensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ ITensor(x::RealOrComplex{Int}, is...) = ITensor(float(x), is...)
# EmptyStorage ITensor constructors
#

# TODO: Replace with a simpler and more generic `zeros` constructor
# when the new `UnallocatedZeros` type lands.
# This is only used internally inside the implementation of `directsum`
# right now.
function zeros_itensor(elt::Type{<:Number}, inds::Index...)
return ITensor(elt, inds...)
end

# TODO: Deprecated!
"""
emptyITensor([::Type{ElT} = NDTensors.EmptyNumber, ]inds)
Expand Down
12 changes: 12 additions & 0 deletions src/qn/qnitensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
return setindex!!(T, x, I...)
end

# TODO: Replace with a simpler and more generic `zeros` constructor
# when the new `UnallocatedZeros` type lands.
# This is needed for now since there is some issue with calling
# `setindex!` on `EmptyTensor`, it's not really worth investigating
# right now since that type will be removed soon anyway in
# https://github.com/ITensor/ITensors.jl/pull/1213.
# This is only used internally inside the implementation of `directsum`
# right now.
function zeros_itensor(elt::Type{<:Number}, inds::QNIndex...)
return itensor(tensor(BlockSparse(elt, undef, NDTensors.Dictionary{Block{length(inds)},Int}(), 0), inds))
end

"""
ITensor([::Type{ElT} = Float64, ][flux::QN = QN(), ]inds)
ITensor([::Type{ElT} = Float64, ][flux::QN = QN(), ]inds::Index...)
Expand Down
16 changes: 0 additions & 16 deletions src/tensor_operations/tensor_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,22 +275,6 @@ function directsum_projectors!(D1::Tensor, D2::Tensor)
return D1, D2
end

# TODO: Replace with a simpler and more generic `zeros` constructor
# when the new `UnallocatedZeros` type lands.
function zeros_itensor(elt::Type{<:Number}, inds::Index...)
return ITensor(elt, inds...)
end

# TODO: Replace with a simpler and more generic `zeros` constructor
# when the new `UnallocatedZeros` type lands.
# This is needed for now since there is some issue with calling
# `setindex!` on `EmptyTensor`, it's not really worth investigating
# right now since that type will be removed soon anyway in
# https://github.com/ITensor/ITensors.jl/pull/1213.
function zeros_itensor(elt::Type{<:Number}, inds::QNIndex...)
return itensor(tensor(BlockSparse(elt, undef, NDTensors.Dictionary{Block{length(inds)},Int}(), 0), inds))
end

# Helper tensors for performing a partial direct sum
function directsum_projectors(
elt1::Type{<:Number}, elt2::Type{<:Number}, i::Index, j::Index, ij::Index
Expand Down

0 comments on commit 2531031

Please sign in to comment.