Wed, 03 Sep 2025 17:59:24 -0500
No supertraits for Instance
| src/convex.rs | file | annotate | diff | comparison | revisions | |
| src/direct_product.rs | file | annotate | diff | comparison | revisions | |
| src/instance.rs | file | annotate | diff | comparison | revisions | |
| src/linops.rs | file | annotate | diff | comparison | revisions | |
| src/nalgebra_support.rs | file | annotate | diff | comparison | revisions |
--- a/src/convex.rs Wed Sep 03 14:27:21 2025 -0500 +++ b/src/convex.rs Wed Sep 03 17:59:24 2025 -0500 @@ -433,7 +433,7 @@ type Derivative = X::PrincipalV; fn differential_impl<I: Instance<X>>(&self, x: I) -> Self::Derivative { - x.into_owned() + x.own() } }
--- a/src/direct_product.rs Wed Sep 03 14:27:21 2025 -0500 +++ b/src/direct_product.rs Wed Sep 03 17:59:24 2025 -0500 @@ -432,6 +432,7 @@ U: Instance<A, D>, V: Instance<B, Q>, { + #[inline] fn eval_decompose<'b, R>( self, f: impl FnOnce(Pair<D::Decomposition<'b>, Q::Decomposition<'b>>) -> R, @@ -444,6 +445,7 @@ .eval_decompose(|a| self.1.eval_decompose(|b| f(Pair(a, b)))) } + #[inline] fn eval_ref_decompose<'b, R>( &'b self, f: impl FnOnce(Pair<D::Reference<'b>, Q::Reference<'b>>) -> R,
--- a/src/instance.rs Wed Sep 03 14:27:21 2025 -0500 +++ b/src/instance.rs Wed Sep 03 17:59:24 2025 -0500 @@ -321,8 +321,7 @@ /// generalises [`std::borrow::ToOwned`], [`std::borrow::Borrow`], and [`std::borrow::Cow`]. /// /// This is used, for example, by [`crate::mapping::Mapping::apply`]. -pub trait Instance<X, D = <X as Space>::Decomp>: - Sized + Ownable<OwnedVariant = X::Principal> +pub trait Instance<X, D = <X as Space>::Decomp>: Sized where X: Space, D: Decomposition<X>, @@ -342,21 +341,14 @@ Self: 'b; /// Returns an owned instance of `X`, cloning or converting non-true instances when necessary. - fn own(self) -> X::Principal { - self.into_owned() - } - - // ************** automatically implemented methods below from here ************** + fn own(self) -> X::Principal; /// 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::Principal> where - Self: 'b, - { - self.cow_owned() - } + Self: 'b; #[inline] /// Evaluates `f` on a reference to self. @@ -407,6 +399,19 @@ { f(self) } + + #[inline] + fn own(self) -> X::Principal { + self.into_owned() + } + + #[inline] + fn cow<'b>(self) -> MyCow<'b, X::Principal> + where + Self: 'b, + { + self.cow_owned() + } } impl<'a, X: Space> Instance<X, BasicDecomposition> for &'a X { @@ -427,6 +432,19 @@ { f(*self) } + + #[inline] + fn own(self) -> X::Principal { + self.into_owned() + } + + #[inline] + fn cow<'b>(self) -> MyCow<'b, X::Principal> + where + Self: 'b, + { + self.cow_owned() + } } impl<'a, X: Space> Instance<X, BasicDecomposition> for &'a mut X { @@ -447,6 +465,19 @@ { f(*self) } + + #[inline] + fn own(self) -> X::Principal { + self.into_owned() + } + + #[inline] + fn cow<'b>(self) -> MyCow<'b, X::Principal> + where + Self: 'b, + { + self.cow_owned() + } } impl<'a, X: Space> Instance<X, BasicDecomposition> for MyCow<'a, X> { @@ -470,6 +501,19 @@ MyCow::Owned(b) => f(&b), } } + + #[inline] + fn own(self) -> X::Principal { + self.into_owned() + } + + #[inline] + fn cow<'b>(self) -> MyCow<'b, X::Principal> + where + Self: 'b, + { + self.cow_owned() + } } /// Marker type for mutable decompositions to be used with [`InstanceMut`].
--- a/src/linops.rs Wed Sep 03 14:27:21 2025 -0500 +++ b/src/linops.rs Wed Sep 03 17:59:24 2025 -0500 @@ -204,7 +204,7 @@ type Codomain = X::Principal; fn apply<I: Instance<X>>(&self, x: I) -> Self::Codomain { - x.into_owned() + x.own() } }
--- a/src/nalgebra_support.rs Wed Sep 03 14:27:21 2025 -0500 +++ b/src/nalgebra_support.rs Wed Sep 03 17:59:24 2025 -0500 @@ -145,6 +145,7 @@ DefaultAllocator: Allocator<M, K>, ShapeConstraint: StridesOk<E, M, K, S1> + StridesOk<E, M, K, S2>, { + #[inline] fn eval_decompose<'b, R>(self, f: impl FnOnce(OMatrix<E, M, K>) -> R) -> R where Self: 'b, @@ -152,6 +153,7 @@ f(self.into_owned()) } + #[inline] fn eval_ref_decompose<'b, R>( &'b self, f: impl FnOnce(<MatrixDecomposition as Decomposition<Matrix<E, M, K, S1>>>::Reference<'b>) -> R, @@ -167,6 +169,14 @@ fn own(self) -> OMatrix<E, M, K> { self.into_owned() } + + #[inline] + fn cow<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> + where + Self: 'b, + { + self.cow_owned() + } } impl<'a, S1, S2, M, K, E> Instance<Matrix<E, M, K, S1>, MatrixDecomposition> @@ -202,6 +212,14 @@ fn own(self) -> OMatrix<E, M, K> { self.into_owned() } + + #[inline] + fn cow<'b>(self) -> MyCow<'b, OMatrix<E, M, K>> + where + Self: 'b, + { + self.cow_owned() + } } impl<SM, SV, N, M, K, E> Mapping<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM>