// Converts an array of blocks back to a single 2D array // This is the inverse of "split_into_blocks()" // The array of blocks might represent slices or codeblocks const Array2D merge_blocks(const BlockArray& blocks) { // First find picture dimensions int pictureHeight = 0; int pictureWidth = 0; const int yBlocks = blocks.shape()[0]; const int xBlocks = blocks.shape()[1]; for (int y=0; y<yBlocks; ++y) pictureHeight += blocks[y][0].shape()[0]; for (int x=0; x<xBlocks; ++x) pictureWidth += blocks[0][x].shape()[1]; // Define Array2D pictureHeight by PictureWidth Array2D picture(extents[pictureHeight][pictureWidth]); // Now merge the block together // Note Range(top, bottom) and Range(left, right) define half open ranges either // [top, bottom) or [left, right), i.e. the bottom/rightmost element is not included int bottom; for (int y=0, top=0; y<yBlocks; ++y, top=bottom) { bottom = top + blocks[y][0].shape()[0]; int right; for (int x=0, left=0; x<xBlocks; ++x, left=right) { right = left + blocks[0][x].shape()[1]; // Copy block into a view of the picture picture[indices[Range(top,bottom)][Range(left,right)]] = blocks[y][x]; } } return picture; }
const Shape2D shape(const BlockArray& arg) { const Shape2D result = {{static_cast<Index>(arg.shape()[0]), static_cast<Index>(arg.shape()[1])}}; return result; }