4545# matrix factorizations assume copy
4646# maybe: copy=false kwarg
4747
48- function matricize (a:: AbstractArray , biperm :: AbstractBlockPermutation{2} )
49- ndims (a) == length (biperm ) || throw (ArgumentError (" Invalid bipermutation" ))
50- return matricize (FusionStyle (a), a, biperm )
48+ function matricize (a:: AbstractArray , biperm_dest :: AbstractBlockPermutation{2} )
49+ ndims (a) == length (biperm_dest ) || throw (ArgumentError (" Invalid bipermutation" ))
50+ return matricize (FusionStyle (a), a, biperm_dest )
5151end
5252
5353function matricize (
54- style:: FusionStyle , a:: AbstractArray , biperm :: AbstractBlockPermutation{2}
54+ style:: FusionStyle , a:: AbstractArray , biperm_dest :: AbstractBlockPermutation{2}
5555)
56- a_perm = permuteblockeddims (a, biperm )
57- return matricize (style, a_perm, trivialperm (biperm ))
56+ a_perm = permuteblockeddims (a, biperm_dest )
57+ return matricize (style, a_perm, trivialperm (biperm_dest ))
5858end
5959
6060function matricize (
61- style:: FusionStyle , a:: AbstractArray , biperm :: BlockedTrivialPermutation{2}
61+ style:: FusionStyle , a:: AbstractArray , biperm_dest :: BlockedTrivialPermutation{2}
6262)
63- return throw (MethodError (matricize, Tuple{typeof (style),typeof (a),typeof (biperm )}))
63+ return throw (MethodError (matricize, Tuple{typeof (style),typeof (a),typeof (biperm_dest )}))
6464end
6565
6666# default is reshape
67- function matricize (:: ReshapeFusion , a:: AbstractArray , biperm:: BlockedTrivialPermutation{2} )
68- new_axes = fuseaxes (axes (a), biperm)
67+ function matricize (
68+ :: ReshapeFusion , a:: AbstractArray , biperm_dest:: BlockedTrivialPermutation{2}
69+ )
70+ new_axes = fuseaxes (axes (a), biperm_dest)
6971 return reshape (a, new_axes... )
7072end
7173
@@ -74,20 +76,20 @@ function matricize(a::AbstractArray, permblock1::Tuple, permblock2::Tuple)
7476end
7577
7678# ==================================== unmatricize =======================================
77- function unmatricize (m:: AbstractMatrix , axes, biperm_dest :: AbstractBlockPermutation{2} )
78- length (axes ) == length (biperm_dest ) ||
79+ function unmatricize (m:: AbstractMatrix , axes_dest, invbiperm :: AbstractBlockPermutation{2} )
80+ length (axes_dest ) == length (invbiperm ) ||
7981 throw (ArgumentError (" axes do not match permutation" ))
80- return unmatricize (FusionStyle (m), m, axes, biperm_dest )
82+ return unmatricize (FusionStyle (m), m, axes_dest, invbiperm )
8183end
8284
8385function unmatricize (
84- :: FusionStyle , m:: AbstractMatrix , axes, biperm_dest_to_a12 :: AbstractBlockPermutation{2}
86+ :: FusionStyle , m:: AbstractMatrix , axes_dest, invbiperm :: AbstractBlockPermutation{2}
8587)
86- blocked_axes = axes[biperm_dest_to_a12 ]
88+ blocked_axes = axes_dest[invbiperm ]
8789 a12 = unmatricize (m, blocked_axes)
88- biperm_a12_to_dest = biperm (invperm (biperm_dest_to_a12 ), length_codomain (axes ))
90+ biperm_dest = biperm (invperm (invbiperm ), length_codomain (axes_dest ))
8991
90- return permuteblockeddims (a12, biperm_a12_to_dest )
92+ return permuteblockeddims (a12, biperm_dest )
9193end
9294
9395function unmatricize (
@@ -111,20 +113,18 @@ function unmatricize(
111113 return unmatricize (m, blocked_axes)
112114end
113115
114- function unmatricize! (
115- a_dest, m:: AbstractMatrix , biperm_dest_to_a12:: AbstractBlockPermutation{2}
116- )
117- ndims (a_dest) == length (biperm_dest_to_a12) ||
116+ function unmatricize! (a_dest, m:: AbstractMatrix , invbiperm:: AbstractBlockPermutation{2} )
117+ ndims (a_dest) == length (invbiperm) ||
118118 throw (ArgumentError (" destination does not match permutation" ))
119- blocked_axes = axes (a_dest)[biperm_dest_to_a12 ]
119+ blocked_axes = axes (a_dest)[invbiperm ]
120120 a_perm = unmatricize (m, blocked_axes)
121- biperm_a12_to_dest = biperm (invperm (biperm_dest_to_a12 ), length_codomain (axes (a_dest)))
121+ biperm_dest = biperm (invperm (invbiperm ), length_codomain (axes (a_dest)))
122122
123- return permuteblockeddims! (a_dest, a_perm, biperm_a12_to_dest )
123+ return permuteblockeddims! (a_dest, a_perm, biperm_dest )
124124end
125125
126- function unmatricize_add! (a_dest, a_dest_mat, biperm_dest_to_a12 , α, β)
127- a12 = unmatricize (a_dest_mat, axes (a_dest), biperm_dest_to_a12 )
126+ function unmatricize_add! (a_dest, a_dest_mat, invbiperm , α, β)
127+ a12 = unmatricize (a_dest_mat, axes (a_dest), invbiperm )
128128 a_dest .= α .* a12 .+ β .* a_dest
129129 return a_dest
130130end
0 commit comments