MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / _get_fake_spatial_shape

Function _get_fake_spatial_shape

monai/bundle/scripts.py:141–167  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

139
140
141def _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
170def _get_git_release_url(repo_owner: str, repo_name: str, tag_name: str, filename: str) -> str:

Callers 2

_get_fake_input_shapeFunction · 0.85
verify_net_in_outFunction · 0.85

Calls 2

_get_var_namesFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…