Ticket #948 (closed)
Improve NumPy integration
| Reported by: | Nick Draper | Owned by: | Martyn Gigg |
|---|---|---|---|
| Priority: | critical | Milestone: | Iteration 24 |
| Component: | Keywords: | ||
| Cc: | Blocked By: | ||
| Blocking: | Tester: | Mathieu Doucet |
Description (last modified by Nick Draper) (diff)
Martyn can help you with this one, but the comment here should help.
Change History
comment:1 Changed 11 years ago by Nick Draper
- Priority changed from minor to critical
- Status changed from new to assigned
- Description modified (diff)
- Owner changed from Martyn Gigg to Steve Williams
- Milestone changed from Iteration 22 to Iteration 23
comment:2 Changed 10 years ago by Steve Williams
Will Numpy de compulary or not for installation. Get this done in 24.
comment:11 Changed 10 years ago by Martyn Gigg
comment:13 Changed 10 years ago by Mathieu Doucet
- Status changed from verify to verifying
- Tester set to Mathieu Doucet
comment:14 Changed 10 years ago by Mathieu Doucet
comment:16 Changed 5 years ago by Stuart Campbell
This ticket has been transferred to github issue 1796
Note: See
TracTickets for help on using
tickets.

Martyn,
thanks for pointing to me the book with the references to the Numpy C_API. It works very well and very easy to use.
Here is a quick test using std::vector instead of the usual C-array, as well as the command to compile it. I have checked and the data is definitely not copied. Since std::vector is guaranteed to be contiguous in memory on all compilers, we should be in business, and it should be super easy to expose the mantid spectrums.
*code*
#include <boost/python.hpp> #include <numpy/arrayobject.h> #include <vector> using namespace boost::python; std::vector<double> x(1e7); PyObject* testexpose() { npy_intp N=1e7; PyArrayObject* retval=(PyArrayObject*)PyArray_SimpleNewFromData(1,&N,PyArray_DOUBLE,&x[0]); return (PyObject*)retval; } BOOST_PYTHON_MODULE(libexpose) { import_array(); def("testexpose",testexpose); }*compile*
*python test