numrs2 0.3.1

A Rust implementation inspired by NumPy for numerical computing (NumRS2)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
//! Aggregation functions for array operations.
//!
//! This module provides functions for aggregating array elements along axes:
//!
//! - `amax`, `amin` - Axis-aware maximum/minimum
//! - `max`, `min` - NumPy-style maximum/minimum
//! - `sum` - Sum with axis support
//! - `sort` - Sort along axis
//! - `argpartition` - Indirect partition along axis
//! - `round` - Round to nearest integer
//! - `cumulative_sum`, `cumulative_prod` - Cumulative operations

use crate::array::Array;
use crate::error::{NumRs2Error, Result};
use num_traits::{Float, Zero};
use std::ops::{Add, Mul};

// Import cumsum and cumprod from parent module
use super::{cumprod, cumsum};

/// Array maximum along a given axis (alias for max)
///
/// # Parameters
///
/// * `array` - Input array
/// * `axis` - Axis along which to find maximum values. If None, the maximum of the flattened array
/// * `keepdims` - If true, the axes which are reduced are left in the result as dimensions with size one
///
/// # Returns
///
/// Array containing maximum values
///
/// # Examples
///
/// ```
/// use numrs2::prelude::*;
///
/// let a = Array::from_vec(vec![1.0, 3.0, 2.0, 4.0, 5.0, 1.0]).reshape(&[2, 3]);
/// let maxs = amax(&a, Some(1), false).expect("amax should succeed");
/// assert_eq!(maxs.to_vec(), vec![3.0, 5.0]); // max of each row
/// ```
pub fn amax<T>(array: &Array<T>, axis: Option<isize>, keepdims: bool) -> Result<Array<T>>
where
    T: PartialOrd + Clone + Zero,
{
    max(array, axis, keepdims)
}

/// Array minimum along a given axis (alias for min)
///
/// # Parameters
///
/// * `array` - Input array
/// * `axis` - Axis along which to find minimum values. If None, the minimum of the flattened array
/// * `keepdims` - If true, the axes which are reduced are left in the result as dimensions with size one
///
/// # Returns
///
/// Array containing minimum values
///
/// # Examples
///
/// ```
/// use numrs2::prelude::*;
///
/// let a = Array::from_vec(vec![5.0, 3.0, 2.0, 4.0, 1.0, 6.0]).reshape(&[2, 3]);
/// let mins = amin(&a, Some(1), false).expect("amin should succeed");
/// assert_eq!(mins.to_vec(), vec![2.0, 1.0]); // min of each row
/// ```
pub fn amin<T>(array: &Array<T>, axis: Option<isize>, keepdims: bool) -> Result<Array<T>>
where
    T: PartialOrd + Clone + Zero,
{
    min(array, axis, keepdims)
}

