Skip to content

Commit

Permalink
Fix scan ops for empty tensors
Browse files Browse the repository at this point in the history
Change: 131302762
  • Loading branch information
girving authored and tensorflower-gardener committed Aug 25, 2016
1 parent a54aa42 commit b057e0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tensorflow/core/kernels/scan_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class ScanOp : public OpKernel {
Tensor* output = nullptr;
OP_REQUIRES_OK(ctx, ctx->allocate_output(0, output_shape, &output));

// Exit early if there's nothing to compute
if (output_shape.num_elements() == 0) return;

const Device& d = ctx->eigen_device<Device>();
Reducer reducer;

Expand Down
9 changes: 9 additions & 0 deletions tensorflow/python/kernel_tests/scan_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def _compareAll(self, x, axis):
for reverse in [True, False]:
self._compare(x, axis, exclusive, reverse)

def testEmpty(self):
for dtype in self.valid_dtypes:
x = np.zeros([0]).astype(dtype)
self._compareAll(x, 0)

def test1D(self):
for dtype in self.valid_dtypes:
x = np.arange(1, 6).reshape([5]).astype(dtype)
Expand Down Expand Up @@ -155,6 +160,10 @@ def _compareAll(self, x, axis):
for reverse in [True, False]:
self._compare(x, axis, exclusive, reverse)

def testEmpty(self):
for dtype in self.valid_dtypes:
x = np.zeros([0]).astype(dtype)
self._compareAll(x, 0)

def test1D(self):
for dtype in self.valid_dtypes:
Expand Down

0 comments on commit b057e0d

Please sign in to comment.