diff -r 6105b5cd8d89 -r f0e8704d3f0e src/measures/delta.rs --- a/src/measures/delta.rs Tue Aug 01 10:25:09 2023 +0300 +++ b/src/measures/delta.rs Mon Feb 17 13:54:53 2025 -0500 @@ -7,8 +7,9 @@ use crate::types::*; use std::ops::{Div, Mul, DivAssign, MulAssign, Neg}; use serde::ser::{Serialize, Serializer, SerializeStruct}; -use alg_tools::norms::{Norm, Dist}; -use alg_tools::linops::{Apply, Linear}; +use alg_tools::norms::Norm; +use alg_tools::linops::{Mapping, Linear}; +use alg_tools::instance::{Instance, Space}; /// Representation of a delta measure. /// @@ -50,43 +51,50 @@ } -impl Measure for DeltaMeasure { +impl Measure for DeltaMeasure { type Domain = Domain; } -impl Norm for DeltaMeasure { +impl Norm for DeltaMeasure { #[inline] fn norm(&self, _ : Radon) -> F { self.α.abs() } } -impl Dist for DeltaMeasure { +// impl Dist for DeltaMeasure { +// #[inline] +// fn dist(&self, other : &Self, _ : Radon) -> F { +// if self.x == other. x { +// (self.α - other.α).abs() +// } else { +// self.α.abs() + other.α.abs() +// } +// } +// } + +impl Mapping for DeltaMeasure +where + Domain : Space, + G::Codomain : Mul, + G : Mapping + Clone + Space, + for<'b> &'b Domain : Instance, +{ + type Codomain = G::Codomain; + #[inline] - fn dist(&self, other : &Self, _ : Radon) -> F { - if self.x == other. x { - (self.α - other.α).abs() - } else { - self.α.abs() + other.α.abs() - } + fn apply>(&self, g : I) -> Self::Codomain { + g.eval(|g̃| g̃.apply(&self.x) * self.α) } } -impl<'b, Domain, G, F : Num, V : Mul> Apply for DeltaMeasure -where G: for<'a> Apply<&'a Domain, Output = V>, - V : Mul { - type Output = V; - - #[inline] - fn apply(&self, g : G) -> Self::Output { - g.apply(&self.x) * self.α - } -} - -impl> Linear for DeltaMeasure -where G: for<'a> Apply<&'a Domain, Output = V> { - type Codomain = V; -} +impl Linear for DeltaMeasure +where + Domain : Space, + G::Codomain : Mul, + G : Mapping + Clone + Space, + for<'b> &'b Domain : Instance, +{ } // /// Partial blanket implementation of [`DeltaMeasure`] as a linear functional of [`Mapping`]s. // /// A full blanket implementation is not possible due to annoying Rust limitations: only [`Apply`] @@ -141,12 +149,13 @@ } } -/*impl From<(F, F)> for DeltaMeasure, F> { +impl<'a, Domain : Clone, F : Num> From<&'a DeltaMeasure> for DeltaMeasure { #[inline] - fn from((x, α) : (F, F)) -> Self { - DeltaMeasure{x: Loc([x]), α: α} + fn from(d : &'a DeltaMeasure) -> Self { + d.clone() } -}*/ +} + impl DeltaMeasure { /// Set the mass of the spike. @@ -186,6 +195,26 @@ } } +impl IntoIterator for DeltaMeasure { + type Item = Self; + type IntoIter = std::iter::Once; + + #[inline] + fn into_iter(self) -> Self::IntoIter { + std::iter::once(self) + } +} + +impl<'a, Domain, F : Num> IntoIterator for &'a DeltaMeasure { + type Item = Self; + type IntoIter = std::iter::Once; + + #[inline] + fn into_iter(self) -> Self::IntoIter { + std::iter::once(self) + } +} + macro_rules! make_delta_scalarop_rhs { ($trait:ident, $fn:ident, $trait_assign:ident, $fn_assign:ident) => {