@classmethod<EOL><INDENT>def crossover_template(cls, length, points=<NUM_LIT:2>):<DEDENT>
assert isinstance(length, int) and length >= <NUM_LIT:0><EOL>assert isinstance(points, int) and points >= <NUM_LIT:0><EOL>points = random.sample(range(length + <NUM_LIT:1>), points)<EOL>points.sort()<EOL>points.append(length)<EOL>previous = <NUM_LIT:0><EOL>include_range = bool(random.randrange(<NUM_LIT:2>))<EOL>pieces = []<EOL>for point in points:<EOL><INDENT>if point > previous:<EOL><INDENT>fill = (numpy.ones if include_range else numpy.zeros)<EOL>pieces.append(fill(point - previous, dtype=bool))<EOL><DEDENT>include_range = not include_range<EOL>previous = point<EOL><DEDENT>bits = numpy.concatenate(pieces)<EOL>bits.flags.writeable = False<EOL>return cls(bits)<EOL>
Create a crossover template with the given number of points. The
        crossover template can be used as a mask to crossover two
        bitstrings of the same length.

        Usage:
            assert len(parent1) == len(parent2)
            template = BitString.crossover_template(len(parent1))
            inv_template = ~template
            child1 = (parent1 & template) | (parent2 & inv_template)
            child2 = (parent1 & inv_template) | (parent2 & template)

        Arguments:
            length: An int, indicating the desired length of the result.
            points: An int, the number of crossover points.
        Return:
            A BitString instance of the requested length which can be used
            as a crossover template.