NamedDimension
The core named dimension type and the Dim convenience constructor.
torchlinops.nameddim.Dim
Convenience function for splitting a string into a tuple of dimension names.
Parses a compact dimension string into individual dimension names using simple rules:
- A new dimension begins at each uppercase letter.
- A dimension name cannot start with a digit.
- The special token
()(ANY) is recognised and split out.
| PARAMETER | DESCRIPTION |
|---|---|
s
|
The compact dimension string to parse. If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of str
|
A tuple of individual dimension name strings. |
Examples:
>>> Dim("ABCD")
('A', 'B', 'C', 'D')
>>> Dim("NxNyNz")
('Nx', 'Ny', 'Nz')
>>> Dim("A1B2Kx1Ky2")
('A1', 'B2', 'Kx1', 'Ky2')
>>> Dim("()A()B")
('()', 'A', '()', 'B')
Source code in src/torchlinops/nameddim/_nameddim.py
torchlinops.nameddim.NamedDimension
dataclass
Fundamental named dimension type used throughout the library.
Each dimension has a name and an optional integer index i for
creating indexed variants (e.g. A1, A2). Two
NamedDimension instances are considered equal when their string
representations match; the index is folded into the representation
rather than compared separately.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The base name of the dimension (e.g.
TYPE:
|
i
|
Integer index for indexed variants. Defaults to
TYPE:
|
Examples:
Source code in src/torchlinops/nameddim/_nameddim.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
infer
classmethod
Create a NamedDimension by inferring the name and optional index.
If dim is already a NamedDimension it is returned as-is.
A two-character string whose second character is a digit is
interpreted as name=dim[0], i=int(dim[1]). Sequences are
inferred element-wise.
| PARAMETER | DESCRIPTION |
|---|---|
dim
|
A
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NamedDimension or sequence thereof
|
The inferred dimension(s). |
Source code in src/torchlinops/nameddim/_nameddim.py
next_unused
Get the next dim by index that does not occur in tup