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

[lang] Deprecate ti.raw_pow #1330

Merged
merged 1 commit into from
Jun 26, 2020
Merged
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
38 changes: 1 addition & 37 deletions python/taichi/lang/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,42 +207,6 @@ def random(dt=None):
return Expr(ti_core.make_rand_expr(dt))


# TODO: move this to a C++ pass (#944)
def pow(self, power):
import taichi as ti
if not is_taichi_expr(self) and not is_taichi_expr(power):
# Python constant computations (#1188)
return raw_pow(self, power)
if not isinstance(power, int):
return raw_pow(self, power)
if power == 0:
# TODO: remove the hack, use {Expr,Matrix}.dup().fill(1)
# also note that this can be solved by #940
return self * 0 + 1

negative = power < 0
# Why not simply use `power = abs(power)`?
# Because `abs` is overrided by the `ti.abs` above.
if negative:
power = -power

tmp = self
ret = None
while power:
if power & 1:
if ret is None:
ret = tmp
else:
ret = ti.expr_init(ret * tmp)
tmp = ti.expr_init(tmp * tmp)
power >>= 1

if negative:
return 1 / ret
else:
return ret


# NEXT: add matpow(self, power)


Expand Down Expand Up @@ -280,7 +244,7 @@ def expr_python_mod(a, b):


@binary
def raw_pow(a, b):
def pow(a, b):
return _binary_operation(ti_core.expr_pow, ops.pow, a, b)


Expand Down