Beispiel #1
0
 def __new__(cls, *args, **kwargs):
     '''Initialize BitLogic with size (int) or bit string
     '''
     endian = kwargs.pop('endian', 'little')
     try:
         _ = int(args[0], base=2)
     except (TypeError, IndexError):
         # init by length
         ba = bitarray.__new__(cls, *args, endian=endian, **kwargs)
         # init to 0
         ba.setall(False)
     else:
         # init by bit string
         ba = bitarray.__new__(cls, args[0][::-1], *args[1:], endian=endian, **kwargs)
     return ba
Beispiel #2
0
 def __new__(cls, *args, **kwargs):
     '''Initialize BitLogic with size (int) or bit string
     '''
     endian = kwargs.pop('endian', 'little')
     try:
         _ = int(args[0], base=2)
     except (TypeError, IndexError):
         # init by length
         ba = bitarray.__new__(cls, *args, endian=endian, **kwargs)
         # init to 0
         ba.setall(False)
     else:
         # init by bit string
         ba = bitarray.__new__(cls, args[0][::-1], *args[1:], endian=endian, **kwargs)
     return ba
Beispiel #3
0
    def __new__(cls, fmt='', endian='little'):
        '''
        Allocates new memory space for the chromosome

        This function overrides the ``bitarray.__new__`` function to deal with
        the length of the chromosome. It should never be directly used, as it is
        automatically called by the Python interpreter in the moment of object
        creation.

        :Returns:
          A new ``Chromosome`` object.
        '''
        if type(fmt) == int:
            return bitarray.__new__(cls, fmt)
        elif type(fmt) == str:
            size = struct.calcsize(fmt) * 8
            return bitarray.__new__(cls, size)
        elif isinstance(fmt, bitarray):
            return bitarray.__new__(cls, fmt)
Beispiel #4
0
    def __new__(cls, fmt='', endian='little'):
        '''
        Allocates new memory space for the chromosome

        This function overrides the ``bitarray.__new__`` function to deal with
        the length of the chromosome. It should never be directly used, as it is
        automatically called by the Python interpreter in the moment of object
        creation.

        :Returns:
          A new ``Chromosome`` object.
        '''
        if type(fmt) == int:
            return bitarray.__new__(cls, fmt)
        elif type(fmt) == str:
            size = struct.calcsize(fmt) * 8
            return bitarray.__new__(cls, size)
        elif isinstance(fmt, bitarray):
            return bitarray.__new__(cls, fmt)