vortex_array/array/
statistics.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_scalar::Scalar;
5
6use crate::Array;
7use crate::compute::{Cost, IsConstantOpts, is_constant_opts};
8
9impl dyn Array {
10    pub fn is_constant(&self) -> bool {
11        let opts = IsConstantOpts {
12            cost: Cost::Specialized,
13        };
14        is_constant_opts(self, &opts)
15            .inspect_err(|e| log::warn!("Failed to compute IsConstant: {e}"))
16            .ok()
17            .flatten()
18            .unwrap_or_default()
19    }
20
21    pub fn is_constant_opts(&self, cost: Cost) -> bool {
22        let opts = IsConstantOpts { cost };
23        is_constant_opts(self, &opts)
24            .inspect_err(|e| log::warn!("Failed to compute IsConstant: {e}"))
25            .ok()
26            .flatten()
27            .unwrap_or_default()
28    }
29
30    pub fn as_constant(&self) -> Option<Scalar> {
31        self.is_constant().then(|| self.scalar_at(0).ok()).flatten()
32    }
33}