| 1 /*! |
1 /*! |
| 2 Euclidean spaces. |
2 Euclidean spaces. |
| 3 */ |
3 */ |
| 4 |
4 |
| 5 use crate::instance::Instance; |
5 use crate::instance::Instance; |
| |
6 use crate::linops::AXPY; |
| 6 use crate::norms::{HasDual, Reflexive}; |
7 use crate::norms::{HasDual, Reflexive}; |
| 7 use crate::types::*; |
8 use crate::types::*; |
| 8 use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; |
9 use std::ops::{Add, AddAssign, Sub, SubAssign}; |
| 9 |
10 |
| 10 /// Space (type) with Euclidean and vector space structure |
11 /// Space (type) with Euclidean and vector space structure |
| 11 /// |
12 /// |
| 12 /// The type should implement vector space operations (addition, subtraction, scalar |
13 /// The type should implement vector space operations (addition, subtraction, scalar |
| 13 /// multiplication and scalar division) along with their assignment versions, as well |
14 /// multiplication and scalar division) along with their assignment versions, as well |
| 14 /// as an inner product. |
15 /// as an inner product. |
| |
16 // TODO: remove F parameter, use AXPY::Field |
| 15 pub trait Euclidean<F: Float = f64>: |
17 pub trait Euclidean<F: Float = f64>: |
| 16 HasDual<F, DualSpace = Self> |
18 HasDual<F, DualSpace = Self> |
| |
19 + AXPY<Field = F> |
| 17 + Reflexive<F> |
20 + Reflexive<F> |
| 18 + Mul<F, Output = <Self as Euclidean<F>>::Output> |
21 // TODO: move the following to AXPY |
| 19 + MulAssign<F> |
22 + for<'b> Add<&'b Self, Output = <Self as AXPY>::Owned> |
| 20 + Div<F, Output = <Self as Euclidean<F>>::Output> |
23 + for<'b> Sub<&'b Self, Output = <Self as AXPY>::Owned> |
| 21 + DivAssign<F> |
|
| 22 + Add<Self, Output = <Self as Euclidean<F>>::Output> |
|
| 23 + Sub<Self, Output = <Self as Euclidean<F>>::Output> |
|
| 24 + for<'b> Add<&'b Self, Output = <Self as Euclidean<F>>::Output> |
|
| 25 + for<'b> Sub<&'b Self, Output = <Self as Euclidean<F>>::Output> |
|
| 26 + AddAssign<Self> |
|
| 27 + for<'b> AddAssign<&'b Self> |
24 + for<'b> AddAssign<&'b Self> |
| 28 + SubAssign<Self> |
|
| 29 + for<'b> SubAssign<&'b Self> |
25 + for<'b> SubAssign<&'b Self> |
| 30 + Neg<Output = <Self as Euclidean<F>>::Output> |
|
| 31 { |
26 { |
| 32 type Output: Euclidean<F>; |
|
| 33 |
|
| 34 // Inner product |
27 // Inner product |
| 35 fn dot<I: Instance<Self>>(&self, other: I) -> F; |
28 fn dot<I: Instance<Self>>(&self, other: I) -> F; |
| 36 |
29 |
| 37 /// Calculate the square of the 2-norm, $\frac{1}{2}\\|x\\|_2^2$, where `self` is $x$. |
30 /// Calculate the square of the 2-norm, $\frac{1}{2}\\|x\\|_2^2$, where `self` is $x$. |
| 38 /// |
31 /// |