def segmented_process(M, blk_size=(16,16), fun=None):
rows = []
for i in range(0, M.shape[0], blk_size[0]):
cols = []
for j in range(0, M.shape[1], blk_size[1]):
cols.append(fun(M[i:i+blk_size[0], j:j+blk_size[1]]))
rows.append(np.concatenate(cols, axis=1))
return np.concatenate(rows, axis=0)
def blockMM(nr,nc,Nb,x1):
myfun = lambda block:block.reshape((nr*nc,1))
x1 = segmented_process(x1, blk_size=(nr,nc), fun=myfun)
x1 = x1.reshape((nr*nc,Nb))
x1 = x1.sum(axis = 1)
x = x1.reshape((nr,nc))
return x