MCPcopy Create free account
hub / github.com/XingangPan/DragGAN / assert_shape

Function assert_shape

torch_utils/misc.py:82–95  ·  view source on GitHub ↗
(tensor, ref_shape)

Source from the content-addressed store, hash-verified

80# Performs symbolic assertion when used in torch.jit.trace().
81
82def assert_shape(tensor, ref_shape):
83 if tensor.ndim != len(ref_shape):
84 raise AssertionError(f'Wrong number of dimensions: got {tensor.ndim}, expected {len(ref_shape)}')
85 for idx, (size, ref_size) in enumerate(zip(tensor.shape, ref_shape)):
86 if ref_size is None:
87 pass
88 elif isinstance(ref_size, torch.Tensor):
89 with suppress_tracer_warnings(): # as_tensor results are registered as constants
90 symbolic_assert(torch.equal(torch.as_tensor(size), ref_size), f'Wrong size for dimension {idx}')
91 elif isinstance(size, torch.Tensor):
92 with suppress_tracer_warnings(): # as_tensor results are registered as constants
93 symbolic_assert(torch.equal(size, torch.as_tensor(ref_size)), f'Wrong size for dimension {idx}: expected {ref_size}')
94 elif size != ref_size:
95 raise AssertionError(f'Wrong size for dimension {idx}: got {size}, expected {ref_size}')
96
97#----------------------------------------------------------------------------
98# Function decorator that calls torch.autograd.profiler.record_function().

Callers

nothing calls this directly

Calls 1

suppress_tracer_warningsFunction · 0.70

Tested by

no test coverage detected