@@ -81,12 +81,12 @@ use crate::untyped_array::{PyUntypedArray, PyUntypedArrayMethods};
8181/// # Example
8282///
8383/// ```
84- /// use numpy::PyArray;
85- /// use ndarray::array;
84+ /// use numpy::{ PyArray, PyArrayMethods} ;
85+ /// use ndarray::{ array, Array} ;
8686/// use pyo3::Python;
8787///
8888/// Python::with_gil(|py| {
89- /// let pyarray = PyArray::arange (py, 0., 4., 1.).reshape([2, 2]).unwrap();
89+ /// let pyarray = PyArray::arange_bound (py, 0., 4., 1.).reshape([2, 2]).unwrap();
9090/// let array = array![[3., 4.], [5., 6.]];
9191///
9292/// assert_eq!(
@@ -641,11 +641,11 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
641641 /// # Example
642642 ///
643643 /// ```
644- /// use numpy::PyArray;
644+ /// use numpy::{ PyArray, PyArrayMethods} ;
645645 /// use pyo3::Python;
646646 ///
647647 /// Python::with_gil(|py| {
648- /// let pyarray = PyArray::arange (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
648+ /// let pyarray = PyArray::arange_bound (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
649649 ///
650650 /// assert_eq!(unsafe { *pyarray.get([1, 0, 3]).unwrap() }, 11);
651651 /// });
@@ -669,11 +669,11 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
669669 /// # Example
670670 ///
671671 /// ```
672- /// use numpy::PyArray;
672+ /// use numpy::{ PyArray, PyArrayMethods} ;
673673 /// use pyo3::Python;
674674 ///
675675 /// Python::with_gil(|py| {
676- /// let pyarray = PyArray::arange (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
676+ /// let pyarray = PyArray::arange_bound (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
677677 ///
678678 /// unsafe {
679679 /// *pyarray.get_mut([1, 0, 3]).unwrap() = 42;
@@ -704,11 +704,11 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
704704 /// # Example
705705 ///
706706 /// ```
707- /// use numpy::PyArray;
707+ /// use numpy::{ PyArray, PyArrayMethods} ;
708708 /// use pyo3::Python;
709709 ///
710710 /// Python::with_gil(|py| {
711- /// let pyarray = PyArray::arange (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
711+ /// let pyarray = PyArray::arange_bound (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
712712 ///
713713 /// assert_eq!(unsafe { *pyarray.uget([1, 0, 3]) }, 11);
714714 /// });
@@ -758,11 +758,11 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
758758 ///
759759 /// # Example
760760 /// ```
761- /// use numpy::PyArray;
761+ /// use numpy::{ PyArray, PyArrayMethods} ;
762762 /// use pyo3::Python;
763763 ///
764764 /// Python::with_gil(|py| {
765- /// let pyarray = PyArray::arange (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
765+ /// let pyarray = PyArray::arange_bound (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
766766 ///
767767 /// assert_eq!(pyarray.get_owned([1, 0, 3]), Some(11));
768768 /// });
@@ -910,12 +910,12 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
910910 /// # Example
911911 ///
912912 /// ```
913- /// use numpy::PyArray;
913+ /// use numpy::{ PyArray, PyArrayMethods} ;
914914 /// use ndarray::array;
915915 /// use pyo3::Python;
916916 ///
917917 /// Python::with_gil(|py| {
918- /// let pyarray = PyArray::arange (py, 0, 4, 1).reshape([2, 2]).unwrap();
918+ /// let pyarray = PyArray::arange_bound (py, 0, 4, 1).reshape([2, 2]).unwrap();
919919 ///
920920 /// assert_eq!(
921921 /// pyarray.to_owned_array(),
@@ -1241,10 +1241,10 @@ impl<T: Element, D> PyArray<T, D> {
12411241 /// use pyo3::Python;
12421242 ///
12431243 /// Python::with_gil(|py| {
1244- /// let pyarray_f = PyArray::arange (py, 2.0, 5.0, 1.0);
1244+ /// let pyarray_f = PyArray::arange_bound (py, 2.0, 5.0, 1.0);
12451245 /// let pyarray_i = unsafe { PyArray::<i64, _>::new_bound(py, [3], false) };
12461246 ///
1247- /// assert!(pyarray_f.copy_to(pyarray_i.as_gil_ref() ).is_ok());
1247+ /// assert!(pyarray_f.copy_to(& pyarray_i).is_ok());
12481248 ///
12491249 /// assert_eq!(pyarray_i.readonly().as_slice().unwrap(), &[2, 3, 4]);
12501250 /// });
@@ -1262,11 +1262,11 @@ impl<T: Element, D> PyArray<T, D> {
12621262 /// # Example
12631263 ///
12641264 /// ```
1265- /// use numpy::PyArray;
1265+ /// use numpy::{ PyArray, PyArrayMethods} ;
12661266 /// use pyo3::Python;
12671267 ///
12681268 /// Python::with_gil(|py| {
1269- /// let pyarray_f = PyArray::arange (py, 2.0, 5.0, 1.0);
1269+ /// let pyarray_f = PyArray::arange_bound (py, 2.0, 5.0, 1.0);
12701270 ///
12711271 /// let pyarray_i = pyarray_f.cast::<i32>(false).unwrap();
12721272 ///
@@ -1362,28 +1362,37 @@ impl<T: Element, D> PyArray<T, D> {
13621362}
13631363
13641364impl < T : Element + AsPrimitive < f64 > > PyArray < T , Ix1 > {
1365+ /// Deprecated form of [`PyArray<T, Ix1>::arange_bound`]
1366+ #[ deprecated(
1367+ since = "0.21.0" ,
1368+ note = "will be replaced by PyArray::arange_bound in the future"
1369+ ) ]
1370+ pub fn arange < ' py > ( py : Python < ' py > , start : T , stop : T , step : T ) -> & Self {
1371+ Self :: arange_bound ( py, start, stop, step) . into_gil_ref ( )
1372+ }
1373+
13651374 /// Return evenly spaced values within a given interval.
13661375 ///
13671376 /// See [numpy.arange][numpy.arange] for the Python API and [PyArray_Arange][PyArray_Arange] for the C API.
13681377 ///
13691378 /// # Example
13701379 ///
13711380 /// ```
1372- /// use numpy::PyArray;
1381+ /// use numpy::{ PyArray, PyArrayMethods} ;
13731382 /// use pyo3::Python;
13741383 ///
13751384 /// Python::with_gil(|py| {
1376- /// let pyarray = PyArray::arange (py, 2.0, 4.0, 0.5);
1385+ /// let pyarray = PyArray::arange_bound (py, 2.0, 4.0, 0.5);
13771386 /// assert_eq!(pyarray.readonly().as_slice().unwrap(), &[2.0, 2.5, 3.0, 3.5]);
13781387 ///
1379- /// let pyarray = PyArray::arange (py, -2, 4, 3);
1388+ /// let pyarray = PyArray::arange_bound (py, -2, 4, 3);
13801389 /// assert_eq!(pyarray.readonly().as_slice().unwrap(), &[-2, 1]);
13811390 /// });
13821391 /// ```
13831392 ///
13841393 /// [numpy.arange]: https://numpy.org/doc/stable/reference/generated/numpy.arange.html
13851394 /// [PyArray_Arange]: https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_Arange
1386- pub fn arange < ' py > ( py : Python < ' py > , start : T , stop : T , step : T ) -> & Self {
1395+ pub fn arange_bound < ' py > ( py : Python < ' py > , start : T , stop : T , step : T ) -> Bound < ' py , Self > {
13871396 unsafe {
13881397 let ptr = PY_ARRAY_API . PyArray_Arange (
13891398 py,
@@ -1392,7 +1401,7 @@ impl<T: Element + AsPrimitive<f64>> PyArray<T, Ix1> {
13921401 step. as_ ( ) ,
13931402 T :: get_dtype_bound ( py) . num ( ) ,
13941403 ) ;
1395- Self :: from_owned_ptr ( py, ptr)
1404+ Bound :: from_owned_ptr ( py, ptr) . downcast_into_unchecked ( )
13961405 }
13971406 }
13981407}
@@ -1482,11 +1491,11 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
14821491 /// # Example
14831492 ///
14841493 /// ```
1485- /// use numpy::PyArray;
1494+ /// use numpy::{ PyArray, PyArrayMethods} ;
14861495 /// use pyo3::Python;
14871496 ///
14881497 /// Python::with_gil(|py| {
1489- /// let pyarray = PyArray::arange (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
1498+ /// let pyarray = PyArray::arange_bound (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
14901499 ///
14911500 /// assert_eq!(unsafe { *pyarray.get([1, 0, 3]).unwrap() }, 11);
14921501 /// });
@@ -1509,11 +1518,11 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
15091518 /// # Example
15101519 ///
15111520 /// ```
1512- /// use numpy::PyArray;
1521+ /// use numpy::{ PyArray, PyArrayMethods} ;
15131522 /// use pyo3::Python;
15141523 ///
15151524 /// Python::with_gil(|py| {
1516- /// let pyarray = PyArray::arange (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
1525+ /// let pyarray = PyArray::arange_bound (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
15171526 ///
15181527 /// unsafe {
15191528 /// *pyarray.get_mut([1, 0, 3]).unwrap() = 42;
@@ -1543,11 +1552,11 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
15431552 /// # Example
15441553 ///
15451554 /// ```
1546- /// use numpy::PyArray;
1555+ /// use numpy::{ PyArray, PyArrayMethods} ;
15471556 /// use pyo3::Python;
15481557 ///
15491558 /// Python::with_gil(|py| {
1550- /// let pyarray = PyArray::arange (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
1559+ /// let pyarray = PyArray::arange_bound (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
15511560 ///
15521561 /// assert_eq!(unsafe { *pyarray.uget([1, 0, 3]) }, 11);
15531562 /// });
@@ -1604,11 +1613,11 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
16041613 ///
16051614 /// # Example
16061615 /// ```
1607- /// use numpy::PyArray;
1616+ /// use numpy::{ PyArray, PyArrayMethods} ;
16081617 /// use pyo3::Python;
16091618 ///
16101619 /// Python::with_gil(|py| {
1611- /// let pyarray = PyArray::arange (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
1620+ /// let pyarray = PyArray::arange_bound (py, 0, 16, 1).reshape([2, 2, 4]).unwrap();
16121621 ///
16131622 /// assert_eq!(pyarray.get_owned([1, 0, 3]), Some(11));
16141623 /// });
@@ -1742,12 +1751,12 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
17421751 /// # Example
17431752 ///
17441753 /// ```
1745- /// use numpy::PyArray;
1754+ /// use numpy::{ PyArray, PyArrayMethods} ;
17461755 /// use ndarray::array;
17471756 /// use pyo3::Python;
17481757 ///
17491758 /// Python::with_gil(|py| {
1750- /// let pyarray = PyArray::arange (py, 0, 4, 1).reshape([2, 2]).unwrap();
1759+ /// let pyarray = PyArray::arange_bound (py, 0, 4, 1).reshape([2, 2]).unwrap();
17511760 ///
17521761 /// assert_eq!(
17531762 /// pyarray.to_owned_array(),
@@ -1774,10 +1783,10 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
17741783 /// use pyo3::Python;
17751784 ///
17761785 /// Python::with_gil(|py| {
1777- /// let pyarray_f = PyArray::arange (py, 2.0, 5.0, 1.0);
1786+ /// let pyarray_f = PyArray::arange_bound (py, 2.0, 5.0, 1.0);
17781787 /// let pyarray_i = unsafe { PyArray::<i64, _>::new_bound(py, [3], false) };
17791788 ///
1780- /// assert!(pyarray_f.copy_to(pyarray_i.as_gil_ref() ).is_ok());
1789+ /// assert!(pyarray_f.copy_to(& pyarray_i).is_ok());
17811790 ///
17821791 /// assert_eq!(pyarray_i.readonly().as_slice().unwrap(), &[2, 3, 4]);
17831792 /// });
@@ -1795,11 +1804,11 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
17951804 /// # Example
17961805 ///
17971806 /// ```
1798- /// use numpy::PyArray;
1807+ /// use numpy::{ PyArray, PyArrayMethods} ;
17991808 /// use pyo3::Python;
18001809 ///
18011810 /// Python::with_gil(|py| {
1802- /// let pyarray_f = PyArray::arange (py, 2.0, 5.0, 1.0);
1811+ /// let pyarray_f = PyArray::arange_bound (py, 2.0, 5.0, 1.0);
18031812 ///
18041813 /// let pyarray_i = pyarray_f.cast::<i32>(false).unwrap();
18051814 ///
0 commit comments