r"""Get code to calculate a linear term.

    >>> term_code(1, 0, 33, False, False, True)
    '    rhs[1] += (33)*rho[0]\n'
550095
def term_code(mu, nu, coef, matrix_form, rhouv_isconjugated, linear=True):
    

    """
    if coef == 0:
        return ""
    coef = str(coef)

    # We change E_{0i} -> E0[i-1]
    ini = coef.find("E_{0")
    fin = coef.find("}")
    if ini != -1:
        l = int(coef[ini+4: fin])
        coef = coef[:ini]+"Ep["+str(l-1)+"]"+coef[fin+1:]

    # We change r[i, j] -> r[:, i, j]
    coef = coef.replace("rp[", "rp[:, ")
    coef = coef.replace("rm[", "rm[:, ")

    # We change symbolic complex-operations into fast numpy functions.
    coef = coef.replace("conjugate(", "np.conjugate(")
    coef = coef.replace("re(", "np.real(")
    coef = coef.replace("im(", "np.imag(")

    coef = coef.replace("*I", "j")

    if not linear:
        if matrix_form:
            s = "    b["+str(mu)+"] += "+coef+"\n"
        else:
            s = "    rhs["+str(mu)+"] += "+coef+"\n"
        return s

    # We add the syntax to calculate the term and store it in memory.
    s = "    "
    if matrix_form:
        s += "A["+str(mu)+", "+str(nu)+"] += "+coef+"\n"
    else:
        s += "rhs["+str(mu)+"] += ("+coef+")"
        if rhouv_isconjugated:
            s += "*np.conjugate(rho["+str(nu)+'])\n'
        else:
            s += "*rho["+str(nu)+']\n'

    return s
1135761
def rse(label, pred):
    """"""
    numerator = np.sqrt(np.mean(np.square(label - pred), axis = None))
    denominator = np.std(label, axis = None)
    return numerator / denominator
459067
def _Aterm(N, h, m, k, dW):
    """"""
    sqrt2h = np.sqrt(2.0/h)
    Xk = np.random.normal(0.0, 1.0, (N, m, 1))
    Yk = np.random.normal(0.0, 1.0, (N, m, 1))
    term1 = _dot(Xk, _t(Yk + sqrt2h*dW))
    term2 = _dot(Yk + sqrt2h*dW, _t(Xk))
    return (term1 - term2)/k
574673
def _get_val(self, soln, r, c):
        """"""
        for v in range(1, 10):
            if soln[self.X[r, c, v]]:
                return DIGITS[v-1]
        return "X"
361452
def _compute_term_3(self, C, mag, R):
        
        return (
            (C['a12'] + C['a13'] * mag + C['a14'] * np.power(mag, 2) +
             C['a15'] * np.power(mag, 3)) * np.power(R, 2)
        )
33702
def term2hex(code: Numeric, default: Optional[str] = None) -> str:
    
    try:
        val = term2hex_map.get('{:02}'.format(int(code), default))
    except ValueError:
        raise ValueError(
            'Expecting an int or number string, got: {} ({})'.format(
                code,
                getattr(code, '__name__', type(code).__name__)))
    return val
783194
def lhs(self):
        """"""
        lhs = self._lhs
        i = 0
        while lhs is None:
            i -= 1
            lhs = self._prev_lhs[i]
        return lhs
1083324
def _to_linear(M, N, L, q):
    ""
    (x, y, u, k) = q
    return 2 * L * N * x + 2 * L * y + L * u + k
425938
def hmsStrToDeg(ra):
    """"""
    hour, min, sec = ra.split(':')
    ra_deg = hmsToDeg(int(hour), int(min), float(sec))
    return ra_deg
975286
def _call(self, x):
        """"""
        if self.operator is None:
            return self.vector.inner(x) + self.constant
        elif self.vector is None:
            return x.inner(self.operator(x)) + self.constant
        else:
            tmp = self.operator(x)
            tmp += self.vector
            return x.inner(tmp) + self.constant
1092397
def calcMzFromMh(mh, charge):
    
    mz = (mh + (maspy.constants.atomicMassProton * (charge-1))) / charge
    return mz
161225
def get_lr(lr, epoch, steps, factor):
    """"""
    for s in steps:
        if epoch >= s:
            lr *= factor
    return lr
1320783
def _compute_term_4(self, C, mag, R):
        
        return (
            (C['a16'] + C['a17'] * mag + C['a18'] * np.power(mag, 2) +
             C['a19'] * np.power(mag, 3)) * np.power(R, 3)
        )
827602
def _get_magnitude_term(self, C, mag):
        
        if mag >= self.CONSTS["Mh"]:
            return C["e1"] + C["b3"] * (mag - self.CONSTS["Mh"])
        else:
            return C["e1"] + (C["b1"] * (mag - self.CONSTS["Mh"])) +\
                (C["b2"] * (mag - self.CONSTS["Mh"]) ** 2.)
680398
function makeNumIsoH(code, bonds) {
        var valence;

        if (code === 15) {
            valence = 0;
        } else if (code === 0) {
            valence = -1;
        } else {
            // num_iso_H should never be negative when valence is set
            valence = Math.max(0, code - bonds);
        }

        return [valence, 0, 0, 0];
    }
244516
def _compute_term2(self, C, mag, r):
        
        return (C['c4'] + C['c5'] * mag) * \
            np.log(np.sqrt(r**2 + C['c6']**2)) + C['c7'] * r
145072
def _get_f1rx(self, C, r_x, r_1):
        
        rxr1 = r_x / r_1
        return C["h1"] + (C["h2"] * rxr1) + (C["h3"] * (rxr1 ** 2.))