| 220 { |
220 { |
| 221 self.cow_owned() |
221 self.cow_owned() |
| 222 } |
222 } |
| 223 } |
223 } |
| 224 |
224 |
| 225 impl<SM, SV, N, M, K, E> Mapping<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
225 impl<SM, N, M, K, E> Mapping<OMatrix<E, M, K>> for Matrix<E, N, M, SM> |
| 226 where |
226 where |
| 227 SM: Storage<E, N, M>, |
227 SM: Storage<E, N, M>, |
| 228 SV: Storage<E, M, K>, |
|
| 229 N: Dim, |
228 N: Dim, |
| 230 M: Dim, |
229 M: Dim, |
| 231 K: Dim, |
230 K: Dim, |
| 232 E: Scalar + Zero + One + Copy + ClosedMulAssign + ClosedAddAssign, |
231 E: Scalar + Zero + One + Copy + ClosedMulAssign + ClosedAddAssign, |
| 233 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M>, |
232 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M>, |
| 234 ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, M, K, SV> + StridesOk<E, N, K>, |
233 ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, M, K> + StridesOk<E, N, K>, |
| 235 { |
234 { |
| 236 type Codomain = OMatrix<E, N, K>; |
235 type Codomain = OMatrix<E, N, K>; |
| 237 |
236 |
| 238 #[inline] |
237 #[inline] |
| 239 fn apply<I: Instance<Matrix<E, M, K, SV>>>(&self, x: I) -> Self::Codomain { |
238 fn apply<I: Instance<OMatrix<E, M, K>>>(&self, x: I) -> Self::Codomain { |
| 240 x.either(|owned| self.mul(owned), |refr| self.mul(refr)) |
239 x.either(|owned| self.mul(owned), |refr| self.mul(refr)) |
| 241 } |
240 } |
| 242 } |
241 } |
| 243 |
242 |
| 244 impl<'a, SM, SV, N, M, K, E> Linear<Matrix<E, M, K, SV>> for Matrix<E, N, M, SM> |
243 impl<'a, SM, N, M, K, E> Linear<OMatrix<E, M, K>> for Matrix<E, N, M, SM> |
| 245 where |
244 where |
| 246 SM: Storage<E, N, M>, |
245 SM: Storage<E, N, M>, |
| 247 SV: Storage<E, M, K>, |
|
| 248 N: Dim, |
246 N: Dim, |
| 249 M: Dim, |
247 M: Dim, |
| 250 K: Dim, |
248 K: Dim, |
| 251 E: Scalar + Zero + One + Copy + ClosedMulAssign + ClosedAddAssign, |
249 E: Scalar + Zero + One + Copy + ClosedMulAssign + ClosedAddAssign, |
| 252 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M>, |
250 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M>, |
| 253 ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, M, K, SV> + StridesOk<E, N, K>, |
251 ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, M, K> + StridesOk<E, N, K>, |
| 254 { |
252 { |
| 255 } |
253 } |
| 256 |
254 |
| 257 impl<SM, SV1, SV2, N, M, K, E> GEMV<E, Matrix<E, M, K, SV1>, Matrix<E, N, K, SV2>> |
255 impl<SM, SV2, N, M, K, E> GEMV<E, OMatrix<E, M, K>, Matrix<E, N, K, SV2>> for Matrix<E, N, M, SM> |
| 258 for Matrix<E, N, M, SM> |
|
| 259 where |
256 where |
| 260 SM: Storage<E, N, M>, |
257 SM: Storage<E, N, M>, |
| 261 SV1: Storage<E, M, K>, |
|
| 262 SV2: StorageMut<E, N, K>, |
258 SV2: StorageMut<E, N, K>, |
| 263 N: Dim, |
259 N: Dim, |
| 264 M: Dim, |
260 M: Dim, |
| 265 K: Dim, |
261 K: Dim, |
| 266 E: Scalar + Zero + One + Float, |
262 E: Scalar + Zero + One + Float, |
| 267 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M>, |
263 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M>, |
| 268 ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, M, K, SV1> + StridesOk<E, N, K, SV2>, |
264 ShapeConstraint: StridesOk<E, N, M, SM> + StridesOk<E, N, K, SV2> + StridesOk<E, M, K>, |
| 269 { |
265 { |
| 270 #[inline] |
266 #[inline] |
| 271 fn gemv<I: Instance<Matrix<E, M, K, SV1>>>( |
267 fn gemv<I: Instance<OMatrix<E, M, K>>>( |
| 272 &self, |
268 &self, y: &mut Matrix<E, N, K, SV2>, α: E, x: I, β: E |
| 273 y: &mut Matrix<E, N, K, SV2>, |
|
| 274 α: E, |
|
| 275 x: I, |
|
| 276 β: E, |
|
| 277 ) { |
269 ) { |
| 278 x.eval(|x̃| Matrix::gemm(y, α, self, x̃, β)) |
270 x.eval(|x̃| Matrix::gemm(y, α, self, x̃, β)) |
| 279 } |
271 } |
| 280 |
272 |
| 281 #[inline] |
273 #[inline] |
| 282 fn apply_mut<'a, I: Instance<Matrix<E, M, K, SV1>>>(&self, y: &mut Matrix<E, N, K, SV2>, x: I) { |
274 fn apply_mut<'a, I: Instance<OMatrix<E, M, K>>>(&self, y: &mut Matrix<E, N, K, SV2>, x: I) { |
| 283 x.eval(|x̃| self.mul_to(x̃, y)) |
275 x.eval(|x̃| self.mul_to(x̃, y)) |
| 284 } |
276 } |
| 285 } |
277 } |
| 286 |
278 |
| 287 impl<S, M, N, E> VectorSpace for Matrix<E, M, N, S> |
279 impl<S, M, N, E> VectorSpace for Matrix<E, M, N, S> |
| 379 self.iter_mut() |
371 self.iter_mut() |
| 380 .for_each(|v| *v = num_traits::clamp(*v, -ρ, ρ)) |
372 .for_each(|v| *v = num_traits::clamp(*v, -ρ, ρ)) |
| 381 } |
373 } |
| 382 } |
374 } |
| 383 |
375 |
| 384 impl<'own, SV1, SV2, SM, N, M, K, E> Adjointable<Matrix<E, M, K, SV1>, Matrix<E, N, K, SV2>> |
376 impl<'own, SM, N, M, K, E> Adjointable<OMatrix<E, M, K>, OMatrix<E, N, K>> for Matrix<E, N, M, SM> |
| 385 for Matrix<E, N, M, SM> |
|
| 386 where |
377 where |
| 387 SM: Storage<E, N, M>, |
378 SM: Storage<E, N, M>, |
| 388 SV1: Storage<E, M, K> + Clone, |
|
| 389 SV2: Storage<E, N, K> + Clone, |
|
| 390 N: Dim, |
379 N: Dim, |
| 391 M: Dim, |
380 M: Dim, |
| 392 K: Dim, |
381 K: Dim, |
| 393 E: Scalar + Zero + One + Copy + SimdComplexField, |
382 E: Scalar + Zero + One + Copy + SimdComplexField, |
| 394 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
383 DefaultAllocator: Allocator<N, K> + Allocator<M, K> + Allocator<N, M> + Allocator<M, N>, |
| 395 ShapeConstraint: StridesOk<E, N, M, SM> |
384 ShapeConstraint: |
| 396 + StridesOk<E, M, K, SV1> |
385 StridesOk<E, N, M, SM> + StridesOk<E, N, K> + StridesOk<E, M, N> + StridesOk<E, M, K>, |
| 397 + StridesOk<E, N, K, SV2> |
|
| 398 + StridesOk<E, M, N>, |
|
| 399 { |
386 { |
| 400 type AdjointCodomain = OMatrix<E, M, K>; |
387 type AdjointCodomain = OMatrix<E, M, K>; |
| 401 type Adjoint<'a> |
388 type Adjoint<'a> |
| 402 = OMatrix<E, M, N> |
389 = OMatrix<E, M, N> |
| 403 where |
390 where |