MathGroup Archive 2009

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

Search the Archive

Re: Can I do this faster?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103007] Re: [mg102962] Can I do this faster?
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Thu, 3 Sep 2009 19:55:51 -0400 (EDT)
  • References: <200909030939.FAA20853@smc.vnet.net>

Andreas wrote:
> I start with two 2 dimensional lists.  The have equal depths, but may
> or may not have equal lengths.  Possible data looks like this:
> 
> list1 = RandomReal[{0, 1}, {1500, 3}];
> list2 = RandomReal[ExponentialDistribution[2], {1000, 3}];
> 
> The following produces the results I need, but takes longer to run
> than I'd like:
> 
> Rest[FoldList[Times, 1,  Transpose[(t = #; 1 + Inner[Times, t, # - 1,
> Plus] & /@ list1) & /@
>     list2]]]
> 
> Any suggestions rewriting this so I can make it run faster?
> 
> Thanks.

Could do:

Rest[FoldList[Times, 1, (list1-1).Transpose[(list2)]+1]]

One bottleneck is that you will run into software arithmetic because 
numbers become too small for machine double representation. If you don't 
mind having them clipped, I think the code below might do what you want.

foldTimesC = Compile[{{mat,_Real,2}}, Module[
   {current=ConstantArray[1.,Length[mat[[1]]]]},
    Table[current = current*mat[[j]], {j,Length[mat]}]]]

foldTimesC[(list1-1).Transpose[(list2)]+1];

Daniel Lichtblau
Wolfram Research


  • Prev by Date: Re: problem with integrating an interpolated list
  • Next by Date: Re: Mapping to a specific column or row in a matrix
  • Previous by thread: Can I do this faster?
  • Next by thread: Re: Can I do this faster?