Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Support complex type in onesLike #1609

Merged
merged 1 commit into from
Mar 13, 2019

Conversation

Lewuathe
Copy link
Contributor

@Lewuathe Lewuathe commented Mar 6, 2019

FEATURE

As TensorFlow supports complex type in ones_like ops, we can support complex64 tensor in onesLike ops.

See: https://www.tensorflow.org/api_docs/python/tf/ones_like

>>> tf.ones_like([[1,2,3], [1,2,3]], dtype='complex64').eval()
array([[1.+0.j, 1.+0.j, 1.+0.j],
       [1.+0.j, 1.+0.j, 1.+0.j]], dtype=complex64)

This change is Reviewable

const b = tf.onesLike(a);
expect(b.dtype).toBe('complex64');
expect(b.shape).toEqual([3]);
expectArraysEqual(b, [1, 0, 1, 0, 1, 0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't these all be ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ones_like of TensorFlow core generates a complex number with real 1 and imaginary 0. So I think it's consistent with TensorFlow core implementation.

>>> tf.ones_like([1,2,3], dtype='complex64')
<tf.Tensor: id=18, shape=(3,), dtype=complex64, numpy=array([1.+0.j, 1.+0.j, 1.+0.j], dtype=complex64)>

Copy link
Contributor

@nsthorat nsthorat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @Lewuathe)


src/ops/array_ops_test.ts, line 521 at r1 (raw file):

Previously, Lewuathe (Kai Sasaki) wrote…

ones_like of TensorFlow core generates a complex number with real 1 and imaginary 0. So I think it's consistent with TensorFlow core implementation.

>>> tf.ones_like([1,2,3], dtype='complex64')
<tf.Tensor: id=18, shape=(3,), dtype=complex64, numpy=array([1.+0.j, 1.+0.j, 1.+0.j], dtype=complex64)>

Ah -- apologies that's correct!

@nsthorat nsthorat merged commit 134616d into tensorflow:master Mar 13, 2019
@Lewuathe Lewuathe deleted the support-complextype branch March 20, 2019 02:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants