| 101 fn apply_mut<'a, I: Instance<Matrix<E, M, K, SV1>>>(&self, y: &mut Matrix<E, N, K, SV2>, x: I) { |
101 fn apply_mut<'a, I: Instance<Matrix<E, M, K, SV1>>>(&self, y: &mut Matrix<E, N, K, SV2>, x: I) { |
| 102 x.eval(|x̃| self.mul_to(x̃, y)) |
102 x.eval(|x̃| self.mul_to(x̃, y)) |
| 103 } |
103 } |
| 104 } |
104 } |
| 105 |
105 |
| 106 impl<SM, SV1, M, E> AXPY<Vector<E, M, SV1>> for Vector<E, M, SM> |
106 impl<SM, SV1, M, N, E> AXPY<Matrix<E, M, N, SV1>> for Matrix<E, M, N, SM> |
| 107 where |
107 where |
| 108 SM: StorageMut<E, M> + Clone, |
108 SM: StorageMut<E, M, N> + Clone, |
| 109 SV1: Storage<E, M> + Clone, |
109 SV1: Storage<E, M, N> + Clone, |
| 110 M: Dim, |
110 M: Dim, |
| |
111 N: Dim, |
| 111 E: Scalar + Zero + One + Float, |
112 E: Scalar + Zero + One + Float, |
| 112 DefaultAllocator: Allocator<M>, |
113 DefaultAllocator: Allocator<M, N>, |
| 113 { |
114 { |
| 114 type Field = E; |
115 type Field = E; |
| 115 type Owned = OVector<E, M>; |
116 type Owned = OMatrix<E, M, N>; |
| 116 |
117 |
| 117 #[inline] |
118 #[inline] |
| 118 fn axpy<I: Instance<Vector<E, M, SV1>>>(&mut self, α: E, x: I, β: E) { |
119 fn axpy<I: Instance<Matrix<E, M, N, SV1>>>(&mut self, α: E, x: I, β: E) { |
| 119 x.eval(|x̃| Matrix::axpy(self, α, x̃, β)) |
120 x.eval(|x̃| { |
| 120 } |
121 assert_eq!(self.ncols(), x̃.ncols()); |
| 121 |
122 // nalgebra does not implement axpy for matrices, and flattenining |
| 122 #[inline] |
123 // also seems difficult, so loop over columns. |
| 123 fn copy_from<I: Instance<Vector<E, M, SV1>>>(&mut self, y: I) { |
124 for (mut y, ỹ) in self.column_iter_mut().zip(x̃.column_iter()) { |
| |
125 Vector::axpy(&mut y, α, &ỹ, β) |
| |
126 } |
| |
127 }) |
| |
128 } |
| |
129 |
| |
130 #[inline] |
| |
131 fn copy_from<I: Instance<Matrix<E, M, N, SV1>>>(&mut self, y: I) { |
| 124 y.eval(|ỹ| Matrix::copy_from(self, ỹ)) |
132 y.eval(|ỹ| Matrix::copy_from(self, ỹ)) |
| 125 } |
133 } |
| 126 |
134 |
| 127 #[inline] |
135 #[inline] |
| 128 fn set_zero(&mut self) { |
136 fn set_zero(&mut self) { |
| 129 self.iter_mut().for_each(|e| *e = E::ZERO); |
137 self.iter_mut().for_each(|e| *e = E::ZERO); |
| 130 } |
138 } |
| 131 |
139 |
| 132 #[inline] |
140 #[inline] |
| 133 fn similar_origin(&self) -> Self::Owned { |
141 fn similar_origin(&self) -> Self::Owned { |
| 134 OVector::zeros_generic(M::from_usize(self.len()), Const) |
142 let (n, m) = self.shape_generic(); |
| |
143 OMatrix::zeros_generic(n, m) |
| 135 } |
144 } |
| 136 } |
145 } |
| 137 |
146 |
| 138 /* Implemented automatically as Euclidean. |
147 /* Implemented automatically as Euclidean. |
| 139 impl<SM,M,E> Projection<E, L2> for Vector<E,M,SM> |
148 impl<SM,M,E> Projection<E, L2> for Vector<E,M,SM> |