/// Find the maximum values along an axis
///
/// # Parameters
///
/// * `array` - Input array
/// * `axis` - Axis along which to find maximum values. If None, the maximum of the flattened array
/// * `keepdims` - If true, the axes which are reduced are left in the result as dimensions with size one
///
/// # Returns
///
/// Array containing maximum values
pub fn max<T>(array: &Array<T>, axis: Option<isize>, keepdims: bool) -> Result<Array<T>>
where
    T: PartialOrd + Clone + Zero,
{
    if array.is_empty() {
        return Err(NumRs2Error::InvalidOperation(
            "Cannot find max of empty array".to_string(),
        ));
    }

    match axis {
        None => {
            // Find max of flattened array
            let data = array.to_vec();
            let max_val =
                data.iter().skip(1).fold(
                    data[0].clone(),
                    |max, x| {
                        if x > &max {
                            x.clone()
                        } else {
                            max
                        }
                    },
                );

            if keepdims {
                let shape = vec![1; array.ndim()];
                Ok(Array::from_vec(vec![max_val]).reshape(&shape))
            } else {
                Ok(Array::from_vec(vec![max_val]))
            }
        }
        Some(ax) => {
            let axis = if ax < 0 {
                (array.ndim() as isize + ax) as usize
            } else {
                ax as usize
            };

            if axis >= array.ndim() {
                return Err(NumRs2Error::DimensionMismatch(format!(
                    "Axis {} out of bounds for array of dimension {}",
                    axis,
                    array.ndim()
                )));
            }

            let shape = array.shape();
            let axis_size = shape[axis];

            // Create output shape
            let mut out_shape = shape.clone();
            if keepdims {
                out_shape[axis] = 1;
            } else {
                out_shape.remove(axis);
            }
            if out_shape.is_empty() {
                out_shape.push(1);
            }

            let out_size: usize = out_shape.iter().product();
            let mut result_data = vec![T::zero(); out_size];

            // Calculate strides
            let mut strides = vec![1; array.ndim()];
            for i in (0..array.ndim() - 1).rev() {
                strides[i] = strides[i + 1] * shape[i + 1];
            }

            // Iterate through output positions
            for out_idx in 0..out_size {
                // Convert flat index to multi-dimensional indices
                let mut indices = vec![0; array.ndim()];
                let mut temp = out_idx;

                for i in 0..array.ndim() {
                    if i < axis {
                        let dim_size = shape[i];
                        indices[i] = temp % dim_size;
                        temp /= dim_size;
                    } else if i > axis || (i == axis && keepdims) {
                        let dim_idx = if keepdims { i } else { i - 1 };
                        if dim_idx < out_shape.len() {
                            let dim_size = out_shape[dim_idx];
                            indices[i] = temp % dim_size;
                            temp /= dim_size;
                        }
                    }
                }

                // Find max along the axis
                let mut max_val = None;

                for j in 0..axis_size {
                    indices[axis] = j;
                    let val = array.get(&indices)?;

                    if max_val.as_ref().is_none_or(|mv| &val > mv) {
                        max_val = Some(val);
                    }
                }

                result_data[out_idx] = max_val.expect("max_val should be set when axis_size > 0");
            }

            Ok(Array::from_vec(result_data).reshape(&out_shape))
        }
    }
}

/// Find the minimum values along an axis
///
/// # Parameters
///
/// * `array` - Input array
/// * `axis` - Axis along which to find minimum values. If None, the minimum of the flattened array
/// * `keepdims` - If true, the axes which are reduced are left in the result as dimensions with size one
///
/// # Returns
///
/// Array containing minimum values
pub fn min<T>(array: &Array<T>, axis: Option<isize>, keepdims: bool) -> Result<Array<T>>
where
    T: PartialOrd + Clone + Zero,
{
    if array.is_empty() {
        return Err(NumRs2Error::InvalidOperation(
            "Cannot find min of empty array".to_string(),
        ));
    }

    match axis {
        None => {
            // Find min of flattened array
            let data = array.to_vec();
            let min_val =
                data.iter().skip(1).fold(
                    data[0].clone(),
                    |min, x| {
                        if x < &min {
                            x.clone()
                        } else {
                            min
                        }
                    },
                );

            if keepdims {
                let shape = vec![1; array.ndim()];
                Ok(Array::from_vec(vec![min_val]).reshape(&shape))
            } else {
                Ok(Array::from_vec(vec![min_val]))
            }
        }
        Some(ax) => {
            let axis = if ax < 0 {
                (array.ndim() as isize + ax) as usize
            } else {
                ax as usize
            };

            if axis >= array.ndim() {
                return Err(NumRs2Error::DimensionMismatch(format!(
                    "Axis {} out of bounds for array of dimension {}",
                    axis,
                    array.ndim()
                )));
            }

            let shape = array.shape();
            let axis_size = shape[axis];

            // Create output shape
            let mut out_shape = shape.clone();
            if keepdims {
                out_shape[axis] = 1;
            } else {
                out_shape.remove(axis);
            }
            if out_shape.is_empty() {
                out_shape.push(1);
            }

            let out_size: usize = out_shape.iter().product();
            let mut result_data = vec![T::zero(); out_size];

            // Calculate strides
            let mut strides = vec![1; array.ndim()];
            for i in (0..array.ndim() - 1).rev() {
                strides[i] = strides[i + 1] * shape[i + 1];
            }

            // Iterate through output positions
            for out_idx in 0..out_size {
                // Convert flat index to multi-dimensional indices
                let mut indices = vec![0; array.ndim()];
                let mut temp = out_idx;

                for i in 0..array.ndim() {
                    if i < axis {
                        let dim_size = shape[i];
                        indices[i] = temp % dim_size;
                        temp /= dim_size;
                    } else if i > axis || (i == axis && keepdims) {
                        let dim_idx = if keepdims { i } else { i - 1 };
                        if dim_idx < out_shape.len() {
                            let dim_size = out_shape[dim_idx];
                            indices[i] = temp % dim_size;
                            temp /= dim_size;
                        }
                    }
                }

                // Find min along the axis
                let mut min_val = None;

                for j in 0..axis_size {
                    indices[axis] = j;
                    let val = array.get(&indices)?;

                    if min_val.as_ref().is_none_or(|mv| &val < mv) {
                        min_val = Some(val);
                    }
                }

                result_data[out_idx] = min_val.expect("min_val should be set when axis_size > 0");
            }

            Ok(Array::from_vec(result_data).reshape(&out_shape))
        }
    }
}

