Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

REP: Introduce new functions for finding minimum and maximum of a serie

 [1/4] from: petr::krenzelok::trz::cz at: 26-Dec-2000 10:51


I was asked yesterday to handle some kind of data, and the part of the task was to find minimum and maximum of a series. To my surprise, current Rebol state showed as ineffective. Rebol currently offers us two functions, 'min and 'max. Let's look at the source:
>> source min
min: native [ "Returns the lesser of the two values." value1 [number! pair! char! money! date! time! tuple! series!] value2 [number! pair! char! money! date! time! tuple! series!] ]
>>
What really surprised me, is a level in which the functionality is solved - native. In my opinion, for returning lesser (or greater in case of 'max) of two values given, some one line mezzanine function would be sufficient (min: func [arg1 arg2][either arg1 < arg2 [arg1][arg2]]). I asked about the easiest way of how to find minimal or maximal value of a series, and was given an answer to use 'sort. Ladislav Mecir suggested me to use iteration though, and I would never believe iteration could be faster than native 'sort. Let's look in a real-life examples: print "Finding min and max values using 'sort ..." start: now/time sort/skip tmpx: copy img-data 4 end: now/time print end - start print "Finding min and max values using iteration ..." start: now/time min: max: copy/part img-data 4 repeat count (length? img-data) / 4 [ if (tmp: copy/part img-data 4) < min [min: tmp] if tmp > max [max: tmp] img-data: skip img-data 4 ] end: now/time print end - start results: sort: 19 sec. iter: 13 sec. even using smaller amount of data, iteration was faster (4 sec sort vs. 3 sec iter) Lack of support of such relatively primitive functionality led me to conclusion to submit this proposal: Introduce new serie of functions: 'minimum and 'maximum. The best way would be to replace current 'min and 'max, as they are merely useless, but to prevent some scripts from crash upon new functionality, we can live with new names ... MINIMUM Usage MINIMUM series Description Returns minimal value or set of values from a series Arguments series - series to find minimal value or set of values in Refinements /skip - skip values to treat series as a set of records /count - returns block of minimal value found, and number of value occurances in series /several - amount of minimal values to return num - number of minimal values to return Conclusion: I am not sure if all the refinements are easy to implement, but we should support at least /skip, although /several could be usefull for some fuzzy purposes, and /count for other yet unspecified purposes. If Rebol can't be faster in it's nature, we should help ourselves by introduction of new natives, or improving existing ones, if a solution doesn't introduce significant overhead to the language .... Comments welcomed ... Cheers, -pekr-

 [2/4] from: g::santilli::tiscalinet::it at: 26-Dec-2000 13:02

Re: REP: Introduce new functions for finding minimum and maximum of a se


Hello Petr! On 26-Dic-00, you wrote: PK> What really surprised me, is a level in which the PK> functionality is solved - native. In my opinion, for It is faster this way. And it IS useful! PK> 'sort. Ladislav Mecir suggested me to use iteration though, PK> and I would never believe iteration could be faster than PK> native 'sort. Let's look in a real-life examples: It's quite normal it is. Finding the max/min is O(n), while sorting is O(n*log(n)). PK> Lack of support of such relatively primitive functionality PK> led me to conclusion to submit this proposal: They're quite easy to do as mezzanine, but maybe a native would be the best choice... Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

 [3/4] from: lmecir:mbox:vol:cz at: 26-Dec-2000 18:41


Hi Pekr, one more suggestion, try the following modification: print "Finding min and max values using iteration ..." start: now/time mn: mx: copy/part img-data 4 loop (length? img-data) / 4 [ mn: min tmp: copy/part img-data 4 mn mx: max tmp mx img-data: skip img-data 4 ] end: now/time print end - start

 [4/4] from: petr:krenzelok:trz:cz at: 26-Dec-2000 22:52


----- Original Message ----- From: "Ladislav Mecir" <[lmecir--mbox--vol--cz]> To: <[rebol-list--rebol--com]> Sent: Tuesday, December 26, 2000 6:41 PM Subject: [REBOL] Re: REP: Introduce new functions for finding minimum and maximum of a serie ...
> Hi Pekr, > one more suggestion, try the following modification:
<<quoted lines omitted: 8>>
> end: now/time > print end - start
Thanks Ladislav. It makes some sec. or two difference on 1500x1200*4 series size, but still 12 sec on my P700 notebook ... that's not acceptable for me and I will have to 1) wait till RT optimizes Rebol or adds requested functionality (but they don't have to accept, if such functionality is not of general purpose) 2) think about library component, but using Rebol runtime my app users will loose the ability to work with console probably, and am loosing multiplatform paradigm 3) will have to leave Rebol in favor of some other, faster multiplatform solution. Java? Thanks anyway, -pekr-

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted