message: ENH: allow stride > window_size in c++ side
diff: @@ -32,7 +32,7 @@ class SlideDatasetOp : public UnaryDatasetOpKernel {
  void MakeDataset(OpKernelContext* ctx, DatasetBase* input,
  DatasetBase** output) override {
  int64 window_size = 0;
  - int64 stride = 1;
  + int64 stride = 0;
  OP_REQUIRES_OK(
  ctx, ParseScalarArgument<int64>(ctx, "window_size", &window_size));
  OP_REQUIRES_OK(ctx, ParseScalarArgument<int64>(ctx, "stride", &stride));
  @@ -40,8 +40,8 @@ class SlideDatasetOp : public UnaryDatasetOpKernel {
  ctx, window_size > 0,
  errors::InvalidArgument("Window size must be greater than zero."));
  OP_REQUIRES(
  - ctx, stride > 0 && stride < window_size,
  - errors::InvalidArgument("Stride must be in [1, window_size)."));
  + ctx, stride > 0,
  + errors::InvalidArgument("Stride must be greater than zero."));
  *output = new Dataset(ctx, window_size, stride, input);
  }
  @@ -124,6 +124,8 @@ class SlideDatasetOp : public UnaryDatasetOpKernel {
  return Status::OK();
  }
  batch_elements.reserve(window_size);
  + // Use cache if stride < window_size.
  + if (stride < window_size) {
  const bool first_call = cache_.empty();
  if (first_call) {
  cache_.reserve(window_size);
  @@ -131,6 +133,7 @@ class SlideDatasetOp : public UnaryDatasetOpKernel {
  // Reuse cache in the previous iteration.
  cache_.swap(batch_elements);
  }
  + }
  // Fill up with new elements.
  *end_of_sequence = false;
  for (size_t i = batch_elements.size(); i < window_size && !*end_of_sequence;
  @@ -149,10 +152,23 @@ class SlideDatasetOp : public UnaryDatasetOpKernel {
  DCHECK(*end_of_sequence);
  return Status::OK();
  }
  +
  + if (stride < window_size) {
  // Cache the data used for the next iteration.
  for (size_t i = stride; i < window_size; ++i) {
  cache_.emplace_back(batch_elements[i]);
  }
  + } else if (stride > window_size) {
  + // Drop the data before the next iteration.
  + std::vector<Tensor> batch_element_tuple;
  + for (size_t i = window_size; i < stride && !*end_of_sequence; ++i) {
  + TF_RETURN_IF_ERROR(input_impl_->GetNext(ctx, &batch_element_tuple,
  + end_of_sequence));
  + if (*end_of_sequence) {
  + input_impl_.reset();
  + }
  + }
  + }
  }
  // Construct output tensors.
  