| MATLAB Central > MATLAB Newsreader > Vectorization : Min/Max Function |
|
|
|
I am just getting onboard with the notion of vectorizing my for loops, and while I have done quite a bit of reading on it, for some reason I may be too daft to figure out why I can't determine how to vectorize the following for loop: |
|
"Eric " <elb@windwardinv.com> wrote in message <h33055$eah$1@fred.mathworks.com>... |
|
"Eric " <elb@windwardinv.com> wrote in message <h330vd$8rd$1@fred.mathworks.com>... |
|
Subject: Vectorization : Min/Max Function From: Bruno Luong Date: 8 Jul, 2009 21:20:17 Message: 4 of 24 |
|
"Eric " <elb@windwardinv.com> wrote in message <h33055$eah$1@fred.mathworks.com>... |
|
Subject: Vectorization : Min/Max Function From: Bruno Luong Date: 8 Jul, 2009 21:30:18 Message: 5 of 24 |
|
Sorry there is a typo, it should read: |
|
Subject: Vectorization : Min/Max Function From: Bruno Luong Date: 8 Jul, 2009 21:43:01 Message: 6 of 24 |
|
Jamais deux sans trois! |
|
Subject: Vectorization : Min/Max Function From: Siyi Deng Date: 9 Jul, 2009 01:32:47 Message: 7 of 24 |
|
On Jul 8, 2:43 pm, "Bruno Luong" <b.lu...@fogale.findmycountry> wrote: |
|
Subject: Vectorization : Min/Max Function From: Matt Fig Date: 9 Jul, 2009 01:56:03 Message: 8 of 24 |
|
Siyi Deng <mr.siyi.deng@gmail.com> wrote in message <690dd0d7-2130-4d08- |
|
Subject: Vectorization : Min/Max Function From: Bruno Luong Date: 9 Jul, 2009 05:01:02 Message: 9 of 24 |
|
Ideally what we need is a Mex implementation of a MAX/MIN filter using a better algorithm (one of the fancy one that does use the sliding nature of the problem). Is there any expert on this problem can make a comment? |
|
Subject: Vectorization : Min/Max Function From: Matt Fig Date: 9 Jul, 2009 06:06:01 Message: 10 of 24 |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h33tie$9c9$1@fred.mathworks.com>... |
|
"Eric " <elb@windwardinv.com> wrote in message <h33055$eah$1@fred.mathworks.com>... |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h333t5$k5b$1@fred.mathworks.com>... |
|
Subject: Vectorization : Min/Max Function From: Bruno Luong Date: 9 Jul, 2009 18:09:03 Message: 13 of 24 |
|
"Eric " <elb@windwardinv.com> wrote in message <h34qvk$r1b$1@fred.mathworks.com>... |
|
Subject: Vectorization : Min/Max Function From: Matt Fig Date: 9 Jul, 2009 18:55:02 Message: 14 of 24 |
|
It seems to me the padding should be at the back, since this is where the maxing isn't occurring. But that is your choice of course. This is a bit faster than the hankel solution, but I still have my doubts about a good For loop not being just as fast or faster. |
|
Thanks Matt. Great solution...the reshape method is certainly a speed improvement on the hankel method...I wonder if there is a way to utilize the filter function instead as this method for doing a similar mean function (as oppose to min/max) is far and away faster (almost 2 orders of magnitude) than both the reshape and hankel approaches. |
|
Subject: Vectorization : Min/Max Function From: Bruno Luong Date: 10 Jul, 2009 18:54:01 Message: 16 of 24 |
|
I have coded a simple for loop that can be faster than the vectorized solution (both Matt's and Hankel) for medium window size. According to my benchmark test when applied on "random" vector, it's worth to use from win>10. |
|
Subject: Vectorization : Min/Max Function From: Matt Fig Date: 10 Jul, 2009 19:05:18 Message: 17 of 24 |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h382o9$f5d$1@fred.mathworks.com>... |
|
Subject: Vectorization : Min/Max Function From: Matt Fig Date: 10 Jul, 2009 19:46:01 Message: 18 of 24 |
|
Hey Bruno, |
|
Subject: Vectorization : Min/Max Function From: Bruno Luong Date: 10 Jul, 2009 20:03:01 Message: 19 of 24 |
|
"Matt Fig" <spamanon@yahoo.com> wrote in message <h385po$663$1@fred.mathworks.com>... |
|
Subject: Vectorization : Min/Max Function From: wicore Date: 11 Jul, 2009 06:59:28 Message: 20 of 24 |
|
On 10 Juli, 22:03, "Bruno Luong" <b.lu...@fogale.findmycountry> wrote: |
|
Subject: Vectorization : Min/Max Function From: Bruno Luong Date: 11 Jul, 2009 07:24:03 Message: 21 of 24 |
|
> |
|
Subject: Vectorization : Min/Max Function From: Bruno Luong Date: 11 Jul, 2009 07:41:02 Message: 22 of 24 |
|
I found this paper: http://www.archipel.uqam.ca/309/1/webmaximinalgo.pdf |
|
Subject: Vectorization : Min/Max Function From: Bruno Luong Date: 11 Jul, 2009 11:49:01 Message: 23 of 24 |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h39fme$ing$1@fred.mathworks.com>... |
|
Subject: Vectorization : Min/Max Function From: Bruno Luong Date: 11 Jul, 2009 23:40:19 Message: 24 of 24 |
|
Bellow is the first attempt of MEX code of the algorithm of the Lemire's paper. |
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.
| Tag Activity for This Thread | ||
|---|---|---|
| Tag | Applied By | Date/Time |
| forloopking | Matt Fig | 10 Jul, 2009 16:01:34 |
| reshape | Eric | 10 Jul, 2009 09:39:15 |
| windowing | Eric | 9 Jul, 2009 09:24:07 |
| hankel | Eric | 9 Jul, 2009 09:24:07 |
| sliding | Eric | 9 Jul, 2009 09:24:07 |
| window | Eric | 9 Jul, 2009 09:24:07 |
| filter | Eric | 8 Jul, 2009 16:54:12 |
| vectorization | Eric | 8 Jul, 2009 16:53:05 |
| conversion | Eric | 8 Jul, 2009 16:44:03 |
| convert | Eric | 8 Jul, 2009 16:44:03 |
| loop | Eric | 8 Jul, 2009 16:44:03 |
| min | Eric | 8 Jul, 2009 16:44:03 |
| max | Eric | 8 Jul, 2009 16:44:03 |
| for | Eric | 8 Jul, 2009 16:44:03 |
| vectorize | Eric | 8 Jul, 2009 16:44:02 |
Contact us at files@mathworks.com
