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

Add support for tensors with 0 in shape #1196

Merged
merged 6 commits into from
Aug 1, 2018
Merged

Add support for tensors with 0 in shape #1196

merged 6 commits into from
Aug 1, 2018

Conversation

dsmilkov
Copy link
Contributor

@dsmilkov dsmilkov commented Jul 31, 2018

Fixes tensorflow/tfjs#567 (see the issue for details)

FEATURE


This change is Reviewable

@dsmilkov dsmilkov changed the title Add support for tensors with 0 in shape WIP Add support for tensors with 0 in shape Jul 31, 2018
@dsmilkov dsmilkov changed the title WIP Add support for tensors with 0 in shape Add support for tensors with 0 in shape Jul 31, 2018
@dsmilkov
Copy link
Contributor Author

Let me know if you have ideas for other ops to test (in addition to matmul, add and concat). Asking since as you can see, the fix sometimes is op-specific, like in the concat case.

Copy link
Collaborator

@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

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

LGTM, you might want to check logic op for example two zero size tensors x > y, expandDim seems to be special for zero size tensors.

Reviewed 11 of 11 files at r1.
Reviewable status: 0 of 1 approvals obtained (waiting on @dsmilkov, @nsthorat, @tafsiri, and @pyu10055)


src/util.ts, line 265 at r1 (raw file):

      }
      implicitIdx = i;
    } else if (shape[i] <= 0) {

shape[i] < 0 ?


src/ops/broadcast_util.ts, line 87 at r1 (raw file):

      b = 1;
    }
    if (a === 1) {

does this method support broadcast [0,2], [2,2] => [0,2] ?

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 11 of 11 files at r1.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @dsmilkov, @nsthorat, and @tafsiri)

Copy link
Contributor Author

@dsmilkov dsmilkov left a comment

Choose a reason for hiding this comment

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

Thanks. Added unit tests for expandDim, and tf.greater to verify it works with 0-sized tensors.

Reviewable status: :shipit: complete! 2 of 1 approvals obtained (waiting on @dsmilkov and @tafsiri)


src/util.ts, line 265 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

shape[i] < 0 ?

Ah nice find, done. The first if fires for shape >= 0, so this if would never fire for 0, but good to be precise.


src/ops/broadcast_util.ts, line 87 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

does this method support broadcast [0,2], [2,2] => [0,2] ?

Yes, see the added unit tests in broadcast_util_test.ts.

@dsmilkov dsmilkov merged commit 2cf38eb into master Aug 1, 2018
@dsmilkov dsmilkov deleted the zero-shape branch August 1, 2018 14:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants