src/euclidean/wrap.rs

branch
dev
changeset 176
21e51de02ab6
parent 175
ef02a80bf4bc
child 177
b071a1b484f8
equal deleted inserted replaced
175:ef02a80bf4bc 176:21e51de02ab6
122 }; 122 };
123 // ($type:ty) => { 123 // ($type:ty) => {
124 // $crate::wrap!(imp<> do $type); 124 // $crate::wrap!(imp<> do $type);
125 // }; 125 // };
126 ($F:ty; $type:ty where $($qual:tt)*) => { 126 ($F:ty; $type:ty where $($qual:tt)*) => {
127
127 $crate::wrap!(impl_unary $type, std::ops::Neg, neg where $($qual)*); 128 $crate::wrap!(impl_unary $type, std::ops::Neg, neg where $($qual)*);
128 $crate::wrap!(impl_binary $type, std::ops::Add, add where $($qual)*); 129 $crate::wrap!(impl_binary $type, std::ops::Add, add where $($qual)*);
129 $crate::wrap!(impl_binary $type, std::ops::Sub, sub where $($qual)*); 130 $crate::wrap!(impl_binary $type, std::ops::Sub, sub where $($qual)*);
130 $crate::wrap!(impl_scalar $F, $type, std::ops::Mul, mul where $($qual)*); 131 $crate::wrap!(impl_scalar $F, $type, std::ops::Mul, mul where $($qual)*);
131 $crate::wrap!(impl_scalar $F, $type, std::ops::Div, div where $($qual)*); 132 $crate::wrap!(impl_scalar $F, $type, std::ops::Div, div where $($qual)*);
138 $crate::self_ownable!($type where $($qual)*); 139 $crate::self_ownable!($type where $($qual)*);
139 140
140 impl<$($qual)*> $crate::norms::Norm<$crate::norms::L2, $F> for $type 141 impl<$($qual)*> $crate::norms::Norm<$crate::norms::L2, $F> for $type
141 { 142 {
142 fn norm(&self, p : $crate::norms::L2) -> $F { 143 fn norm(&self, p : $crate::norms::L2) -> $F {
143 self.get_view().norm(p) 144 $crate::norms::Norm::norm(&self.get_view(), p)
144 } 145 }
145 } 146 }
146 147
147 impl<$($qual)*> $crate::norms::Dist<$crate::norms::L2, $F> for $type 148 impl<$($qual)*> $crate::norms::Dist<$crate::norms::L2, $F> for $type
148 { 149 {
149 fn dist<I: $crate::instance::Instance<Self>>(&self, other : I, p : $crate::norms::L2) -> $F { 150 fn dist<I: $crate::instance::Instance<Self>>(&self, other : I, p : $crate::norms::L2) -> $F {
150 other.eval_decompose(|x| self.get_view().dist(p, x)) 151 other.eval_ref(|x| self.get_view().dist(x, p))
151 } 152 }
152 } 153 }
153 154
154 impl<$($qual)*> $crate::norms::Normed<$F> for $type { 155 impl<$($qual)*> $crate::norms::Normed<$F> for $type {
155 type NormExp = $crate::norms::L2; 156 type NormExp = $crate::norms::L2;
161 162
162 impl<$($qual)*> $crate::norms::HasDual<$F> for $type { 163 impl<$($qual)*> $crate::norms::HasDual<$F> for $type {
163 type DualSpace = Self; 164 type DualSpace = Self;
164 165
165 fn dual_origin(&self) -> Self { 166 fn dual_origin(&self) -> Self {
166 self.similar_origin(self) 167 $crate::linops::VectorSpace::similar_origin(self)
167 } 168 }
168 } 169 }
169 170
170 impl<$($qual)*> $crate::euclidean::Euclidean<$F> for $type 171 impl<$($qual)*> $crate::euclidean::Euclidean<$F> for $type
171 // where 172 // where
229 }) 230 })
230 } 231 }
231 232
232 fn copy_from<I: $crate::instance::Instance<Self>>(&mut self, x: I) { 233 fn copy_from<I: $crate::instance::Instance<Self>>(&mut self, x: I) {
233 x.eval_decompose(|v| { 234 x.eval_decompose(|v| {
234 self.get_view_mut().copy_from(v.get_view()) 235 self.get_view_mut().copy_from(&v.get_view())
235 }) 236 })
236 } 237 }
237 238
238 fn scale_from<I: $crate::instance::Instance<Self>>(&mut self, α: $F, x: I) { 239 fn scale_from<I: $crate::instance::Instance<Self>>(&mut self, α: $F, x: I) {
239 x.eval_decompose(|v| { 240 x.eval_decompose(|v| {
246 self.get_view_mut().set_zero() 247 self.get_view_mut().set_zero()
247 } 248 }
248 } 249 }
249 250
250 impl<$($qual)*> $crate::instance::Space for $type { 251 impl<$($qual)*> $crate::instance::Space for $type {
251 type Decomp = <<Self as $crate::euclidean::wrap::Wrapped>::Unwrapped as $crate::instance::Space>::Decomp; 252 type Decomp = $crate::instance::BasicDecomposition;
252 type Principal = Self; 253 type Principal = Self;
253 } 254 }
254 }; 255 };
255 } 256 }

mercurial