Tips or tricks for a specific element by element operation
Posted: Wed Jul 22, 2015 5:10 am
Dear all,
I was wondering if anyone could provide any tips or tricks to speed up the efficiency of the operation of element by element operations. Please consider the following short program as an example:
As you can see from the comments, im specifically interested in the second half of the code. As !size gets large, this operation begins to take an extremely long time. That is, for all the elements of a 10k,10k matrix, it has to check whether a condition is met a hundred million times, and if so, fill a cell in a second matrix. If the condition isnt met, naturally, it's unchanged.
Does anyone have any ideas on how to speed this kind of thing up? Ive considered some kind of matrix multiplication method with resizing through the 16 decimal place structure, but cant figure out much, or think of anything. As this forum has been a rich treasure chest of tricks for computational efficiency in the past, I would try my luck here, before resorting to another programming language (which might be vectorized like YMAT= XMAT(XMAT > 0.1*max(Xmat)) in another language).
Best wishes!
Charlie
I was wondering if anyone could provide any tips or tricks to speed up the efficiency of the operation of element by element operations. Please consider the following short program as an example:
Code: Select all
wfcreate u 1 'preamble to set up the question
!size = 100 'preamble to set up the question
matrix(!size,!size) XMAT 'preamble to set up the question
matrix(!size,!size) YMAT = 0 'preamble to set up the question
for !a = 1 to !size 'preamble to set up the question
for !b = 1 to !size 'preamble to set up the question
XMAT(!a,!b) = @nrnd 'preamble to set up the question
next 'preamble to set up the question
next 'preamble to set up the question
for !a = 1 to !size
for !b = 1 to !size
if XMAT(!a,!b)<0.1*@max(XMAT) then
YMAT(!a,!b)=XMAT(!a,!b)
endif
next
next
Does anyone have any ideas on how to speed this kind of thing up? Ive considered some kind of matrix multiplication method with resizing through the 16 decimal place structure, but cant figure out much, or think of anything. As this forum has been a rich treasure chest of tricks for computational efficiency in the past, I would try my luck here, before resorting to another programming language (which might be vectorized like YMAT= XMAT(XMAT > 0.1*max(Xmat)) in another language).
Best wishes!
Charlie