Conversation
|
@nilgoyette thanks for your quick review! I was seeking for what would be a better approach, your comment was very helpful! I tried to vectorize it a bit more with |
akern40
left a comment
There was a problem hiding this comment.
@NewBornRustacean great to see you back so soon!
|
@nilgoyette @akern40 sorry to belated reply! thanks to suggestions 🥇 most of the suggestions are included and passes all the tests. |
nilgoyette
left a comment
There was a problem hiding this comment.
The code is really nice with accumulate_axis_inplace! Sorry for the detour. I guess we all learned something ;)
yes indeed! thank you so much 😃 |
|
Thanks for your persistence! Last thing: I don't think |
@akern40 thanks for the suggestion! 😺 how about this one? #[track_caller]
pub fn cumprod(&self, axis: Axis) -> Array<A, D>
where
A: Clone + Mul<Output = A> + MulAssign,
D: Dimension + RemoveAxis,
{
if axis.0 >= self.ndim() {
panic!("axis is out of bounds for array of dimension");
}
let mut result = self.to_owned();
result.accumulate_axis_inplace(axis, |prev, curr| *curr *= prev.clone());
result
} |
|
Looks good to me! Thanks again for your work 😄 |
Add cumprod() to match NumPy behavior
Hello ndarray community!
This is implementation of the
cumprod()function to match NumPy's behavior regarding axis handling.Related links
Details
check- removed since we now useif self.ndim() > 1 && axis.is_none() { panic!(...) }Axisdirectly- removed since we now useSome(axis)branch to use input array values instead of result array valuesAxisdirectlyExample Usage
Testing
All existing tests pass,
Axis(0)The implementation maintains consistency with NumPy's behavior, but there might be more elegant way to implement this(especially for the nested loop). please give me any comment/feedback!
@akern40 what's up! I love the automated CI pipeline, thanks 👍