@@ -18,6 +18,7 @@ using NamedDimsArrays:
1818 named,
1919 nameddimsindices,
2020 setname,
21+ setnameddimsindices,
2122 unname
2223
2324const Tag = String
@@ -79,7 +80,9 @@ struct Index{T,Value<:AbstractUnitRange{T}} <: AbstractNamedUnitRange{T,Value,In
7980 name:: IndexName
8081end
8182
82- Index (length:: Int ; kwargs... ) = Index (Base. OneTo (length), IndexName (; kwargs... ))
83+ function Index (length:: Int ; tags, kwargs... )
84+ return Index (Base. OneTo (length), IndexName (; tags= tagset (tags), kwargs... ))
85+ end
8386function Index (length:: Int , tags:: String ; kwargs... )
8487 return Index (Base. OneTo (length), IndexName (; kwargs... , tags= tagset (tags)))
8588end
@@ -177,17 +180,30 @@ struct AllocatableArrayInterface <: AbstractAllocatableArrayInterface end
177180
178181unallocatable (a:: AbstractITensor ) = NamedDimsArray (a)
179182
180- @interface :: AbstractAllocatableArrayInterface function Base. setindex! (
181- a:: AbstractArray , value, I:: Int...
182- )
183+ function setindex_allocatable! (a:: AbstractArray , value, I... )
183184 allocate! (specify_eltype! (a, typeof (value)))
184185 # TODO : Maybe use `@interface interface(a) a[I...] = value`?
185186 unallocatable (a)[I... ] = value
186187 return a
187188end
188189
190+ # TODO : Combine these by using `Base.to_indices`.
191+ @interface :: AbstractAllocatableArrayInterface function Base. setindex! (
192+ a:: AbstractArray , value, I:: Int...
193+ )
194+ setindex_allocatable! (a, value, I... )
195+ return a
196+ end
197+ @interface :: AbstractAllocatableArrayInterface function Base. setindex! (
198+ a:: AbstractArray , value, I:: AbstractNamedInteger...
199+ )
200+ setindex_allocatable! (a, value, I... )
201+ return a
202+ end
203+
189204@derive AllocatableArrayInterface () (T= AbstractITensor,) begin
190205 Base. setindex! (:: T , :: Any , :: Int... )
206+ Base. setindex! (:: T , :: Any , :: AbstractNamedInteger... )
191207end
192208
193209mutable struct ITensor <: AbstractITensor
@@ -216,6 +232,25 @@ function ITensor()
216232 return ITensor (Zeros {UnspecifiedZero} (), ())
217233end
218234
235+ inds (a:: AbstractITensor ) = nameddimsindices (a)
236+ setinds (a:: AbstractITensor , inds) = setnameddimsindices (a, inds)
237+
238+ function uniqueinds (a1:: AbstractITensor , a_rest:: AbstractITensor... )
239+ return setdiff (inds (a1), inds .(a_rest)... )
240+ end
241+ function uniqueind (a1:: AbstractITensor , a_rest:: AbstractITensor... )
242+ return only (uniqueinds (a1, a_rest... ))
243+ end
244+
245+ function commoninds (a1:: AbstractITensor , a_rest:: AbstractITensor... )
246+ return intersect (inds (a1), inds .(a_rest)... )
247+ end
248+ function commonind (a1:: AbstractITensor , a_rest:: AbstractITensor... )
249+ return only (commoninds (a1, a_rest... ))
250+ end
251+
252+ prime (a:: AbstractITensor ) = setinds (a, prime .(inds (a)))
253+
219254include (" quirks.jl" )
220255
221256end
0 commit comments