@@ -82,7 +82,7 @@ use crate::untyped_array::{PyUntypedArray, PyUntypedArrayMethods};
82
82
///
83
83
/// ```
84
84
/// use numpy::PyArray;
85
- /// use ndarray::{ array, Array} ;
85
+ /// use ndarray::array;
86
86
/// use pyo3::Python;
87
87
///
88
88
/// Python::with_gil(|py| {
@@ -575,24 +575,33 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
575
575
}
576
576
}
577
577
578
+ /// Deprecated form of [`PyArray<T, D>::from_owned_array_bound`]
579
+ #[ deprecated(
580
+ since = "0.21.0" ,
581
+ note = "will be replaced by PyArray::from_owned_array_bound in the future"
582
+ ) ]
583
+ pub fn from_owned_array < ' py > ( py : Python < ' py > , arr : Array < T , D > ) -> & ' py Self {
584
+ Self :: from_owned_array_bound ( py, arr) . into_gil_ref ( )
585
+ }
586
+
578
587
/// Constructs a NumPy from an [`ndarray::Array`]
579
588
///
580
589
/// This method uses the internal [`Vec`] of the [`ndarray::Array`] as the base object of the NumPy array.
581
590
///
582
591
/// # Example
583
592
///
584
593
/// ```
585
- /// use numpy::PyArray;
594
+ /// use numpy::{ PyArray, PyArrayMethods} ;
586
595
/// use ndarray::array;
587
596
/// use pyo3::Python;
588
597
///
589
598
/// Python::with_gil(|py| {
590
- /// let pyarray = PyArray::from_owned_array (py, array![[1, 2], [3, 4]]);
599
+ /// let pyarray = PyArray::from_owned_array_bound (py, array![[1, 2], [3, 4]]);
591
600
///
592
601
/// assert_eq!(pyarray.readonly().as_array(), array![[1, 2], [3, 4]]);
593
602
/// });
594
603
/// ```
595
- pub fn from_owned_array < ' py > ( py : Python < ' py > , mut arr : Array < T , D > ) -> & ' py Self {
604
+ pub fn from_owned_array_bound ( py : Python < ' _ > , mut arr : Array < T , D > ) -> Bound < ' _ , Self > {
596
605
let ( strides, dims) = ( arr. npy_strides ( ) , arr. raw_dim ( ) ) ;
597
606
let data_ptr = arr. as_mut_ptr ( ) ;
598
607
unsafe {
@@ -603,7 +612,6 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
603
612
data_ptr,
604
613
PySliceContainer :: from ( arr) ,
605
614
)
606
- . into_gil_ref ( )
607
615
}
608
616
}
609
617
@@ -963,6 +971,15 @@ where
963
971
}
964
972
965
973
impl < D : Dimension > PyArray < PyObject , D > {
974
+ /// Deprecated form of [`PyArray<T, D>::from_owned_object_array_bound`]
975
+ #[ deprecated(
976
+ since = "0.21.0" ,
977
+ note = "will be replaced by PyArray::from_owned_object_array_bound in the future"
978
+ ) ]
979
+ pub fn from_owned_object_array < ' py , T > ( py : Python < ' py > , arr : Array < Py < T > , D > ) -> & ' py Self {
980
+ Self :: from_owned_object_array_bound ( py, arr) . into_gil_ref ( )
981
+ }
982
+
966
983
/// Construct a NumPy array containing objects stored in a [`ndarray::Array`]
967
984
///
968
985
/// This method uses the internal [`Vec`] of the [`ndarray::Array`] as the base object of the NumPy array.
@@ -972,7 +989,7 @@ impl<D: Dimension> PyArray<PyObject, D> {
972
989
/// ```
973
990
/// use ndarray::array;
974
991
/// use pyo3::{pyclass, Py, Python};
975
- /// use numpy::PyArray;
992
+ /// use numpy::{ PyArray, PyArrayMethods} ;
976
993
///
977
994
/// #[pyclass]
978
995
/// struct CustomElement {
@@ -992,12 +1009,15 @@ impl<D: Dimension> PyArray<PyObject, D> {
992
1009
/// }).unwrap(),
993
1010
/// ];
994
1011
///
995
- /// let pyarray = PyArray::from_owned_object_array (py, array);
1012
+ /// let pyarray = PyArray::from_owned_object_array_bound (py, array);
996
1013
///
997
1014
/// assert!(pyarray.readonly().as_array().get(0).unwrap().as_ref(py).is_instance_of::<CustomElement>());
998
1015
/// });
999
1016
/// ```
1000
- pub fn from_owned_object_array < ' py , T > ( py : Python < ' py > , mut arr : Array < Py < T > , D > ) -> & ' py Self {
1017
+ pub fn from_owned_object_array_bound < T > (
1018
+ py : Python < ' _ > ,
1019
+ mut arr : Array < Py < T > , D > ,
1020
+ ) -> Bound < ' _ , Self > {
1001
1021
let ( strides, dims) = ( arr. npy_strides ( ) , arr. raw_dim ( ) ) ;
1002
1022
let data_ptr = arr. as_mut_ptr ( ) as * const PyObject ;
1003
1023
unsafe {
@@ -1008,7 +1028,6 @@ impl<D: Dimension> PyArray<PyObject, D> {
1008
1028
data_ptr,
1009
1029
PySliceContainer :: from ( arr) ,
1010
1030
)
1011
- . into_gil_ref ( )
1012
1031
}
1013
1032
}
1014
1033
}
0 commit comments