psillymathhead
06-13-2012, 05:55 PM
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.
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...
# 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 :)
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.
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...
# 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 :)