Re: SparseArray and Compile
- To: mathgroup at smc.vnet.net
- Subject: [mg99833] Re: SparseArray and Compile
- From: Ray Koopman <koopman at sfu.ca>
- Date: Fri, 15 May 2009 06:25:18 -0400 (EDT)
- References: <gub7a9$4cf$1@smc.vnet.net>
It's not clear how you intend to use rp, so it's hard to say much more than that you can cut the uncompiled time substantially by defining rp = SparseArray[ UnitStep[ .01 - dat - dat[[#]] ] ] & /@ Range[Length[dat]]; The resulting rp will be exactly the same as in your version. On May 12, 12:08 am, andreas.kohlma... at gmx.de wrote: > Greetings, > > I have difficulties to speed up my calculation regarding SparseArray: > > Date[] > rp = {}; > AppendTo[rp, SparseArray[UnitStep[0.01 - dat - dat[[#]]]]] & /@ > Range[Length[dat]]; > Date[] > > dat is a list of Reals containing approx. 24000 elements. I had to > use SparseArray for each line to prevent a memory crash; the final > matrix has 574 million elements. The calculation takes 2' 43'' on > my WinXP Dell workstation (DualCore @ 1.6 GHz, 3 GB RAM) > > I would like to speed up the calculation using compile, but the > SparseArray object doesn't fit the tensor format. I have tried: > > Compile[{{data, _Real, 1}}, > Block[{rp}, rp = {}; > AppendTo[rp, SparseArray[UnitStep[0.01 - data - data[[#]]]]] & /@ > Range[Length[data]]]] > > Compile::cpts: The result after evaluating Insert[rp,SparseArray > [UnitStep[0.01-data-data[[System`Private`CompileSymbol[<<1>>] > [[System`Private`CompileSymbol[<<1>>]]]]]]],-1] should be a tensor. > Nontensor lists are not supported at present; evaluation will proceed > with the uncompiled function. >> > > The calculation is used calculate a recurrence plot. The fixed value > of 0.01 will be replaced by a variable later on; therefore, I need to > speed up the calculation. > > Any help is appreciated.