Re: Large SparseArray in Mathematica 9 and the predictive interface
- To: mathgroup at smc.vnet.net
- Subject: [mg129308] Re: Large SparseArray in Mathematica 9 and the predictive interface
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Mon, 31 Dec 2012 19:45:31 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
- References: <20121231015009.7BF9F6857@smc.vnet.net>
Turn off the predictive interface by unchecking: Mathematica |
Preferences... | Show Suggestions Bar after last input.
Also, your Module does not need an explicit Return nor a definition
for the local variable res.
gmat[K_,l_,m_]:=Module[
{bandU,bandL,bandD},
bandU=Table[l,{K-1}];
bandL=Table[m,{K-1}];
bandD=Table[-l-m,{K}];
bandD[[1]]=-l;
bandD[[K]]=-m;
DiagonalMatrix[SparseArray[bandU],1]+
DiagonalMatrix[SparseArray[bandD]]+
DiagonalMatrix[SparseArray[bandL],-1]];
g1=gmat[100,0.8,1]
SparseArray[<298>,{100,100}]
Unitize[g1 // Flatten] // Total
298
g2=gmat[10000,0.8,1]
SparseArray[<29998>,{10000,10000}]
Unitize[g2 // Flatten] // Total
29998
Bob Hanlon
On Sun, Dec 30, 2012 at 8:50 PM, <jmmv73 at gmail.com> wrote:
> Hi there,
>
> I was generating a banded sparse array with the following code
> in the new Mathematica 9.0:
>
> gmat[K_, l_, m_] :=
> Module[{bandU, bandL, bandD, res},
>
> bandU = Table[l, {K - 1}];
> bandL = Table[m, {K - 1}];
> bandD = Table[-l - m, {K}];
> bandD[[1]] = -l;
> bandD[[K]] = -m;
>
> res = DiagonalMatrix[SparseArray[bandU], 1]
> + DiagonalMatrix[SparseArray[bandD]]
> + DiagonalMatrix[SparseArray[bandL], -1];
>
> Return[res];
> ];
>
>
> then I used the function with the following parameters (without semicolon):
>
>
> gmat[100, 0.8, 1]
>
>
> ...and everything was ok! a 100x100 sparse matrix was created and the
> "predictive interface bar" appeared.
>
> Nevertheless, when I typed (without semicolon):
>
>
> gmat[10000, 0.8, 1]
>
>
> ...everything went not so good, a 10000x10000 sparse matrix was created
> (what was ok), but the kernel went nuts with the memory use, some gigabytes
> for a small sparsearray (You can try with greater parameters, but starting
> with K=5000 things go weird)
>
> I think the problem has to do with the "predictive interface" that tries to
> generate the normal form of the matrix, so it uses a lot of memory (and even
> produces a kernel crash).
>
> Has anyone had the same problem with SparseArray? or have any
> explanation to what actually happens? or it is just me?
>
> Many thanks in advance for any help or advice with this issue.
>
> Regards,
>
> Jose M. Martinez
> Ph.D. Student
> Department of Electronic Engineering
> Universidad Tecnica Federico Santa Maria
> Valparaiso, Chile
>
- References:
- Large SparseArray in Mathematica 9 and the predictive interface
- From: jmmv73@gmail.com
- Large SparseArray in Mathematica 9 and the predictive interface