Commit 5056ef8
authored
Add traits and types to capture dimensionality (#1568)
ndarray has a history of encoding arrays’ dimensionality in the type system; this turns out to be useful both for debugging and for writing complex array libraries. However, some arrays don’t (or can’t) have their dimensionality known at compile time. One good example of this is the output of ArrayBase::squeeze: even if the array’s dimensionality is known before the operation, the dimensionality of the output depends on how many axes have length one.
The Dimensionality trait is intended to unify both the known- and unknown-dimensionality cases. Compile-time dimensionalities are represented using NDim, while cases where the dimensionality cannot be known at compile time are represented using DDyn.
A key design choice is that there is no way to recover the number of dimensions as a runtime value from a type implementing Dimensionality. A dynamic dimensionality here does not mean “known at runtime”, but rather “cannot be known at compile time”. The actual number of axes is always taken from the array’s shape, which avoids having two separate sources of truth.1 parent 953f2e9 commit 5056ef8
File tree
5 files changed
+364
-1
lines changed- src
- dimension
- layout
5 files changed
+364
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
79 | 85 | | |
80 | 86 | | |
81 | 87 | | |
| |||
420 | 426 | | |
421 | 427 | | |
422 | 428 | | |
| 429 | + | |
| 430 | + | |
423 | 431 | | |
424 | 432 | | |
425 | 433 | | |
| |||
470 | 478 | | |
471 | 479 | | |
472 | 480 | | |
| 481 | + | |
| 482 | + | |
473 | 483 | | |
474 | 484 | | |
475 | 485 | | |
| |||
603 | 613 | | |
604 | 614 | | |
605 | 615 | | |
| 616 | + | |
| 617 | + | |
606 | 618 | | |
607 | 619 | | |
608 | 620 | | |
| |||
778 | 790 | | |
779 | 791 | | |
780 | 792 | | |
| 793 | + | |
| 794 | + | |
781 | 795 | | |
782 | 796 | | |
783 | 797 | | |
| |||
910 | 924 | | |
911 | 925 | | |
912 | 926 | | |
| 927 | + | |
| 928 | + | |
913 | 929 | | |
914 | 930 | | |
915 | 931 | | |
| |||
960 | 976 | | |
961 | 977 | | |
962 | 978 | | |
| 979 | + | |
| 980 | + | |
963 | 981 | | |
964 | 982 | | |
965 | 983 | | |
| |||
0 commit comments