Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Method 1
- let mut batch_lower_bound = 0usize;
- while batch_lower_bound + batch_size < examples.len() {
- batches[i] = &examples[batch_lower_bound..batch_lower_bound + batch_size];
- batch_lower_bound += batch_size;
- }
- batches[batches.len() - 1] = &examples[batch_lower_bound..examples.len()];
- // Method 2
- let mut batch_lower_bound = 0usize;
- let mut batch_upper_bound = batch_lower_bound + batch_size;
- while batch_upper_bound < examples.len() {
- batches[i] = &examples[batch_lower_bound..batch_upper_bound];
- batch_lower_bound = batch_upper_bound;
- batch_upper_bound += batch_size;
- }
- batches[batches.len() - 1] = &examples[batch_lower_bound..examples.len()];
- // Method 3
- let mut batch_lower_bound = 0usize;
- let batch_upper_bound = || -> usize {batch_lower_bound + batch_size};
- while batch_upper_bound() < examples.len() {
- batches[i] = &examples[batch_lower_bound..batch_upper_bound()];
- batch_lower_bound = batch_upper_bound();
- }
- batches[batches.len() - 1] = &examples[batch_lower_bound..examples.len()];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement