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

[Doc] Update docstring of pow() #6046

Merged
merged 5 commits into from
Sep 13, 2022
Merged
Changes from 2 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
26 changes: 17 additions & 9 deletions python/taichi/lang/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,18 @@ def expr_python_mod(a, b):
def pow(x, a): # pylint: disable=W0622
strongoier marked this conversation as resolved.
Show resolved Hide resolved
"""First array elements raised to powers from second array :math:`x^a`, element-wise.

Negative values raised to a non-integral value will return `nan`.
A zero value raised to a negative value will return `inf`.
If debug mode or optimization passes are on, an exception will be raised
when an integral value is raised to a negative value; otherwise 1 will be returned.
The result type of two scalar operands is determined as follows:
- If the exponent is an integral value, then the result type takes the type of the base.
- Otherwise, the result type follows
[Implicit type casting in binary operations](https://docs.taichi-lang.org/docs/type#implicit-type-casting-in-binary-operations).

With the above rules, an integral value raised to a negative integral value cannot have a
feasible type. Therefore, an exception will be raised if debug mode or optimization passes
are on; otherwise 1 will be returned.

In the following situations, the result is undefined:
- A negative value raised to a non-integral value.
- A zero value raised to a non-positive value.

Args:
x (Union[:mod:`~taichi.types.primitive_types`, :class:`~taichi.Matrix`]): \
Expand All @@ -744,20 +752,20 @@ def pow(x, a): # pylint: disable=W0622
The exponents.

Returns:
The bases in `x1` raised to the exponents in `x2`. This is a scalar if both \
`x1` and `x2` are scalars.
The bases in `x` raised to the exponents in `a`. This is a scalar if both \
`x` and `a` are scalars.

Example::

>>> @ti.kernel
>>> def test():
>>> x = ti.Matrix([-2.0, 0.0, 2.0])
>>> y = -2.2
>>> x = ti.Matrix([-2.0, 2.0])
>>> y = -3
>>> z = ti.pow(x, y)
>>> print(z)
>>>
>>> test()
[-nan, inf, 0.217638]
[-0.125000, 0.125000]
"""
return _binary_operation(_ti_core.expr_pow, _bt_ops_mod.pow, x, a)

Expand Down