MathGroup Archive 2012

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

Search the Archive

fast summing alternative?

  • To: mathgroup at
  • Subject: [mg128332] fast summing alternative?
  • From: Chris <kristoph.steikert at>
  • Date: Mon, 8 Oct 2012 02:28:43 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:

Dear all

The code below is part of a large compile function I wrote and the inputs, like the matrices weights and newData, are in fact large data files. Thus, I provide them in the following problem as random. Although, written as compile code (with CompilationTarget->"C") it is still too slow for the amounts of data I have to process. I provide two of my fastest alternatives, which sadly are not that fast. I do appreciate any help to make the code faster. Thanks in advance!

What I do is simple: For each row of newMat and weights I construct a new row. The elements of this new row are the sums of the elements in weights if a certain requirement of the same element in newMat is met.



sortMat=Table[i,{i, -10, 10, 0.1}]; (*elements always evenly spaced*)

(*first alternative*)
Sum[weights[[k,i]]*If[newMat[[k,i]] <= sortMat[[j]],1.,0.],{i,1,nNum}],{k,1,bNum},

(*second alternative*)
Sow[Table[Sum[weights[[k,i]]*If[newMat[[k,i]] <= sortMat[[j]],1.,0.],{i,1,nNum}],{j,1,Length[sortMat]}]];

  • Prev by Date: Re: Open interval
  • Next by Date: Re: Integrating DiracDelta in Mathematica: how to suppress ConditionalExpression
  • Previous by thread: Re: Open interval
  • Next by thread: Re: fast summing alternative?