vortex_array/array/
statistics.rs1use vortex_scalar::Scalar;
2
3use crate::Array;
4use crate::compute::{IsConstantOpts, is_constant_opts, scalar_at};
5use crate::stats::StatsSetRef;
6
7pub trait ArrayStatistics {
9 fn is_constant(&self) -> bool;
11
12 fn as_constant(&self) -> Option<Scalar>;
14}
15
16impl<A: Array + 'static> ArrayStatistics for A {
17 fn is_constant(&self) -> bool {
18 let opts = IsConstantOpts {
19 canonicalize: false,
20 };
21 is_constant_opts(self, &opts)
22 .inspect_err(|e| log::warn!("Failed to compute IsConstant: {e}"))
23 .ok()
24 .unwrap_or_default()
25 }
26
27 fn as_constant(&self) -> Option<Scalar> {
28 self.is_constant()
29 .then(|| scalar_at(self, 0).ok())
30 .flatten()
31 }
32}
33
34pub trait ArrayStatisticsImpl {
35 fn _stats_ref(&self) -> StatsSetRef<'_>;
36}