alg_tools update

Sun, 15 Dec 2024 01:10:52 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 15 Dec 2024 01:10:52 -0500
changeset 55
15f01efc034b
parent 54
cfd8d2304e9e
child 56
34f8ec636368

alg_tools update

Cargo.lock file | annotate | diff | comparison | revisions
src/dist.rs file | annotate | diff | comparison | revisions
src/main.rs file | annotate | diff | comparison | revisions
src/scaled.rs file | annotate | diff | comparison | revisions
src/zero.rs file | annotate | diff | comparison | revisions
--- a/Cargo.lock	Sat Dec 07 21:54:59 2024 -0500
+++ b/Cargo.lock	Sun Dec 15 01:10:52 2024 -0500
@@ -24,7 +24,8 @@
  "colored",
  "cpu-time",
  "csv",
- "itertools 0.10.5",
+ "either",
+ "itertools 0.13.0",
  "nalgebra",
  "num",
  "num-traits",
@@ -32,7 +33,6 @@
  "rayon",
  "serde",
  "serde_json",
- "trait-set",
 ]
 
 [[package]]
@@ -421,18 +421,18 @@
 
 [[package]]
 name = "itertools"
-version = "0.10.5"
+version = "0.12.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
+checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
 dependencies = [
  "either",
 ]
 
 [[package]]
 name = "itertools"
-version = "0.12.1"
+version = "0.13.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
+checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
 dependencies = [
  "either",
 ]
@@ -545,9 +545,9 @@
 
 [[package]]
 name = "nalgebra"
-version = "0.31.4"
+version = "0.33.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "20bd243ab3dbb395b39ee730402d2e5405e448c75133ec49cc977762c4cba3d1"
+checksum = "26aecdf64b707efd1310e3544d709c5c0ac61c13756046aaaba41be5c4f66a3b"
 dependencies = [
  "approx",
  "matrixmultiply",
@@ -561,13 +561,13 @@
 
 [[package]]
 name = "nalgebra-macros"
-version = "0.1.0"
+version = "0.2.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "01fcc0b8149b4632adc89ac3b7b31a12fb6099a0317a4eb2ebff574ef7de7218"
+checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 1.0.109",
+ "syn 2.0.90",
 ]
 
 [[package]]
@@ -1006,9 +1006,9 @@
 
 [[package]]
 name = "simba"
-version = "0.7.3"
+version = "0.9.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2f3fd720c48c53cace224ae62bef1bbff363a70c68c4802a78b5cc6159618176"
+checksum = "b3a386a501cd104797982c15ae17aafe8b9261315b5d07e3ec803f2ea26be0fa"
 dependencies = [
  "approx",
  "num-complex",
@@ -1145,17 +1145,6 @@
 ]
 
 [[package]]
-name = "trait-set"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "875c4c873cc824e362fa9a9419ffa59807244824275a44ad06fec9684fff08f2"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 1.0.109",
-]
-
-[[package]]
 name = "typenum"
 version = "1.17.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
--- a/src/dist.rs	Sat Dec 07 21:54:59 2024 -0500
+++ b/src/dist.rs	Sun Dec 15 01:10:52 2024 -0500
@@ -2,7 +2,7 @@
 Implementations of the distance function and the distance function squared, on manifolds.
 */
 
-use alg_tools::mapping::Apply;
+use alg_tools::mapping::{Mapping, Instance};
 use alg_tools::euclidean::Euclidean;
 use crate::manifold::ManifoldPoint;
 use crate::fb::{Grad, Desc, Prox};
@@ -10,39 +10,22 @@
 /// Structure for distance-to functions
 pub struct DistTo<M : ManifoldPoint>(pub M);
 