/// Sum of array elements over a given axis
///
/// # Parameters
///
/// * `array` - Input array
/// * `axis` - Axis along which to sum. If None, sum over flattened array
/// * `keepdims` - If true, the axes which are reduced are left in the result as dimensions with size one
///
/// # Returns
///
/// Array containing sum values
///
/// # Examples
///
/// ```
/// use numrs2::prelude::*;
///
/// let a = Array::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]).reshape(&[2, 3]);
/// let sums = sum(&a, Some(1), false).expect("sum should succeed");
/// assert_eq!(sums.to_vec(), vec![6.0, 15.0]); // sum of each row
/// ```
pub fn sum<T>(array: &Array<T>, axis: Option<isize>, keepdims: bool) -> Result<Array<T>>
where
    T: Float + Clone + Add<Output = T> + Zero,
{
    if array.is_empty() {
        return Ok(if keepdims {
            let shape = if axis.is_none() {
                vec![1; array.ndim()]
            } else {
                let mut shape = array.shape();
                let ax = if let Some(a) = axis {
                    if a < 0 {
                        (array.ndim() as isize + a) as usize
                    } else {
                        a as usize
                    }
                } else {
                    0
                };
                if ax < shape.len() {
                    shape[ax] = 1;
                }
                shape
            };
            Array::zeros(&shape)
        } else {
            Array::zeros(&[1])
        });
    }

    match axis {
        None => {
            // Sum of flattened array
            let data = array.to_vec();
            let sum_val = data.iter().fold(T::zero(), |acc, x| acc + *x);

            if keepdims {
                let shape = vec![1; array.ndim()];
                Ok(Array::from_vec(vec![sum_val]).reshape(&shape))
            } else {
                Ok(Array::from_vec(vec![sum_val]))
            }
        }
        Some(ax) => {
            let axis = if ax < 0 {
                (array.ndim() as isize + ax) as usize
            } else {
                ax as usize
            };

            if axis >= array.ndim() {
                return Err(NumRs2Error::DimensionMismatch(format!(
                    "Axis {} out of bounds for array of dimension {}",
                    axis,
                    array.ndim()
                )));
            }

            let shape = array.shape();
            let axis_size = shape[axis];

            // Create output shape
            let mut out_shape = shape.clone();
            if keepdims {
                out_shape[axis] = 1;
            } else {
                out_shape.remove(axis);
            }
            if out_shape.is_empty() {
                out_shape.push(1);
            }

            let out_size: usize = out_shape.iter().product();
            let mut result_data = vec![T::zero(); out_size];

            // Calculate strides
            let mut strides = vec![1; array.ndim()];
            for i in (0..array.ndim() - 1).rev() {
                strides[i] = strides[i + 1] * shape[i + 1];
            }

            // Iterate through output positions
            for out_idx in 0..out_size {
                // Convert flat index to multi-dimensional indices
                let mut indices = vec![0; array.ndim()];
                let mut temp = out_idx;

                for i in 0..array.ndim() {
                    if i < axis {
                        let dim_size = shape[i];
                        indices[i] = temp % dim_size;
                        temp /= dim_size;
                    } else if i > axis || (i == axis && keepdims) {
                        let dim_idx = if keepdims { i } else { i - 1 };
                        if dim_idx < out_shape.len() {
                            let dim_size = out_shape[dim_idx];
                            indices[i] = temp % dim_size;
                            temp /= dim_size;
                        }
                    }
                }

                // Compute sum along the axis
                let mut sum = T::zero();
                for j in 0..axis_size {
                    indices[axis] = j;
                    sum = sum + array.get(&indices)?;
                }

                result_data[out_idx] = sum;
            }

            Ok(Array::from_vec(result_data).reshape(&out_shape))
        }
    }
}

