'Compute index of ``gen`` in ``self.gens``.'

def index(self, gen):

    if (gen is None):
        if self.ngens:
            i = 0
        else:
            i = (-1)
    elif isinstance(gen, int):
        i = gen
        if ((0 <= i) and (i < self.ngens)):
            pass
        elif (((- self.ngens) <= i) and (i <= (-1))):
            i = ((- i) - 1)
        else:
            raise ValueError(('invalid    generator    index:    %s' % gen))
    elif isinstance(gen, self.dtype):
        try:
            i = self.gens.index(gen)
        except ValueError:
            raise ValueError(('invalid    generator:    %s' % gen))
    elif isinstance(gen, string_types):
        try:
            i = self.symbols.index(gen)
        except ValueError:
            raise ValueError(('invalid    generator:    %s' % gen))
    else:
        raise ValueError(('expected    a    polynomial    generator,    an    integer,    a    string    or    None,    got    %s' % gen))
    return i
