On 03/08/2013 07:49 AM, Александров Петр wrote:
I have the C++ method which resize boost::numeric::array:

void solve(const TReal start_t, const TReal end_t, boost::python::numeric::array 
&result) {
     ...
     result.resize(make_tuple(...));
     ...
}

and this method is called from Python:
some_object.solve(0, 10, solution)

where solution = numpy.ndarray([])

In C++ file (where Python module is defined) I use
numeric::array::set_module_and_type("numpy", "ndarray");

The program exits with the following message:

Traceback (most recent call last):
   File ...
     some_object.solve(0, 10, solution)
ValueError: cannot resize an array references or is referenced
by another array in this way.  Use the resize function

How can I resize the boost::numeric::array?

I'm afraid it's probably impossible in this situation.  NumPy arrays can share 
memory to create views, and because resizing requires the array to be 
reallocated, you're not allowed to do that if any views already exist - and 
that's impossible to guarantee if you don't control where your array is coming 
from.  In general, I would recommend against trying resize NumPy arrays in 
*any* context.  It just doesn't fit well with how arrays work under the hood, 
and IMO there should never have been a resize method.

Jim

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to