@@ -35,33 +35,44 @@ Base.keys(A::SparseTensorArray) = keys(A.data)
3535Base. values (A:: SparseTensorArray ) = values (A. data)
3636
3737TensorKit. space (A:: SparseTensorArray ) = A. space
38+ TensorKit. codomain (A:: SparseTensorArray ) = codomain (space (A))
39+ TensorKit. domain (A:: SparseTensorArray ) = domain (space (A))
40+
41+ TensorKit. numout (A:: SparseTensorArray ) = numout (eltype (A))
42+ TensorKit. numout (:: Type{T} ) where {T <: SparseTensorArray } = numout (eltype (A))
43+ TensorKit. numin (A:: SparseTensorArray ) = numin (eltype (A))
44+ TensorKit. numin (:: Type{T} ) where {T <: SparseTensorArray } = numin (eltype (A))
3845
3946# AbstractArray interface
4047# -----------------------
41- Base. size (A:: SparseTensorArray ) = ntuple (i -> length (space (A)[i]), ndims (A))
48+ Base. size (A:: SparseTensorArray ) = ntuple (Base. Fix1 (size, A), ndims (A))
49+ function Base. size (A:: SparseTensorArray , i:: Int )
50+ 1 ≤ i ≤ ndims (A) || throw (ArgumentError (" Invalid number of dimensions" ))
51+ return i <= numout (A) ? length (codomain (A)[i]) : length (domain (A)[i - numout (A)])
52+ end
4253
43- @inline function Base. getindex (
54+ @propagate_inbounds function Base. getindex (
4455 A:: SparseTensorArray{S, N₁, N₂, T, N} , I:: Vararg{Int, N}
4556 ) where {S, N₁, N₂, T, N}
4657 @boundscheck checkbounds (A, I... )
4758 return @inbounds get (A. data, CartesianIndex (I)) do
4859 return fill! (similar (T, eachspace (A)[I... ]), zero (scalartype (T)))
4960 end
5061end
51- @inline function getindex! (
62+ @propagate_inbounds function getindex! (
5263 A:: SparseTensorArray{S, N₁, N₂, T, N} , I:: CartesianIndex{N}
5364 ) where {S, N₁, N₂, T, N}
5465 @boundscheck checkbounds (A, I)
5566 return @inbounds get! (A. data, I) do
5667 return fill! (similar (T, eachspace (A)[I]), zero (scalartype (T)))
5768 end
5869end
59- @inline function getindex! (
70+ @propagate_inbounds function getindex! (
6071 A:: SparseTensorArray{S, N₁, N₂, T, N} , I:: Vararg{Int, N}
6172 ) where {S, N₁, N₂, T, N}
6273 return getindex! (A, CartesianIndex (I))
6374end
64- @inline function Base. setindex! (
75+ @propagate_inbounds function Base. setindex! (
6576 A:: SparseTensorArray{S, N₁, N₂, T, N} , v, I:: Vararg{Int, N}
6677 ) where {S, N₁, N₂, T, N}
6778 @boundscheck begin
0 commit comments