in source/python/neuropod/utils/config_utils.py [0:0]
def validate_tensor_spec(spec):
"""
Validates a tensor spec
"""
for item in spec:
name = item["name"]
dtype = item["dtype"]
shape = item["shape"]
if dtype not in ALLOWED_DTYPES:
raise ValueError("{} is not an allowed data type!".format(dtype))
if not isinstance(name, string_types):
raise ValueError(
"Field 'name' must be a string! Got value {} of type {}.".format(
name, type(name)
)
)
if not isinstance(shape, (list, tuple)):
raise ValueError(
"Field 'shape' must be a tuple! Got value {} of type {}.".format(
shape, type(shape)
)
)
for dim in shape:
# A bool is an instance of an int so we have to do that check first
is_uint = (
(not isinstance(dim, bool))
and isinstance(dim, integer_types)
and dim > 0
)
if dim is None or is_uint or isinstance(dim, string_types):
continue
else:
raise ValueError(
"All items in 'shape' must either be None, a string, or a positive integer! Got {}".format(
dim
)
)