@@ -120,8 +120,8 @@ unsafe impl<T: Element, D: Dimension> PyTypeInfo for PyArray<T, D> {
120120 const MODULE : :: std:: option:: Option < & ' static str > = Some ( "numpy" ) ;
121121
122122 #[ inline]
123- fn type_object_raw ( _py : Python ) -> * mut ffi:: PyTypeObject {
124- unsafe { npyffi:: PY_ARRAY_API . get_type_object ( npyffi:: NpyTypes :: PyArray_Type ) }
123+ fn type_object_raw ( py : Python ) -> * mut ffi:: PyTypeObject {
124+ unsafe { npyffi:: PY_ARRAY_API . get_type_object ( py , npyffi:: NpyTypes :: PyArray_Type ) }
125125 }
126126
127127 fn is_type_of ( ob : & PyAny ) -> bool {
@@ -144,7 +144,7 @@ impl<'py, T: Element, D: Dimension> FromPyObject<'py> for &'py PyArray<T, D> {
144144 // 3. Checks if the dimension is same as D
145145 fn extract ( ob : & ' py PyAny ) -> PyResult < Self > {
146146 let array = unsafe {
147- if npyffi:: PyArray_Check ( ob. as_ptr ( ) ) == 0 {
147+ if npyffi:: PyArray_Check ( ob. py ( ) , ob . as_ptr ( ) ) == 0 {
148148 return Err ( PyDowncastError :: new ( ob, "PyArray<T, D>" ) . into ( ) ) ;
149149 }
150150 & * ( ob as * const PyAny as * const PyArray < T , D > )
@@ -376,7 +376,6 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
376376 }
377377
378378 fn ndarray_shape_ptr ( & self ) -> ( StrideShape < D > , * mut T , InvertedAxises ) {
379- const ERR_MSG : & str = "PyArray::ndarray_shape: dimension mismatching" ;
380379 let shape_slice = self . shape ( ) ;
381380 let shape: Shape < _ > = Dim ( self . dims ( ) ) . into ( ) ;
382381 let sizeof_t = mem:: size_of :: < T > ( ) ;
@@ -400,7 +399,8 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
400399 new_strides[ i] = strides[ i] as usize / sizeof_t;
401400 }
402401 }
403- let st = D :: from_dimension ( & Dim ( new_strides) ) . expect ( ERR_MSG ) ;
402+ let st = D :: from_dimension ( & Dim ( new_strides) )
403+ . expect ( "PyArray::ndarray_shape: dimension mismatching" ) ;
404404 ( shape. strides ( st) , data_ptr, InvertedAxises ( inverted_axises) )
405405 }
406406
@@ -461,7 +461,8 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
461461 {
462462 let dims = dims. into_dimension ( ) ;
463463 let ptr = PY_ARRAY_API . PyArray_NewFromDescr (
464- PY_ARRAY_API . get_type_object ( npyffi:: NpyTypes :: PyArray_Type ) ,
464+ py,
465+ PY_ARRAY_API . get_type_object ( py, npyffi:: NpyTypes :: PyArray_Type ) ,
465466 T :: get_dtype ( py) . into_dtype_ptr ( ) ,
466467 dims. ndim_cint ( ) ,
467468 dims. as_dims_ptr ( ) ,
@@ -485,7 +486,8 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
485486 {
486487 let dims = dims. into_dimension ( ) ;
487488 let ptr = PY_ARRAY_API . PyArray_NewFromDescr (
488- PY_ARRAY_API . get_type_object ( npyffi:: NpyTypes :: PyArray_Type ) ,
489+ py,
490+ PY_ARRAY_API . get_type_object ( py, npyffi:: NpyTypes :: PyArray_Type ) ,
489491 T :: get_dtype ( py) . into_dtype_ptr ( ) ,
490492 dims. ndim_cint ( ) ,
491493 dims. as_dims_ptr ( ) ,
@@ -496,6 +498,7 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
496498 ) ;
497499
498500 PY_ARRAY_API . PyArray_SetBaseObject (
501+ py,
499502 ptr as * mut npyffi:: PyArrayObject ,
500503 container as * mut ffi:: PyObject ,
501504 ) ;
@@ -600,6 +603,7 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
600603 let dims = dims. into_dimension ( ) ;
601604 unsafe {
602605 let ptr = PY_ARRAY_API . PyArray_Zeros (
606+ py,
603607 dims. ndim_cint ( ) ,
604608 dims. as_dims_ptr ( ) ,
605609 T :: get_dtype ( py) . into_dtype_ptr ( ) ,
@@ -1046,7 +1050,7 @@ impl<T: Element> PyArray<T, Ix1> {
10461050 /// });
10471051 /// ```
10481052 pub fn resize ( & self , new_elems : usize ) -> PyResult < ( ) > {
1049- self . resize_ ( [ new_elems] , 1 , NPY_ORDER :: NPY_ANYORDER )
1053+ self . resize_ ( self . py ( ) , [ new_elems] , 1 , NPY_ORDER :: NPY_ANYORDER )
10501054 }
10511055
10521056 /// Iterates all elements of this array.
@@ -1059,6 +1063,7 @@ impl<T: Element> PyArray<T, Ix1> {
10591063
10601064 fn resize_ < D : IntoDimension > (
10611065 & self ,
1066+ py : Python ,
10621067 dims : D ,
10631068 check_ref : c_int ,
10641069 order : NPY_ORDER ,
@@ -1067,6 +1072,7 @@ impl<T: Element> PyArray<T, Ix1> {
10671072 let mut np_dims = dims. to_npy_dims ( ) ;
10681073 let res = unsafe {
10691074 PY_ARRAY_API . PyArray_Resize (
1075+ py,
10701076 self . as_array_ptr ( ) ,
10711077 & mut np_dims as * mut npyffi:: PyArray_Dims ,
10721078 check_ref,
@@ -1175,7 +1181,7 @@ impl<T: Element, D> PyArray<T, D> {
11751181 pub fn copy_to < U : Element > ( & self , other : & PyArray < U , D > ) -> PyResult < ( ) > {
11761182 let self_ptr = self . as_array_ptr ( ) ;
11771183 let other_ptr = other. as_array_ptr ( ) ;
1178- let result = unsafe { PY_ARRAY_API . PyArray_CopyInto ( other_ptr, self_ptr) } ;
1184+ let result = unsafe { PY_ARRAY_API . PyArray_CopyInto ( self . py ( ) , other_ptr, self_ptr) } ;
11791185 if result == -1 {
11801186 Err ( PyErr :: fetch ( self . py ( ) ) )
11811187 } else {
@@ -1197,6 +1203,7 @@ impl<T: Element, D> PyArray<T, D> {
11971203 pub fn cast < ' py , U : Element > ( & ' py self , is_fortran : bool ) -> PyResult < & ' py PyArray < U , D > > {
11981204 let ptr = unsafe {
11991205 PY_ARRAY_API . PyArray_CastToType (
1206+ self . py ( ) ,
12001207 self . as_array_ptr ( ) ,
12011208 U :: get_dtype ( self . py ( ) ) . into_dtype_ptr ( ) ,
12021209 if is_fortran { -1 } else { 0 } ,
@@ -1250,6 +1257,7 @@ impl<T: Element, D> PyArray<T, D> {
12501257 let mut np_dims = dims. to_npy_dims ( ) ;
12511258 let ptr = unsafe {
12521259 PY_ARRAY_API . PyArray_Newshape (
1260+ self . py ( ) ,
12531261 self . as_array_ptr ( ) ,
12541262 & mut np_dims as * mut npyffi:: PyArray_Dims ,
12551263 order,
@@ -1281,6 +1289,7 @@ impl<T: Element + AsPrimitive<f64>> PyArray<T, Ix1> {
12811289 pub fn arange ( py : Python , start : T , stop : T , step : T ) -> & Self {
12821290 unsafe {
12831291 let ptr = PY_ARRAY_API . PyArray_Arange (
1292+ py,
12841293 start. as_ ( ) ,
12851294 stop. as_ ( ) ,
12861295 step. as_ ( ) ,
0 commit comments