@@ -14,9 +14,7 @@ use std::ops::{Add, Div, Mul, Sub};
1414
1515use crate :: imp_prelude:: * ;
1616use crate :: numeric_util;
17- use crate :: ScalarOperand ;
1817use crate :: Slice ;
19- use crate :: Zip ;
2018
2119/// # Numerical Methods for Arrays
2220impl < A , D > ArrayRef < A , D >
@@ -126,26 +124,18 @@ where D: Dimension
126124 #[ track_caller]
127125 pub fn cumprod ( & self , axis : Axis ) -> Array < A , D >
128126 where
129- A : Clone + One + Mul < Output = A > + ScalarOperand ,
127+ A : Copy + Clone + Mul < Output = A > ,
130128 D : Dimension + RemoveAxis ,
131129 {
132- // Check if axis is valid before any array operations
133130 if axis. 0 >= self . ndim ( ) {
134131 panic ! ( "axis is out of bounds for array of dimension" ) ;
135132 }
136133
137- let mut res = Array :: ones ( self . raw_dim ( ) ) ;
138- let running_product = Array :: ones ( self . raw_dim ( ) . remove_axis ( axis) ) ;
139-
140- Zip :: from ( self . axis_iter ( axis) )
141- . and ( res. axis_iter_mut ( axis) )
142- . fold ( running_product, |mut running_product, view, mut res| {
143- running_product = running_product * & view;
144- res. assign ( & running_product) ;
145- running_product
146- } ) ;
147-
148- res
134+ let mut result = self . to_owned ( ) ;
135+ result. accumulate_axis_inplace ( axis, |& prev, curr| {
136+ * curr = * curr * prev;
137+ } ) ;
138+ result
149139 }
150140
151141 /// Return variance of elements in the array.
0 commit comments