Skip to content

Commit

Permalink
Rename diagITensor to diag_itensor
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed May 16, 2024
1 parent d47fc48 commit e9b4332
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 143 deletions.
8 changes: 4 additions & 4 deletions docs/src/ITensorType.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ ITensor(::Type{<:Number}, ::UndefInitializer, ::QN, ::ITensors.Indices)
## Diagonal constructors

```@docs
diagITensor(::Type{<:Number}, ::ITensors.Indices)
diagITensor(::ITensors.AliasStyle, ::Type{<:Number}, ::Vector{<:Number}, ::ITensors.Indices)
diagITensor(::ITensors.AliasStyle, ::Type{<:Number}, ::Number, ::ITensors.Indices)
diag_itensor(::Type{<:Number}, ::ITensors.Indices)
diag_itensor(::ITensors.AliasStyle, ::Type{<:Number}, ::Vector{<:Number}, ::ITensors.Indices)
diag_itensor(::ITensors.AliasStyle, ::Type{<:Number}, ::Number, ::ITensors.Indices)
delta(::Type{<:Number}, ::ITensors.Indices)
```

## QN Diagonal constructors

```@docs
diagITensor(::Type{<:Number}, ::QN, ::ITensors.Indices)
diag_itensor(::Type{<:Number}, ::QN, ::ITensors.Indices)
delta(::Type{<:Number}, ::QN, ::ITensors.Indices)
```