/// Sort an array along the given axis
///
/// # Parameters
///
/// * `array` - Array to be sorted
/// * `axis` - Axis along which to sort. If None, the array is flattened before sorting
/// * `kind` - Sorting algorithm (currently only supports default stable sort)
/// * `order` - Not used (for NumPy compatibility)
///
/// # Returns
///
/// Sorted array
///
/// # Examples
///
/// ```
/// use numrs2::prelude::*;
///
/// let a = Array::from_vec(vec![3.0, 1.0, 4.0, 1.0, 5.0, 9.0]).reshape(&[2, 3]);
/// let sorted = sort(&a, Some(1), None, None).expect("sort should succeed");
/// assert_eq!(sorted.get(&[0, 0]).expect("valid index"), 1.0);
/// assert_eq!(sorted.get(&[0, 1]).expect("valid index"), 3.0);
/// assert_eq!(sorted.get(&[0, 2]).expect("valid index"), 4.0);
/// ```
pub fn sort<T>(
    array: &Array<T>,
    axis: Option<isize>,
    _kind: Option<&str>,
    _order: Option<&[&str]>,
) -> Result<Array<T>>
where
    T: PartialOrd + Clone + Zero,
{
    if array.is_empty() {
        return Ok(array.clone());
    }

    match axis {
        None => {
            // Sort flattened array
            let mut data = array.to_vec();
            data.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal));
            Ok(Array::from_vec(data))
        }
        Some(ax) => {
            let axis = if ax < 0 {
                (array.ndim() as isize + ax) as usize
            } else {
                ax as usize
            };

            if axis >= array.ndim() {
                return Err(NumRs2Error::DimensionMismatch(format!(
                    "Axis {} out of bounds for array of dimension {}",
                    axis,
                    array.ndim()
                )));
            }

            let shape = array.shape();
            let axis_size = shape[axis];
            let total_size: usize = shape.iter().product();
            let mut result_data = vec![T::zero(); total_size];

            // Calculate strides
            let mut strides = vec![1; array.ndim()];
            for i in (0..array.ndim() - 1).rev() {
                strides[i] = strides[i + 1] * shape[i + 1];
            }

            // Number of sorts to perform
            let n_sorts = total_size / axis_size;

            for sort_idx in 0..n_sorts {
                // Collect values along the axis for this position
                let mut values: Vec<T> = Vec::with_capacity(axis_size);

                // Determine the base indices for this sort
                let mut base_indices = vec![0; array.ndim()];
                let mut temp = sort_idx;

                for i in 0..array.ndim() {
                    if i != axis {
                        let size = shape[i];
                        base_indices[i] = temp % size;
                        temp /= size;
                    }
                }

                // Collect values along the axis
                for j in 0..axis_size {
                    base_indices[axis] = j;
                    values.push(array.get(&base_indices)?);
                }

                // Sort values
                values.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal));

                // Place sorted values in result
                for (k, val) in values.into_iter().enumerate() {
                    base_indices[axis] = k;
                    let flat_idx = base_indices
                        .iter()
                        .enumerate()
                        .map(|(i, &idx)| idx * strides[i])
                        .sum::<usize>();
                    result_data[flat_idx] = val;
                }
            }

            Ok(Array::from_vec(result_data).reshape(&shape))
        }
    }
}

