98 #[inline] |
98 #[inline] |
99 fn copy_from<I : Instance<Vector<E,M,SV1>>>(&mut self, y : I) { |
99 fn copy_from<I : Instance<Vector<E,M,SV1>>>(&mut self, y : I) { |
100 y.eval(|ỹ| Matrix::copy_from(self, ỹ)) |
100 y.eval(|ỹ| Matrix::copy_from(self, ỹ)) |
101 } |
101 } |
102 } |
102 } |
|
103 |
|
104 /* Implemented automatically as Euclidean. |
|
105 impl<SM,M,E> Projection<E, L2> for Vector<E,M,SM> |
|
106 where SM: StorageMut<E,M> + Clone, |
|
107 M : Dim, E : Scalar + Zero + One + Float + RealField, |
|
108 DefaultAllocator : Allocator<M> { |
|
109 #[inline] |
|
110 fn proj_ball_mut(&mut self, ρ : E, _ : L2) { |
|
111 let n = self.norm(L2); |
|
112 if n > ρ { |
|
113 self.iter_mut().for_each(|v| *v *= ρ/n) |
|
114 } |
|
115 } |
|
116 }*/ |
103 |
117 |
104 impl<SM,M,E> Projection<E, Linfinity> for Vector<E,M,SM> |
118 impl<SM,M,E> Projection<E, Linfinity> for Vector<E,M,SM> |
105 where SM: StorageMut<E,M> + Clone, |
119 where SM: StorageMut<E,M> + Clone, |
106 M : Dim, E : Scalar + Zero + One + Float + RealField, |
120 M : Dim, E : Scalar + Zero + One + Float + RealField, |
107 DefaultAllocator : Allocator<M> { |
121 DefaultAllocator : Allocator<M> { |
203 fn origin() -> OVector<E, M> { |
217 fn origin() -> OVector<E, M> { |
204 OVector::zeros() |
218 OVector::zeros() |
205 } |
219 } |
206 } |
220 } |
207 |
221 |
|
222 /// The default norm for `Vector` is [`L2`]. |
|
223 impl<E,M,S> Normed<E> |
|
224 for Vector<E,M,S> |
|
225 where M : Dim, |
|
226 S : Storage<E,M> + Clone, |
|
227 E : Float + Scalar + Zero + One + RealField, |
|
228 DefaultAllocator : Allocator<M> { |
|
229 |
|
230 type NormExp = L2; |
|
231 |
|
232 #[inline] |
|
233 fn norm_exponent(&self) -> Self::NormExp { |
|
234 L2 |
|
235 } |
|
236 |
|
237 #[inline] |
|
238 fn is_zero(&self) -> bool { |
|
239 Vector::<E,M,S>::norm_squared(self) == E::ZERO |
|
240 } |
|
241 } |
|
242 |
|
243 impl<E,M,S> HasDual<E> |
|
244 for Vector<E,M,S> |
|
245 where M : Dim, |
|
246 S : Storage<E,M> + Clone, |
|
247 E : Float + Scalar + Zero + One + RealField, |
|
248 DefaultAllocator : Allocator<M> { |
|
249 // TODO: Doesn't work with different storage formats. |
|
250 type DualSpace = Self; |
|
251 } |
|
252 |
208 impl<E,M,S> Norm<E, L1> |
253 impl<E,M,S> Norm<E, L1> |
209 for Vector<E,M,S> |
254 for Vector<E,M,S> |
210 where M : Dim, |
255 where M : Dim, |
211 S : StorageMut<E,M>, |
256 S : Storage<E,M>, |
212 E : Float + Scalar + Zero + One + RealField, |
257 E : Float + Scalar + Zero + One + RealField, |
213 DefaultAllocator : Allocator<M> { |
258 DefaultAllocator : Allocator<M> { |
214 |
259 |
215 #[inline] |
260 #[inline] |
216 fn norm(&self, _ : L1) -> E { |
261 fn norm(&self, _ : L1) -> E { |
219 } |
264 } |
220 |
265 |
221 impl<E,M,S> Dist<E, L1> |
266 impl<E,M,S> Dist<E, L1> |
222 for Vector<E,M,S> |
267 for Vector<E,M,S> |
223 where M : Dim, |
268 where M : Dim, |
224 S : StorageMut<E,M>, |
269 S : Storage<E,M>, |
225 E : Float + Scalar + Zero + One + RealField, |
270 E : Float + Scalar + Zero + One + RealField, |
226 DefaultAllocator : Allocator<M> { |
271 DefaultAllocator : Allocator<M> { |
227 #[inline] |
272 #[inline] |
228 fn dist(&self, other : &Self, _ : L1) -> E { |
273 fn dist(&self, other : &Self, _ : L1) -> E { |
229 LpNorm(1).metric_distance(self, other) |
274 LpNorm(1).metric_distance(self, other) |
231 } |
276 } |
232 |
277 |
233 impl<E,M,S> Norm<E, L2> |
278 impl<E,M,S> Norm<E, L2> |
234 for Vector<E,M,S> |
279 for Vector<E,M,S> |
235 where M : Dim, |
280 where M : Dim, |
236 S : StorageMut<E,M>, |
281 S : Storage<E,M>, |
237 E : Float + Scalar + Zero + One + RealField, |
282 E : Float + Scalar + Zero + One + RealField, |
238 DefaultAllocator : Allocator<M> { |
283 DefaultAllocator : Allocator<M> { |
239 |
284 |
240 #[inline] |
285 #[inline] |
241 fn norm(&self, _ : L2) -> E { |
286 fn norm(&self, _ : L2) -> E { |
244 } |
289 } |
245 |
290 |
246 impl<E,M,S> Dist<E, L2> |
291 impl<E,M,S> Dist<E, L2> |
247 for Vector<E,M,S> |
292 for Vector<E,M,S> |
248 where M : Dim, |
293 where M : Dim, |
249 S : StorageMut<E,M>, |
294 S : Storage<E,M>, |
250 E : Float + Scalar + Zero + One + RealField, |
295 E : Float + Scalar + Zero + One + RealField, |
251 DefaultAllocator : Allocator<M> { |
296 DefaultAllocator : Allocator<M> { |
252 #[inline] |
297 #[inline] |
253 fn dist(&self, other : &Self, _ : L2) -> E { |
298 fn dist(&self, other : &Self, _ : L2) -> E { |
254 LpNorm(2).metric_distance(self, other) |
299 LpNorm(2).metric_distance(self, other) |
256 } |
301 } |
257 |
302 |
258 impl<E,M,S> Norm<E, Linfinity> |
303 impl<E,M,S> Norm<E, Linfinity> |
259 for Vector<E,M,S> |
304 for Vector<E,M,S> |
260 where M : Dim, |
305 where M : Dim, |
261 S : StorageMut<E,M>, |
306 S : Storage<E,M>, |
262 E : Float + Scalar + Zero + One + RealField, |
307 E : Float + Scalar + Zero + One + RealField, |
263 DefaultAllocator : Allocator<M> { |
308 DefaultAllocator : Allocator<M> { |
264 |
309 |
265 #[inline] |
310 #[inline] |
266 fn norm(&self, _ : Linfinity) -> E { |
311 fn norm(&self, _ : Linfinity) -> E { |
269 } |
314 } |
270 |
315 |
271 impl<E,M,S> Dist<E, Linfinity> |
316 impl<E,M,S> Dist<E, Linfinity> |
272 for Vector<E,M,S> |
317 for Vector<E,M,S> |
273 where M : Dim, |
318 where M : Dim, |
274 S : StorageMut<E,M>, |
319 S : Storage<E,M>, |
275 E : Float + Scalar + Zero + One + RealField, |
320 E : Float + Scalar + Zero + One + RealField, |
276 DefaultAllocator : Allocator<M> { |
321 DefaultAllocator : Allocator<M> { |
277 #[inline] |
322 #[inline] |
278 fn dist(&self, other : &Self, _ : Linfinity) -> E { |
323 fn dist(&self, other : &Self, _ : Linfinity) -> E { |
279 UniformNorm.metric_distance(self, other) |
324 UniformNorm.metric_distance(self, other) |