src/kernels/hat.rs

branch
dev
changeset 35
b087e3eab191
parent 0
eb3c7813b67a
child 38
0f59c0d02e13
--- a/src/kernels/hat.rs	Thu Aug 29 00:00:00 2024 -0500
+++ b/src/kernels/hat.rs	Tue Dec 31 09:25:45 2024 -0500
@@ -14,8 +14,9 @@
     GlobalAnalysis,
     Bounded,
 };
-use alg_tools::mapping::Apply;
-use alg_tools::maputil::{array_init};
+use alg_tools::mapping::{Mapping, Instance};
+use alg_tools::maputil::array_init;
+use crate::types::Lipschitz;
 
 /// Representation of the hat function $f(x)=1-\\|x\\|\_1/ε$ of `width` $ε$ on $ℝ^N$.
 #[derive(Copy,Clone,Serialize,Debug,Eq,PartialEq)]
@@ -25,26 +26,17 @@
 }
 
 #[replace_float_literals(C::Type::cast_from(literal))]
-impl<'a, C : Constant, const N : usize> Apply<&'a Loc<C::Type, N>> for Hat<C, N> {
-    type Output = C::Type;
+impl<'a, C : Constant, const N : usize> Mapping<Loc<C::Type, N>> for Hat<C, N> {
+    type Codomain = C::Type;
+
     #[inline]
-    fn apply(&self, x : &'a Loc<C::Type, N>) -> Self::Output {
+    fn apply<I : Instance<Loc<C::Type, N>>>(&self, x : I) -> Self::Codomain {
         let ε = self.width.value();
-        0.0.max(1.0-x.norm(L1)/ε)
+        0.0.max(1.0-x.cow().norm(L1)/ε)
     }
 }
 
 #[replace_float_literals(C::Type::cast_from(literal))]
-impl<C : Constant, const N : usize> Apply<Loc<C::Type, N>> for Hat<C, N> {
-    type Output = C::Type;
-    #[inline]
-    fn apply(&self, x : Loc<C::Type, N>) -> Self::Output {
-        self.apply(&x)
-    }
-}
-
-
-#[replace_float_literals(C::Type::cast_from(literal))]
 impl<'a, C : Constant, const N : usize> Support<C::Type, N> for Hat<C, N> {
     #[inline]
     fn support_hint(&self) -> Cube<C::Type,N> {
@@ -94,6 +86,26 @@
     }
 }
 
+#[replace_float_literals(C::Type::cast_from(literal))]
+impl<'a, C : Constant, const N : usize> Lipschitz<L1> for Hat<C, N> {
+    type FloatType = C::Type;
+
+    fn lipschitz_factor(&self, _l1 : L1) -> Option<C::Type> {
+        Some(1.0/self.width.value())
+    }
+}
+
+#[replace_float_literals(C::Type::cast_from(literal))]
+impl<'a, C : Constant, const N : usize> Lipschitz<L2> for Hat<C, N> {
+    type FloatType = C::Type;
+
+    fn lipschitz_factor(&self, _l2 : L2) -> Option<C::Type> {
+        self.lipschitz_factor(L1).map(|l1|
+            <L2 as Dominated<C::Type, L1, Loc<C::Type,N>>>::from_norm(&L2, l1, L1)
+        )
+    }
+}
+
 impl<'a, C : Constant, const N : usize>
 LocalAnalysis<C::Type, Bounds<C::Type>, N>
 for Hat<C, N> {

mercurial