@@ -2,15 +2,17 @@ using .BaseExtensions: BaseExtensions
22using BlockArrays: blocklengths
33
44# default: if no bipartion is specified, all axes to domain
5- invbiperm (perm, :: Any ) = invbiperm (perm, Val (0 ))
6- invbiperm (perm, t:: Tuple{Tuple,Tuple} ) = invbiperm (perm, tuplemortar (t))
7- invbiperm (perm, t:: AbstractBlockTuple{2} ) = invbiperm (perm, Val (first (blocklength (t))))
8-
9- function invbiperm (perm, :: Val{N1} ) where {N1}
10- perm_out = invperm (Tuple (perm))
11- length (perm) <= N1 && return blockedpermvcat (perm_out, ())
12- return blockedpermvcat (perm_out[begin : N1], (perm_out[(N1 + 1 ): end ]))
5+ function biperm (perm, blocklength1:: Integer )
6+ return biperm (perm, Val (blocklength1))
137end
8+ function biperm (perm, :: Val{BlockLength1} ) where {BlockLength1}
9+ length (perm) < BlockLength1 && throw (ArgumentError (" Invalid codomain length" ))
10+ return blockedperm (Tuple (perm), (BlockLength1, length (perm) - BlockLength1))
11+ end
12+
13+ length_codomain (t:: AbstractBlockTuple{2} ) = first (blocklengths (t))
14+ # Assume all dimensions are in the domain by default
15+ length_codomain (t) = 0
1416
1517function blockedperms (
1618 f:: typeof (contract), alg:: Algorithm , dimnames_dest, dimnames1, dimnames2
@@ -32,7 +34,7 @@ function blockedperms(::typeof(contract), dimnames_dest, dimnames1, dimnames2)
3234 perm_codomain_dest = BaseExtensions. indexin (codomain, dimnames_dest)
3335 perm_domain_dest = BaseExtensions. indexin (domain, dimnames_dest)
3436 biperm_dest_to_a12 = (perm_codomain_dest... , perm_domain_dest... )
35- biperm_a12_to_dest = invbiperm ( biperm_dest_to_a12, dimnames_dest)
37+ biperm_a12_to_dest = biperm ( invperm ( biperm_dest_to_a12), length_codomain ( dimnames_dest) )
3638
3739 perm_codomain1 = BaseExtensions. indexin (codomain, dimnames1)
3840 perm_domain1 = BaseExtensions. indexin (contracted, dimnames1)
0 commit comments