two typedefs
std::vector<double> Matrix;
std::vector<Matrix> MatrixBlocks;
The Matrix is represented by a 1D vector, and the MatrixBlocks represents a vector of matrix.
The problem is that given that matrix blocks which contains sub matrices from a larger matrix with a specific ordering, I need to reconstruct the large matrix with the matrix block. So For example
Assume the Large Matrix( stored as std::vector<double> ) has the following data:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
and the MatrixBlocks below which contains the sub matrices of the above matrix has the following data:
index 0:
1 2
5 6
index 1:
3 4
7 8
index 2:
9 10
13 14
index 3:
11 12
15 16
So given that MatrixBlock I need to reconstruct the original vector of double; 1D matrix. Anyone got any general solution?
You can assume that if the large Matrix is always a square sized matrix.
EDIT:
For NxN matrix, that gets broken down to K mxm matrix where N is divisible for m, you can assume that the ordering of the MatrixBlock as so:
index 0: will contain the matrix starting from [0,0] to (m,m)
index 1: will contain the matrix starting from [0,m] to (m, m + m)
index 2: will contain the matrix starting from [0,m+m] to (m, m + m + m)
…
until the last index will contain the matrix starting from [m*i – m,m*i – m] to [m,m]
So for example if the Master matrix is 512×512
1 2 3 4 ... 512
513 ... 1014
...
261632(512*512-512) … 262144(512*512)
and we wanted to split the 512×512 matrix int 256 32×32 blocks, the 32 is picked by the user, then the MatrixBlock would contain something like
index 0:
1 2 3 … 32
513 … 513 + 32
//..up to the first 32 rows of column length 32
index 1:
33 34 … (33+32)
(513+32+1) … (513 + 32 + 1 + 32)
//… same as above
So you can see that it starts from index (0,0) and extracts the first 32×32 element from (0,0) to (31,31); thats for index 0. Then for index 1, the starting position is (0,32) and it extracts data from the rectangle (0,32),(0,63), (31,32), (31,63)
Hope that is clear. So basically the same pattern observed for the 4×4 matrix above, will be the same pattern for any matrix size, the only difference is that the Master matrix is not always of size 4×4, and the block size we split it into is not always 2×2.
This basically boils down to indexing correctly.
Output: