Commit 5982692e authored by Akshay Modi's avatar Akshay Modi Committed by TensorFlower Gardener
Browse files

Tighten up constant_op.constant casting in eager-mode.

Previously, eager would always cast all values to the requested dtype.
This didn't match graph mode, which would only allow casting values between
'compatible' types (e.g. all integer types are compatible with each other, but
no floating type is compatible with any integer type).
Graph mode uses _AssertCompatible (https://github.com/tensorflow/tensorflow/blob/dc10ac4559f795db2d070b0cc1371123c70a4caf/tensorflow/python/framework/tensor_util.py#L345)
to determine type compatibility. Eager mode type inference is a little
different.

After this CL, the intention is that constant_op.constant behave identically in graph and eager.

Note that this doesn't check correctly for overflows (in graph or eager). This means "tf.constant(544444, dtype=tf.uint8) < 200" will both return True.

PiperOrigin-RevId: 218717988
parent 52c3f583
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment