File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -530,19 +530,35 @@ impl<T: TypeNum> PyArray<T, Ix1> {
530
530
if length >= capacity {
531
531
capacity *= 2 ;
532
532
array
533
- . resize_ ( [ capacity] , 0 , NPY_ORDER :: NPY_ANYORDER )
533
+ . resize ( capacity)
534
534
. expect ( "PyArray::from_iter: Failed to allocate memory" ) ;
535
535
}
536
536
* array. uget_mut ( [ i] ) = item;
537
537
}
538
538
}
539
539
if capacity > length {
540
- array. resize_ ( [ length] , 0 , NPY_ORDER :: NPY_ANYORDER ) . unwrap ( )
540
+ array. resize ( length) . unwrap ( )
541
541
}
542
542
array
543
543
}
544
544
545
- // TODO: expose?
545
+ /// Extends or trancates the length of 1 dimension PyArray.
546
+ ///
547
+ /// # Example
548
+ /// ```
549
+ /// # extern crate pyo3; extern crate numpy; fn main() {
550
+ /// use numpy::PyArray;
551
+ /// let gil = pyo3::Python::acquire_gil();
552
+ /// let pyarray = PyArray::arange(gil.python(), 0, 10, 1);
553
+ /// assert_eq!(pyarray.len(), 10);
554
+ /// pyarray.resize(100).unwrap();
555
+ /// assert_eq!(pyarray.len(), 100);
556
+ /// # }
557
+ /// ```
558
+ pub fn resize ( & self , new_elems : usize ) -> Result < ( ) , ErrorKind > {
559
+ self . resize_ ( [ new_elems] , 1 , NPY_ORDER :: NPY_ANYORDER )
560
+ }
561
+
546
562
fn resize_ < ' py , D : IntoDimension > (
547
563
& ' py self ,
548
564
dims : D ,
You can’t perform that action at this time.
0 commit comments