@@ -432,31 +432,26 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
432
432
PY_ARRAY_API . get_type_object ( npyffi:: NpyTypes :: PyArray_Type ) ,
433
433
dims. ndim_cint ( ) ,
434
434
dims. as_dims_ptr ( ) ,
435
- T :: npy_type ( ) as i32 ,
436
- strides as * mut _ , // strides
437
- ptr:: null_mut ( ) , // data
438
- 0 , // itemsize
439
- flag, // flag
440
- ptr:: null_mut ( ) , // obj
435
+ T :: npy_type ( ) as c_int ,
436
+ strides as * mut npy_intp , // strides
437
+ ptr:: null_mut ( ) , // data
438
+ 0 , // itemsize
439
+ flag, // flag
440
+ ptr:: null_mut ( ) , // obj
441
441
) ;
442
442
Self :: from_owned_ptr ( py, ptr)
443
443
}
444
444
445
- pub ( crate ) unsafe fn from_raw_parts < ' py , ID , O > (
445
+ unsafe fn new_with_data < ' py , ID > (
446
446
py : Python < ' py > ,
447
447
dims : ID ,
448
448
strides : * const npy_intp ,
449
449
data_ptr : * const T ,
450
- owner : O ,
450
+ owner : * mut PyAny ,
451
451
) -> & ' py Self
452
452
where
453
453
ID : IntoDimension < Dim = D > ,
454
- Owner : From < O > ,
455
454
{
456
- let owner = pyo3:: PyClassInitializer :: from ( Owner :: from ( owner) )
457
- . create_cell ( py)
458
- . expect ( "Object creation failed." ) ;
459
-
460
455
let dims = dims. into_dimension ( ) ;
461
456
let ptr = PY_ARRAY_API . PyArray_New (
462
457
PY_ARRAY_API . get_type_object ( npyffi:: NpyTypes :: PyArray_Type ) ,
@@ -478,6 +473,24 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
478
473
Self :: from_owned_ptr ( py, ptr)
479
474
}
480
475
476
+ pub ( crate ) unsafe fn from_raw_parts < ' py , ID , O > (
477
+ py : Python < ' py > ,
478
+ dims : ID ,
479
+ strides : * const npy_intp ,
480
+ data_ptr : * const T ,
481
+ owner : O ,
482
+ ) -> & ' py Self
483
+ where
484
+ ID : IntoDimension < Dim = D > ,
485
+ Owner : From < O > ,
486
+ {
487
+ let owner = pyo3:: PyClassInitializer :: from ( Owner :: from ( owner) )
488
+ . create_cell ( py)
489
+ . expect ( "Object creation failed." ) ;
490
+
491
+ Self :: new_with_data ( py, dims, strides, data_ptr, owner as * mut PyAny )
492
+ }
493
+
481
494
/// Creates a NumPy array backed by `array` and ties its ownership to the Python object `owner`.
482
495
///
483
496
/// # Safety
@@ -515,26 +528,15 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
515
528
let ( strides, dims) = ( array. npy_strides ( ) , array. raw_dim ( ) ) ;
516
529
let data_ptr = array. as_ptr ( ) ;
517
530
518
- let ptr = PY_ARRAY_API . PyArray_New (
519
- PY_ARRAY_API . get_type_object ( npyffi:: NpyTypes :: PyArray_Type ) ,
520
- dims. ndim_cint ( ) ,
521
- dims. as_dims_ptr ( ) ,
522
- T :: npy_type ( ) as c_int ,
523
- strides. as_ptr ( ) as * mut npy_intp , // strides
524
- data_ptr as * mut c_void , // data
525
- mem:: size_of :: < T > ( ) as c_int , // itemsize
526
- 0 , // flag
527
- ptr:: null_mut ( ) , // obj
528
- ) ;
529
-
530
531
mem:: forget ( owner. to_object ( owner. py ( ) ) ) ;
531
532
532
- PY_ARRAY_API . PyArray_SetBaseObject (
533
- ptr as * mut npyffi:: PyArrayObject ,
534
- owner as * const PyAny as * mut PyAny as * mut ffi:: PyObject ,
535
- ) ;
536
-
537
- Self :: from_owned_ptr ( owner. py ( ) , ptr)
533
+ Self :: new_with_data (
534
+ owner. py ( ) ,
535
+ dims,
536
+ strides. as_ptr ( ) ,
537
+ data_ptr,
538
+ owner as * const PyAny as * mut PyAny ,
539
+ )
538
540
}
539
541
540
542
/// Construct a new nd-dimensional array filled with 0.
0 commit comments