diff --git a/candle-datasets/src/batcher.rs b/candle-datasets/src/batcher.rs index b74f14177..03e4bbef8 100644 --- a/candle-datasets/src/batcher.rs +++ b/candle-datasets/src/batcher.rs @@ -78,7 +78,7 @@ impl> Iterator for Batcher> { match self.inner.inner.next() { Some(item) => items.push(item), None => { - if self.return_last_incomplete_batch { + if self.return_last_incomplete_batch && !items.is_empty() { break; } return None; @@ -102,7 +102,7 @@ impl> Iterator for Batcher> { ys.push(y) } None => { - if self.return_last_incomplete_batch { + if self.return_last_incomplete_batch && !xs.is_empty() && !ys.is_empty() { break; } return None; @@ -127,7 +127,7 @@ impl>> Iterator for Batcher> { match self.inner.inner.next() { Some(item) => items.push(item), None => { - if self.return_last_incomplete_batch { + if self.return_last_incomplete_batch && !items.is_empty() { break; } return None; @@ -154,7 +154,7 @@ impl>> Iterator for Batcher errs.push(err), None => { - if self.return_last_incomplete_batch { + if self.return_last_incomplete_batch && !xs.is_empty() && !ys.is_empty() { break; } return None;