Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore parentheses when check vectorizability #4038

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1973,14 +1973,19 @@ private void checkVectorizability(MethodCallExpr n, Expression[] expressions, Py

// Python vectorized functions(numba, DH) return arrays of primitive/Object types. This will break the generated
// expression evaluation code that expects singular values. This check makes sure that numba/dh vectorized
// functions must be used alone as the entire expression.
n.getParentNode().ifPresent(parent -> {
if (parent.getClass() == CastExpr.class) {
// functions must be used alone as the entire expression after removing the enclosing parentheses.
Node n1 = n;
while (n1.hasParentNode()) {
n1 = n1.getParentNode().get();
Class cls = n1.getClass();

if (cls == CastExpr.class) {
throw new RuntimeException(
"The return values of Python vectorized function can't be cast: " + parent);
"The return values of Python vectorized function can't be cast: " + n1);
} else if (cls != EnclosedExpr.class) {
throw new RuntimeException("Python vectorized function can't be used in another expression: " + n1);
}
throw new RuntimeException("Python vectorized function can't be used in another expression: " + parent);
});
}

for (int i = 0; i < expressions.length; i++) {
if (!(expressions[i] instanceof NameExpr) && !(expressions[i] instanceof LiteralExpr)) {
Expand Down
14 changes: 14 additions & 0 deletions py/server/tests/test_vectorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ def my_sum(*args):
result = source.update(f"X = my_sum({','.join(cols)})")
self.assertEqual(len(cols) + 1, len(result.columns))

def test_enclosed_by_parentheses(self):
def sinc(x) -> np.double:
return np.sinc(x)

t = empty_table(100).update(["X = 0.1 * i", "SincXS=((sinc(X)))"])
self.assertEqual(t.columns[1].data_type, dtypes.double)
self.assertEqual(deephaven.table._vectorized_count, 1)

def sinc2(x):
return np.sinc(x)

t = empty_table(100).update(["X = 0.1 * i", "SincXS=((sinc2(X)))"])
self.assertEqual(t.columns[1].data_type, dtypes.PyObject)


if __name__ == "__main__":
unittest.main()