<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Reshaping block matrix in block diagonal form in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-block-matrix-in-block-diagonal-form/m-p/473750#M4242</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a block matrix of the form A = {A1, A2, ..., AN} with symmetric matrices A1, .., AN each of the same order 9*9 (N could be as large as 400). I want to shape the matrix in the block-diagonal form B = {C 0 0, 0 D 0, ..., 0 0 E} with matrices of the form C = {2A1 A1 A1, A1 2A1 A1, A1 A1 2A1} and D and E of the same form with A2 vs. AN instead of A1. If I allow loops, I can figure out a solution, but I try to avoid loops. Any suggestions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bye, Daniel&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jun 2018 14:24:43 GMT</pubDate>
    <dc:creator>Daniel_Paul</dc:creator>
    <dc:date>2018-06-27T14:24:43Z</dc:date>
    <item>
      <title>Reshaping block matrix in block diagonal form</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-block-matrix-in-block-diagonal-form/m-p/473750#M4242</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a block matrix of the form A = {A1, A2, ..., AN} with symmetric matrices A1, .., AN each of the same order 9*9 (N could be as large as 400). I want to shape the matrix in the block-diagonal form B = {C 0 0, 0 D 0, ..., 0 0 E} with matrices of the form C = {2A1 A1 A1, A1 2A1 A1, A1 A1 2A1} and D and E of the same form with A2 vs. AN instead of A1. If I allow loops, I can figure out a solution, but I try to avoid loops. Any suggestions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bye, Daniel&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 14:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-block-matrix-in-block-diagonal-form/m-p/473750#M4242</guid>
      <dc:creator>Daniel_Paul</dc:creator>
      <dc:date>2018-06-27T14:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping block matrix in block diagonal form</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-block-matrix-in-block-diagonal-form/m-p/473768#M4243</link>
      <description>&lt;P&gt;Use &lt;A href="https://blogs.sas.com/content/iml/2014/12/08/direct-product-kronecker-product.html" target="_self"&gt;Kronecker products&lt;/A&gt; to construct the C, D, and E matrices from A1, A2, and A3.&lt;/P&gt;
&lt;P&gt;Use &lt;A href="https://blogs.sas.com/content/iml/2012/11/07/constructing-block-matrices.html" target="_self"&gt;the BLOCK function&lt;/A&gt; to get the block diagonal matrix of C, D, and E.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
N = 3;
N2 = N*(N+1)/2;
A1 = sqrsym(1:N2);
A2 = sqrsym(N2:1);

M = j(N, N, 1) + I(N);
C = M @ A1;
D = M @ A2;
print C, D;

B = block(C, D);
print B;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jun 2018 14:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-block-matrix-in-block-diagonal-form/m-p/473768#M4243</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-06-27T14:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping block matrix in block diagonal form</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-block-matrix-in-block-diagonal-form/m-p/473775#M4244</link>
      <description>&lt;P&gt;I see the principal idee, but N can be large, so I have to loop in the block part. I try to avoid that loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
p = 3;
N = 2;

start TBlock(AN, p); 
M = j(p,p,1) + I(p);
C = M @ AN;
return (C);
finish TBlock;

start AD(N, A, p);
t = 1;
do rs=1 to N;
	B = A[t:(t+2),];
	BB = TBlock(B, p);
	AF = block(AF, BB);
	t = t + p;
end;
return (AF);
finish AD;

A1 = {1 2 3, 
	  2 4 5,
      3 5 7};
A2 = {1 7 9,
	  7 8 1,
	  9 1 1};

AC = A1//A2;

AF = AD(N, AC, p);

print AF;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jun 2018 15:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-block-matrix-in-block-diagonal-form/m-p/473775#M4244</guid>
      <dc:creator>Daniel_Paul</dc:creator>
      <dc:date>2018-06-27T15:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping block matrix in block diagonal form</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-block-matrix-in-block-diagonal-form/m-p/474019#M4245</link>
      <description>&lt;P&gt;It looks too complicated to be able to avoid the loop.&amp;nbsp; What might be slowing things down, is the fact that you are 'growing' the&amp;nbsp;matrix AF by steps within the loop.&amp;nbsp; After each iteration a new version of AF&amp;nbsp;is declared, and ever more data needs to be moved around in memory.&amp;nbsp; It would be more efficient to declare AF as a zero matrix, at it's final size, before the loop, and then write the block diagonal sub-matrices using row and column indexing.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jun 2018 10:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-block-matrix-in-block-diagonal-form/m-p/474019#M4245</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2018-06-28T10:31:13Z</dc:date>
    </item>
  </channel>
</rss>

