| 
1 | 1 | module ITensors  | 
2 | 2 | 
 
  | 
3 |  | -# Write your package code here.  | 
 | 3 | +using BroadcastMapConversion: Mapped  | 
 | 4 | +using NamedDimsArrays:  | 
 | 5 | +  NamedDimsArrays,  | 
 | 6 | +  AbstractName,  | 
 | 7 | +  AbstractNamedDimsArray,  | 
 | 8 | +  AbstractNamedInteger,  | 
 | 9 | +  AbstractNamedUnitRange,  | 
 | 10 | +  AbstractNamedVector,  | 
 | 11 | +  dename,  | 
 | 12 | +  dimnames,  | 
 | 13 | +  name,  | 
 | 14 | +  named,  | 
 | 15 | +  unname  | 
 | 16 | + | 
 | 17 | +@kwdef struct IndexName <: AbstractName  | 
 | 18 | +  id::UInt64 = rand(UInt64)  | 
 | 19 | +  plev::Int = 0  | 
 | 20 | +  tags::Set{String} = Set{String}()  | 
 | 21 | +  namedtags::Dict{Symbol,String} = Dict{Symbol,String}()  | 
 | 22 | +end  | 
 | 23 | +NamedDimsArrays.randname(n::IndexName) = IndexName()  | 
 | 24 | + | 
 | 25 | +struct IndexVal{Value<:Integer} <: AbstractNamedInteger{Value,IndexName}  | 
 | 26 | +  value::Value  | 
 | 27 | +  name::IndexName  | 
 | 28 | +end  | 
 | 29 | + | 
 | 30 | +# Interface  | 
 | 31 | +NamedDimsArrays.dename(i::IndexVal) = i.value  | 
 | 32 | +NamedDimsArrays.name(i::IndexVal) = i.name  | 
 | 33 | + | 
 | 34 | +# Constructor  | 
 | 35 | +NamedDimsArrays.named(i::Integer, name::IndexName) = IndexVal(i, name)  | 
 | 36 | + | 
 | 37 | +struct Index{T,Value<:AbstractUnitRange{T}} <: AbstractNamedUnitRange{T,Value,IndexName}  | 
 | 38 | +  value::Value  | 
 | 39 | +  name::IndexName  | 
 | 40 | +end  | 
 | 41 | + | 
 | 42 | +Index(length::Int) = Index(Base.OneTo(length), IndexName())  | 
 | 43 | + | 
 | 44 | +# Interface  | 
 | 45 | +# TODO: Overload `Base.parent` instead.  | 
 | 46 | +NamedDimsArrays.dename(i::Index) = i.value  | 
 | 47 | +NamedDimsArrays.name(i::Index) = i.name  | 
 | 48 | + | 
 | 49 | +# Constructor  | 
 | 50 | +NamedDimsArrays.named(i::AbstractUnitRange, name::IndexName) = Index(i, name)  | 
 | 51 | + | 
 | 52 | +struct NoncontiguousIndex{T,Value<:AbstractVector{T}} <:  | 
 | 53 | +       AbstractNamedVector{T,Value,IndexName}  | 
 | 54 | +  value::Value  | 
 | 55 | +  name::IndexName  | 
 | 56 | +end  | 
 | 57 | + | 
 | 58 | +# Interface  | 
 | 59 | +# TODO: Overload `Base.parent` instead.  | 
 | 60 | +NamedDimsArrays.dename(i::NoncontiguousIndex) = i.value  | 
 | 61 | +NamedDimsArrays.name(i::NoncontiguousIndex) = i.name  | 
 | 62 | + | 
 | 63 | +# Constructor  | 
 | 64 | +NamedDimsArrays.named(i::AbstractVector, name::IndexName) = NoncontiguousIndex(i, name)  | 
 | 65 | + | 
 | 66 | +abstract type AbstractITensor <: AbstractNamedDimsArray{Any,Any} end  | 
 | 67 | + | 
 | 68 | +NamedDimsArrays.nameddimsarraytype(::Type{<:IndexName}) = ITensor  | 
 | 69 | + | 
 | 70 | +Base.ndims(::Type{<:AbstractITensor}) = Any  | 
 | 71 | + | 
 | 72 | +struct ITensor <: AbstractITensor  | 
 | 73 | +  parent::AbstractArray  | 
 | 74 | +  nameddimsindices  | 
 | 75 | +end  | 
 | 76 | +Base.parent(a::ITensor) = a.parent  | 
 | 77 | +NamedDimsArrays.nameddimsindices(a::ITensor) = a.nameddimsindices  | 
4 | 78 | 
 
  | 
5 | 79 | end  | 
0 commit comments