@@ -81,12 +81,12 @@ use crate::untyped_array::{PyUntypedArray, PyUntypedArrayMethods};
81
81
/// # Example
82
82
///
83
83
/// ```
84
- /// use numpy::PyArray;
85
- /// use ndarray::array;
84
+ /// use numpy::{ PyArray, PyArrayMethods} ;
85
+ /// use ndarray::{ array, Array} ;
86
86
/// use pyo3::Python;
87
87
///
88
88
/// 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();
90
90
/// let array = array![[3., 4.], [5., 6.]];
91
91
///
92
92
/// assert_eq!(
@@ -641,11 +641,11 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
641
641
/// # Example
642
642
///
643
643
/// ```
644
- /// use numpy::PyArray;
644
+ /// use numpy::{ PyArray, PyArrayMethods} ;
645
645
/// use pyo3::Python;
646
646
///
647
647
/// 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();
649
649
///
650
650
/// assert_eq!(unsafe { *pyarray.get([1, 0, 3]).unwrap() }, 11);
651
651
/// });
@@ -669,11 +669,11 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
669
669
/// # Example
670
670
///
671
671
/// ```
672
- /// use numpy::PyArray;
672
+ /// use numpy::{ PyArray, PyArrayMethods} ;
673
673
/// use pyo3::Python;
674
674
///
675
675
/// 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();
677
677
///
678
678
/// unsafe {
679
679
/// *pyarray.get_mut([1, 0, 3]).unwrap() = 42;
@@ -704,11 +704,11 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
704
704
/// # Example
705
705
///
706
706
/// ```
707
- /// use numpy::PyArray;
707
+ /// use numpy::{ PyArray, PyArrayMethods} ;
708
708
/// use pyo3::Python;
709
709
///
710
710
/// 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();
712
712
///
713
713
/// assert_eq!(unsafe { *pyarray.uget([1, 0, 3]) }, 11);
714
714
/// });
@@ -758,11 +758,11 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
758
758
///
759
759
/// # Example
760
760
/// ```
761
- /// use numpy::PyArray;
761
+ /// use numpy::{ PyArray, PyArrayMethods} ;
762
762
/// use pyo3::Python;
763
763
///
764
764
/// 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();
766
766
///
767
767
/// assert_eq!(pyarray.get_owned([1, 0, 3]), Some(11));
768
768
/// });
@@ -910,12 +910,12 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
910
910
/// # Example
911
911
///
912
912
/// ```
913
- /// use numpy::PyArray;
913
+ /// use numpy::{ PyArray, PyArrayMethods} ;
914
914
/// use ndarray::array;
915
915
/// use pyo3::Python;
916
916
///
917
917
/// 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();
919
919
///
920
920
/// assert_eq!(
921
921
/// pyarray.to_owned_array(),
@@ -1241,10 +1241,10 @@ impl<T: Element, D> PyArray<T, D> {
1241
1241
/// use pyo3::Python;
1242
1242
///
1243
1243
/// 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);
1245
1245
/// let pyarray_i = unsafe { PyArray::<i64, _>::new_bound(py, [3], false) };
1246
1246
///
1247
- /// assert!(pyarray_f.copy_to(pyarray_i.as_gil_ref() ).is_ok());
1247
+ /// assert!(pyarray_f.copy_to(& pyarray_i).is_ok());
1248
1248
///
1249
1249
/// assert_eq!(pyarray_i.readonly().as_slice().unwrap(), &[2, 3, 4]);
1250
1250
/// });
@@ -1262,11 +1262,11 @@ impl<T: Element, D> PyArray<T, D> {
1262
1262
/// # Example
1263
1263
///
1264
1264
/// ```
1265
- /// use numpy::PyArray;
1265
+ /// use numpy::{ PyArray, PyArrayMethods} ;
1266
1266
/// use pyo3::Python;
1267
1267
///
1268
1268
/// 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);
1270
1270
///
1271
1271
/// let pyarray_i = pyarray_f.cast::<i32>(false).unwrap();
1272
1272
///
@@ -1362,28 +1362,37 @@ impl<T: Element, D> PyArray<T, D> {
1362
1362
}
1363
1363
1364
1364
impl < 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
+
1365
1374
/// Return evenly spaced values within a given interval.
1366
1375
///
1367
1376
/// See [numpy.arange][numpy.arange] for the Python API and [PyArray_Arange][PyArray_Arange] for the C API.
1368
1377
///
1369
1378
/// # Example
1370
1379
///
1371
1380
/// ```
1372
- /// use numpy::PyArray;
1381
+ /// use numpy::{ PyArray, PyArrayMethods} ;
1373
1382
/// use pyo3::Python;
1374
1383
///
1375
1384
/// 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);
1377
1386
/// assert_eq!(pyarray.readonly().as_slice().unwrap(), &[2.0, 2.5, 3.0, 3.5]);
1378
1387
///
1379
- /// let pyarray = PyArray::arange (py, -2, 4, 3);
1388
+ /// let pyarray = PyArray::arange_bound (py, -2, 4, 3);
1380
1389
/// assert_eq!(pyarray.readonly().as_slice().unwrap(), &[-2, 1]);
1381
1390
/// });
1382
1391
/// ```
1383
1392
///
1384
1393
/// [numpy.arange]: https://numpy.org/doc/stable/reference/generated/numpy.arange.html
1385
1394
/// [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 > {
1387
1396
unsafe {
1388
1397
let ptr = PY_ARRAY_API . PyArray_Arange (
1389
1398
py,
@@ -1392,7 +1401,7 @@ impl<T: Element + AsPrimitive<f64>> PyArray<T, Ix1> {
1392
1401
step. as_ ( ) ,
1393
1402
T :: get_dtype_bound ( py) . num ( ) ,
1394
1403
) ;
1395
- Self :: from_owned_ptr ( py, ptr)
1404
+ Bound :: from_owned_ptr ( py, ptr) . downcast_into_unchecked ( )
1396
1405
}
1397
1406
}
1398
1407
}
@@ -1482,11 +1491,11 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
1482
1491
/// # Example
1483
1492
///
1484
1493
/// ```
1485
- /// use numpy::PyArray;
1494
+ /// use numpy::{ PyArray, PyArrayMethods} ;
1486
1495
/// use pyo3::Python;
1487
1496
///
1488
1497
/// 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();
1490
1499
///
1491
1500
/// assert_eq!(unsafe { *pyarray.get([1, 0, 3]).unwrap() }, 11);
1492
1501
/// });
@@ -1509,11 +1518,11 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
1509
1518
/// # Example
1510
1519
///
1511
1520
/// ```
1512
- /// use numpy::PyArray;
1521
+ /// use numpy::{ PyArray, PyArrayMethods} ;
1513
1522
/// use pyo3::Python;
1514
1523
///
1515
1524
/// 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();
1517
1526
///
1518
1527
/// unsafe {
1519
1528
/// *pyarray.get_mut([1, 0, 3]).unwrap() = 42;
@@ -1543,11 +1552,11 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
1543
1552
/// # Example
1544
1553
///
1545
1554
/// ```
1546
- /// use numpy::PyArray;
1555
+ /// use numpy::{ PyArray, PyArrayMethods} ;
1547
1556
/// use pyo3::Python;
1548
1557
///
1549
1558
/// 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();
1551
1560
///
1552
1561
/// assert_eq!(unsafe { *pyarray.uget([1, 0, 3]) }, 11);
1553
1562
/// });
@@ -1604,11 +1613,11 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
1604
1613
///
1605
1614
/// # Example
1606
1615
/// ```
1607
- /// use numpy::PyArray;
1616
+ /// use numpy::{ PyArray, PyArrayMethods} ;
1608
1617
/// use pyo3::Python;
1609
1618
///
1610
1619
/// 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();
1612
1621
///
1613
1622
/// assert_eq!(pyarray.get_owned([1, 0, 3]), Some(11));
1614
1623
/// });
@@ -1742,12 +1751,12 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
1742
1751
/// # Example
1743
1752
///
1744
1753
/// ```
1745
- /// use numpy::PyArray;
1754
+ /// use numpy::{ PyArray, PyArrayMethods} ;
1746
1755
/// use ndarray::array;
1747
1756
/// use pyo3::Python;
1748
1757
///
1749
1758
/// 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();
1751
1760
///
1752
1761
/// assert_eq!(
1753
1762
/// pyarray.to_owned_array(),
@@ -1774,10 +1783,10 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
1774
1783
/// use pyo3::Python;
1775
1784
///
1776
1785
/// 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);
1778
1787
/// let pyarray_i = unsafe { PyArray::<i64, _>::new_bound(py, [3], false) };
1779
1788
///
1780
- /// assert!(pyarray_f.copy_to(pyarray_i.as_gil_ref() ).is_ok());
1789
+ /// assert!(pyarray_f.copy_to(& pyarray_i).is_ok());
1781
1790
///
1782
1791
/// assert_eq!(pyarray_i.readonly().as_slice().unwrap(), &[2, 3, 4]);
1783
1792
/// });
@@ -1795,11 +1804,11 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
1795
1804
/// # Example
1796
1805
///
1797
1806
/// ```
1798
- /// use numpy::PyArray;
1807
+ /// use numpy::{ PyArray, PyArrayMethods} ;
1799
1808
/// use pyo3::Python;
1800
1809
///
1801
1810
/// 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);
1803
1812
///
1804
1813
/// let pyarray_i = pyarray_f.cast::<i32>(false).unwrap();
1805
1814
///
0 commit comments