Rebase & squash of get_num_examples #880

Fixes #851, #852, #903.