File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -952,8 +952,18 @@ impl<T: Element> PyArray<T, Ix1> {
952
952
/// });
953
953
/// ```
954
954
pub fn from_slice < ' py > ( py : Python < ' py > , slice : & [ T ] ) -> & ' py Self {
955
- let data = slice. to_vec ( ) ;
956
- data. into_pyarray ( py)
955
+ unsafe {
956
+ let array = PyArray :: new ( py, [ slice. len ( ) ] , false ) ;
957
+ if T :: IS_COPY {
958
+ ptr:: copy_nonoverlapping ( slice. as_ptr ( ) , array. data ( ) , slice. len ( ) ) ;
959
+ } else {
960
+ let data_ptr = array. data ( ) ;
961
+ for ( i, item) in slice. iter ( ) . enumerate ( ) {
962
+ data_ptr. add ( i) . write ( item. clone ( ) ) ;
963
+ }
964
+ }
965
+ array
966
+ }
957
967
}
958
968
959
969
/// Construct one-dimension PyArray
@@ -969,7 +979,7 @@ impl<T: Element> PyArray<T, Ix1> {
969
979
/// });
970
980
/// ```
971
981
pub fn from_vec < ' py > ( py : Python < ' py > , vec : Vec < T > ) -> & ' py Self {
972
- IntoPyArray :: into_pyarray ( vec , py)
982
+ vec . into_pyarray ( py)
973
983
}
974
984
975
985
/// Construct one-dimension PyArray from a type which implements
You can’t perform that action at this time.
0 commit comments