@@ -1659,15 +1659,46 @@ def permutek_back(Ak, k, N):
16591659 @staticmethod
16601660 def vec_block (A , N , sz , IDX_upper ):
16611661 """
1662- Vectorize the upper-triangular image-pair blocks of a block matrix.
1662+ Pack the upper-triangular image-pair blocks of a block matrix.
1663+
1664+ The input is interpreted as an N-by-N array of sz-by-sz blocks.
1665+ Blocks from the upper triangle, including the diagonal, are vectorized
1666+ column-wise and stored as columns of the returned array.
1667+
1668+ :param A: Block matrix with shape (N * sz, N * sz).
1669+ :param N: Number of block rows and columns, corresponding to the
1670+ number of images.
1671+ :param sz: Row and column size of each square block.
1672+ :param IDX_upper: Linear indices of the upper-triangular blocks in
1673+ the flattened N-by-N block grid.
1674+
1675+ :return: Packed block array with shape (sz**2, N * (N + 1) // 2).
16631676 """
16641677 vecA = (A .reshape (N , sz , N , sz ).transpose (0 , 2 , 3 , 1 )).reshape (N ** 2 , sz ** 2 ).T
16651678 return vecA [:, IDX_upper ]
16661679
16671680 @staticmethod
16681681 def mat_block (vecA , N , sz , IDX_upper , IDX_lower , idx_offdiag ):
16691682 """
1670- Reconstruct a symmetric block matrix from its vectorized upper-triangular blocks.
1683+ Unpack upper-triangular blocks into a symmetric block matrix.
1684+
1685+ Each column of `vecA` is reshaped column-wise into an sz-by-sz block.
1686+ The blocks are placed in the upper triangle of an N-by-N block grid,
1687+ including the diagonal. Transposes of the off-diagonal blocks are placed
1688+ in the corresponding lower-triangular positions.
1689+
1690+ :param vecA: Packed block array with shape (sz**2, N * (N + 1) // 2).
1691+ :param N: Number of block rows and columns, corresponding to the
1692+ number of images.
1693+ :param sz: Row and column size of each square block.
1694+ :param IDX_upper: Linear indices of the upper-triangular blocks in
1695+ the flattened N-by-N block grid.
1696+ :param IDX_lower: Linear indices of the corresponding
1697+ lower-triangular off-diagonal blocks in the flattened block grid.
1698+ :param idx_offdiag: Column indices selecting the off-diagonal blocks
1699+ from vecA.
1700+
1701+ :return: Symmetric block matrix with shape (N * sz, N * sz).
16711702 """
16721703 tmp = vecA .T .reshape (N * (N + 1 ) // 2 , sz , sz ).transpose (0 , 2 , 1 )
16731704 AA = xp .zeros ((N ** 2 , sz , sz ), dtype = vecA .dtype )
0 commit comments