| 107 | |
| 108 | |
| 109 | def expand_to(x, *, ndim, axes): |
| 110 | # Force axes into a tuple |
| 111 | |
| 112 | try: |
| 113 | axes = tuple(axes) |
| 114 | except TypeError: |
| 115 | axes = tuple([axes]) |
| 116 | |
| 117 | if len(axes) != x.ndim: |
| 118 | raise RuntimeError( |
| 119 | "Shape mismatch between axes={} and input x.shape={}".format(axes, x.shape) |
| 120 | ) |
| 121 | |
| 122 | if ndim < x.ndim: |
| 123 | raise RuntimeError( |
| 124 | "Cannot expand x.shape={} to fewer dimensions ndim={}".format(x.shape, ndim) |
| 125 | ) |
| 126 | |
| 127 | shape = [1] * ndim |
| 128 | for i, axi in enumerate(axes): |
| 129 | shape[axi] = x.shape[i] |
| 130 | |
| 131 | return x.reshape(shape) |
| 132 | |
| 133 | |
| 134 | def dtype_r2c(d, *, default=np.complex64): |