Skip to content

Tensor

Tenet.Tensor Type
julia
Tensor{T,N,A<:AbstractArray{T,N}} <: AbstractArray{T,N}

An array-like object with named dimensions.

source
Tenet.Tensor Method
julia
Tensor(data::AbstractArray{T,N}, inds::AbstractVector{Symbol})
Tensor(data::AbstractArray{T,N}, inds::NTuple{N,Symbol}) where {T,N}
Tensor(data::AbstractArray{T,0}) where {T}
Tensor(data::Number)

Construct a tensor with the given data and indices.

source
Base.adjoint Method
julia
Base.adjoint(::Tensor)

Return the adjoint of the tensor.

Note

This method doesn't transpose the array. It is equivalent to conj.

source
Base.conj Method
julia
Base.conj(::Tensor)

Return the conjugate of the tensor.

source
Base.dropdims Method
julia
Base.dropdims(tensor::Tensor; dims)

Return a tensor where the dimensions specified by dims are removed. size(tensor, dim) == 1 for each dimension in dims.

source
Base.getindex Method
julia
Base.getindex(::Tensor, i...)
Base.getindex(::Tensor; i...)
(::Tensor)[index=i...]

Return the element of the tensor at the given indices. If kwargs are provided, then it is equivalent to calling view.

source
Base.length Method
julia
Base.length(::Tensor)

Return the length of the underlying array.

source
Base.parent Method
julia
Base.parent(::Tensor)

Return the underlying array of the tensor.

source
Base.permutedims Method
julia
Base.permutedims(tensor::Tensor, perm)

Permute the dimensions of tensor according to the given permutation perm. The inds will be permuted accordingly.

source
Base.replace Method
julia
Base.replace(::Tensor, old_new::Pair{Symbol,Symbol}...)

Replace the indices of the tensor according to the given pairs of old and new indices.

Warning

This method does not support cyclic replacements.

source
Base.selectdim Method
julia
Base.selectdim(tensor::Tensor, dim::Symbol, i)
Base.selectdim(tensor::Tensor, dim::Integer, i)

Return a view of the tensor where the index for dimension dim equals i.

Note

This method doesn't return a SubArray, but a Tensor wrapping a SubArray.

See also: selectdim

source
Base.setindex! Method
julia
Base.setindex!(t::Tensor, v, i...)
Base.setindex(::Tensor; i...)
(::Tensor)[index=i...]

Set the element of the tensor at the given indices to v. If kwargs are provided, then it is equivalent to calling .= on view.

source
Base.similar Method
julia
Base.similar(::Tensor{T,N}[, S::Type, dims::Base.Dims{N}; inds])

Return a uninitialize tensor of the same size, eltype and inds as tensor. If S is provided, the eltype of the tensor will be S. If dims is provided, the size of the tensor will be dims.

source
Base.size Method
julia
Base.size(::Tensor[, i::Symbol])

Return the size of the underlying array. If the dimension i (specified by Symbol or Integer) is specified, then the size of the corresponding dimension is returned.

source
Base.view Method
julia
Base.view(tensor::Tensor, i...)
Base.view(tensor::Tensor, inds::Pair{Symbol,<:Any}...)

Return a view of the tensor with the given indices. If a Pair is given, the index is replaced by the value of the pair.

Note

This method doesn't return a SubArray, but a Tensor wrapping a SubArray.

source
Base.zero Method
julia
Base.zero(tensor::Tensor)

Return a tensor of the same size, eltype and inds as tensor but filled with zeros.

source
EinExprs.inds Method
julia
inds(tensor::Tensor)

Return the indices of the tensor in the order of the dimensions.

source
Tenet.dim Method
julia
dim(tensor::Tensor, i::Symbol)

Return the location of the dimension of tensor corresponding to the given index i.

source
Tenet.expand Method
julia
expand(tensor::Tensor; label[, axis=1, size=1, method=:zeros])

