Skip to content

Commit

Permalink
Fix discrepancy between docs and registered kernels for `tf.ones_like…
Browse files Browse the repository at this point in the history
…`/`tf.zeros_like` (tensorflow#13598)

* Fix discrepancy between docs and registered kernels for `tf.ones_like`

This fix tries to address the discrepancy between docs and registered
kernels for `tf.ones_like`. From the implementation the OnesLike is
registered with all POD types. However, in the documentation several
data types are missing (uint8, int8, uint16, int16, bool).

This fix addresses the issue by adding missing types to documentation.

Signed-off-by: Yong Tang <[email protected]>

* Fix python docs for `tf.ones_like`

This commit fixes python docs for `tf.ones_like`

Signed-off-by: Yong Tang <[email protected]>

* Fix python docs for `tf.zeros_like`

This commit fixes python docs for `tf.zeros_like`

Signed-off-by: Yong Tang <[email protected]>

* Add test cases for different dtypes on `tf.ones_like` and `tf.zeros_like`

Signed-off-by: Yong Tang <[email protected]>
  • Loading branch information
yongtang authored and gunan committed Nov 2, 2017
1 parent 0288097 commit 6a8322f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 3 additions & 1 deletion tensorflow/core/ops/array_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,9 @@ y: a tensor of the same shape and type as x but filled with zeros.
REGISTER_OP("OnesLike")
.Input("x: T")
.Output("y: T")
.Attr("T: {float, double, int32, int64, complex64, complex128}")
.Attr(
"T: {float, double, int8, uint8, int16, uint16, int32, int64, "
"complex64, complex128, bool}")
.SetShapeFn(shape_inference::UnchangedShape)
.Doc(R"doc(
Returns a tensor of ones with the same shape and type as x.
Expand Down
14 changes: 8 additions & 6 deletions tensorflow/python/kernel_tests/constant_op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,10 @@ def _compareZeros(self, dtype, fully_defined_shape, use_gpu):

def testZerosLikeCPU(self):
for dtype in [
dtypes_lib.float32, dtypes_lib.float64, dtypes_lib.int32,
dtypes_lib.uint8, dtypes_lib.int16, dtypes_lib.int8,
dtypes_lib.complex64, dtypes_lib.complex128, dtypes_lib.int64,
dtypes_lib.float32, dtypes_lib.float64,
dtypes_lib.int8, dtypes_lib.uint8, dtypes_lib.int16, dtypes_lib.uint16,
dtypes_lib.int32, dtypes_lib.int64, dtypes_lib.bool,
dtypes_lib.complex64, dtypes_lib.complex128,
dtypes_lib.string
]:
self._compareZeros(dtype, fully_defined_shape=False, use_gpu=False)
Expand Down Expand Up @@ -573,9 +574,10 @@ class OnesLikeTest(test.TestCase):

def testOnesLike(self):
for dtype in [
dtypes_lib.float32, dtypes_lib.float64, dtypes_lib.int32,
dtypes_lib.uint8, dtypes_lib.int16, dtypes_lib.int8,
dtypes_lib.complex64, dtypes_lib.complex128, dtypes_lib.int64
dtypes_lib.float32, dtypes_lib.float64,
dtypes_lib.int8, dtypes_lib.uint8, dtypes_lib.int16, dtypes_lib.uint16,
dtypes_lib.int32, dtypes_lib.int64, dtypes_lib.bool,
dtypes_lib.complex64, dtypes_lib.complex128
]:
numpy_dtype = dtype.as_numpy_dtype
with self.test_session():
Expand Down
7 changes: 4 additions & 3 deletions tensorflow/python/ops/array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,8 @@ def zeros_like(tensor, dtype=None, name=None, optimize=True):
Args:
tensor: A `Tensor`.
dtype: A type for the returned `Tensor`. Must be `float32`, `float64`,
`int8`, `int16`, `int32`, `int64`, `uint8`, `complex64`, or `complex128`.
`int8`, `uint8`, `int16`, `uint16`, int32`, `int64`,
`complex64`, `complex128` or `bool`.
name: A name for the operation (optional).
optimize: if true, attempt to statically determine the shape of 'tensor'
and encode it as a constant.
Expand Down Expand Up @@ -1546,8 +1547,8 @@ def ones_like(tensor, dtype=None, name=None, optimize=True):
Args:
tensor: A `Tensor`.
dtype: A type for the returned `Tensor`. Must be `float32`, `float64`,
`int8`, `int16`, `int32`, `int64`, `uint8`, `complex64`, `complex128` or
`bool`.
`int8`, `uint8`, `int16`, `uint16`, int32`, `int64`,
`complex64`, `complex128` or `bool`.
name: A name for the operation (optional).
optimize: if true, attempt to statically determine the shape of 'tensor'
and encode it as a constant.
Expand Down

0 comments on commit 6a8322f

Please sign in to comment.