diff -r 9738b51d90d7 -r 4f468d35fa29 src/kernels/linear.rs --- a/src/kernels/linear.rs Sun Apr 27 15:03:51 2025 -0500 +++ b/src/kernels/linear.rs Thu Feb 26 11:38:43 2026 -0500 @@ -1,94 +1,82 @@ //! Implementation of the linear function +use alg_tools::bisection_tree::Support; +use alg_tools::bounds::{Bounded, Bounds, GlobalAnalysis, LocalAnalysis}; +use alg_tools::loc::Loc; +use alg_tools::norms::*; +use alg_tools::sets::Cube; +use alg_tools::types::*; use numeric_literals::replace_float_literals; use serde::Serialize; -use alg_tools::types::*; -use alg_tools::norms::*; -use alg_tools::loc::Loc; -use alg_tools::sets::Cube; -use alg_tools::bisection_tree::{ - Support, - Bounds, - LocalAnalysis, - GlobalAnalysis, - Bounded, -}; -use alg_tools::mapping::{Mapping, Instance}; + +use alg_tools::euclidean::Euclidean; +use alg_tools::mapping::{Instance, Mapping}; use alg_tools::maputil::array_init; -use alg_tools::euclidean::Euclidean; /// Representation of the hat function $f(x)=1-\\|x\\|\_1/ε$ of `width` $ε$ on $ℝ^N$. -#[derive(Copy,Clone,Serialize,Debug,Eq,PartialEq)] -pub struct Linear { +#[derive(Copy, Clone, Serialize, Debug, Eq, PartialEq)] +pub struct Linear { /// The parameter $ε>0$. - pub v : Loc, + pub v: Loc, } #[replace_float_literals(F::cast_from(literal))] -impl Mapping> for Linear { +impl Mapping> for Linear { type Codomain = F; #[inline] - fn apply>>(&self, x : I) -> Self::Codomain { + fn apply>>(&self, x: I) -> Self::Codomain { x.eval(|x| self.v.dot(x)) } } - #[replace_float_literals(F::cast_from(literal))] -impl<'a, F : Float, const N : usize> Support for Linear { +impl<'a, F: Float, const N: usize> Support for Linear { #[inline] - fn support_hint(&self) -> Cube { + fn support_hint(&self) -> Cube { array_init(|| [F::NEG_INFINITY, F::INFINITY]).into() } #[inline] - fn in_support(&self, _x : &Loc) -> bool { + fn in_support(&self, _x: &Loc) -> bool { true } - + /*fn fully_in_support(&self, _cube : &Cube) -> bool { todo!("Not implemented, but not used at the moment") }*/ #[inline] - fn bisection_hint(&self, _cube : &Cube) -> [Option; N] { + fn bisection_hint(&self, _cube: &Cube) -> [Option; N] { [None; N] } } - #[replace_float_literals(F::cast_from(literal))] -impl<'a, F : Float, const N : usize> -GlobalAnalysis> -for Linear { +impl<'a, F: Float, const N: usize> GlobalAnalysis> for Linear { #[inline] fn global_analysis(&self) -> Bounds { Bounds(F::NEG_INFINITY, F::INFINITY) } } -impl<'a, F : Float, const N : usize> -LocalAnalysis, N> -for Linear { +impl<'a, F: Float, const N: usize> LocalAnalysis, N> for Linear { #[inline] - fn local_analysis(&self, cube : &Cube) -> Bounds { - let (lower, upper) = cube.iter_corners() - .map(|x| self.apply(x)) - .fold((F::INFINITY, F::NEG_INFINITY), |(lower, upper), v| { - (lower.min(v), upper.max(v)) - }); + fn local_analysis(&self, cube: &Cube) -> Bounds { + let (lower, upper) = cube + .iter_corners() + .map(|x| self.apply(x)) + .fold((F::INFINITY, F::NEG_INFINITY), |(lower, upper), v| { + (lower.min(v), upper.max(v)) + }); Bounds(lower, upper) } } #[replace_float_literals(F::cast_from(literal))] -impl<'a, F : Float, const N : usize> -Norm -for Linear { +impl<'a, F: Float, const N: usize> Norm for Linear { #[inline] - fn norm(&self, _ : Linfinity) -> F { + fn norm(&self, _: Linfinity) -> F { self.bounds().upper() } } -