def test_cast(broadcast): itof = oir.Cast(dtype=common.DataType.FLOAT64, expr=oir.Literal(value="42", dtype=common.DataType.INT32)) result = OirToNpir().visit(itof, broadcast=broadcast) assert isinstance(result, npir.BroadCast if broadcast else npir.Cast) cast = result if broadcast: assert isinstance(result, npir.BroadCast) assert isinstance(result, npir.VectorExpression) cast = result.expr assert cast.dtype == itof.dtype assert cast.expr.value == "42"
def visit_Cast(self, node: gtir.Cast) -> oir.Cast: return oir.Cast(dtype=node.dtype, expr=self.visit(node.expr), loc=node.loc)
def visit_Literal(self, node: oir.Cast, in_idx=False): if in_idx: return node else: return oir.Cast(dtype=node.dtype, expr=node)
def visit_Cast(self, node: gtir.Cast, **kwargs: Any) -> oir.Cast: return oir.Cast(dtype=node.dtype, expr=self.visit(node.expr))
def test_cast(oir_int_expr, npir_type) -> None: assert isinstance( OirToNpir().visit(oir.Cast(dtype=common.DataType.FLOAT64, expr=oir_int_expr)), npir_type )