Re: [F-Script-talk] Adding Math Methods to Arrays
Brought to you by:
pmougin
From: Philippe M. <pm...@ac...> - 2008-06-23 22:34:49
|
Great. BTW, if you haven't read it yet, you will find some useful information on the design of the optimized array programming model in the OOPAL paper, section 8.2, at http://www.fscript.org/documentation/OOPAL.pdf Philippe Le 24 juin 08 à 00:23, Peter A Passaro a écrit : > > Excellent, thanks again Philippe, that is exactly what I was looking > for. I do need every bit of speed I can get as I am working with data > sets of a few Gb in size and performing a number of intensive > operations on them, so I'll try to apply my optimization tricks where > appropriate. I'll start experimenting and let you know how it turns > out. > > Peter > > On 23 Jun 2008, at 20:23, Philippe Mougin wrote: > >> Peter, >> >> You'll not need to modify the existing F-Script source code. The >> system is extensible and you can achieve what you want in a modular >> way by putting your code in Objective-C categories that you can >> build as separate bundles and load dynamically if you want. >> >> For method that deal with whole arrays (i.e., that have no meaning >> for single numbers; e.g. calculating an average value given an array >> of numbers), you should first implement your method in a category of >> NSArray, in order to deal with the situation where you'd have an >> array of NSNumber objects. See for instance how the method "reverse" >> is implemented in F-Script's FSNSArray category. In your case you'll >> also need to make sure you raise an error if objects other that >> NSNumbers are found in the array. Then, if you want to have >> optimized implementations for situations where F-Script is able to >> determine that the array is made of numbers, you should add little >> stubs in a category of Array (again, for an example, see how the >> "reverse" method is implemented in the Array class) as well as your >> optimized implementations in a category of ArrayRepDouble (see how >> the "reverse" method is implemented in the ArrayRepDouble class). >> >> For math methods that make sense on single numbers (like cos, sin, >> abs, etc.), you should first implement your method on single number >> objects. To do that, implement them for NSNumber objects in your own >> category of NSNumber (look at FSNSNumber for examples). Note that, >> at this point, you automatically get array programming for these >> methods. F-Script will take care of automatically broadcasting >> messages when you deal with arrays. In general this is fast enough. >> If you need to go even faster, you can implement optimized versions >> of your methods in a category of ArrayRepDouble. You'll just have to >> add simpleLoop_xxx or doubleLoop_xxx methods in your category >> (depending on the message pattern your math operation supports). See >> ArrayRepDouble.m for example of implementing these simpleLoop_xxx >> and doubleLoop_xxx methods. >> >> Feel free to ask for further clarifications if needed. >> >> Philippe >> >> Le 23 juin 08 à 19:29, Peter A Passaro a écrit : >> >>> >>> Hi Philippe and All, >>> >>> I'm starting to work my way through the F-Script framework code, and >>> the first thing I would like to do is add some additional math >>> operators to the ArrayRepDouble class. Could you possibly give me a >>> quick overview of the framework classes I will need to modify in >>> order >>> for this to work properly? >>> >>> Specifically, what I would like to add is a bunch of statistics and >>> vector operations for arrays of doubles. I have been writing Obj-C >>> wrappers (or alternative functions) for many of the functions in the >>> GNU Scientific Library, and I would like to bring these into F- >>> Script >>> so I can avoid the back and forth conversion of arrays of doubles- >>>> NSNumbers->doubles. >>> >>> I may also be interested in contributing a plotting/graphing >>> application for arrays of doubles to F-Script, I have one I am >>> developing for visualizing large time series data sets that will >>> probably work well. Let me know if this might be interesting. >>> >>> Best, >>> Peter >>> >>> Peter Passaro >>> Research Officer >>> Dept of Informatics/Dept of Biology >>> Pevensey III >>> University of Sussex >>> Falmer, Brighton BN1 9QH, UK >>> Office + 44 (0)1273 877590 >>> P.A...@su... |