:param qi: int: current state, qi ∈ Q
        :param u:str: transition character u ∈ S
        :returns Q': int :  δ(qi, u) = q
519453
def transition_function(self, qi, u):
        
        try:
            return self.transition[qi][u]
        except KeyError:
            if u in self.alphabet:
                try:
                    return self.transition[qi]['*']
                except KeyError:
                    return None
            return None
1101483
def extract_q_df(self, state_key, action_key):
        '''
        

        '''
        q = 0.0
        if self.q_df is None:
            self.save_q_df(state_key, action_key, q)
            return q

        q_df = self.q_df[self.q_df.state_key == state_key]
        q_df = q_df[q_df.action_key == action_key]

        if q_df.shape[0]:
            q = float(q_df["q_value"])
        else:
            self.save_q_df(state_key, action_key, q)
        return q
754495
def consume(self, char):
        

        if self.state == "stream":
            self._stream(char)
        elif self.state == "escape":
            self._escape_sequence(char)
        elif self.state == "escape-lb":
            self._escape_parameters(char)
        elif self.state == "mode":
            self._mode(char)
        elif self.state == "charset-g0":
            self._charset_g0(char)
        elif self.state == "charset-g1":
            self._charset_g1(char)
326048
def convertToRateMatrix(self, Q):
        
        rowSums             = Q.sum(axis=1).getA1()
        idxRange            = np.arange(Q.shape[0])
        Qdiag               = coo_matrix((rowSums,(idxRange,idxRange)),shape=Q.shape).tocsr()
        return Q-Qdiag
154938
def python_to_ucn(uni_char, as_bytes=False):
    
    ucn = uni_char.encode('unicode_escape').decode('latin1')
    ucn = text_type(ucn).replace('\\', '').upper().lstrip('U')
    if len(ucn) > int(4):
        # get rid of the zeroes that Python uses to pad 32 byte UCNs
        ucn = ucn.lstrip("0")
    ucn = "U+" + ucn.upper()

    if as_bytes:
        ucn = ucn.encode('latin1')

    return ucn
443585
def U_ij(q_vars: List[fl.Var], mass: np.ndarray, i: int, j: int):
    """"""
    # Check that the lengths are consistent
    assert len(q_vars) == 3 * len(mass)
    
    # Masses of the bodies i and j
    mi = mass[i]
    mj = mass[j]
    
    # Gravitational potential is -G * m1 * m2 / r
    U = -(G * mi * mj) / flux_r(q_vars, i, j)
    return U
1175004
def _BernI_to_Flavio_I(C, qq):
    """'"""
    qqf = qq[::-1]  # flavio uses "bs" instead of "sb" etc.
    if qq in ['sb', 'db', 'ds', 'cu']:
        return {
            'CVLL_' + 2*qqf: C["1" + 2*qq],
            'CSLL_' + 2*qqf: C["2" + 2*qq] - 1 / 2 * C["3" + 2*qq],
            'CTLL_' + 2*qqf: -1 / 8 * C["3" + 2*qq],
            'CVLR_' + 2*qqf: -1 / 2 * C["5" + 2*qq],
            'CVRR_' + 2*qqf: C["1p" + 2*qq],
            'CSRR_' + 2*qqf: C["2p" + 2*qq] - 1 / 2 * C["3p" + 2*qq],
            'CTRR_' + 2*qqf: -1 / 8 * C["3p" + 2*qq],
            'CSLR_' + 2*qqf: C["4" + 2*qq]
            }
    else:
        raise ValueError("not in Flavio_I: ".format(qq))
