class_docstr: Class defining mutations, and holding a random state used for random generation.
class_docstr_tok: ["Class","defining","mutations",",","and","holding","a","random","state","used","for","random","generation","."]
code: def crossover(
      self,
      parent: tp.ArrayLike,
      donor: tp.ArrayLike,
      rotation: bool = False,
      crossover_type: str = "none",
  ) -> tp.ArrayLike:
      if rotation:
          dim = len(parent)
          k = self.random_state.randint(1, dim)
          mix = [
              self.random_state.choice(
                  [donor[(i + k) % dim], parent[i]]
              )
              for i in range(len(parent))
          ]
      else:
          if crossover_type == "rand":
              crossover_type = str(
                  self.random_state.choice(
                      ["max", "min", "onepoint", "twopoint"]
                  )
              )
          if crossover_type == "max":
              mix = [min([d, p]) for (p, d) in zip(parent, donor)]
          elif crossover_type == "min":
              mix = [max([d, p]) for (p, d) in zip(parent, donor)]
          elif crossover_type == "onepoint" and len(parent) > 4:
              sig = self.random_state.choice([-1.0, 1.0])
              idx = self.random_state.randint(len(parent) - 1) + 0.5
              mix = [
                  (d if (i - idx) * sig < 0 else p)
                  for i, (p, d) in enumerate(zip(parent, donor))
              ]
          elif crossover_type == "twopoint" and len(parent) > 6:
              sig = self.random_state.choice([-1.0, 1.0])
              idx = self.random_state.randint(len(parent) - 1) + 0.5
              idx2 = self.random_state.randint(len(parent) - 1) + 0.5
              while idx == idx2:
                  idx2 = (
                      self.random_state.randint(len(parent) - 1) + 0.5
                  )
              mix = [
                  (d if (i - idx) * (i - idx2) * sig < 0 else p)
                  for i, (p, d) in enumerate(zip(parent, donor))
              ]
          else:
              mix = [
                  self.random_state.choice([d, p])
                  for (p, d) in zip(parent, donor)
              ]
      return self.discrete_mutation(mix)
  
file_path: nevergrad/nevergrad/optimization/mutations.py
imports: import numpy
  import nevergrad.common.typing
  from nevergrad.parametrization import discretization
  from .None import utils
label_desc: Use image node_id 9 for calling the Mutator obj's underlying member method code with example usage: obj.crossover(parent, donor, rotation, crossover_type) and returns: self