Get spatial shape for fake data according to the specified shape pattern. It supports `int` number and `string` with formats like: "32", "32 * n", "32 ** p", "32 ** p *n". Args: shape: specified pattern for the spatial shape. p: power factor to generate fake data shape
(shape: Sequence[str | int], p: int = 1, n: int = 1, any: int = 1)
| 139 | |
| 140 | |
| 141 | def _get_fake_spatial_shape(shape: Sequence[str | int], p: int = 1, n: int = 1, any: int = 1) -> tuple: |
| 142 | """ |
| 143 | Get spatial shape for fake data according to the specified shape pattern. |
| 144 | It supports `int` number and `string` with formats like: "32", "32 * n", "32 ** p", "32 ** p *n". |
| 145 | |
| 146 | Args: |
| 147 | shape: specified pattern for the spatial shape. |
| 148 | p: power factor to generate fake data shape if dim of expected shape is "x**p", default to 1. |
| 149 | p: multiply factor to generate fake data shape if dim of expected shape is "x*n", default to 1. |
| 150 | any: specified size to generate fake data shape if dim of expected shape is "*", default to 1. |
| 151 | |
| 152 | """ |
| 153 | ret = [] |
| 154 | for i in shape: |
| 155 | if isinstance(i, int): |
| 156 | ret.append(i) |
| 157 | elif isinstance(i, str): |
| 158 | if i == "*": |
| 159 | ret.append(any) |
| 160 | else: |
| 161 | for c in _get_var_names(i): |
| 162 | if c not in ["p", "n"]: |
| 163 | raise ValueError(f"only support variables 'p' and 'n' so far, but got: {c}.") |
| 164 | ret.append(eval(i, {"p": p, "n": n})) |
| 165 | else: |
| 166 | raise ValueError(f"spatial shape items must be int or string, but got: {type(i)} {i}.") |
| 167 | return tuple(ret) |
| 168 | |
| 169 | |
| 170 | def _get_git_release_url(repo_owner: str, repo_name: str, tag_name: str, filename: str) -> str: |
no test coverage detected
searching dependent graphs…