# HG changeset patch # User Tuomo Valkonen # Date 1756912108 18000 # Node ID fd9dba51afd3cb5386c86a951ca24e12e1cacfc2 # Parent b4a47e8e80d13329c46d45c8649c5f80377d5a42 OwnedSpace -> Principal diff -r b4a47e8e80d1 -r fd9dba51afd3 src/bisection_tree/btfn.rs --- a/src/bisection_tree/btfn.rs Wed Sep 03 09:52:30 2025 -0500 +++ b/src/bisection_tree/btfn.rs Wed Sep 03 10:08:28 2025 -0500 @@ -66,7 +66,7 @@ G::SupportType: LocalAnalysis, BT: BTImpl, { - type OwnedSpace = Self; + type Principal = Self; type Decomp = BasicDecomposition; } diff -r b4a47e8e80d1 -r fd9dba51afd3 src/convex.rs --- a/src/convex.rs Wed Sep 03 09:52:30 2025 -0500 +++ b/src/convex.rs Wed Sep 03 10:08:28 2025 -0500 @@ -57,7 +57,7 @@ /// The conjugate type has to implement [`ConvexMapping`], but a `Conjugable` mapping need /// not be convex. pub trait Prox: Mapping { - type Prox<'a>: Mapping + type Prox<'a>: Mapping where Self: 'a; @@ -65,15 +65,15 @@ fn prox_mapping(&self, τ: Self::Codomain) -> Self::Prox<'_>; /// Calculate the proximal mapping with weight τ - fn prox>(&self, τ: Self::Codomain, z: I) -> Domain::OwnedSpace { + fn prox>(&self, τ: Self::Codomain, z: I) -> Domain::Principal { self.prox_mapping(τ).apply(z) } /// Calculate the proximal mapping with weight τ in-place - fn prox_mut<'b>(&self, τ: Self::Codomain, y: &'b mut Domain::OwnedSpace) + fn prox_mut<'b>(&self, τ: Self::Codomain, y: &'b mut Domain::Principal) where Domain::Decomp: DecompositionMut, - for<'a> &'a Domain::OwnedSpace: Instance, + for<'a> &'a Domain::Principal: Instance, { *y = self.prox(τ, &*y); } @@ -98,7 +98,7 @@ impl Mapping for NormConstraint where Domain: Space, - Domain::OwnedSpace: Norm, + Domain::Principal: Norm, F: Float, E: NormExponent, { @@ -127,7 +127,7 @@ E: HasDualExponent, F: Float, Domain: HasDual, - Domain::OwnedSpace: Norm, + Domain::Principal: Norm, >::DualSpace: Norm, { type Conjugate<'a> @@ -146,7 +146,7 @@ E: HasDualExponent, F: Float, Domain: HasDual, - Domain::OwnedSpace: Norm, + Domain::Principal: Norm, >::DualSpace: Norm, { type Conjugate<'a> @@ -165,10 +165,10 @@ impl Prox for NormConstraint where Domain: Space, - Domain::OwnedSpace: Norm, + Domain::Principal: Norm, E: NormExponent, F: Float, - NormProjection: Mapping, + NormProjection: Mapping, { type Prox<'a> = NormProjection @@ -206,11 +206,11 @@ impl Mapping for NormProjection where Domain: Space, - Domain::OwnedSpace: ClosedSpace + Projection, + Domain::Principal: ClosedSpace + Projection, F: Float, E: NormExponent, { - type Codomain = Domain::OwnedSpace; + type Codomain = Domain::Principal; fn apply>(&self, d: I) -> Self::Codomain { d.own().proj_ball(self.radius, self.exponent) @@ -253,7 +253,7 @@ impl Preconjugable for Zero where Domain: Normed, - Predual: HasDual, + Predual: HasDual, { type Preconjugate<'a> = ZeroIndicator @@ -292,7 +292,7 @@ where F: Float, Domain: Space, - Domain::OwnedSpace: Normed, + Domain::Principal: Normed, { type Codomain = F; @@ -305,7 +305,7 @@ impl ConvexMapping for ZeroIndicator where Domain: Space, - Domain::OwnedSpace: Normed, + Domain::Principal: Normed, { fn factor_of_strong_convexity(&self) -> F { F::INFINITY @@ -315,7 +315,7 @@ impl Conjugable for ZeroIndicator where Domain: HasDual, - Domain::Owned: Normed, + Domain::PrincipalV: Normed, { type Conjugate<'a> = Zero @@ -331,7 +331,7 @@ impl Preconjugable for ZeroIndicator where Domain: Space, - Domain::OwnedSpace: Normed, + Domain::Principal: Normed, Predual: HasDual, { type Preconjugate<'a> @@ -347,7 +347,7 @@ impl Prox for ZeroIndicator where - Domain: AXPY + Normed, + Domain: AXPY + Normed, F: Float, { type Prox<'a> @@ -430,7 +430,7 @@ F: Float, X: Euclidean, { - type Derivative = X::Owned; + type Derivative = X::PrincipalV; fn differential_impl>(&self, x: I) -> Self::Derivative { x.into_owned() diff -r b4a47e8e80d1 -r fd9dba51afd3 src/direct_product.rs --- a/src/direct_product.rs Wed Sep 03 09:52:30 2025 -0500 +++ b/src/direct_product.rs Wed Sep 03 10:08:28 2025 -0500 @@ -311,7 +311,7 @@ // + for<'b> SubAssign<&'b Self> // + Neg, { - type OwnedEuclidean = Pair; + type PrincipalE = Pair; fn dot>(&self, other: I) -> F { other.eval_decompose(|Pair(u, v)| self.0.dot(u) + self.1.dot(v)) @@ -333,10 +333,10 @@ F: Num, { type Field = F; - type Owned = Pair; + type PrincipalV = Pair; /// Return a similar zero as `self`. - fn similar_origin(&self) -> Self::Owned { + fn similar_origin(&self) -> Self::PrincipalV { Pair(self.0.similar_origin(), self.1.similar_origin()) } @@ -389,7 +389,7 @@ pub struct PairDecomposition(D, Q); impl Space for Pair { - type OwnedSpace = Pair; + type Principal = Pair; type Decomp = PairDecomposition; } @@ -449,7 +449,7 @@ } #[inline] - fn cow<'b>(self) -> MyCow<'b, Pair> + fn cow<'b>(self) -> MyCow<'b, Pair> where Self: 'b, { @@ -457,7 +457,7 @@ } #[inline] - fn own(self) -> Pair { + fn own(self) -> Pair { Pair(self.0.own(), self.1.own()) } } @@ -500,7 +500,7 @@ } #[inline] - fn cow<'b>(self) -> MyCow<'b, Pair> + fn cow<'b>(self) -> MyCow<'b, Pair> where Self: 'b, { @@ -508,7 +508,7 @@ } #[inline] - fn own(self) -> Pair { + fn own(self) -> Pair { let Pair(ref u, ref v) = self; Pair(u.own(), v.own()) } @@ -601,7 +601,7 @@ { type DualSpace = Pair; - fn dual_origin(&self) -> ::Owned { + fn dual_origin(&self) -> ::PrincipalV { Pair(self.0.dual_origin(), self.1.dual_origin()) } } diff -r b4a47e8e80d1 -r fd9dba51afd3 src/euclidean.rs --- a/src/euclidean.rs Wed Sep 03 09:52:30 2025 -0500 +++ b/src/euclidean.rs Wed Sep 03 10:08:28 2025 -0500 @@ -18,10 +18,11 @@ /// as an inner product. // TODO: remove F parameter, use VectorSpace::Field pub trait Euclidean: - VectorSpace - + Reflexive + VectorSpace + Reflexive { - type OwnedEuclidean: ClosedEuclidean; + /// Principal form of the space; always equal to [`Space::Principal`] and + /// [`VectorSpace::PrincipalV`], but with more traits guaranteed. + type PrincipalE: ClosedEuclidean; // Inner product fn dot>(&self, other: I) -> F; @@ -56,7 +57,7 @@ /// Projection to the 2-ball. #[inline] - fn proj_ball2(self, ρ: F) -> Self::Owned { + fn proj_ball2(self, ρ: F) -> Self::PrincipalV { let r = self.norm2(); if r > ρ { self * (ρ / r) @@ -67,10 +68,10 @@ } pub trait ClosedEuclidean: - Instance + Euclidean + Instance + Euclidean { } -impl + Euclidean> ClosedEuclidean for X {} +impl + Euclidean> ClosedEuclidean for X {} // TODO: remove F parameter, use AXPY::Field pub trait EuclideanMut: Euclidean + AXPY { @@ -89,5 +90,5 @@ /// Trait for [`Euclidean`] spaces with dimensions known at compile time. pub trait StaticEuclidean: Euclidean { /// Returns the origin - fn origin() -> ::Owned; + fn origin() -> ::PrincipalV; } diff -r b4a47e8e80d1 -r fd9dba51afd3 src/instance.rs --- a/src/instance.rs Wed Sep 03 09:52:30 2025 -0500 +++ b/src/instance.rs Wed Sep 03 10:08:28 2025 -0500 @@ -113,8 +113,9 @@ } /// Trait for abitrary mathematical spaces. -pub trait Space: Ownable + Sized { - type OwnedSpace: ClosedSpace; +pub trait Space: Ownable + Sized { + /// Principal, typically owned realisation of the space. + type Principal: ClosedSpace; /// Default decomposition for the space type Decomp: Decomposition; @@ -131,8 +132,8 @@ /// Helper trait for working with closed spaces, operations in which should /// return members of the same space -pub trait ClosedSpace: Space + Owned + Instance {} -impl + Owned + Instance> ClosedSpace for X {} +pub trait ClosedSpace: Space + Owned + Instance {} +impl + Owned + Instance> ClosedSpace for X {} #[macro_export] macro_rules! impl_basic_space { @@ -141,7 +142,7 @@ }; ($type:ty where $($where:tt)*) => { impl<$($where)*> $crate::instance::Space for $type { - type OwnedSpace = Self; + type Principal = Self; type Decomp = $crate::instance::BasicDecomposition; } @@ -215,7 +216,7 @@ /// /// This is used, for example, by [`crate::mapping::Mapping::apply`]. pub trait Instance::Decomp>: - Sized + Ownable + Sized + Ownable where X: Space, D: Decomposition, @@ -235,7 +236,7 @@ Self: 'b; /// Returns an owned instance of `X`, cloning or converting non-true instances when necessary. - fn own(self) -> X::OwnedSpace { + fn own(self) -> X::Principal { self.into_owned() } @@ -244,7 +245,7 @@ /// Returns an owned instance or reference to `X`, converting non-true instances when necessary. /// /// Default implementation uses [`Self::own`]. Consumes the input. - fn cow<'b>(self) -> MyCow<'b, X::OwnedSpace> + fn cow<'b>(self) -> MyCow<'b, X::Principal> where Self: 'b, { @@ -255,7 +256,7 @@ /// Evaluates `f` on a reference to self. /// /// Default implementation uses [`Self::cow`]. Consumes the input. - fn eval<'b, R>(self, f: impl FnOnce(&X::OwnedSpace) -> R) -> R + fn eval<'b, R>(self, f: impl FnOnce(&X::Principal) -> R) -> R where X: 'b, Self: 'b, @@ -269,8 +270,8 @@ /// Default implementation uses [`Self::cow`]. Consumes the input. fn either<'b, R>( self, - f: impl FnOnce(X::OwnedSpace) -> R, - g: impl FnOnce(&X::OwnedSpace) -> R, + f: impl FnOnce(X::Principal) -> R, + g: impl FnOnce(&X::Principal) -> R, ) -> R where Self: 'b, diff -r b4a47e8e80d1 -r fd9dba51afd3 src/linops.rs --- a/src/linops.rs Wed Sep 03 09:52:30 2025 -0500 +++ b/src/linops.rs Wed Sep 03 10:08:28 2025 -0500 @@ -28,35 +28,39 @@ /// Vector spaces #[replace_float_literals(Self::Field::cast_from(literal))] pub trait VectorSpace: - Space - + Mul - + Div - + Add - + Add - + Sub - + Sub + Space + + Mul + + Div + + Add + + Add + + Sub + + Sub + Neg - + for<'b> Add<&'b Self, Output = ::Owned> - + for<'b> Sub<&'b Self, Output = ::Owned> + + for<'b> Add<&'b Self, Output = ::PrincipalV> + + for<'b> Sub<&'b Self, Output = ::PrincipalV> { + /// Underlying scalar field type Field: Num; - type Owned: ClosedSpace + + /// Principal form of the space; always equal to [`Space::Principal`], but with + /// more traits guaranteed. + type PrincipalV: ClosedSpace + AXPY< Self, Field = Self::Field, - Owned = Self::Owned, - OwnedVariant = Self::Owned, - OwnedSpace = Self::Owned, + PrincipalV = Self::PrincipalV, + OwnedVariant = Self::PrincipalV, + Principal = Self::PrincipalV, >; /// Return a similar zero as `self`. - fn similar_origin(&self) -> Self::Owned; + fn similar_origin(&self) -> Self::PrincipalV; // { // self.make_origin_generator().make_origin() // } /// Return a similar zero as `x`. - fn similar_origin_inst>(x: I) -> Self::Owned { + fn similar_origin_inst>(x: I) -> Self::PrincipalV { x.eval(|xr| xr.similar_origin()) } } @@ -68,9 +72,9 @@ + MulAssign + DivAssign + AddAssign - + AddAssign + + AddAssign + SubAssign - + SubAssign + + SubAssign + for<'b> AddAssign<&'b Self> + for<'b> SubAssign<&'b Self> where @@ -93,8 +97,8 @@ fn set_zero(&mut self); } -pub trait ClosedVectorSpace: Instance + VectorSpace {} -impl + VectorSpace> ClosedVectorSpace for X {} +pub trait ClosedVectorSpace: Instance + VectorSpace {} +impl + VectorSpace> ClosedVectorSpace for X {} /// Efficient in-place application for [`Linear`] operators. #[replace_float_literals(F::cast_from(literal))] @@ -197,7 +201,7 @@ } impl Mapping for IdOp { - type Codomain = X::OwnedSpace; + type Codomain = X::Principal; fn apply>(&self, x: I) -> Self::Codomain { x.into_owned() @@ -233,10 +237,10 @@ } } -impl Adjointable for IdOp { - type AdjointCodomain = X::OwnedSpace; +impl Adjointable for IdOp { + type AdjointCodomain = X::Principal; type Adjoint<'a> - = IdOp + = IdOp where X: 'a; @@ -245,10 +249,10 @@ } } -impl Preadjointable for IdOp { - type PreadjointCodomain = X::OwnedSpace; +impl Preadjointable for IdOp { + type PreadjointCodomain = X::Principal; type Preadjoint<'a> - = IdOp + = IdOp where X: 'a; @@ -262,9 +266,9 @@ pub struct SimpleZeroOp; impl Mapping for SimpleZeroOp { - type Codomain = X::Owned; + type Codomain = X::PrincipalV; - fn apply>(&self, x: I) -> X::Owned { + fn apply>(&self, x: I) -> X::PrincipalV { X::similar_origin_inst(x) } } @@ -323,7 +327,7 @@ where Self: 'b; - fn origin(&self) -> Y::Owned; + fn origin(&self) -> Y::PrincipalV; fn as_ref(&self) -> Self::Ref<'_>; } @@ -334,7 +338,7 @@ Self: 'b; #[inline] - fn origin(&self) -> Y::Owned { + fn origin(&self) -> Y::PrincipalV { return self.similar_origin(); } @@ -351,7 +355,7 @@ Self: 'c; #[inline] - fn origin(&self) -> Y::Owned { + fn origin(&self) -> Y::PrincipalV { return self.similar_origin(); } @@ -392,8 +396,8 @@ X: HasDual, Y: HasDual, F: Float, - Xprime: VectorSpace, - Xprime::Owned: AXPY, + Xprime: VectorSpace, + Xprime::PrincipalV: AXPY, Yprime: Space + Instance, { pub fn new_dualisable(y_og: OY, xprime_og: OXprime) -> Self { @@ -412,9 +416,9 @@ F: Float, OY: OriginGenerator, { - type Codomain = Y::Owned; + type Codomain = Y::PrincipalV; - fn apply>(&self, _x: I) -> Y::Owned { + fn apply>(&self, _x: I) -> Y::PrincipalV { self.codomain_origin_generator.origin() } } @@ -432,7 +436,7 @@ impl GEMV for ZeroOp where X: Space, - Y: AXPY, + Y: AXPY, F: Float, OY: OriginGenerator, { @@ -450,7 +454,7 @@ where X: Space + Instance + Norm, Y: VectorSpace, - Y::Owned: Clone, + Y::PrincipalV: Clone, F: Float, E1: NormExponent, E2: NormExponent, @@ -920,10 +924,10 @@ where F: Float, Domain: Space, - Domain::OwnedSpace: Mul, - >::Output: ClosedSpace, + Domain::Principal: Mul, + >::Output: ClosedSpace, { - type Codomain = >::Output; + type Codomain = >::Output; /// Compute the value of `self` at `x`. fn apply>(&self, x: I) -> Self::Codomain { @@ -935,7 +939,7 @@ where F: Float, Domain: Space, - Domain::OwnedSpace: Mul, - >::Output: ClosedSpace, + Domain::Principal: Mul, + >::Output: ClosedSpace, { } diff -r b4a47e8e80d1 -r fd9dba51afd3 src/loc.rs --- a/src/loc.rs Wed Sep 03 09:52:30 2025 -0500 +++ b/src/loc.rs Wed Sep 03 10:08:28 2025 -0500 @@ -456,7 +456,7 @@ domination!(L2, L1); impl Euclidean for Loc { - type OwnedEuclidean = Self; + type PrincipalE = Self; /// This implementation is not stabilised as it's meant to be used for very small vectors. /// Use [`nalgebra`] for larger vectors. @@ -739,7 +739,7 @@ } impl Space for Loc { - type OwnedSpace = Self; + type Principal = Self; type Decomp = BasicDecomposition; } @@ -755,7 +755,7 @@ impl VectorSpace for Loc { type Field = F; - type Owned = Self; + type PrincipalV = Self; // #[inline] // fn make_origin_generator(&self) -> StaticEuclideanOriginGenerator { @@ -763,12 +763,12 @@ // } #[inline] - fn similar_origin(&self) -> Self::Owned { + fn similar_origin(&self) -> Self::PrincipalV { Self::ORIGIN } #[inline] - fn similar_origin_inst>(_: I) -> Self::Owned { + fn similar_origin_inst>(_: I) -> Self::PrincipalV { Self::ORIGIN } diff -r b4a47e8e80d1 -r fd9dba51afd3 src/nalgebra_support.rs --- a/src/nalgebra_support.rs Wed Sep 03 09:52:30 2025 -0500 +++ b/src/nalgebra_support.rs Wed Sep 03 10:08:28 2025 -0500 @@ -95,7 +95,7 @@ DefaultAllocator: Allocator, ShapeConstraint: StridesOk + StridesOk, { - type OwnedSpace = OMatrix; + type Principal = OMatrix; type Decomp = MatrixDecomposition; } @@ -270,10 +270,10 @@ ShapeConstraint: StridesOk, { type Field = E; - type Owned = OMatrix; + type PrincipalV = OMatrix; #[inline] - fn similar_origin(&self) -> Self::Owned { + fn similar_origin(&self) -> Self::PrincipalV { let (n, m) = self.shape_generic(); OMatrix::zeros_generic(n, m) } @@ -335,7 +335,7 @@ ShapeConstraint: StridesOk, { #[inline] - fn proj_ball(self, ρ: E, exp: Linfinity) -> ::OwnedSpace { + fn proj_ball(self, ρ: E, exp: Linfinity) -> ::Principal { let mut owned = self.into_owned(); owned.proj_ball_mut(ρ, exp); owned @@ -418,7 +418,7 @@ DefaultAllocator: Allocator, ShapeConstraint: StridesOk, { - type OwnedEuclidean = OVector; + type PrincipalE = OVector; #[inline] fn dot>(&self, other: I) -> E { diff -r b4a47e8e80d1 -r fd9dba51afd3 src/norms.rs --- a/src/norms.rs Wed Sep 03 09:52:30 2025 -0500 +++ b/src/norms.rs Wed Sep 03 10:08:28 2025 -0500 @@ -202,7 +202,7 @@ F: Float, E: NormExponent, Domain: Space, - Domain::OwnedSpace: Norm, + Domain::Principal: Norm, { type Codomain = F; @@ -232,18 +232,18 @@ pub trait HasDual: Normed + VectorSpace { type DualSpace: Normed + ClosedVectorSpace; - fn dual_origin(&self) -> ::Owned; + fn dual_origin(&self) -> ::PrincipalV; } /// Automatically implemented trait for reflexive spaces pub trait Reflexive: HasDual where - Self::DualSpace: HasDual, + Self::DualSpace: HasDual, { } impl> Reflexive for X where - X::DualSpace: HasDual + X::DualSpace: HasDual { } diff -r b4a47e8e80d1 -r fd9dba51afd3 src/sets.rs --- a/src/sets.rs Wed Sep 03 09:52:30 2025 -0500 +++ b/src/sets.rs Wed Sep 03 10:08:28 2025 -0500 @@ -51,8 +51,8 @@ impl Set for $range where U : Space, - U::OwnedSpace : PartialOrd, - Idx : PartialOrd + PartialOrd, + U::Principal : PartialOrd, + Idx : PartialOrd + PartialOrd, { #[inline] fn contains>(&self, item : I) -> bool {