Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def generic_value_to_scalar(gv, t):
assert isinstance(t, ptype.ScalarT), "Expected %s to be scalar" % t
if isinstance(t, ptype.IntT):
x = gv.as_int()
else:
assert isinstance(t, ptype.FloatT)
x = gv.as_real(dtype_to_lltype(t.dtype))
return t.dtype.type(x)
def scalar_to_generic_value(x, t):
if isinstance(t, ptype.FloatT):
return GenericValue.real(dtype_to_lltype(t.dtype), x)
elif t == ptype.Bool:
return GenericValue.int(int8_t, x)
else:
assert isinstance(t, ptype.IntT)
# assume it's an integer
return GenericValue.int(dtype_to_lltype(t.dtype), x)
def generic_value_to_scalar(gv, t):
assert isinstance(t, ptype.ScalarT), "Expected %s to be scalar" % t
if isinstance(t, ptype.IntT):
x = gv.as_int()
else:
assert isinstance(t, ptype.FloatT)
x = gv.as_real(dtype_to_lltype(t.dtype))
return t.dtype.type(x)
def scalar_to_generic_value(x, t):
if isinstance(t, ptype.FloatT):
return GenericValue.real(dtype_to_lltype(t.dtype), x)
elif t == ptype.Bool:
return GenericValue.int(int8_t, x)
else:
assert isinstance(t, ptype.IntT)
# assume it's an integer
return GenericValue.int(dtype_to_lltype(t.dtype), x)