Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def combine(self, other):
if isinstance(other, TupleT) and len(other.elt_types) == len(self.elt_types):
combined_elt_types = [t1.combine(t2) for \
(t1, t2) in zip(self.elt_types, other.elt_tyepes)]
if combined_elt_types != self.elt_types:
return TupleT(combined_elt_types)
else:
return self
else:
raise IncompatibleTypes(self, other)
def type_of_value(x):
if np.isscalar(x):
return type_of_scalar(x)
elif isinstance(x, tuple):
elt_types = map(type_of_value, x)
return TupleT(elt_types)
elif isinstance(x, np.ndarray):
return ArrayT(from_dtype(x.dtype), np.rank(x))
else:
raise RuntimeError("Unsupported type " + str(type(x)))
def combine(self, other):
if isinstance(other, TupleT) and len(other.elt_types) == len(self.elt_types):
combined_elt_types = [t1.combine(t2) for \
(t1, t2) in zip(self.elt_types, other.elt_tyepes)]
if combined_elt_types != self.elt_types:
return TupleT(combined_elt_types)
else:
return self
else:
raise IncompatibleTypes(self, other)
def repeat_tuple(t, n):
"""Given the base type t, construct the n-tuple t*t*...*t"""
elt_types = tuple([t] * n)
if elt_types in _tuple_types:
return _tuple_types[elt_types]
else:
tuple_t = TupleT(elt_types)
_tuple_types[elt_types] = tuple_t
return tuple_t
def make_tuple_type(elt_types):
"""
Use this memoized construct to avoid
constructing too many distinct tuple type
objects and speeding up equality checks
"""
key = tuple(elt_types)
if key in _tuple_types:
return _tuple_types[key]
else:
t = TupleT(key)
_tuple_types[key] = t
return t