@@ -63,19 +63,23 @@ _stridedordiag(A::Diagonal) = A
6363
6464Check that `C` has `numind(pC)` indices and that `pC` constitutes a valid permutation.
6565"""
66- function argcheck_index2tuple (C:: AbstractArray , pC:: Index2Tuple )
67- return ndims (C) == numind (pC) && isperm (linearize (pC)) ||
66+ argcheck_index2tuple (C:: AbstractArray , pC:: Index2Tuple ) = argcheck_indextuple (C, linearize (pC))
67+ function argcheck_indextuple (C:: AbstractArray , pC:: IndexTuple )
68+ ndims (C) == numind (pC) && isperm (pC) ||
6869 throw (IndexError (lazy " invalid permutation of length $(ndims(C)): $pC" ))
70+ return nothing
6971end
7072
7173"""
7274 argcheck_tensoradd(C::AbstractArray, A::AbstractArray, pA::Index2Tuple)
7375
7476Check that `C` and `A` have `numind(pA)` indices and that `pA` constitutes a valid permutation.
7577"""
76- function argcheck_tensoradd (C:: AbstractArray , A:: AbstractArray , pA:: Index2Tuple )
78+ argcheck_tensoradd (C:: AbstractArray , A:: AbstractArray , pA:: Index2Tuple ) =
79+ argcheck_tensoradd (C, A, linearize (pA))
80+ function argcheck_tensoradd (C:: AbstractArray , A:: AbstractArray , pA:: IndexTuple )
7781 ndims (C) == ndims (A) || throw (IndexError (" non-matching number of dimensions" ))
78- argcheck_index2tuple (A, pA)
82+ argcheck_indextuple (A, pA)
7983 return nothing
8084end
8185
8589Check that the partial trace of `A` over indices `q` and with permutation of the remaining
8690indices `p` is compatible with output `C`.
8791"""
92+ argcheck_tensortrace (C:: AbstractArray , A:: AbstractArray , p:: Index2Tuple , q:: Index2Tuple ) =
93+ argcheck_tensortrace (C, A, linearize (p), q)
8894function argcheck_tensortrace (
89- C:: AbstractArray , A:: AbstractArray , p:: Index2Tuple , q:: Index2Tuple
95+ C:: AbstractArray , A:: AbstractArray , p:: IndexTuple , q:: Index2Tuple
9096 )
9197 ndims (C) == numind (p) ||
9298 throw (IndexError (lazy " invalid selection of length $(ndims(C)): $p" ))
9399 2 * numin (q) == 2 * numout (q) == ndims (A) - ndims (C) ||
94100 throw (IndexError (" invalid number of trace dimensions" ))
95- argcheck_index2tuple (A, ((p[ 1 ] . .. , q[1 ]. .. ), (p[ 2 ] . .. , q[2 ]. .. ) ))
101+ argcheck_indextuple (A, (p ... , q[1 ]. .. , q[2 ]. .. ))
96102 return nothing
97103end
98104
@@ -108,7 +114,15 @@ function argcheck_tensorcontract(
108114 B:: AbstractArray , pB:: Index2Tuple ,
109115 pAB:: Index2Tuple
110116 )
111- argcheck_index2tuple (C, pAB)
117+ return argcheck_tensorcontract (C, A, pA, B, pB, linearize (pAB))
118+ end
119+ function argcheck_tensorcontract (
120+ C:: AbstractArray ,
121+ A:: AbstractArray , pA:: Index2Tuple ,
122+ B:: AbstractArray , pB:: Index2Tuple ,
123+ pAB:: IndexTuple
124+ )
125+ argcheck_indextuple (C, pAB)
112126 argcheck_index2tuple (A, pA)
113127 argcheck_index2tuple (B, pB)
114128 numout (pA) + numin (pB) == ndims (C) ||
@@ -123,27 +137,28 @@ end
123137
124138Check that `C` and `A` have compatible sizes for the addition specified by `pA`.
125139"""
126- function dimcheck_tensoradd (C:: AbstractArray , A:: AbstractArray , pA:: Index2Tuple )
140+ dimcheck_tensoradd (C:: AbstractArray , A:: AbstractArray , pA:: Index2Tuple ) = dimcheck_tensoradd (C, A, linearize (pA))
141+ function dimcheck_tensoradd (C:: AbstractArray , A:: AbstractArray , pA:: IndexTuple )
127142 szA, szC = size (A), size (C)
128- TupleTools. getindices (szA, linearize (pA) ) == szC ||
143+ TupleTools. getindices (szA, pA ) == szC ||
129144 throw (DimensionMismatch (" non-matching sizes in uncontracted dimensions" ))
130145 return nothing
131146end
132147
133148"""
134- dimcheck_tensorcontract(C::AbstractArray, A::AbstractArray,
135- p::Index2Tuple, q::Index2Tuple)
149+ dimcheck_tensorcontract(C::AbstractArray, A::AbstractArray, p::Index2Tuple, q::Index2Tuple)
136150
137- Check that `C` and `A` have compatible sizes for the trace and addition specified by `p` and
138- `q`.
151+ Check that `C` and `A` have compatible sizes for the trace and addition specified by `p` and `q`.
139152"""
153+ dimcheck_tensortrace (C:: AbstractArray , A:: AbstractArray , p:: Index2Tuple , q:: Index2Tuple ) =
154+ dimcheck_tensortrace (C, A, linearize (p), q)
140155function dimcheck_tensortrace (
141- C:: AbstractArray , A:: AbstractArray , p:: Index2Tuple , q:: Index2Tuple
156+ C:: AbstractArray , A:: AbstractArray , p:: IndexTuple , q:: Index2Tuple
142157 )
143158 szA, szC = size (A), size (C)
144159 TupleTools. getindices (szA, q[1 ]) == TupleTools. getindices (szA, q[2 ]) ||
145160 throw (DimensionMismatch (" non-matching sizes in traced dimensions" ))
146- TupleTools. getindices (szA, linearize (p) ) == szC ||
161+ TupleTools. getindices (szA, p ) == szC ||
147162 throw (DimensionMismatch (" non-matching sizes in uncontracted dimensions" ))
148163 return nothing
149164end
@@ -163,11 +178,19 @@ function dimcheck_tensorcontract(
163178 B:: AbstractArray , pB:: Index2Tuple ,
164179 pAB:: Index2Tuple
165180 )
181+ return dimcheck_tensorcontract (C, A, pA, B, pB, linearize (pAB))
182+ end
183+ function dimcheck_tensorcontract (
184+ C:: AbstractArray ,
185+ A:: AbstractArray , pA:: Index2Tuple ,
186+ B:: AbstractArray , pB:: Index2Tuple ,
187+ pAB:: IndexTuple
188+ )
166189 szA, szB, szC = size (A), size (B), size (C)
167190 TupleTools. getindices (szA, pA[2 ]) == TupleTools. getindices (szB, pB[1 ]) ||
168191 throw (DimensionMismatch (" non-matching sizes in contracted dimensions" ))
169192 szAB = (TupleTools. getindices (szA, pA[1 ])... , TupleTools. getindices (szB, pB[2 ])... )
170- TupleTools. getindices (szAB, linearize ( pAB) ) == szC ||
193+ TupleTools. getindices (szAB, pAB) == szC ||
171194 throw (DimensionMismatch (" non-matching sizes in uncontracted dimensions" ))
172195 return nothing
173196end
0 commit comments