def get_blocks_3d(A, blocksizes, pagesizes=None):
assert (A.shape[<NUM_LIT:0>]==A.shape[<NUM_LIT:1>]) and len(A.shape)==<NUM_LIT:3>, "<STR_LIT>"<EOL>N = np.sum(blocksizes)<EOL>assert A.shape[<NUM_LIT:0>] == N, "<STR_LIT>"<EOL>num_blocks = len(blocksizes)<EOL>if pagesizes == None:<EOL><INDENT>pagesizes = range(A.shape[<NUM_LIT:2>])<EOL><DEDENT>num_pages = len(pagesizes)<EOL>B = np.empty(shape=(num_blocks, num_blocks, num_pages), dtype=np.object)<EOL>count_k = <NUM_LIT:0><EOL>for Bk in pagesizes:<EOL><INDENT>count_i = <NUM_LIT:0><EOL>for Bi, i in enumerate(blocksizes):<EOL><INDENT>count_j = <NUM_LIT:0><EOL>for Bj, j in enumerate(blocksizes):<EOL><INDENT>B[Bi, Bj, Bk] = A[count_i:count_i + i, count_j:count_j + j, Bk]<EOL>count_j += j<EOL><DEDENT>count_i += i<EOL><DEDENT><DEDENT>return B<EOL>
Given a 3d matrix, make a block matrix, where the first and second dimensions are blocked according
to blocksizes, and the pages are blocked using pagesizes