jax_privacy.batch_selection.pad_to_multiple_of

jax_privacy.batch_selection.pad_to_multiple_of#

jax_privacy.batch_selection.pad_to_multiple_of(indices, multiple, microbatch_size=None)[source]#

Pads the last dimension of indices to a multiple of multiple.

Creates a new 1D array of indices whose length is a multiple of multiple. Padding positions are filled with -1; callers should derive is_padding_example = (indices == -1) and pass it to clipped_grad() or clipped_fun().

Example Usage:
>>> indices = np.arange(10)
>>> pad_to_multiple_of(indices, multiple=4)
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1])
Parameters:
  • indices (ndarray) – A 1D array of batch indices.

  • multiple (int) – A positive integer. The input batch will be padded to a multiple of this value.

  • microbatch_size (int | None) – If set, must divide multiple. Reorders the padded indices so that padding examples cluster into the last microbatches under Fortran-order reshaping. See compute_early_stopping_order().

Return type:

ndarray

Returns:

The padded array of indices.