Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.40 KB | None | 0 0
  1.                 // Method 1
  2.                 let mut batch_lower_bound = 0usize;
  3.                 while batch_lower_bound + batch_size < examples.len() {
  4.                     batches[i] = &examples[batch_lower_bound..batch_lower_bound + batch_size];
  5.                     batch_lower_bound += batch_size;
  6.                 }
  7.                 batches[batches.len() - 1] = &examples[batch_lower_bound..examples.len()];
  8.  
  9.                 // Method 2
  10.                 let mut batch_lower_bound = 0usize;
  11.                 let mut batch_upper_bound = batch_lower_bound + batch_size;
  12.                 while batch_upper_bound < examples.len() {
  13.                     batches[i] = &examples[batch_lower_bound..batch_upper_bound];
  14.                     batch_lower_bound = batch_upper_bound;
  15.                     batch_upper_bound += batch_size;
  16.                 }
  17.                 batches[batches.len() - 1] = &examples[batch_lower_bound..examples.len()];
  18.  
  19.                 // Method 3
  20.                 let mut batch_lower_bound = 0usize;
  21.                 let batch_upper_bound = || -> usize {batch_lower_bound + batch_size};
  22.                 while batch_upper_bound() < examples.len() {
  23.                     batches[i] = &examples[batch_lower_bound..batch_upper_bound()];
  24.                     batch_lower_bound = batch_upper_bound();
  25.                 }
  26.                 batches[batches.len() - 1] = &examples[batch_lower_bound..examples.len()];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement