numexpr

Parallelizing a Numpy vector operation

坚强是说给别人听的谎言 提交于 2019-11-27 06:07:42
Let's use, for example, numpy.sin() The following code will return the value of the sine for each value of the array a : import numpy a = numpy.arange( 1000000 ) result = numpy.sin( a ) But my machine has 32 cores, so I'd like to make use of them. (The overhead might not be worthwhile for something like numpy.sin() but the function I actually want to use is quite a bit more complicated, and I will be working with a huge amount of data.) Is this the best (read: smartest or fastest) method: from multiprocessing import Pool if __name__ == '__main__': pool = Pool() result = pool.map( numpy.sin, a

Evaluating a mathematical expression (function) for a large number of input values fast

僤鯓⒐⒋嵵緔 提交于 2019-11-27 02:49:21
问题 The following questions Evaluating a mathematical expression in a string Equation parsing in Python Safe way to parse user-supplied mathematical formula in Python Evaluate math equations from unsafe user input in Python and their respective answers made me think how I could parse a single mathematical expression (in general terms along the lines of this answer https://stackoverflow.com/a/594294/1672565) given by a (more or less trusted) user efficiently for 20k to 30k input values coming from

Parallelizing a Numpy vector operation

醉酒当歌 提交于 2019-11-26 11:52:04
问题 Let\'s use, for example, numpy.sin() The following code will return the value of the sine for each value of the array a : import numpy a = numpy.arange( 1000000 ) result = numpy.sin( a ) But my machine has 32 cores, so I\'d like to make use of them. (The overhead might not be worthwhile for something like numpy.sin() but the function I actually want to use is quite a bit more complicated, and I will be working with a huge amount of data.) Is this the best (read: smartest or fastest) method: