# llvmlite ir.IntType specialises the formatting of the constant for a # cpython bool. A NumPy np.bool_ is not a cpython bool so force it to be one # so that the constant renders correctly! if isinstance(pyval, np.bool_): pyval = bool(pyval) lty = context.get_value_type(ty) return lty(pyval) #------------------------------------------------------------------------------- # View def scalar_view(scalar, viewty): """ Typing for the np scalar 'view' method. """ if (isinstance(scalar, (types.Float, types.Integer)) and isinstance(viewty, types.abstract.DTypeSpec)): if scalar.bitwidth != viewty.dtype.bitwidth: raise errors.TypingError( "Changing the dtype of a 0d array is only supported if the " "itemsize is unchanged") def impl(scalar, viewty): return viewer(scalar, viewty) return impl overload_method(types.Float, 'view')(scalar_view) overload_method(types.Integer, 'view')(scalar_view)
@lower_constant(types.Integer) @lower_constant(types.Float) @lower_constant(types.Boolean) def constant_integer(context, builder, ty, pyval): lty = context.get_value_type(ty) return lty(pyval) # ------------------------------------------------------------------------------- # View def scalar_view(scalar, viewty): """ Typing for the np scalar 'view' method. """ if isinstance(scalar, (types.Float, types.Integer)) and isinstance( viewty, types.abstract.DTypeSpec): if scalar.bitwidth != viewty.dtype.bitwidth: raise errors.TypingError( "Changing the dtype of a 0d array is only supported if the " "itemsize is unchanged") def impl(scalar, viewty): return viewer(scalar, viewty) return impl overload_method(types.Float, "view")(scalar_view) overload_method(types.Integer, "view")(scalar_view)