226241
def qn_to_qubo(expr):
    
    try:
        import sympy
    except ImportError:
        raise ImportError("This function requires sympy. Please install it.")
    assert type(expr) == sympy.Add
    to_i = lambda s: int(str(s)[1:])
    max_i = max(map(to_i, expr.free_symbols)) + 1
    qubo = [[0.] * max_i for _ in range(max_i)]
    for arg in expr.args:
        syms = arg.free_symbols
        assert len(syms) <= 2
        if len(syms) == 2:
            assert type(arg) == sympy.Mul
            i, j = list(map(to_i, syms))
            if i > j:
                i, j = j, i
            if i == j:
                if len(arg.args) == 2:
                    qubo[i][i] = float(arg.args[0])
                elif len(arg.args) == 1:
                    qubo[i][i] = 1.0
                else:
                    raise ValueError(f"Too many args! arg.args = {arg.args}")
                continue
            if len(arg.args) == 3:
                qubo[i][j] = float(arg.args[0])
            elif len(arg.args) == 2:
                qubo[i][j]
        if len(syms) == 1:
            if len(arg.args) == 2:
                assert type(arg) == sympy.Mul
                i = to_i(next(iter(syms)))
                qubo[i][i] = float(arg.args[0])
            elif len(arg.args) == 1:
                qubo[i][i] = 1.0
            else:
                raise ValueError(f"Too many args! arg.args = {arg.args}")
    return qubo
361093
def q(self):
        
        if self._q is None:
            if self._euler is not None:
                # get q from euler
                self._q = self._euler_to_q(self.euler)
            elif self._dcm is not None:
                # get q from DCM
                self._q = self._dcm_to_q(self.dcm)
        return self._q
176961
def _intesect(self):
        """"""
        p1automaton = self.mma
        p2automaton = self.mmb
        p3automaton = PDA(self.alphabet)
        self._break_terms()
        p1counter = 0
        p3counter = 0
        p2states = list(p2automaton.states)
        print 'PDA States: ' + repr(p1automaton.n)
        print 'DFA States: ' + repr(len(list(p2states)))
        ignorechars = p1automaton.nonterminals+ [0] + ['@closing']
        del(ignorechars[ignorechars.index('S')])
        while p1counter < p1automaton.n + 1:
            p1state = p1automaton.s[p1counter]
            p2counter = 0
            while p2counter < len(list(p2states)):
                p2state = p2states[p2counter]
                tempstate = PDAState()
                tempstate.id = (p1state.id, p2state.stateid)
                tempstate.sym = p1state.sym
                tempstate.type = p1state.type
                tempstate.trans = {}
                found = 0
                for char in self.alphabet:
                    if char in ignorechars:
                        continue
                    # DFA has single destination from a state
                    p2dest = self._delta(p2automaton, p2state, char)
                    # PDA may have multiple destinations from a state
                    # print p1state.trans
                    if p2dest is not None:
                        for potential in p1state.trans:
                            if char in p1state.trans[potential]:
                                found = 1
                                p1dest = potential
                                if (p1dest,
                                        p2dest.stateid) not in tempstate.trans:
                                    tempstate.trans[
                                        (p1dest, p2dest.stateid)] = []
                                    # print 'Appending A Transition to
                                    # ('+`p1dest`+','+`p2dest.stateid`+') for
                                    # input '+`char`
                                tempstate.trans[
                                    (p1dest, p2dest.stateid)].append(char)

                                # THEN THE NONTERMINALS + 0 3 transitions
                                # print p1state.trans
                                #               print p1automaton.nonterminals
                if found == 0 and  p1state.type == 3 and len(p1state.trans) >0:
                    assert 1==1,'Check Failed: A READ state with transitions' \
                                ' did not participate in the cross product'
                if p2dest is not None:
                    for nonterm in p1automaton.nonterminals + \
                            [0] + ['@closing']:
                        for potential in p1state.trans:
                            if nonterm in p1state.trans[potential]:
                                p1dest = potential
                                if (p1dest,
                                        p2state.stateid) not in tempstate.trans:
                                    tempstate.trans[
                                        (p1dest, p2state.stateid)] = []
                                # print 'Appending B Transition to
                                # ('+`p1dest`+','+`p2state.stateid`+') for
                                # input '+`nonterm`
                                tempstate.trans[
                                    (p1dest, p2state.stateid)].append(nonterm)
                p3automaton.s[p3counter] = tempstate
                p3counter = p3counter + 1
                p2counter = p2counter + 1
            p1counter = p1counter + 1
        # print 'Total States Appended '+`len(p3automaton.input_string)`
        p3automaton.n = p3counter - 1

        p3automaton.accepted = []
        for state in p2automaton.states:
            if state.final != TropicalWeight(float('inf')):
                p3automaton.accepted.append(state.stateid)
        return p3automaton
