Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Numerical Recipes Third Edition Forum > Using NR3 with Python

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-13-2012, 06:55 PM
psillymathhead psillymathhead is offline
Registered User
 
Join Date: Jun 2012
Posts: 1
A HelloWorld Experience

Ello NR World! To start I just want to say that I really enjoy your book for its exposition and find the C/C++ code very useful. I think it is great that you are exploring linking NR into Python, and have taken the time to work out the basic formalities! I was actually looking at ctypes/swig today for this before I stumbled upon the announcement...

I was having trouble getting the HelloWorld example to compile on my machine(s). I do believe I have narrowed it down to a scope issue with the typedefs, and was able to compile by simply changing the Int to int on lines 349 and 514 in nr3python.h . Unfortunately, my c++ skill are not sharp enough to correct the error properly for the community.

Code:
gerald@demeter:~/Dropbox/NumericalRecipes/elloWorld$ g++ -fPIC -fpermissive -w -c somemodule.cpp -o somemodule.o -I/usr/include/python2.6
In file included from somemodule.cpp:1:
nr3python.h: In member function ?void NRvector<T>::initpyvec(PyObject*)?:
nr3python.h:349: error: ?Int? was not declared in this scope
nr3python.h:349: error: expected ?;? before ?i?
nr3python.h:351: error: ?i? was not declared in this scope
nr3python.h:351: error: ?ndim? was not declared in this scope
nr3python.h:351: error: ?dims? was not declared in this scope
nr3python.h: In member function ?void NRmatrix<T>::initpymat(PyObject*)?:
nr3python.h:514: error: ?Int? was not declared in this scope
nr3python.h:514: error: expected ?;? before ?i?
nr3python.h:515: error: ?dims? was not declared in this scope
nr3python.h:517: error: ?nel? was not declared in this scope
nr3python.h:520: error: ?i? was not declared in this scope
Otherwise, by forcing the type, I was able to get function to run in Python! Worked for me on both CentOS5 and Ubuntu10.04 with the vanilla distro gnu-compilers/python etc. Also, there is a small typo in the tutorial...

Code:
# Python code
import somemodule #XXXinclude somemodule
somemodule.somefunction()
Hope this might help encourage some others interested in NR via Python, and get them over the hurdle
Reply With Quote
  #2  
Old 08-15-2012, 09:13 AM
RochaPinto RochaPinto is offline
Registered User
 
Join Date: Aug 2012
Posts: 2
Quote:
Originally Posted by psillymathhead View Post
I was having trouble getting the HelloWorld example to compile on my machine(s). I do believe I have narrowed it down to a scope issue with the typedefs, and was able to compile by simply changing the Int to int on lines 349 and 514 in nr3python.h .
This change in nr3python.h also helped me.

Quote:
Originally Posted by psillymathhead View Post
Unfortunately, my c++ skill are not sharp enough to correct the error properly for the community.
I've also faced several scope errors in the compilation like you, but I've managed to bypass them by pointing the include directive in nr3python.h to the right arrayobject.h. I had a couple of files with this name in my computer; the right one was under the numpy directory. Beware of a similar file in a python/Numeric directory which is not the correct one.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 03:11 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.