Tips or tricks for a specific element by element operation

For requesting general information about EViews, sharing your own tips and tricks, and information on EViews training or guides.

Moderators: EViews Gareth, EViews Moderator

CharlieEVIEWS
Posts: 202
Joined: Tue Jul 17, 2012 9:47 am

Tips or tricks for a specific element by element operation

Postby CharlieEVIEWS » 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:

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
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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

Re: Tips or tricks for a specific element by element operati

Postby EViews Gareth » Wed Jul 22, 2015 10:16 am

How about a 13,040x speed up?

Code: Select all

wfcreate u 1 'preamble to set up the question !size = 400 '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 tic 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 scalar time1 = @toc 'Gareth's go tic matrix(!size, !size) test = 0.1*@max(xmat) matrix ymat2 = @emult(@elt(xmat, test),xmat) scalar time2 = @toc

CharlieEVIEWS
Posts: 202
Joined: Tue Jul 17, 2012 9:47 am

Re: Tips or tricks for a specific element by element operati

Postby CharlieEVIEWS » Wed Jul 22, 2015 11:14 am

Had no idea of that function. They should introduce a hand clapping emoji into the forums just for you, Gareth! :idea:


Return to “General Information and Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 2 guests