Hi there,
I've been working on a fairly ugly project for quite a while now, and whilst it all works fine, it could do with some optimisation. I won't bore you with the details, I'll just outline the problem. The reason I'm asking here is because I could fix this problem in a sec in e.g. Matlab or S-PLUS, but as a mere novice with C I'm not sure if similar functionality exists and I've love some help.
Anywho,
Imagine I have a multi-dimensional sorted binary array, which is say
25x100x5 (25 rows, 100 columns, 5 "layers").
I also have a single sorted list which is 25 rows, so...
array 1:
array 2:Code:1 0 1...[100]...[5] 0 0 1 1 0 1 0 1 1 1 0 1 1 1 0 1 0 0 1 1 1 ... [25]
All I want to do is multiply each of the 5x100 columns in array 1, by the corresponding value in array 2, so,Code:0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 ... [25]
Is there anyway to do this without using loops and looping through each column of array 1, and looping through array 2 every time to do the multiplication? I appreciate this could be done marginally more efficiently by multplying in column order to save having to loop array2 every time, e.g.Code:array1[0][0][0]=array1[0][0][0]*array2[0][0]; array1[1][0][0]=array1[1][0][0]*array2[1][0]; array1[2][0][0]=array1[2][0][0]*array2[2][0];
but at the moment I actually need to do this in row order by column (not column order by row).Code:array1[0][0][0]=array1[0][0][0]*array2[0][0]; array1[0][1][0]=array1[0][1][0]*array2[0][0];
In Matlab or S-PLUS the process is straightforward (I could do a single for and just multiply the 2 together, or even create array2 the same size as array1 and go array1*array2...).
Is there any way to the same in C/C++ and avoid using lots of loops? (the arrays I'm using are more like 25*500000*5 so efficiency is pretty important...)
Many thanks!
Matt



LinkBack URL
About LinkBacks



