MCPcopy Create free account
hub / github.com/pytorch/executorch / to_nd_array

Function to_nd_array

backends/cadence/runtime/runtime.py:155–167  ·  view source on GitHub ↗
(v: Union[bool, numbers.Number, ndarray, torch.Tensor])

Source from the content-addressed store, hash-verified

153
154
155def to_nd_array(v: Union[bool, numbers.Number, ndarray, torch.Tensor]) -> np.ndarray:
156 if isinstance(v, np.ndarray):
157 return v
158
159 if isinstance(v, torch.Tensor):
160 # If v was quantized, we compare its int representation.
161 v = v.int_repr() if v.is_quantized else v
162 return v.cpu().detach().numpy()
163
164 if isinstance(v, (numbers.Number, bool)):
165 return np.array([v])
166
167 raise RuntimeError(f"Unknown type {type(v)}")

Callers 1

compareFunction · 0.85

Calls 1

int_reprMethod · 0.45

Tested by

no test coverage detected