Skip to content

Commit

Permalink
[ITensors] Generalize diag_itensor constructors to AbstractVector
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Jun 23, 2024
1 parent b00f772 commit 1b12219
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensors"
uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5"
authors = ["Matthew Fishman <[email protected]>", "Miles Stoudenmire <[email protected]>"]
version = "0.6.14"
version = "0.6.15"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
20 changes: 11 additions & 9 deletions src/itensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ diag_itensor(is::Indices) = diag_itensor(Float64, is)
diag_itensor(is...) = diag_itensor(indices(is...))

"""
diag_itensor([ElT::Type, ]v::Vector, inds...)
diagitensor([ElT::Type, ]v::Vector, inds...)
diag_itensor([ElT::Type, ]v::AbstractVector, inds...)
diagitensor([ElT::Type, ]v::AbstractVector, inds...)
Make a sparse ITensor with non-zero elements only along the diagonal.
In general, the diagonal elements will be those stored in `v` and
Expand All @@ -467,29 +467,31 @@ The version `diagitensor` might output an ITensor whose storage data
is an alias of the input vector data in order to minimize operations.
"""
function diag_itensor(
as::AliasStyle, eltype::Type{<:Number}, v::Vector{<:Number}, is::Indices
as::AliasStyle, eltype::Type{<:Number}, v::AbstractVector{<:Number}, is::Indices
)
length(v) mindim(is) && error(
"Length of vector for diagonal must equal minimum of the dimension of the input indices",
)
data = Vector{eltype}(as, v)
data = set_eltype(typeof(v), eltype)(as, v)
return itensor(Diag(data), is)
end

function diag_itensor(as::AliasStyle, eltype::Type{<:Number}, v::Vector{<:Number}, is...)
function diag_itensor(
as::AliasStyle, eltype::Type{<:Number}, v::AbstractVector{<:Number}, is...
)
return diag_itensor(as, eltype, v, indices(is...))
end

function diag_itensor(as::AliasStyle, v::Vector, is...)
function diag_itensor(as::AliasStyle, v::AbstractVector, is...)
return diag_itensor(as, eltype(v), v, is...)
end

function diag_itensor(as::AliasStyle, v::Vector{<:RealOrComplex{Int}}, is...)
function diag_itensor(as::AliasStyle, v::AbstractVector{<:RealOrComplex{Int}}, is...)
return diag_itensor(AllowAlias(), float(eltype(v)), v, is...)
end

diag_itensor(v::Vector{<:Number}, is...) = diag_itensor(NeverAlias(), v, is...)
function diag_itensor(eltype::Type{<:Number}, v::Vector{<:Number}, is...)
diag_itensor(v::AbstractVector{<:Number}, is...) = diag_itensor(NeverAlias(), v, is...)
function diag_itensor(eltype::Type{<:Number}, v::AbstractVector{<:Number}, is...)
return diag_itensor(NeverAlias(), eltype, v, is...)
end

Expand Down

0 comments on commit 1b12219

Please sign in to comment.