/// Perform an indirect partition along the given axis
///
/// # Parameters
///
/// * `array` - Input array
/// * `kth` - Element index to partition by. The element at this index will be in its final sorted position
/// * `axis` - Axis along which to sort. If None, the array is flattened
/// * `kind` - Selection algorithm (currently only supports default)
/// * `order` - Not used (for NumPy compatibility)
///
/// # Returns
///
/// Array of indices that partition the array
///
/// # Examples
///
/// ```
/// use numrs2::prelude::*;
///
/// let a = Array::from_vec(vec![3.0, 4.0, 2.0, 1.0]);
/// let indices = argpartition(&a, 2, None, None, None).expect("argpartition should succeed");
/// // After partitioning: values at indices[0] and indices[1] are <= value at indices[2]
/// // and value at indices[3] >= value at indices[2]
/// ```
pub fn argpartition<T>(
    array: &Array<T>,
    kth: usize,
    axis: Option<isize>,
    _kind: Option<&str>,
    _order: Option<&[&str]>,
) -> Result<Array<usize>>
where
    T: PartialOrd + Clone + Zero,
{
    let axis = if let Some(ax) = axis {
        if ax < 0 {
            (array.ndim() as isize + ax) as usize
        } else {
            ax as usize
        }
    } else {
        // If axis is None, flatten the array
        let data = array.to_vec();
        let mut indices: Vec<usize> = (0..data.len()).collect();

        if kth >= data.len() {
            return Err(NumRs2Error::InvalidOperation(format!(
                "kth ({}) out of bounds for array of size {}",
                kth,
                data.len()
            )));
        }

        // Partition the indices
        indices.select_nth_unstable_by(kth, |&a, &b| {
            data[a]
                .partial_cmp(&data[b])
                .unwrap_or(std::cmp::Ordering::Equal)
        });

        return Ok(Array::from_vec(indices));
    };

    if axis >= array.ndim() {
        return Err(NumRs2Error::DimensionMismatch(format!(
            "Axis {} out of bounds for array of dimension {}",
            axis,
            array.ndim()
        )));
    }

    let shape = array.shape();
    let axis_size = shape[axis];

    if kth >= axis_size {
        return Err(NumRs2Error::InvalidOperation(format!(
            "kth ({}) out of bounds for axis {} of size {}",
            kth, axis, axis_size
        )));
    }

    // The output has the same shape as input
    let total_size: usize = shape.iter().product();
    let mut result_data = vec![0_usize; total_size];

    // Calculate strides
    let mut strides = vec![1; array.ndim()];
    for i in (0..array.ndim() - 1).rev() {
        strides[i] = strides[i + 1] * shape[i + 1];
    }

    // Number of partitions to perform
    let n_partitions = total_size / axis_size;

    for part_idx in 0..n_partitions {
        // Collect values along the axis for this position
        let mut values_with_indices: Vec<(T, usize)> = Vec::with_capacity(axis_size);

        // Determine the base indices for this partition
        let mut base_indices = vec![0; array.ndim()];
        let mut temp = part_idx;

        for i in 0..array.ndim() {
            if i != axis {
                let size = shape[i];
                base_indices[i] = temp % size;
                temp /= size;
            }
        }

        // Collect values along the axis
        for j in 0..axis_size {
            base_indices[axis] = j;
            let val = array.get(&base_indices)?;
            values_with_indices.push((val, j));
        }

        // Create indices array
        let mut indices: Vec<usize> = (0..axis_size).collect();

        // Partition by kth element
        indices.select_nth_unstable_by(kth, |&a, &b| {
            values_with_indices[a]
                .0
                .partial_cmp(&values_with_indices[b].0)
                .unwrap_or(std::cmp::Ordering::Equal)
        });

        // Place partitioned indices in result
        for (k, &idx) in indices.iter().enumerate() {
            base_indices[axis] = k;
            let flat_idx = base_indices
                .iter()
                .enumerate()
                .map(|(i, &idx)| idx * strides[i])
                .sum::<usize>();
            result_data[flat_idx] = values_with_indices[idx].1;
        }
    }

    Ok(Array::from_vec(result_data).reshape(&shape))
}

/// Round array elements to the nearest integer
///
/// # Parameters
///
/// * `array` - Input array
///
/// # Returns
///
/// Array with rounded values
///
/// # Examples
///
/// ```
/// use numrs2::prelude::*;
/// use numrs2::math::round;
///
/// let a = Array::from_vec(vec![1.5, 2.3, 3.7, 4.5]);
/// let rounded = round(&a).expect("round failed");
/// assert_eq!(rounded.to_vec(), vec![2.0, 2.0, 4.0, 5.0]);
/// ```
pub fn round<T>(array: &Array<T>) -> Result<Array<T>>
where
    T: Float + Clone,
{
    Ok(array.map(|x| x.round()))
}

/// Alias for cumsum - Return the cumulative sum of array elements
pub fn cumulative_sum<T>(
    array: &Array<T>,
    axis: Option<isize>,
    _out: Option<&mut Array<T>>,
) -> Result<Array<T>>
where
    T: Float + Clone + Add<Output = T> + Send + Sync + 'static,
{
    cumsum(array, axis, _out)
}

/// Alias for cumprod - Return the cumulative product of array elements
pub fn cumulative_prod<T>(
    array: &Array<T>,
    axis: Option<isize>,
    _out: Option<&mut Array<T>>,
) -> Result<Array<T>>
where
    T: Float + Clone + Mul<Output = T> + Send + Sync,
{
    cumprod(array, axis, _out)
}