Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/operators_lazytensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,26 @@ end

identityoperator(::Type{<:LazyTensor}, ::Type{T}, b1::Basis, b2::Basis) where {T<:Number} = LazyTensor(b1, b2, Int[], Tuple{}(), one(T))

"""
embed_lazy(b::Basis, i, op::AbstractOperator)

Embed an operator in a larger hilbert space, at site(s) `i` of basis `b`, using a
lazy representation of the tensor product and preserving LazySum.

This has different meaning to `LazyTensor()` and `embed()`. The former
always constructs a `LazyTensor` operator and the latter will not embed dense
and sparse operators lazily. This function need not return a `LazyTensor`
(it sometimes returns a `LazySum` of `LazyTensor`) and it will always prefer a
lazy representation.
"""
embed_lazy(b::Basis, i, op::AbstractOperator) = LazyTensor(b, i, op)
function embed_lazy(b::Basis, i, op::LazySum)
_embed_ops(b, i, ops::Tuple) = ((embed_lazy(b, i, o) for o in ops)...,)
_embed_ops(b, i, ops) = [embed_lazy(b, i, o) for o in ops]
LazySum(b, b, op.factors, _embed_ops(b, i, op.operators))
end
embed_lazy(b::Basis, indices, op::LazyTensor) = LazyTensor(b, b, indices, op.operators, op.factor)

## LazyTensor global cache

function lazytensor_default_cache_size()
Expand Down