MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Merge of Matrices 2

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71198] Merge of Matrices 2
  • From: Oliver Ruebenkoenig <ruebenko at uni-freiburg.de>
  • Date: Fri, 10 Nov 2006 06:37:58 -0500 (EST)
  • References: <eisglr$nf9$1@smc.vnet.net> <eiush7$gs5$1@smc.vnet.net>

Hi,

> LinearAlgebra`MatrixManipulation`BlockMatrix[]
> 
> does not help ??

No. Not always that is.

In[1]:= n = 5;
In[2]:= a = b = c = d = SparseArray[ {i_, i_} :> i, {n, n} ];
In[3]:= << LinearAlgebra`MatrixManipulation`
In[4]:= res = BlockMatrix[ {{a, b}, {c, d}} ]
Out[4]= 
{SparseArray[<2>, {10}], SparseArray[<2>, {10}], SparseArray[<2>, {10}], 
 
>   SparseArray[<2>, {10}], SparseArray[<2>, {10}], SparseArray[<2>, 
{10}], 
 
>   SparseArray[<2>, {10}], SparseArray[<2>, {10}], SparseArray[<2>, 
{10}], 
 
>   SparseArray[<2>, {10}]}

Hm, that is not what I would have expected to happen, OK, nevertheless 

n[5]:= res2 = SparseArray[ res ]
Out[5]= 
SparseArray[<20>, {10, 10}]

fixes this issue.

if we now increase n

n[6]:= n = 5000;
In[7]:= a = b = c = d = SparseArray[ {i_, i_} :> i, {n, n} ];
In[8]:= Timing[ res = BlockMatrix[ {{a, b}, {c, d}} ]; ]
Out[8]= 
{0.176011 Second, Null}
In[9]:= Timing[ res2 = SparseArray[ res ] ]
Out[9]= 
{0.988062 Second, SparseArray[<20000>, {10000, 10000}]}

Hm, also not overwhelming. if we further increase n

In[14]:= n = 50000;
In[15]:= a = b = c = d = SparseArray[ {i_, i_} :> i, {n, n} ];
In[16]:= res = BlockMatrix[ {{a, b}, {c, d}} ];
SparseArray::ntb: 
   Cannot convert the sparse array SparseArray[<50000>, {50000, 50000}]
     to an ordinary array because the 2500000000
     elements required exceeds the current size limit.
Out[16]= 
Hold[SystemException[SparseArrayNormalLimit, 
 
>    Normal[SparseArray[<50000>, {50000, 50000}]]], 
 
>   SystemException[SparseArrayNormalLimit, 
 
>    Normal[SparseArray[<50000>, {50000, 50000}]]]]

it fails. 

If you look into the code it is clear why this happens. So I think if you 
use SparseArrays avoid BlockMatrix. Too slow and breaks. I think Bill Rows 
approach is nice. If you have storage problems, you might want to use a 
Table command and delete the old sub matrix. Something like

stiffness = SparseArray[ {}, { 3 numberOfNodes, 3 numberOfNodes } ];
Table[ stiffness[[ Range[ (i - 1) numberOfNodes + 1, i numberOfNodes ], 
          Range[ (j - 1) numberOfNodes + 1, j numberOfNodes ] ]] = 
      sparseArrays[[ i, j ]]; sparseArray[[i,j]]={};, { i, dimensions }, { 
j, dimensions } ];

is sparseArrays is something like {{a,b},{c,d}}

HTH,

Oliver

Oliver Ruebenkoenig, <ruebenko at uni-freiburg.de>
   Phone: ++49 +761 203 7388


  • Prev by Date: Re: Understanding N and Precision
  • Next by Date: RE: Challenge problem
  • Previous by thread: RE: Sovling non-linear eq-sys (beginners question)
  • Next by thread: Bairstow Method