Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate the shape of count for RepeatDataset #18150

Merged
merged 3 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def testInfiniteRepeat(self):
# Test repeat empty dataset
self.run_core_tests(lambda: self._build_repeat_dataset(-1, 0), None, 0)

def testInvalidRepeat(self):
with self.assertRaisesRegexp(
ValueError, 'Shape must be rank 0 but is rank 1'):
self.run_core_tests(lambda: self._build_repeat_dataset([1, 2], 0),
None, 0)


if __name__ == "__main__":
test.main()
7 changes: 5 additions & 2 deletions tensorflow/core/ops/dataset_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ REGISTER_OP("RepeatDataset")
.Output("handle: variant")
.Attr("output_types: list(type) >= 1")
.Attr("output_shapes: list(shape) >= 1")
.SetShapeFn(shape_inference::ScalarShape); // TODO(mrry): Validate the
// shape of `count`.
.SetShapeFn([](shape_inference::InferenceContext* c) {
shape_inference::ShapeHandle count_shape;
TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 0, &count_shape));
return shape_inference::ScalarShape(c);
});

REGISTER_OP("TakeDataset")
.Input("input_dataset: variant")
Expand Down