Expand Down
1 change: 1 addition & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# itensor.jl
@deprecate commonindex(args...; kwargs...) commonind(args...; kwargs...)
@deprecate diagITensor(args...; kwargs...) diag_itensor(args...; kwargs...)
@deprecate emptyITensor(::Type{Any}) emptyITensor()
@deprecate findindex(args...; kwargs...) firstind(args...; kwargs...)
@deprecate findinds(args...; kwargs...) inds(args...; kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export
denseblocks,
δ,
diagitensor,
diagITensor,
diag_itensor,
directsum,
eachnzblock,
firstind,
Expand Down
62 changes: 31 additions & 31 deletions src/itensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -429,26 +429,26 @@ end
#

"""
diagITensor([::Type{ElT} = Float64, ]inds)
diagITensor([::Type{ElT} = Float64, ]inds::Index...)
diag_itensor([::Type{ElT} = Float64, ]inds)
diag_itensor([::Type{ElT} = Float64, ]inds::Index...)
Make a sparse ITensor of element type `ElT` with only elements
along the diagonal stored. Defaults to having `zero(T)` along
the diagonal.
The storage will have `NDTensors.Diag` type.
"""
function diagITensor(::Type{ElT}, is::Indices) where {ElT<:Number}
function diag_itensor(::Type{ElT}, is::Indices) where {ElT<:Number}
return itensor(Diag(ElT, mindim(is)), is)
end

diagITensor(::Type{ElT}, is...) where {ElT<:Number} = diagITensor(ElT, indices(is...))
diag_itensor(::Type{ElT}, is...) where {ElT<:Number} = diag_itensor(ElT, indices(is...))

diagITensor(is::Indices) = diagITensor(Float64, is)
diagITensor(is...) = diagITensor(indices(is...))
diag_itensor(is::Indices) = diag_itensor(Float64, is)
diag_itensor(is...) = diag_itensor(indices(is...))

"""
diagITensor([ElT::Type, ]v::Vector, inds...)
diag_itensor([ElT::Type, ]v::Vector, inds...)
diagitensor([ElT::Type, ]v::Vector, inds...)
Make a sparse ITensor with non-zero elements only along the diagonal.
Expand All @@ -460,13 +460,13 @@ In the case when `eltype(v) isa Union{Int, Complex{Int}}`, by default it will
be converted to `float(v)`. Note that this behavior is subject to change
in the future.
The version `diagITensor` will never output an ITensor whose storage data
The version `diag_itensor` will never output an ITensor whose storage data
is an alias of the input vector data.
The version `diagitensor` might output an ITensor whose storage data
is an alias of the input vector data in order to minimize operations.
"""
function diagITensor(
function diag_itensor(
as::AliasStyle, eltype::Type{<:Number}, v::Vector{<:Number}, is::Indices
)
length(v) mindim(is) && error(
Expand All @@ -476,29 +476,29 @@ function diagITensor(
return itensor(Diag(data), is)
end

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

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

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

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

diagitensor(args...; kwargs...) = diagITensor(AllowAlias(), args...; kwargs...)
diagitensor(args...; kwargs...) = diag_itensor(AllowAlias(), args...; kwargs...)

# XXX TODO: explain conversion from Int
# XXX TODO: proper conversion
"""
diagITensor([ElT::Type, ]x::Number, inds...)
diag_itensor([ElT::Type, ]x::Number, inds...)
diagitensor([ElT::Type, ]x::Number, inds...)
Make a sparse ITensor with non-zero elements only along the diagonal.
Expand All @@ -510,27 +510,27 @@ In the case when `x isa Union{Int, Complex{Int}}`, by default it will
be converted to `float(x)`. Note that this behavior is subject to change
in the future.
"""
function diagITensor(as::AliasStyle, eltype::Type{<:Number}, x::Number, is::Indices)
return diagITensor(AllowAlias(), eltype, fill(eltype(x), mindim(is)), is...)
function diag_itensor(as::AliasStyle, eltype::Type{<:Number}, x::Number, is::Indices)
return diag_itensor(AllowAlias(), eltype, fill(eltype(x), mindim(is)), is...)
end

function diagITensor(as::AliasStyle, eltype::Type{<:Number}, x::Number, is...)
return diagITensor(as, eltype, x, indices(is...))
function diag_itensor(as::AliasStyle, eltype::Type{<:Number}, x::Number, is...)
return diag_itensor(as, eltype, x, indices(is...))
end

function diagITensor(as::AliasStyle, x::Number, is...)
return diagITensor(as, typeof(x), x, is...)
function diag_itensor(as::AliasStyle, x::Number, is...)
return diag_itensor(as, typeof(x), x, is...)
end

function diagITensor(as::AliasStyle, x::RealOrComplex{Int}, is...)
return diagITensor(as, float(typeof(x)), x, is...)
function diag_itensor(as::AliasStyle, x::RealOrComplex{Int}, is...)
return diag_itensor(as, float(typeof(x)), x, is...)
end

function diagITensor(eltype::Type{<:Number}, x::Number, is...)
return diagITensor(NeverAlias(), eltype, x, is...)
function diag_itensor(eltype::Type{<:Number}, x::Number, is...)
return diag_itensor(NeverAlias(), eltype, x, is...)
end

diagITensor(x::Number, is...) = diagITensor(NeverAlias(), x, is...)
diag_itensor(x::Number, is...) = diag_itensor(NeverAlias(), x, is...)

"""
delta([::Type{ElT} = Float64, ]inds)
Expand Down
32 changes: 16 additions & 16 deletions src/qn/qnitensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,53 +455,53 @@ end
#

"""
diagITensor([::Type{ElT} = Float64, ][flux::QN = QN(), ]is)
diagITensor([::Type{ElT} = Float64, ][flux::QN = QN(), ]is::Index...)
diag_itensor([::Type{ElT} = Float64, ][flux::QN = QN(), ]is)
diag_itensor([::Type{ElT} = Float64, ][flux::QN = QN(), ]is::Index...)
Make an ITensor with storage type `NDTensors.DiagBlockSparse` with elements
`zero(ElT)`. The ITensor only has diagonal blocks consistent with the specified `flux`.
If the element type is not specified, it defaults to `Float64`. If theflux
is not specified, it defaults to `QN()`.
"""
function diagITensor(::Type{ElT}, flux::QN, inds::Indices) where {ElT<:Number}
function diag_itensor(::Type{ElT}, flux::QN, inds::Indices) where {ElT<:Number}
is = Tuple(inds)
blocks = nzdiagblocks(flux, is)
T = DiagBlockSparseTensor(ElT, blocks, is)
return itensor(T)
end

function diagITensor(::Type{ElT}, flux::QN, is...) where {ElT<:Number}
return diagITensor(ElT, flux, indices(is...))
function diag_itensor(::Type{ElT}, flux::QN, is...) where {ElT<:Number}
return diag_itensor(ElT, flux, indices(is...))
end

function diagITensor(x::ElT, flux::QN, inds::QNIndices) where {ElT<:Number}
function diag_itensor(x::ElT, flux::QN, inds::QNIndices) where {ElT<:Number}
is = Tuple(inds)
blocks = nzdiagblocks(flux, is)
T = DiagBlockSparseTensor(float(ElT), blocks, is)
NDTensors.data(T) .= x
return itensor(T)
end

function diagITensor(x::Number, flux::QN, is...)
return diagITensor(x, flux, indices(is...))
function diag_itensor(x::Number, flux::QN, is...)
return diag_itensor(x, flux, indices(is...))
end

diagITensor(x::Number, is::QNIndices) = diagITensor(x, QN(), is)
diag_itensor(x::Number, is::QNIndices) = diag_itensor(x, QN(), is)

# TODO: generalize to list of Tuple, Vector, and QNIndex
diagITensor(x::Number, is::QNIndex...) = diagITensor(x, indices(is...))
diag_itensor(x::Number, is::QNIndex...) = diag_itensor(x, indices(is...))

diagITensor(flux::QN, is::Indices) = diagITensor(Float64, flux, is)
diag_itensor(flux::QN, is::Indices) = diag_itensor(Float64, flux, is)

diagITensor(flux::QN, is...) = diagITensor(Float64, flux, indices(is...))
diag_itensor(flux::QN, is...) = diag_itensor(Float64, flux, indices(is...))

function diagITensor(::Type{ElT}, inds::QNIndices) where {ElT<:Number}
return diagITensor(ElT, QN(), inds)
function diag_itensor(::Type{ElT}, inds::QNIndices) where {ElT<:Number}
return diag_itensor(ElT, QN(), inds)
end

function diagITensor(inds::QNIndices)
return diagITensor(Float64, QN(), inds)
function diag_itensor(inds::QNIndices)
return diag_itensor(Float64, QN(), inds)
end

"""
Expand Down
4 changes: 2 additions & 2 deletions src/tensor_operations/matrix_decomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ end
function sqrt_decomp(D::ITensor, u::Index, v::Index)
(storage(D) isa Union{Diag,DiagBlockSparse}) ||
error("Must be a diagonal matrix ITensor.")
sqrtDL = diagITensor(u, dag(u)')
sqrtDR = diagITensor(v, dag(v)')
sqrtDL = diag_itensor(u, dag(u)')
sqrtDR = diag_itensor(v, dag(v)')
map_diag!(sqrt abs, sqrtDL, D)
map_diag!(sqrt abs, sqrtDR, D)
δᵤᵥ = copy(D)
Expand Down
Loading

0 comments on commit e9b4332

Please sign in to comment.