@@ -518,7 +518,7 @@ impl<A, D: Dimension> NdProducer for RawArrayViewMut<A, D> {
518
518
/// The order elements are visited is not specified. The producers don’t have to
519
519
/// have the same item type.
520
520
///
521
- /// The `Zip` has two methods for function application: `apply ` and
521
+ /// The `Zip` has two methods for function application: `for_each ` and
522
522
/// `fold_while`. The zip object can be split, which allows parallelization.
523
523
/// A read-only zip object (no mutable producers) can be cloned.
524
524
///
@@ -546,7 +546,7 @@ impl<A, D: Dimension> NdProducer for RawArrayViewMut<A, D> {
546
546
/// .and(&b)
547
547
/// .and(&c)
548
548
/// .and(&d)
549
- /// .apply (|w, &x, &y, &z| {
549
+ /// .for_each (|w, &x, &y, &z| {
550
550
/// *w += x + y * z;
551
551
/// });
552
552
///
@@ -563,7 +563,7 @@ impl<A, D: Dimension> NdProducer for RawArrayViewMut<A, D> {
563
563
///
564
564
/// Zip::from(&mut totals)
565
565
/// .and(a.rows())
566
- /// .apply (|totals, row| *totals = row.sum());
566
+ /// .for_each (|totals, row| *totals = row.sum());
567
567
///
568
568
/// // Check the result against the built in `.sum_axis()` along axis 1.
569
569
/// assert_eq!(totals, a.sum_axis(Axis(1)));
@@ -692,21 +692,21 @@ impl<P, D> Zip<P, D>
692
692
where
693
693
D : Dimension ,
694
694
{
695
- fn apply_core < F , Acc > ( & mut self , acc : Acc , mut function : F ) -> FoldWhile < Acc >
695
+ fn for_each_core < F , Acc > ( & mut self , acc : Acc , mut function : F ) -> FoldWhile < Acc >
696
696
where
697
697
F : FnMut ( Acc , P :: Item ) -> FoldWhile < Acc > ,
698
698
P : ZippableTuple < Dim = D > ,
699
699
{
700
700
if self . dimension . ndim ( ) == 0 {
701
701
function ( acc, unsafe { self . parts . as_ref ( self . parts . as_ptr ( ) ) } )
702
702
} else if self . layout . is ( CORDER | FORDER ) {
703
- self . apply_core_contiguous ( acc, function)
703
+ self . for_each_core_contiguous ( acc, function)
704
704
} else {
705
- self . apply_core_strided ( acc, function)
705
+ self . for_each_core_strided ( acc, function)
706
706
}
707
707
}
708
708
709
- fn apply_core_contiguous < F , Acc > ( & mut self , acc : Acc , mut function : F ) -> FoldWhile < Acc >
709
+ fn for_each_core_contiguous < F , Acc > ( & mut self , acc : Acc , mut function : F ) -> FoldWhile < Acc >
710
710
where
711
711
F : FnMut ( Acc , P :: Item ) -> FoldWhile < Acc > ,
712
712
P : ZippableTuple < Dim = D > ,
@@ -744,7 +744,7 @@ where
744
744
}
745
745
746
746
747
- fn apply_core_strided < F , Acc > ( & mut self , acc : Acc , function : F ) -> FoldWhile < Acc >
747
+ fn for_each_core_strided < F , Acc > ( & mut self , acc : Acc , function : F ) -> FoldWhile < Acc >
748
748
where
749
749
F : FnMut ( Acc , P :: Item ) -> FoldWhile < Acc > ,
750
750
P : ZippableTuple < Dim = D > ,
@@ -754,14 +754,14 @@ where
754
754
panic ! ( "Unreachable: ndim == 0 is contiguous" )
755
755
}
756
756
if n == 1 || self . layout_tendency >= 0 {
757
- self . apply_core_strided_c ( acc, function)
757
+ self . for_each_core_strided_c ( acc, function)
758
758
} else {
759
- self . apply_core_strided_f ( acc, function)
759
+ self . for_each_core_strided_f ( acc, function)
760
760
}
761
761
}
762
762
763
763
// Non-contiguous but preference for C - unroll over Axis(ndim - 1)
764
- fn apply_core_strided_c < F , Acc > ( & mut self , mut acc : Acc , mut function : F ) -> FoldWhile < Acc >
764
+ fn for_each_core_strided_c < F , Acc > ( & mut self , mut acc : Acc , mut function : F ) -> FoldWhile < Acc >
765
765
where
766
766
F : FnMut ( Acc , P :: Item ) -> FoldWhile < Acc > ,
767
767
P : ZippableTuple < Dim = D > ,
@@ -785,7 +785,7 @@ where
785
785
}
786
786
787
787
// Non-contiguous but preference for F - unroll over Axis(0)
788
- fn apply_core_strided_f < F , Acc > ( & mut self , mut acc : Acc , mut function : F ) -> FoldWhile < Acc >
788
+ fn for_each_core_strided_f < F , Acc > ( & mut self , mut acc : Acc , mut function : F ) -> FoldWhile < Acc >
789
789
where
790
790
F : FnMut ( Acc , P :: Item ) -> FoldWhile < Acc > ,
791
791
P : ZippableTuple < Dim = D > ,
@@ -939,15 +939,24 @@ macro_rules! map_impl {
939
939
{
940
940
/// Apply a function to all elements of the input arrays,
941
941
/// visiting elements in lock step.
942
- pub fn apply <F >( mut self , mut function: F )
942
+ pub fn for_each <F >( mut self , mut function: F )
943
943
where F : FnMut ( $( $p:: Item ) ,* )
944
944
{
945
- self . apply_core ( ( ) , move |( ) , args| {
945
+ self . for_each_core ( ( ) , move |( ) , args| {
946
946
let ( $( $p, ) * ) = args;
947
947
FoldWhile :: Continue ( function( $( $p) ,* ) )
948
948
} ) ;
949
949
}
950
950
951
+ /// Apply a function to all elements of the input arrays,
952
+ /// visiting elements in lock step.
953
+ #[ deprecated( note="Renamed to .for_each()" , since="0.15.0" ) ]
954
+ pub fn apply<F >( self , function: F )
955
+ where F : FnMut ( $( $p:: Item ) ,* )
956
+ {
957
+ self . for_each( function)
958
+ }
959
+
951
960
/// Apply a fold function to all elements of the input arrays,
952
961
/// visiting elements in lock step.
953
962
///
@@ -980,7 +989,7 @@ macro_rules! map_impl {
980
989
where
981
990
F : FnMut ( Acc , $( $p:: Item ) ,* ) -> Acc ,
982
991
{
983
- self . apply_core ( acc, move |acc, args| {
992
+ self . for_each_core ( acc, move |acc, args| {
984
993
let ( $( $p, ) * ) = args;
985
994
FoldWhile :: Continue ( function( acc, $( $p) ,* ) )
986
995
} ) . into_inner( )
@@ -993,7 +1002,7 @@ macro_rules! map_impl {
993
1002
-> FoldWhile <Acc >
994
1003
where F : FnMut ( Acc , $( $p:: Item ) ,* ) -> FoldWhile <Acc >
995
1004
{
996
- self . apply_core ( acc, move |acc, args| {
1005
+ self . for_each_core ( acc, move |acc, args| {
997
1006
let ( $( $p, ) * ) = args;
998
1007
function( acc, $( $p) ,* )
999
1008
} )
@@ -1015,7 +1024,7 @@ macro_rules! map_impl {
1015
1024
pub fn all<F >( mut self , mut predicate: F ) -> bool
1016
1025
where F : FnMut ( $( $p:: Item ) ,* ) -> bool
1017
1026
{
1018
- !self . apply_core ( ( ) , move |_, args| {
1027
+ !self . for_each_core ( ( ) , move |_, args| {
1019
1028
let ( $( $p, ) * ) = args;
1020
1029
if predicate( $( $p) ,* ) {
1021
1030
FoldWhile :: Continue ( ( ) )
@@ -1065,12 +1074,11 @@ macro_rules! map_impl {
1065
1074
}
1066
1075
}
1067
1076
1068
- /// Apply and collect the results into a new array, which has the same size as the
1077
+ /// Map and collect the results into a new array, which has the same size as the
1069
1078
/// inputs.
1070
1079
///
1071
1080
/// If all inputs are c- or f-order respectively, that is preserved in the output.
1072
- pub fn apply_collect<R >( self , f: impl FnMut ( $( $p:: Item , ) * ) -> R ) -> Array <R , D >
1073
- {
1081
+ pub fn map_collect<R >( self , f: impl FnMut ( $( $p:: Item , ) * ) -> R ) -> Array <R , D > {
1074
1082
// Make uninit result
1075
1083
let mut output = self . uninitalized_for_current_layout:: <R >( ) ;
1076
1084
@@ -1086,21 +1094,43 @@ macro_rules! map_impl {
1086
1094
}
1087
1095
}
1088
1096
1089
- /// Apply and assign the results into the producer `into`, which should have the same
1097
+ /// Map and collect the results into a new array, which has the same size as the
1098
+ /// inputs.
1099
+ ///
1100
+ /// If all inputs are c- or f-order respectively, that is preserved in the output.
1101
+ #[ deprecated( note="Renamed to .map_collect()" , since="0.15.0" ) ]
1102
+ pub fn apply_collect<R >( self , f: impl FnMut ( $( $p:: Item , ) * ) -> R ) -> Array <R , D > {
1103
+ self . map_collect( f)
1104
+ }
1105
+
1106
+ /// Map and assign the results into the producer `into`, which should have the same
1090
1107
/// size as the other inputs.
1091
1108
///
1092
1109
/// The producer should have assignable items as dictated by the `AssignElem` trait,
1093
1110
/// for example `&mut R`.
1094
- pub fn apply_assign_into <R , Q >( self , into: Q , mut f: impl FnMut ( $( $p:: Item , ) * ) -> R )
1111
+ pub fn map_assign_into <R , Q >( self , into: Q , mut f: impl FnMut ( $( $p:: Item , ) * ) -> R )
1095
1112
where Q : IntoNdProducer <Dim =D >,
1096
1113
Q :: Item : AssignElem <R >
1097
1114
{
1098
1115
self . and( into)
1099
- . apply ( move |$( $p, ) * output_| {
1116
+ . for_each ( move |$( $p, ) * output_| {
1100
1117
output_. assign_elem( f( $( $p ) ,* ) ) ;
1101
1118
} ) ;
1102
1119
}
1103
1120
1121
+ /// Map and assign the results into the producer `into`, which should have the same
1122
+ /// size as the other inputs.
1123
+ ///
1124
+ /// The producer should have assignable items as dictated by the `AssignElem` trait,
1125
+ /// for example `&mut R`.
1126
+ #[ deprecated( note="Renamed to .map_assign_into()" , since="0.15.0" ) ]
1127
+ pub fn apply_assign_into<R , Q >( self , into: Q , f: impl FnMut ( $( $p:: Item , ) * ) -> R )
1128
+ where Q : IntoNdProducer <Dim =D >,
1129
+ Q :: Item : AssignElem <R >
1130
+ {
1131
+ self . map_assign_into( into, f)
1132
+ }
1133
+
1104
1134
1105
1135
) ;
1106
1136
@@ -1150,7 +1180,7 @@ macro_rules! map_impl {
1150
1180
// Apply the mapping function on this zip
1151
1181
// if we panic with unwinding; Partial will drop the written elements.
1152
1182
let partial_len = & mut partial. len;
1153
- self . apply ( move |$( $p, ) * output_elem: * mut R | {
1183
+ self . for_each ( move |$( $p, ) * output_elem: * mut R | {
1154
1184
output_elem. write( f( $( $p) ,* ) ) ;
1155
1185
if std:: mem:: needs_drop:: <R >( ) {
1156
1186
* partial_len += 1 ;
0 commit comments