Created
December 14, 2011 17:09
-
-
Save tpoisot/1477488 to your computer and use it in GitHub Desktop.
Move along a 2D numpy array in weave/inline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy as sp | |
from scipy.weave import inline | |
def along2Darray(rows,cols): | |
arr = np.zeros((rows,cols)) | |
code = """ | |
int Pos; | |
for(int Row = 0; Row < rows; Row++) | |
{ | |
for(int Col = 0; Col < cols; Col++) | |
{ | |
Pos = Row*cols + Col; | |
arr[Pos] = Pos; | |
return_val = 1; | |
""" | |
res = inline(code, ['arr','cols','rows'], headers = ['<math.h>'], compiler = 'gcc') | |
return arr | |
newarr = along2Darray(10,10) | |
# Things to know | |
# 1 - Narr will have infos about the size of the array, so passing 'rows' and 'cols' is not necessary | |
# 2 - inline modifies the original array, so this is not a copy. Use np.copy if you want to keep the original array intact | |
# 3 - using the blitz library allows to of arr(Row,Col) instead of finding the position |
Ouais, bonne ide.
En attendant, je suis pass de 2e5 generations en 6 heures 1e6 gnrations en 3 heures sur mon portable. Et sur le serveur, c'est encore plus rentable
a+
t
Le 14 dc. 2011 14:41, Philippe Desjardins-Proulx a crit :
… Il faudrait essayer avec le compilateur d'intel (icc), il est hyper-rapide surtout pour les math/matrices.
Il est install sur le serveur et il est gratuit sur Linux :P
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1477488
---
Timothe Poisot, PhD
Universit du Qubec Rimouski
Dpartement de Biologie, Room A-017
300, Alle des Ursulines
Rimouski (QC), G5L 3A1
Email [email protected]
Web http://www.timotheepoisot.fr/
Skype timothee.poisot
## Office (418) 723-1986 # 1751
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Il faudrait essayer avec le compilateur d'intel (icc), il est hyper-rapide surtout pour les math/matrices.
Il est installé sur le serveur et il est gratuit sur Linux :P