def _binary_crossover(population,<EOL>population_size,<EOL>mutants,<EOL>crossover_prob,<EOL>seed):
sizes = [tf.cast(tf.size(input=x), dtype=tf.float64) for x in population]<EOL>seed_stream = distributions.SeedStream(seed, salt='<STR_LIT>')<EOL>force_crossover_group = distributions.Categorical(sizes).sample(<EOL>[population_size, <NUM_LIT:1>], seed=seed_stream())<EOL>recombinants = []<EOL>for i, population_part in enumerate(population):<EOL><INDENT>pop_part_flat = tf.reshape(population_part, [population_size, -<NUM_LIT:1>])<EOL>mutant_part_flat = tf.reshape(mutants[i], [population_size, -<NUM_LIT:1>])<EOL>part_size = tf.size(input=population_part) // population_size<EOL>force_crossovers = tf.one_hot(<EOL>tf.random.uniform([population_size],<EOL>minval=<NUM_LIT:0>,<EOL>maxval=part_size,<EOL>dtype=tf.int32,<EOL>seed=seed_stream()),<EOL>part_size,<EOL>on_value=True,<EOL>off_value=False,<EOL>dtype=tf.bool)  <EOL>group_mask = tf.math.equal(force_crossover_group, i)<EOL>force_crossovers &= group_mask<EOL>do_binary_crossover = tf.random.uniform(<EOL>[population_size, part_size],<EOL>dtype=crossover_prob.dtype.base_dtype,<EOL>seed=seed_stream()) < crossover_prob<EOL>do_binary_crossover |= force_crossovers<EOL>recombinant_flat = tf.where(<EOL>do_binary_crossover,<EOL>x=mutant_part_flat,<EOL>y=pop_part_flat)<EOL>recombinant = tf.reshape(recombinant_flat, tf.shape(input=population_part))<EOL>recombinants.append(recombinant)<EOL><DEDENT>return recombinants<EOL>
Performs recombination by binary crossover for the current population.

    Let v_i denote the i'th component of the member v and m_i the corresponding
    component of the mutant vector corresponding to v. Then the crossed over
    vector w_i is determined by setting w_i =
    (m_i with probability=crossover_prob else v_i). In addition, DE requires that
    at least one of the components is crossed over (otherwise we end
    up with no change). This is done by choosing on index say k randomly where
    a force crossover is performed (i.e. w_k = m_k). This is the scheme
    implemented in this function.

    Args:
      population: A Python list of `Tensor`s where each `Tensor` in the list
        must be of rank at least 1 and all the elements must have a common
        first dimension. The base population to cross over.
      population_size: A scalar integer `Tensor`. The number of elements in the
        population (i.e. size of the first dimension of any member of
        `population`).
      mutants: A Python list of `Tensor`s with the same structure as `population`.
        The mutated population.
      crossover_prob: A postive real scalar `Tensor` bounded above by 1.0. The
        probability of a crossover being performed for each axis.
      seed: `int` or None. The random seed for this `Op`. If `None`, no seed is
        applied.

    Returns:
      A list of `Tensor`s of the same structure, dtype and shape as `population`.
      The recombined population.