title: Partitioned matrix multiplication in tensorflow or pytorch
body: <p>Assume I have matrices P with the size <code>[4, 4]</code> which partitioned (block) into 4 smaller matrices <code>[2,2]</code>. How can I <strong>efficiently</strong> multiply this block-matrix into another matrix (not partitioned matrix but smaller)?</p>
  
  <p>Let's Assume our original matric is:</p>
  
  <pre><code>P = [ 1 1 2 2
        1 1 2 2
        3 3 4 4
        3 3 4 4]
  </code></pre>
  
  <p>Which split into submatrices:</p>
  
  <pre><code>P_1 = [1 1    , P_2 = [2 2  , P_3 = [3 3   P_4 = [4 4
         1 1]            2 2]          3 3]         4 4]
  </code></pre>
  
  <p>Now our P is:</p>
  
  <pre><code>P = [P_1 P_2
       P_3 p_4]
  </code></pre>
  
  <p>In the next step, I want to do element-wise multiplication between P and smaller matrices which its size is equal to number of sub-matrices:</p>
  
  <pre><code>P * [ 1 0   =   [P_1  0  = [1 1 0 0 
        0 0 ]      0    0]    1 1 0 0
                              0 0 0 0
                              0 0 0 0]    
  </code></pre>