Expand the tensor by adding a new dimension label with the given size at the specified axis. Currently the supported methods are :zeros and :repeat.

source
Tenet.fuse Method
julia
fuse(tensor, parinds; ind=first(parinds))

Fuses parinds, leaves them on the right-side internally permuted with permutator and names it as ind.

source
Base.:* Method
julia
*(::Tensor, ::Tensor)
*(::Tensor, ::Number)
*(::Number, ::Tensor)

Alias for contract.

source
Base.:+ Method
julia
+(::Tensor, ::Tensor)

Add two tensors element-wise. The tensors must have the same indices, alghough the order of the indices can be different.

source
Base.:- Method
julia
-(::Tensor, ::Tensor)

Subtract two tensors element-wise. The tensors must have the same indices, alghough the order of the indices can be different.

source
LinearAlgebra.lu Method
julia
LinearAlgebra.lu(tensor::Tensor; left_inds, right_inds, virtualind, kwargs...)

Perform LU factorization on a tensor. Either left_inds or right_inds must be specified, unless ndims(tensor) == 2 in which case no indices need to be specified.

Keyword arguments

  • left_inds: left indices to be used in the LU factorization. Defaults to all indices of t except right_inds.

  • right_inds: right indices to be used in the LU factorization. Defaults to all indices of t except left_inds.

  • virtualind: name of the virtual bond. Defaults to a random Symbol.

source
LinearAlgebra.qr Method
julia
LinearAlgebra.qr(tensor::Tensor; left_inds, right_inds, virtualind, kwargs...)

Perform QR factorization on a tensor. Either left_inds or right_inds must be specified, unless ndims(tensor) == 2 in which case no indices need to be specified.

Keyword arguments

  • left_inds: left indices to be used in the QR factorization. Defaults to all indices of t except right_inds.

  • right_inds: right indices to be used in the QR factorization. Defaults to all indices of t except left_inds.

  • virtualind: name of the virtual bond. Defaults to a random Symbol.

source
LinearAlgebra.svd Method
julia
LinearAlgebra.svd(tensor::Tensor; left_inds, right_inds, virtualind, kwargs...)

Perform SVD factorization on a tensor. Either left_inds or right_inds must be specified, unless ndims(tensor) == 2 in which case no indices need to be specified.

Keyword arguments

  • left_inds: left indices to be used in the SVD factorization. Defaults to all indices of t except right_inds.

  • right_inds: right indices to be used in the SVD factorization. Defaults to all indices of t except left_inds.

  • virtualind: name of the virtual bond. Defaults to a random Symbol.

source
Tenet.contract! Method
julia
contract!(c::Tensor, a::Tensor, b::Tensor)

Perform a binary tensor contraction operation between a and b and store the result in c.

source
Tenet.contract! Method
julia
contract!(c::Tensor, a::Tensor)

Perform a unary tensor contraction operation on a and store the result in c.

source
Tenet.contract Method
julia
contract(a::Tensor, b::Tensor; dims=∩(inds(a), inds(b)), out=nothing)

Perform a binary tensor contraction operation.

Keyword arguments

- `dims`: indices to contract over. Defaults to the set intersection of the indices of `a` and `b`.
- `out`: indices of the output tensor. Defaults to the set difference of the indices of `a` and `b`.

Todo

We are in the process of making contract multi-backend; i.e. let the user choose between different einsum libraries as the engine powering contract. Currently, we use OMEinsum.jl, but it has proven to be slow when used dynamically like we do.

source
Tenet.contract Method
julia
contract(a::Tensor; dims=∩(inds(a), inds(b)), out=nothing)

Perform a unary tensor contraction operation.

Keyword arguments

- `dims`: indices to contract over. Defaults to the repeated indices.
- `out`: indices of the output tensor. Defaults to the unique indices.
source

DocumenterMermaid.MermaidScriptBlock([...])

Made with DocumenterVitepress.jl