169809
def get(cls, uni_char):
        """"""
        uni_char = unicod(uni_char)  # Force to Unicode
        code_point = ord(uni_char)
        if Block._RANGE_KEYS is None:
            Block._RANGE_KEYS = sorted(Block._RANGES.keys())
        idx = bisect.bisect_left(Block._RANGE_KEYS, code_point)
        if (idx > 0 and
            code_point >= Block._RANGES[Block._RANGE_KEYS[idx - 1]].start and
            code_point <= Block._RANGES[Block._RANGE_KEYS[idx - 1]].end):
            return Block._RANGES[Block._RANGE_KEYS[idx - 1]]
        elif (idx < len(Block._RANGES) and
              code_point >= Block._RANGES[Block._RANGE_KEYS[idx]].start and
              code_point <= Block._RANGES[Block._RANGE_KEYS[idx]].end):
            return Block._RANGES[Block._RANGE_KEYS[idx]]
        else:
            return Block.UNKNOWN
1188619
def parse_qs(qs):
    
    result = {}
    qs = bstr(qs, 'latin1')
    pairs = [s2 for s1 in qs.split(b'&') for s2 in s1.split(b';')]
    uq = urlparse.unquote if PY2 else urlparse.unquote_to_bytes
    for name_value in pairs:
        if not name_value:
            continue
        nv = name_value.split(b'=', 1)
        if len(nv) != 2:
            nv.append(b'')

        name = nv[0].replace(b'+', b' ')
        name = uq(name)
        if not PY2:  # pragma: no cover py2
            name = ustr(name, 'latin1')
        value = nv[1].replace(b'+', b' ')
        value = uq(value)
        result.setdefault(name, []).append(value)
    return result
1185361
def encoded(text, encoding=DEFAULT_ENCODING):
    
    # already a string item
    if type(text) == bytes_type:
        return text

    elif type(text) != unicode_type:
        # convert a QString value
        if type(text).__name__ == 'QString':
            if encoding == 'utf-8':
                return unicode_type(text.toUtf8(), 'utf-8')
            elif encoding == 'latin-1':
                return unicode_type(text.toLatin1(), 'latin-1')
            elif encoding == 'ascii':
                return unicode_type(text.toAscii(), 'ascii')
            else:
                return unicode_type(text, encoding)

        # convert a standard item
        else:
            try:
                return bytes_type(text)
            except StandardError:
                return '????'

    if encoding:
        try:
            return text.encode(encoding)
        except StandardError:
            return text.encode(encoding, errors='ignore')

    else:
        for enc in SUPPORTED_ENCODINGS:
            try:
                return text.encode(enc)
            except StandardError:
                pass

    return '????'
394372
def q_sign(self):
        
        if self.reactive_power_mode.lower() == 'inductive':
            return -1
        elif self.reactive_power_mode.lower() == 'capacitive':
            return 1
        else:
            raise ValueError("Unknown value {} in reactive_power_mode".format(
                self.reactive_power_mode))
383503
def result(self):
        
        ret = self.get('result')
        if ret is not None:
            ret = u(ret)
        return ret
239100
def U(self):
        
        u = self.call("U")
        if u is not None:
            mat_name = u.getClass().getSimpleName()
            if mat_name == "RowMatrix":
                return RowMatrix(u)
            elif mat_name == "IndexedRowMatrix":
                return IndexedRowMatrix(u)
            else:
                raise TypeError("Expected RowMatrix/IndexedRowMatrix got %s" % mat_name)
640352
def getch(self):
        
        ch = self._get_one_char()
        if self.keep_input_clean:
            self.clear_input_buffer()

        try:
            # accept only unicode characters (for Python 2)
            uch = to_unicode(ch, 'ascii')
        except UnicodeError:
            return ''

        return uch if self._check_key_repeat(uch) else ''