Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #12003
| From | Chris <kristoph.steikert@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | fast summing alternative? |
| Date | 2012-10-08 06:57 +0000 |
| Message-ID | <k4tth1$sgq$1@smc.vnet.net> (permalink) |
| Organization | Time-Warner Telecom |
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.
*)
Clear[bNum,nNum,weights,newMat,sortMat,tab];
bNum;
nNum=100;
weights=Table[RandomReal[{-10,10}],{b,1,bNum},{n,1,nNum}];
newMat=Table[RandomReal[{-10,10}],{b,1,bNum},{n,1,nNum}];
sortMat=Table[i,{i, -10, 10, 0.1}]; (*elements always evenly spaced*)
(*first alternative*)
tab=Table[
Sum[weights[[k,i]]*If[newMat[[k,i]] <= sortMat[[j]],1.,0.],{i,1,nNum}],{k,1,bNum},
{j,1,Length[sortMat]}];//AbsoluteTiming
(*second alternative*)
mat=Block[{k=1},
Reap[Do[
Sow[Table[Sum[weights[[k,i]]*If[newMat[[k,i]] <= sortMat[[j]],1.,0.],{i,1,nNum}],{j,1,Length[sortMat]}]];
k++,{bNum}]]][[2,1]];//AbsoluteTiming
Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread
fast summing alternative? Chris <kristoph.steikert@gmail.com> - 2012-10-08 06:57 +0000
Re: fast summing alternative? Roland Franzius <roland.franzius@uos.de> - 2012-10-09 04:46 +0000
Re: fast summing alternative? Ray Koopman <koopman@sfu.ca> - 2012-10-09 04:46 +0000
Re: fast summing alternative? Ray Koopman <koopman@sfu.ca> - 2012-10-10 05:33 +0000
Re: fast summing alternative? Ray Koopman <koopman@sfu.ca> - 2012-10-11 06:13 +0000
csiph-web