Debian Codegraph @

debian/missing-sources/nalgebra/tests/core/edition.rs

raw
1 use na::{
2 DMatrix, Matrix, Matrix3, Matrix3x4, Matrix3x5, Matrix4, Matrix4x3, Matrix4x5, Matrix5,
3 Matrix5x3, Matrix5x4,
4 };
5 use na::{Dyn, U3, U5};
6
7 #[test]
8 #[rustfmt::skip]
9 fn upper_lower_triangular() {
10 let m = Matrix4::new(
11 11.0, 12.0, 13.0, 14.0,
12 21.0, 22.0, 23.0, 24.0,
13 31.0, 32.0, 33.0, 34.0,
14 41.0, 42.0, 43.0, 44.0);
15
16 let um = Matrix4::new(
17 11.0, 12.0, 13.0, 14.0,
18 0.0, 22.0, 23.0, 24.0,
19 0.0, 0.0, 33.0, 34.0,
20 0.0, 0.0, 0.0, 44.0);
21
22 let lm = Matrix4::new(
23 11.0, 0.0, 0.0, 0.0,
24 21.0, 22.0, 0.0, 0.0,
25 31.0, 32.0, 33.0, 0.0,
26 41.0, 42.0, 43.0, 44.0);
27
28 let computed_um = m.upper_triangle();
29 let computed_lm = m.lower_triangle();
30
31 assert_eq!(um, computed_um);
32 assert_eq!(lm, computed_lm);
33
34 let symm_um = Matrix4::new(
35 11.0, 12.0, 13.0, 14.0,
36 12.0, 22.0, 23.0, 24.0,
37 13.0, 23.0, 33.0, 34.0,
38 14.0, 24.0, 34.0, 44.0);
39
40 let symm_lm = Matrix4::new(
41 11.0, 21.0, 31.0, 41.0,
42 21.0, 22.0, 32.0, 42.0,
43 31.0, 32.0, 33.0, 43.0,
44 41.0, 42.0, 43.0, 44.0);
45
46 let mut computed_symm_um = m.clone();
47 let mut computed_symm_lm = m.clone();
48
49 computed_symm_um.fill_lower_triangle_with_upper_triangle();
50 computed_symm_lm.fill_upper_triangle_with_lower_triangle();
51 assert_eq!(symm_um, computed_symm_um);
52 assert_eq!(symm_lm, computed_symm_lm);
53
54
55 let m = Matrix5x3::new(
56 11.0, 12.0, 13.0,
57 21.0, 22.0, 23.0,
58 31.0, 32.0, 33.0,
59 41.0, 42.0, 43.0,
60 51.0, 52.0, 53.0);
61
62 let um = Matrix5x3::new(
63 11.0, 12.0, 13.0,
64 0.0, 22.0, 23.0,
65 0.0, 0.0, 33.0,
66 0.0, 0.0, 0.0,
67 0.0, 0.0, 0.0);
68
69 let lm = Matrix5x3::new(
70 11.0, 0.0, 0.0,
71 21.0, 22.0, 0.0,
72 31.0, 32.0, 33.0,
73 41.0, 42.0, 43.0,
74 51.0, 52.0, 53.0);
75
76 let computed_um = m.upper_triangle();
77 let computed_lm = m.lower_triangle();
78
79 assert_eq!(um, computed_um);
80 assert_eq!(lm, computed_lm);
81
82
83 let m = Matrix3x5::new(
84 11.0, 12.0, 13.0, 14.0, 15.0,
85 21.0, 22.0, 23.0, 24.0, 25.0,
86 31.0, 32.0, 33.0, 34.0, 35.0);
87
88 let um = Matrix3x5::new(
89 11.0, 12.0, 13.0, 14.0, 15.0,
90 0.0, 22.0, 23.0, 24.0, 25.0,
91 0.0, 0.0, 33.0, 34.0, 35.0);
92
93 let lm = Matrix3x5::new(
94 11.0, 0.0, 0.0, 0.0, 0.0,
95 21.0, 22.0, 0.0, 0.0, 0.0,
96 31.0, 32.0, 33.0, 0.0, 0.0);
97
98 let computed_um = m.upper_triangle();
99 let computed_lm = m.lower_triangle();
100
101 assert_eq!(um, computed_um);
102 assert_eq!(lm, computed_lm);
103
104 let mut m = Matrix4x5::new(
105 11.0, 12.0, 13.0, 14.0, 15.0,
106 21.0, 22.0, 23.0, 24.0, 25.0,
107 31.0, 32.0, 33.0, 34.0, 35.0,
108 41.0, 42.0, 43.0, 44.0, 45.0);
109
110 let expected_m = Matrix4x5::new(
111 11.0, 12.0, 0.0, 0.0, 0.0,
112 21.0, 22.0, 23.0, 0.0, 0.0,
113 31.0, 32.0, 33.0, 34.0, 0.0,
114 41.0, 42.0, 43.0, 44.0, 45.0);
115
116 m.fill_upper_triangle(0.0, 2);
117
118 assert_eq!(m, expected_m);
119
120 let mut m = Matrix4x5::new(
121 11.0, 12.0, 13.0, 14.0, 15.0,
122 21.0, 22.0, 23.0, 24.0, 25.0,
123 31.0, 32.0, 33.0, 34.0, 35.0,
124 41.0, 42.0, 43.0, 44.0, 45.0);
125
126 let expected_m = Matrix4x5::new(
127 11.0, 12.0, 13.0, 14.0, 15.0,
128 21.0, 22.0, 23.0, 24.0, 25.0,
129 0.0, 32.0, 33.0, 34.0, 35.0,
130 0.0, 0.0, 43.0, 44.0, 45.0);
131
132 m.fill_lower_triangle(0.0, 2);
133
134 assert_eq!(m, expected_m);
135
136 let mut m = Matrix5x4::new(
137 11.0, 12.0, 13.0, 14.0,
138 21.0, 22.0, 23.0, 24.0,
139 31.0, 32.0, 33.0, 34.0,
140 41.0, 42.0, 43.0, 44.0,
141 51.0, 52.0, 53.0, 54.0);
142
143 let expected_m = Matrix5x4::new(
144 11.0, 12.0, 0.0, 0.0,
145 21.0, 22.0, 23.0, 0.0,
146 31.0, 32.0, 33.0, 34.0,
147 41.0, 42.0, 43.0, 44.0,
148 51.0, 52.0, 53.0, 54.0);
149
150 m.fill_upper_triangle(0.0, 2);
151
152 assert_eq!(m, expected_m);
153
154 let mut m = Matrix5x4::new(
155 11.0, 12.0, 13.0, 14.0,
156 21.0, 22.0, 23.0, 24.0,
157 31.0, 32.0, 33.0, 34.0,
158 41.0, 42.0, 43.0, 44.0,
159 51.0, 52.0, 53.0, 54.0);
160
161 let expected_m = Matrix5x4::new(
162 11.0, 12.0, 13.0, 14.0,
163 21.0, 22.0, 23.0, 24.0,
164 0.0, 32.0, 33.0, 34.0,
165 0.0, 0.0, 43.0, 44.0,
166 0.0, 0.0, 0.0, 54.0);
167
168 m.fill_lower_triangle(0.0, 2);
169
170 assert_eq!(m, expected_m);
171 }
172
173 #[test]
174 #[rustfmt::skip]
175 fn swap_rows() {
176 let mut m = Matrix5x3::new(
177 11.0, 12.0, 13.0,
178 21.0, 22.0, 23.0,
179 31.0, 32.0, 33.0,
180 41.0, 42.0, 43.0,
181 51.0, 52.0, 53.0);
182
183 let expected = Matrix5x3::new(
184 11.0, 12.0, 13.0,
185 41.0, 42.0, 43.0,
186 31.0, 32.0, 33.0,
187 21.0, 22.0, 23.0,
188 51.0, 52.0, 53.0);
189
190 m.swap_rows(1, 3);
191
192 assert_eq!(m, expected);
193 }
194
195 #[test]
196 #[rustfmt::skip]
197 fn swap_columns() {
198 let mut m = Matrix3x5::new(
199 11.0, 12.0, 13.0, 14.0, 15.0,
200 21.0, 22.0, 23.0, 24.0, 25.0,
201 31.0, 32.0, 33.0, 34.0, 35.0);
202
203 let expected = Matrix3x5::new(
204 11.0, 14.0, 13.0, 12.0, 15.0,
205 21.0, 24.0, 23.0, 22.0, 25.0,
206 31.0, 34.0, 33.0, 32.0, 35.0);
207
208 m.swap_columns(1, 3);
209
210 assert_eq!(m, expected);
211 }
212
213 #[test]
214 #[rustfmt::skip]
215 fn remove_columns() {
216 let m = Matrix3x5::new(
217 11, 12, 13, 14, 15,
218 21, 22, 23, 24, 25,
219 31, 32, 33, 34, 35);
220
221 let expected_a1 = Matrix3x4::new(
222 12, 13, 14, 15,
223 22, 23, 24, 25,
224 32, 33, 34, 35);
225
226 let expected_a2 = Matrix3x4::new(
227 11, 12, 13, 14,
228 21, 22, 23, 24,
229 31, 32, 33, 34);
230
231 let expected_a3 = Matrix3x4::new(
232 11, 12, 14, 15,
233 21, 22, 24, 25,
234 31, 32, 34, 35);
235
236 assert_eq!(m.remove_column(0), expected_a1);
237 assert_eq!(m.remove_column(4), expected_a2);
238 assert_eq!(m.remove_column(2), expected_a3);
239
240 let expected_b1 = Matrix3::new(
241 13, 14, 15,
242 23, 24, 25,
243 33, 34, 35);
244
245 let expected_b2 = Matrix3::new(
246 11, 12, 13,
247 21, 22, 23,
248 31, 32, 33);
249
250 let expected_b3 = Matrix3::new(
251 11, 12, 15,
252 21, 22, 25,
253 31, 32, 35);
254
255 assert_eq!(m.remove_fixed_columns::<2>(0), expected_b1);
256 assert_eq!(m.remove_fixed_columns::<2>(3), expected_b2);
257 assert_eq!(m.remove_fixed_columns::<2>(2), expected_b3);
258
259 // The following is just to verify that the return type dimensions is correctly inferred.
260 let computed: Matrix<_, U3, Dyn, _> = m.remove_columns(3, 2);
261 assert!(computed.eq(&expected_b2));
262
263 /*
264 * Same thing but using a non-copy scalar type.
265 */
266 let m = m.map(Box::new);
267 let expected_a1 = expected_a1.map(Box::new);
268 let expected_a2 = expected_a2.map(Box::new);
269 let expected_a3 = expected_a3.map(Box::new);
270
271 assert_eq!(m.clone().remove_column(0), expected_a1);
272 assert_eq!(m.clone().remove_column(4), expected_a2);
273 assert_eq!(m.clone().remove_column(2), expected_a3);
274
275 let expected_b1 = expected_b1.map(Box::new);
276 let expected_b2 = expected_b2.map(Box::new);
277 let expected_b3 = expected_b3.map(Box::new);
278
279 assert_eq!(m.clone().remove_fixed_columns::<2>(0), expected_b1);
280 assert_eq!(m.clone().remove_fixed_columns::<2>(3), expected_b2);
281 assert_eq!(m.remove_fixed_columns::<2>(2), expected_b3);
282 }
283
284 #[test]
285 #[rustfmt::skip]
286 fn remove_columns_at() {
287 let m = DMatrix::from_row_slice(5, 5, &[
288 11, 12, 13, 14, 15,
289 21, 22, 23, 24, 25,
290 31, 32, 33, 34, 35,
291 41, 42, 43, 44, 45,
292 51, 52, 53, 54, 55
293 ]);
294
295 let expected1 = DMatrix::from_row_slice(5, 4, &[
296 12, 13, 14, 15,
297 22, 23, 24, 25,
298 32, 33, 34, 35,
299 42, 43, 44, 45,
300 52, 53, 54, 55
301 ]);
302
303 assert_eq!(m.remove_columns_at(&[0]), expected1);
304
305 let m = DMatrix::from_row_slice(5, 5, &[
306 11, 12, 13, 14, 15,
307 21, 22, 23, 24, 25,
308 31, 32, 33, 34, 35,
309 41, 42, 43, 44, 45,
310 51, 52, 53, 54, 55
311 ]);
312
313 let expected2 = DMatrix::from_row_slice(5, 3, &[
314 11, 13, 15,
315 21, 23, 25,
316 31, 33, 35,
317 41, 43, 45,
318 51, 53, 55
319 ]);
320
321 assert_eq!(m.remove_columns_at(&[1,3]), expected2);
322
323 let m = DMatrix::from_row_slice(5, 5, &[
324 11, 12, 13, 14, 15,
325 21, 22, 23, 24, 25,
326 31, 32, 33, 34, 35,
327 41, 42, 43, 44, 45,
328 51, 52, 53, 54, 55
329 ]);
330
331 let expected3 = DMatrix::from_row_slice(5, 2, &[
332 12, 13,
333 22, 23,
334 32, 33,
335 42, 43,
336 52, 53,
337 ]);
338
339 assert_eq!(m.remove_columns_at(&[0,3,4]), expected3);
340 }
341
342 #[test]
343 #[rustfmt::skip]
344 fn remove_rows() {
345 let m = Matrix5x3::new(
346 11, 12, 13,
347 21, 22, 23,
348 31, 32, 33,
349 41, 42, 43,
350 51, 52, 53);
351
352 let expected1 = Matrix4x3::new(
353 21, 22, 23,
354 31, 32, 33,
355 41, 42, 43,
356 51, 52, 53);
357
358 let expected2 = Matrix4x3::new(
359 11, 12, 13,
360 21, 22, 23,
361 31, 32, 33,
362 41, 42, 43);
363
364 let expected3 = Matrix4x3::new(
365 11, 12, 13,
366 21, 22, 23,
367 41, 42, 43,
368 51, 52, 53);
369
370 assert_eq!(m.remove_row(0), expected1);
371 assert_eq!(m.remove_row(4), expected2);
372 assert_eq!(m.remove_row(2), expected3);
373
374 let expected1 = Matrix3::new(
375 31, 32, 33,
376 41, 42, 43,
377 51, 52, 53);
378
379 let expected2 = Matrix3::new(
380 11, 12, 13,
381 21, 22, 23,
382 31, 32, 33);
383
384 let expected3 = Matrix3::new(
385 11, 12, 13,
386 21, 22, 23,
387 51, 52, 53);
388
389 assert_eq!(m.remove_fixed_rows::<2>(0), expected1);
390 assert_eq!(m.remove_fixed_rows::<2>(3), expected2);
391 assert_eq!(m.remove_fixed_rows::<2>(2), expected3);
392
393 // The following is just to verify that the return type dimensions is correctly inferred.
394 let computed: Matrix<_, Dyn, U3, _> = m.remove_rows(3, 2);
395 assert!(computed.eq(&expected2));
396 }
397
398 #[test]
399 #[rustfmt::skip]
400 fn remove_rows_at() {
401 let m = DMatrix::from_row_slice(5, 5, &[
402 11, 12, 13, 14, 15,
403 21, 22, 23, 24, 25,
404 31, 32, 33, 34, 35,
405 41, 42, 43, 44, 45,
406 51, 52, 53, 54, 55
407 ]);
408
409 let expected1 = DMatrix::from_row_slice(4, 5, &[
410 21, 22, 23, 24, 25,
411 31, 32, 33, 34, 35,
412 41, 42, 43, 44, 45,
413 51, 52, 53, 54, 55
414 ]);
415
416 assert_eq!(m.remove_rows_at(&[0]), expected1);
417
418 let m = DMatrix::from_row_slice(5, 5, &[
419 11, 12, 13, 14, 15,
420 21, 22, 23, 24, 25,
421 31, 32, 33, 34, 35,
422 41, 42, 43, 44, 45,
423 51, 52, 53, 54, 55
424 ]);
425
426 let expected2 = DMatrix::from_row_slice(3, 5, &[
427 11, 12, 13, 14, 15,
428 31, 32, 33, 34, 35,
429 51, 52, 53, 54, 55
430 ]);
431
432 assert_eq!(m.remove_rows_at(&[1,3]), expected2);
433
434 let m = DMatrix::from_row_slice(5, 5, &[
435 11, 12, 13, 14, 15,
436 21, 22, 23, 24, 25,
437 31, 32, 33, 34, 35,
438 41, 42, 43, 44, 45,
439 51, 52, 53, 54, 55
440 ]);
441
442 let expected3 = DMatrix::from_row_slice(2, 5, &[
443 21, 22, 23, 24, 25,
444 31, 32, 33, 34, 35
445 ]);
446
447 assert_eq!(m.remove_rows_at(&[0,3,4]), expected3);
448 }
449
450 #[test]
451 #[rustfmt::skip]
452 fn insert_columns() {
453 let m = Matrix5x3::new(
454 11, 12, 13,
455 21, 22, 23,
456 31, 32, 33,
457 41, 42, 43,
458 51, 52, 53);
459
460 let expected1 = Matrix5x4::new(
461 0, 11, 12, 13,
462 0, 21, 22, 23,
463 0, 31, 32, 33,
464 0, 41, 42, 43,
465 0, 51, 52, 53);
466
467 let expected2 = Matrix5x4::new(
468 11, 12, 13, 0,
469 21, 22, 23, 0,
470 31, 32, 33, 0,
471 41, 42, 43, 0,
472 51, 52, 53, 0);
473
474 let expected3 = Matrix5x4::new(
475 11, 12, 0, 13,
476 21, 22, 0, 23,
477 31, 32, 0, 33,
478 41, 42, 0, 43,
479 51, 52, 0, 53);
480
481 assert_eq!(m.insert_column(0, 0), expected1);
482 assert_eq!(m.insert_column(3, 0), expected2);
483 assert_eq!(m.insert_column(2, 0), expected3);
484
485 let expected1 = Matrix5::new(
486 0, 0, 11, 12, 13,
487 0, 0, 21, 22, 23,
488 0, 0, 31, 32, 33,
489 0, 0, 41, 42, 43,
490 0, 0, 51, 52, 53);
491
492 let expected2 = Matrix5::new(
493 11, 12, 13, 0, 0,
494 21, 22, 23, 0, 0,
495 31, 32, 33, 0, 0,
496 41, 42, 43, 0, 0,
497 51, 52, 53, 0, 0);
498
499 let expected3 = Matrix5::new(
500 11, 12, 0, 0, 13,
501 21, 22, 0, 0, 23,
502 31, 32, 0, 0, 33,
503 41, 42, 0, 0, 43,
504 51, 52, 0, 0, 53);
505
506 assert_eq!(m.insert_fixed_columns::<2>(0, 0), expected1);
507 assert_eq!(m.insert_fixed_columns::<2>(3, 0), expected2);
508 assert_eq!(m.insert_fixed_columns::<2>(2, 0), expected3);
509
510 // The following is just to verify that the return type dimensions is correctly inferred.
511 let computed: Matrix<_, U5, Dyn, _> = m.insert_columns(3, 2, 0);
512 assert!(computed.eq(&expected2));
513 }
514
515 #[test]
516 #[rustfmt::skip]
517 fn insert_columns_to_empty_matrix() {
518 let m1 = DMatrix::repeat(0, 0, 0);
519 let m2 = DMatrix::repeat(3, 0, 0);
520
521 let expected1 = DMatrix::repeat(0, 5, 42);
522 let expected2 = DMatrix::repeat(3, 5, 42);
523
524 assert_eq!(expected1, m1.insert_columns(0, 5, 42));
525 assert_eq!(expected2, m2.insert_columns(0, 5, 42));
526 }
527
528 #[test]
529 #[rustfmt::skip]
530 fn insert_rows() {
531 let m = Matrix3x5::new(
532 11, 12, 13, 14, 15,
533 21, 22, 23, 24, 25,
534 31, 32, 33, 34, 35);
535
536 let expected1 = Matrix4x5::new(
537 0, 0, 0, 0, 0,
538 11, 12, 13, 14, 15,
539 21, 22, 23, 24, 25,
540 31, 32, 33, 34, 35);
541
542 let expected2 = Matrix4x5::new(
543 11, 12, 13, 14, 15,
544 21, 22, 23, 24, 25,
545 31, 32, 33, 34, 35,
546 0, 0, 0, 0, 0);
547
548 let expected3 = Matrix4x5::new(
549 11, 12, 13, 14, 15,
550 21, 22, 23, 24, 25,
551 0, 0, 0, 0, 0,
552 31, 32, 33, 34, 35);
553
554 assert_eq!(m.insert_row(0, 0), expected1);
555 assert_eq!(m.insert_row(3, 0), expected2);
556 assert_eq!(m.insert_row(2, 0), expected3);
557
558 let expected1 = Matrix5::new(
559 0, 0, 0, 0, 0,
560 0, 0, 0, 0, 0,
561 11, 12, 13, 14, 15,
562 21, 22, 23, 24, 25,
563 31, 32, 33, 34, 35);
564
565 let expected2 = Matrix5::new(
566 11, 12, 13, 14, 15,
567 21, 22, 23, 24, 25,
568 31, 32, 33, 34, 35,
569 0, 0, 0, 0, 0,
570 0, 0, 0, 0, 0);
571
572 let expected3 = Matrix5::new(
573 11, 12, 13, 14, 15,
574 21, 22, 23, 24, 25,
575 0, 0, 0, 0, 0,
576 0, 0, 0, 0, 0,
577 31, 32, 33, 34, 35);
578
579 assert_eq!(m.insert_fixed_rows::<2>(0, 0), expected1);
580 assert_eq!(m.insert_fixed_rows::<2>(3, 0), expected2);
581 assert_eq!(m.insert_fixed_rows::<2>(2, 0), expected3);
582
583 // The following is just to verify that the return type dimensions is correctly inferred.
584 let computed: Matrix<_, Dyn, U5, _> = m.insert_rows(3, 2, 0);
585 assert!(computed.eq(&expected2));
586 }
587
588 #[test]
589 fn insert_rows_to_empty_matrix() {
590 let m1 = DMatrix::repeat(0, 0, 0);
591 let m2 = DMatrix::repeat(0, 5, 0);
592
593 let expected1 = DMatrix::repeat(3, 0, 42);
594 let expected2 = DMatrix::repeat(3, 5, 42);
595
596 assert_eq!(expected1, m1.insert_rows(0, 3, 42));
597 assert_eq!(expected2, m2.insert_rows(0, 3, 42));
598 }
599
600 #[test]
601 #[rustfmt::skip]
602 fn resize() {
603 let m = Matrix3x5::new(
604 11, 12, 13, 14, 15,
605 21, 22, 23, 24, 25,
606 31, 32, 33, 34, 35);
607
608 let add_colls = DMatrix::from_row_slice(3, 6, &[
609 11, 12, 13, 14, 15, 42,
610 21, 22, 23, 24, 25, 42,
611 31, 32, 33, 34, 35, 42]);
612
613 let del_colls = DMatrix::from_row_slice(3, 4, &[
614 11, 12, 13, 14,
615 21, 22, 23, 24,
616 31, 32, 33, 34]);
617
618 let add_rows = DMatrix::from_row_slice(4, 5, &[
619 11, 12, 13, 14, 15,
620 21, 22, 23, 24, 25,
621 31, 32, 33, 34, 35,
622 42, 42, 42, 42, 42]);
623
624 let del_rows = DMatrix::from_row_slice(2, 5, &[
625 11, 12, 13, 14, 15,
626 21, 22, 23, 24, 25]);
627
628 let add_add = DMatrix::from_row_slice(5, 6, &[
629 11, 12, 13, 14, 15, 42,
630 21, 22, 23, 24, 25, 42,
631 31, 32, 33, 34, 35, 42,
632 42, 42, 42, 42, 42, 42,
633 42, 42, 42, 42, 42, 42]);
634
635 let del_del = DMatrix::from_row_slice(1, 2, &[11, 12]);
636
637 let add_del = DMatrix::from_row_slice(5, 2, &[
638 11, 12,
639 21, 22,
640 31, 32,
641 42, 42,
642 42, 42]);
643
644 let del_add = DMatrix::from_row_slice(1, 8, &[
645 11, 12, 13, 14, 15, 42, 42, 42]);
646
647 assert_eq!(add_colls, m.resize(3, 6, 42));
648 assert_eq!(del_colls, m.resize(3, 4, 42));
649 assert_eq!(add_rows, m.resize(4, 5, 42));
650 assert_eq!(del_rows, m.resize(2, 5, 42));
651 assert_eq!(del_del, m.resize(1, 2, 42));
652 assert_eq!(add_add, m.resize(5, 6, 42));
653 assert_eq!(add_del, m.resize(5, 2, 42));
654 assert_eq!(del_add, m.resize(1, 8, 42));
655 }
656
657 #[test]
658 fn resize_empty_matrix() {
659 let m1 = DMatrix::repeat(0, 0, 0);
660 let m2 = DMatrix::repeat(1, 0, 0); // Less rows than target size.
661 let m3 = DMatrix::repeat(3, 0, 0); // Same rows as target size.
662 let m4 = DMatrix::repeat(9, 0, 0); // More rows than target size.
663 let m5 = DMatrix::repeat(0, 1, 0); // Less columns than target size.
664 let m6 = DMatrix::repeat(0, 5, 0); // Same columns as target size.
665 let m7 = DMatrix::repeat(0, 9, 0); // More columns than target size.
666
667 let resized = DMatrix::repeat(3, 5, 42);
668 let resized_wo_rows = DMatrix::repeat(0, 5, 42);
669 let resized_wo_cols = DMatrix::repeat(3, 0, 42);
670
671 assert_eq!(resized, m1.clone().resize(3, 5, 42));
672 assert_eq!(resized, m2.clone().resize(3, 5, 42));
673 assert_eq!(resized, m3.clone().resize(3, 5, 42));
674 assert_eq!(resized, m4.clone().resize(3, 5, 42));
675 assert_eq!(resized, m5.clone().resize(3, 5, 42));
676 assert_eq!(resized, m6.clone().resize(3, 5, 42));
677 assert_eq!(resized, m7.clone().resize(3, 5, 42));
678
679 assert_eq!(resized_wo_rows, m1.clone().resize(0, 5, 42));
680 assert_eq!(resized_wo_rows, m2.clone().resize(0, 5, 42));
681 assert_eq!(resized_wo_rows, m3.clone().resize(0, 5, 42));
682 assert_eq!(resized_wo_rows, m4.clone().resize(0, 5, 42));
683 assert_eq!(resized_wo_rows, m5.clone().resize(0, 5, 42));
684 assert_eq!(resized_wo_rows, m6.clone().resize(0, 5, 42));
685 assert_eq!(resized_wo_rows, m7.clone().resize(0, 5, 42));
686
687 assert_eq!(resized_wo_cols, m1.clone().resize(3, 0, 42));
688 assert_eq!(resized_wo_cols, m2.clone().resize(3, 0, 42));
689 assert_eq!(resized_wo_cols, m3.clone().resize(3, 0, 42));
690 assert_eq!(resized_wo_cols, m4.clone().resize(3, 0, 42));
691 assert_eq!(resized_wo_cols, m5.clone().resize(3, 0, 42));
692 assert_eq!(resized_wo_cols, m6.clone().resize(3, 0, 42));
693 assert_eq!(resized_wo_cols, m7.clone().resize(3, 0, 42));
694
695 assert_eq!(m1, m1.clone().resize(0, 0, 42));
696 assert_eq!(m1, m2.resize(0, 0, 42));
697 assert_eq!(m1, m3.resize(0, 0, 42));
698 assert_eq!(m1, m4.resize(0, 0, 42));
699 assert_eq!(m1, m5.resize(0, 0, 42));
700 assert_eq!(m1, m6.resize(0, 0, 42));
701 assert_eq!(m1, m7.resize(0, 0, 42));
702 }