Add python built-in types support for `tf.as_dtype` (#17652)
authorYong Tang <yong.tang.github@outlook.com>
Tue, 10 Apr 2018 17:34:32 +0000 (10:34 -0700)
committerDerek Murray <derek.murray@gmail.com>
Tue, 10 Apr 2018 17:34:32 +0000 (10:34 -0700)
commit049dfd5e070cfa84c82eea71c6c746a70cba4a3f
tree6dbc7ba5ef2066bf8da2e0b154a8fedd0dfd151b
parent6b0ec4bab215169c8cde893b022288f8bf7c8835
Add python built-in types support for `tf.as_dtype` (#17652)

* Add python built-in types support for `tf.as_dtype`

This fix tries to address the issue raised in 17641 where
it was not possible to use `tf.as_dtype(float)` the same
way as numpy `np.dtype(float)`.
This fix adds the built-in types support for `tf.as_dtype`,
so that it is possible to specify:
```
dtypes.as_dtype(float)   # dtypes.float64
dtypes.as_dtype(int)     # dtypes.int32
dtypes.as_dtype(long)    # dtypes.int64
dtypes.as_dtype(complex) # dtypes.complex128
dtypes.as_dtype(bool)    # dtypes.bool
```

This fix fixes 17641.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
* Add test cases for built-in types support with `tf.as_dtype`

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
* Fix failed test cases with added built-in types support of tf.as_dtype

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
* Fix python 3 build

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
* Restrict the changes to float and bool based on review feedback

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
tensorflow/python/framework/dtypes.py
tensorflow/python/framework/dtypes_test.py