src/nalgebra_support.rs

branch
dev
changeset 177
b071a1b484f8
parent 176
21e51de02ab6
child 178
073ea94b119a
equal deleted inserted replaced
176:21e51de02ab6 177:b071a1b484f8
357 let (n, m) = self.shape_generic(); 357 let (n, m) = self.shape_generic();
358 OMatrix::zeros_generic(n, m) 358 OMatrix::zeros_generic(n, m)
359 } 359 }
360 } 360 }
361 361
362 impl<SM, SV1, M, N, E> AXPY<Matrix<E, M, N, SV1>> for Matrix<E, M, N, SM> 362 // This can only be implemented for the “principal” OMatrix as parameter, as otherwise
363 where 363 // we run into problems of multiple implementations when calling the methods.
364 SM: StorageMut<E, M, N>, 364 impl<M, N, E, S> AXPY<OMatrix<E, M, N>> for Matrix<E, M, N, S>
365 SV1: Storage<E, M, N>, 365 where
366 S: StorageMut<E, M, N>,
366 M: Dim, 367 M: Dim,
367 N: Dim, 368 N: Dim,
368 E: Scalar + Zero + One + Float, 369 E: Scalar + Zero + One + Float,
369 DefaultAllocator: Allocator<M, N>, 370 DefaultAllocator: Allocator<M, N>,
370 ShapeConstraint: StridesOk<E, M, N>, 371 ShapeConstraint: StridesOk<E, M, N>,
371 { 372 {
372 #[inline] 373 #[inline]
373 fn axpy<I: Instance<Matrix<E, M, N, SV1>>>(&mut self, α: E, x: I, β: E) { 374 fn axpy<I: Instance<OMatrix<E, M, N>>>(&mut self, α: E, x: I, β: E) {
374 x.eval(|x̃| { 375 x.eval(|x̃| {
375 assert_eq!(self.ncols(), x̃.ncols()); 376 assert_eq!(self.ncols(), x̃.ncols());
376 // nalgebra does not implement axpy for matrices, and flattenining 377 // nalgebra does not implement axpy for matrices, and flattenining
377 // also seems difficult, so loop over columns. 378 // also seems difficult, so loop over columns.
378 for (mut y, ỹ) in self.column_iter_mut().zip(x̃.column_iter()) { 379 for (mut y, ỹ) in self.column_iter_mut().zip(x̃.column_iter()) {
380 } 381 }
381 }) 382 })
382 } 383 }
383 384
384 #[inline] 385 #[inline]
385 fn copy_from<I: Instance<Matrix<E, M, N, SV1>>>(&mut self, y: I) { 386 fn copy_from<I: Instance<OMatrix<E, M, N>>>(&mut self, y: I) {
386 y.eval_ref(|ỹ| Matrix::copy_from(self, &ỹ)) 387 y.eval_ref(|ỹ| Matrix::copy_from(self, &ỹ))
387 } 388 }
388 389
389 #[inline] 390 #[inline]
390 fn set_zero(&mut self) { 391 fn set_zero(&mut self) {

mercurial