-impl<M : ManifoldPoint> Apply<M> for DistTo<M> {
-    type Output = f64;
+impl<M : ManifoldPoint> Mapping<M> for DistTo<M> {
+    type Codomain = f64;
 
-    fn apply(&self, x : M) -> Self::Output {
-        self.0.dist_to(&x)
-    }
-}
-
-impl<'a, M : ManifoldPoint> Apply<&'a M> for DistTo<M> {
-    type Output = f64;
-
-    fn apply(&self, x : &'a M) -> Self::Output {
-        self.0.dist_to(x)
+    fn apply<I : Instance<M>>(&self, x : I) -> Self::Codomain {
+        x.eval(|x̃| self.0.dist_to(x̃))
     }
 }
 
 /// Structure for distance-to functions
 pub struct DistToSquaredDiv2<M : ManifoldPoint>(pub M);
 
-impl<M : ManifoldPoint> Apply<M> for DistToSquaredDiv2<M> {
-    type Output = f64;
+impl<M : ManifoldPoint> Mapping<M> for DistToSquaredDiv2<M> {
+    type Codomain = f64;
 
-    fn apply(&self, x : M) -> Self::Output {
-        let d = self.0.dist_to(&x);
-        d*d / 2.0
-    }
-}
-
-impl<'a, M : ManifoldPoint> Apply<&'a M> for DistToSquaredDiv2<M> {
-    type Output = f64;
-
-    fn apply(&self, x : &'a M) -> Self::Output {
-        let d = self.0.dist_to(x);
+    fn apply<I : Instance<M>>(&self, x : I) -> Self::Codomain {
+        let d = x.eval(|x̃| self.0.dist_to(x̃));
         d*d / 2.0
     }
 }
--- a/src/main.rs	Sat Dec 07 21:54:59 2024 -0500
+++ b/src/main.rs	Sun Dec 15 01:10:52 2024 -0500
@@ -23,9 +23,8 @@
 use alg_tools::lingrid::LinSpace;
 use alg_tools::loc::Loc;
 use alg_tools::types::*;
-use alg_tools::mapping::{Sum, Apply};
+use alg_tools::mapping::{Sum, Mapping};
 use alg_tools::iterate::{AlgIteratorOptions, AlgIteratorFactory, Verbose};
-use alg_tools::mapping::Mapping;
 use image::{ImageFormat, ImageBuffer, Rgb};
 
 use dist::{DistTo, DistToSquaredDiv2};
--- a/src/scaled.rs	Sat Dec 07 21:54:59 2024 -0500
+++ b/src/scaled.rs	Sun Dec 15 01:10:52 2024 -0500
@@ -2,7 +2,7 @@
 Implementation of scaling of functions on a manifold by a scalar.
 */
 
-use alg_tools::mapping::Apply;
+use alg_tools::mapping::{Mapping, Instance};
 use crate::manifold::ManifoldPoint;
 use crate::fb::{Grad, Desc, Prox};
 
@@ -22,10 +22,10 @@
     }
 }
 
-impl<M, G : Apply<M, Output=f64>> Apply<M> for Scaled< G> {
-    type Output = f64;
+impl<M, G : Mapping<M, Codomain=f64>> Mapping<M> for Scaled< G> {
+    type Codomain = f64;
 
-    fn apply(&self, x : M) -> Self::Output {
+    fn apply<I : Instance<M>>(&self, x : I) -> Self::Codomain {
         self.g.apply(x) * self.α
     }
 }
--- a/src/zero.rs	Sat Dec 07 21:54:59 2024 -0500
+++ b/src/zero.rs	Sun Dec 15 01:10:52 2024 -0500
@@ -2,7 +2,7 @@
 Implementation of the the constant zero function on a manifold.
 */
 
-use alg_tools::mapping::Apply;
+use alg_tools::mapping::{Mapping, Instance};
 use crate::manifold::ManifoldPoint;
 use crate::fb::{Grad, Desc, Prox};
 use std::marker::PhantomData;
@@ -19,21 +19,14 @@
     }
 }
 
-impl<M : ManifoldPoint> Apply<M> for ZeroFn<M> {
-    type Output = f64;
+impl<M : ManifoldPoint> Mapping<M> for ZeroFn<M> {
+    type Codomain = f64;
 
-    fn apply(&self, _x : M) -> Self::Output {
+    fn apply<I : Instance<M>>(&self, _x : I) -> Self::Codomain {
         0.0
     }
 }
 
-impl<'a, M : ManifoldPoint> Apply<&'a M> for ZeroFn<M> {
-    type Output = f64;
-
-    fn apply(&self, _x : &'a M) -> Self::Output {
-        0.0
-    }
-}
 
 impl<M : ManifoldPoint> Desc<M> for ZeroFn<M> {
     fn desc(&self, _τ : f64, x : M) -> M {

mercurial