Esempio n. 1
0
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"
Esempio n. 2
0
 def visit_Cast(self, node: gtir.Cast) -> oir.Cast:
     return oir.Cast(dtype=node.dtype, expr=self.visit(node.expr), loc=node.loc)
Esempio n. 3
0
 def visit_Literal(self, node: oir.Cast, in_idx=False):
     if in_idx:
         return node
     else:
         return oir.Cast(dtype=node.dtype, expr=node)
Esempio n. 4
0
 def visit_Cast(self, node: gtir.Cast, **kwargs: Any) -> oir.Cast:
     return oir.Cast(dtype=node.dtype, expr=self.visit(node.expr))
Esempio n. 5
0
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
    )