inaos / iron-array

2 stars 0 forks source link

Glitch in evaluating ~ operand (as logical not) #561

Closed FrancescAlted closed 2 years ago

FrancescAlted commented 2 years ago

This reproduces the issue:

import iarray as ia
import numpy as np

shape = [10, 1_000]
x = ia.linspace(shape, 0.0, 10.0)
y = ia.arange(shape)
z = ia.linspace(shape, 0.0, 10.0)

# lazyexpr = (x[(y == 30) & ~(z == 4)])  # works!
lazyexpr = (x[~(z == 4)])  # does not work.  lazyexpr here: (o1[(not(o0 == 4))]))
res = lazyexpr.eval()
print(y.data)

# check
xnp = x.data
ynp = y.data
znp = z.data
# resnp = np.where((ynp == 30) & ~(znp == 4), xnp, np.nan)
resnp = np.where(~(znp == 4), xnp, np.nan)
np.testing.assert_almost_equal(resnp, res.data, decimal=3)

Error is:

/Users/faltet/miniconda3/envs/iron-array-python/bin/python /Users/faltet/iarray/iron-array-python/examples/lazy_expr-bug.py
Traceback (most recent call last):
  File "/Users/faltet/iarray/iron-array-python/examples/lazy_expr-bug.py", line 11, in <module>
    res = lazyexpr.eval()
  File "/Users/faltet/iarray/iron-array-python/iarray/lazy_expr.py", line 226, in eval
    expr = expr_udf(self.expression, self.operands, debug=0)
  File "/Users/faltet/iarray/iron-array-python/iarray/expr_udf.py", line 214, in expr_udf
    udf_func = udf.jit(py_func, ast=tree, debug=debug)
  File "/Users/faltet/iarray/iron-array-python/iarray/udf.py", line 234, in jit
    return super().jit(*args, **kwargs)
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 1338, in jit
    function.compile(node=ast, debug=debug)
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 1264, in compile
    GenVisitor(debug, self).traverse(node)
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 232, in traverse
    value = [self.traverse(x, node) for x in field if isinstance(x, ast.AST)]
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 232, in <listcomp>
    value = [self.traverse(x, node) for x in field if isinstance(x, ast.AST)]
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 232, in traverse
    value = [self.traverse(x, node) for x in field if isinstance(x, ast.AST)]
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 232, in <listcomp>
    value = [self.traverse(x, node) for x in field if isinstance(x, ast.AST)]
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 232, in traverse
    value = [self.traverse(x, node) for x in field if isinstance(x, ast.AST)]
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 232, in <listcomp>
    value = [self.traverse(x, node) for x in field if isinstance(x, ast.AST)]
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 232, in traverse
    value = [self.traverse(x, node) for x in field if isinstance(x, ast.AST)]
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 232, in <listcomp>
    value = [self.traverse(x, node) for x in field if isinstance(x, ast.AST)]
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 234, in traverse
    value = self.traverse(field, node)
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 243, in traverse
    return self.callback("exit", node, parent, *args)
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 253, in callback
    value = cb(node, parent, *args) if cb is not None else None
  File "/Users/faltet/iarray/iron-array-python/iarray/py2llvm/py2llvm.py", line 842, in Subscript_exit
    raise NotImplementedError(f"{type(value)} does not support subscript []")
NotImplementedError: <class 'llvmlite.ir.instructions.LoadInstr'> does not support subscript []

Process finished with exit code 1
FrancescAlted commented 2 years ago

BTW, this is in develop, where I already merged most of the enhanced masks and reductions in lazy expression.