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

[Bug] [lang] Fix some missing operator overrides like __rlshift__ #1978

Merged
merged 3 commits into from
Oct 21, 2020
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
41 changes: 41 additions & 0 deletions python/taichi/lang/common_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,51 @@ def __and__(self, other):
_taichi_skip_traceback = 1
return ti.bit_and(self, other)

def __rand__(self, other):
import taichi as ti
_taichi_skip_traceback = 1
return ti.bit_and(other, self)

def __or__(self, other):
import taichi as ti
_taichi_skip_traceback = 1
return ti.bit_or(self, other)

def __ror__(self, other):
import taichi as ti
_taichi_skip_traceback = 1
return ti.bit_or(other, self)

def __xor__(self, other):
import taichi as ti
_taichi_skip_traceback = 1
return ti.bit_xor(self, other)

def __rxor__(self, other):
import taichi as ti
_taichi_skip_traceback = 1
return ti.bit_xor(other, self)

def __lshift__(self, other):
import taichi as ti
_taichi_skip_traceback = 1
return ti.bit_shl(self, other)

def __rlshift__(self, other):
import taichi as ti
_taichi_skip_traceback = 1
return ti.bit_shl(other, self)

def __rshift__(self, other):
import taichi as ti
_taichi_skip_traceback = 1
return ti.bit_sar(self, other)

def __rrshift__(self, other):
import taichi as ti
_taichi_skip_traceback = 1
return ti.bit_sar(other, self)

def logical_and(self, other):
import taichi as ti
_taichi_skip_traceback = 1
Expand Down Expand Up @@ -229,6 +254,18 @@ def __imod__(self, other):
self.assign(ti.mod(self, other))
return self

def __ilshift__(self, other):
import taichi as ti
_taichi_skip_traceback = 1
self.assign(ti.bit_shl(self, other))
return self

def __irshift__(self, other):
import taichi as ti
_taichi_skip_traceback = 1
self.assign(ti.bit_shr(self, other))
return self

def assign(self, other):
import taichi as ti
_taichi_skip_traceback = 1
Expand All @@ -254,6 +291,10 @@ def augassign(self, x, op):
self |= x
elif op == 'BitXor':
self ^= x
elif op == 'RShift':
self >>= x
elif op == 'LShift':
self <<= x
else:
assert False, op

Expand Down
3 changes: 2 additions & 1 deletion taichi/transforms/type_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ class TypeCheck : public IRVisitor {
TI_ASSERT(stmt->width() == 1);
if (stmt->val->ret_type != stmt->dest->ret_type.ptr_removed()) {
// TODO: make sure the ptr_removed type is indeed a numerical type
TI_WARN("[{}] Atomic add ({} to {}) may lose precision.", stmt->name(),
TI_WARN("[{}] Atomic add ({} to {}) may lose precision, at", stmt->name(),
data_type_name(stmt->val->ret_type),
data_type_name(stmt->dest->ret_type.ptr_removed()));
TI_WARN("\n{}", stmt->tb);
stmt->val = insert_type_cast_before(stmt, stmt->val,
stmt->dest->ret_type.ptr_removed());
}
Expand Down