Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Refine dtype logic for Power node #326

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 8 additions & 2 deletions gem/gem.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,18 @@ def __new__(cls, base, exponent):

# Constant folding
if isinstance(base, Zero):
dtype = numpy.result_type(base.dtype, exponent.dtype)
if isinstance(exponent, Constant):
dtype = numpy.result_type(base.dtype, exponent.dtype)
else:
dtype = base.dtype
if isinstance(exponent, Zero):
raise ValueError("cannot solve 0^0")
return Zero(dtype=dtype)
elif isinstance(exponent, Zero):
dtype = numpy.result_type(base.dtype, exponent.dtype)
if isinstance(base, Constant):
dtype = numpy.result_type(base.dtype, exponent.dtype)
else:
dtype = exponent.dtype
return Literal(1, dtype=dtype)
elif isinstance(base, Constant) and isinstance(exponent, Constant):
dtype = numpy.result_type(base.dtype, exponent.dtype)
Expand Down
Loading