Skip to main content

vortex_tensor/scalar_fns/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Scalar function expressions defined on tensor and tensor-like extension types.
5
6use std::fmt;
7
8pub mod cosine_similarity;
9pub mod inner_product;
10pub mod l2_denorm;
11pub mod l2_norm;
12
13/// Options for tensor-related expressions that might have error.
14#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
15pub enum ApproxOptions {
16    /// Computes the exact result.
17    #[default]
18    Exact,
19    /// Allows approximate results.
20    Approximate,
21}
22
23impl ApproxOptions {
24    /// Returns `true` if the option is [`Exact`](Self::Exact).
25    pub fn is_exact(&self) -> bool {
26        matches!(self, Self::Exact)
27    }
28
29    /// Returns `true` if the option is [`Approximate`](Self::Approximate).
30    pub fn is_approx(&self) -> bool {
31        matches!(self, Self::Approximate)
32    }
33}
34
35impl fmt::Display for ApproxOptions {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        match self {
38            Self::Exact => write!(f, "Exact"),
39            Self::Approximate => write!(f, "Approximate"),
40        }
41    }
42}