rusty_tree/helpers.rs
1//! This module contains useful helper functions.
2
3use ndarray::{ArrayView2, Axis};
4use num;
5use rusty_kernel_tools::RealType;
6
7
8/// Compute the bounds of a (3, N) array
9///
10/// This function returns a (3, 2) array `bounds`, where `bounds[i][0]`
11/// is the lower bound along the ith axis, and `bounds[i][1]` is the
12/// upper bound along the jth axis.
13///
14/// # Arguments
15///
16/// * `arr` - A (3, N) array.
17///
18pub fn compute_bounds<T: RealType>(arr: ArrayView2<T>) -> [[T; 2]; 3] {
19 let mut bounds: [[T; 2]; 3] = [[num::traits::zero(); 2]; 3];
20
21 arr.axis_iter(Axis(0)).enumerate().for_each(|(i, axis)| {
22 bounds[i][0] = axis.iter().copied().reduce(T::min).unwrap();
23 bounds[i][1] = axis.iter().copied().reduce(T::max).unwrap()
24 });
25
26 bounds
27}
28