Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7824313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:33:28+00:00 2026-06-02T08:33:28+00:00

two typedefs std::vector<double> Matrix; std::vector<Matrix> MatrixBlocks; The Matrix is represented by a 1D vector,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:33:30+00:00Added an answer on June 2, 2026 at 8:33 am

    This basically boils down to indexing correctly.

    #include <cmath>
    #include <iostream>
    #include <vector>
    
    int main()
    {
      std::vector<double> v(16);
      std::vector<std::vector<double> > m;
      std::vector<double> m1 {1,2,5,6};
      m.push_back(m1);
      std::vector<double> m2 {3,4,7,8};
      m.push_back(m2);
      std::vector<double> m3 {9,10,13,14};
      m.push_back(m3);
      std::vector<double> m4 {11,12,15,16};
      m.push_back(m4);
    
      size_t idx = 0;
      for (size_t big_row = 0; big_row < std::sqrt(m.size()); ++big_row)
      for (size_t small_row = 0; small_row < std::sqrt(m1.size()); ++small_row)
      for (size_t big_col = 0; big_col < std::sqrt(m.size()); ++big_col)
      for (size_t small_col = 0; small_col < std::sqrt(m1.size()); ++small_col)
      {
        v[idx] = m[big_col + std::sqrt(m.size()) * big_row][small_col + std::sqrt(m1.size()) * small_row];
        ++idx;
      }
    
      for (unsigned i = 0; i < 16; ++i)
        std::cout << v[i] << std::endl;
    }
    

    Output:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem I have a template container MyContainer<std::unique_ptr<Foo>> which has a std::deque<T> and a std::vector<T>
Let's say I have two maps: typedef int Id; std::map<Id, std::string> idToStringMap; std::map<Id, double>
There is the class A containing two overloaded methods getItems(); typedef std::vector <int> TItems;
I have two vectors typedef std::vector<std::string> messages; typedef std::vector<std::string> addMessage; messages st; addMessage additionlMsgs;
Say I need a new type in my application, that consists of a std::vector<int>
I have defined two dimensional array using following definition typedef std::vector<std::vector<short> > table_t; Can
I have two (unrelated) classes. The first one is Point: typedef std::complex<double> complex_number; class
I have two vectors of predicates: typedef std::function<bool(int)> pred; vector<pred> v1; vector<pred> v2; I
Given two structure in c: typedef struct _X_ { int virtual_a; int virtual_b; void
When a container contains elements which has a pointer to the container itself, the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.