I finally find the solution by looking the code code arrayobject.c.
Maybe it will help someone.

The half-free documentation in pdf that I received in 04.11.2005 on numpy is not up to date in page 203 for PyArray_Resize. Is there an newer version ?

The code :

from scipy import *
from scipy import weave
from scipy.weave import converters

c = ones((3,6))

code = """
 #line 8 "test_weave.py"
 printf("%d %d\\n",c_array->dimensions[0],c_array->dimensions[1]);
 
  PyArray_Dims dims;
  dims.len = 2;
  dims.ptr = new int[2];
  dims.ptr[0] = 4;
  dims.ptr[1] = 7;
  PyArray_Resize(c_array,&dims,1,PyArray_CORDER);
 
  printf("%d %d\\n",c_array->dimensions[0],c_array->dimensions[1]);
"""
err = weave.inline(code,
    ['c'])

print c.shape    #I want (4,7) !!!
print c


and it works !!!

Samuel


Samuel GARCIA wrote:
No I can't it resize from python because it is to slow.
There are a lot of iteration and for some of them I add a new value to a vector.
My code was only an example, of course.
Is it easier to add one element to a 1D array than a ND ?
I am porting a old code from matlab and I was able to to do that in mex file with mxRealloc.

thanks

Sam


Prabhu Ramachandran a écrit :
"Samuel" == Samuel GARCIA <sgarcia@olfac.univ-lyon1.fr> writes:
            

    Samuel> Hi, how to resize a array in the c++ code with
    Samuel> weave.inline()
[...]
    Samuel> c = ones((3,6))
[...]
    Samuel> err = weave.inline(code, ['c'], type_converters=converters.blitz) 
    Samuel> print c.shape #I want (4,7) !!!

I am not sure why you'd want to do that.  Can't you resize it from
Python?  In any case, if you really must do it, take a look at the c++
code generated by weave and look at it.  You'll see that c_array is a
PyArrayObject that you can use if you want it.  However, I am not sure
what will happen if you do resize the array and are using blitz.  I
suspect something bad may happen.  Resizing the array might also
relocate the entire block of memory for the array so accessing the
older pointer will likely be disastrous.  So, you should be careful
doing this.

cheers,
prabhu

_______________________________________________
SciPy-user mailing list
SciPy-user@scipy.net
http://www.scipy.net/mailman/listinfo/scipy-user
  

_______________________________________________ SciPy-user mailing list SciPy-user@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user