Generates balanced reaction at mixing ratio x : (1-x) for
        self.comp1 : self.comp2.

        Args:
            x (float): Mixing ratio x of reactants, a float between 0 and 1.

        Returns:
            Reaction object.
191082
def _get_reaction(self, x):
        
        mix_comp = self.comp1 * x + self.comp2 * (1-x)
        decomp = self.pd.get_decomposition(mix_comp)

        # Uses original composition for reactants.
        if np.isclose(x, 0):
            reactant = [self.c2_original]
        elif np.isclose(x, 1):
            reactant = [self.c1_original]
        else:
            reactant = list(set([self.c1_original, self.c2_original]))

        if self.grand:
            reactant += [Composition(e.symbol)
                         for e, v in self.pd.chempots.items()]

        product = [Composition(k.name) for k, v in decomp.items()]
        reaction = Reaction(reactant, product)

        x_original = self._get_original_composition_ratio(reaction)
        if np.isclose(x_original, 1):
            reaction.normalize_to(self.c1_original, x_original)
        else:
            reaction.normalize_to(self.c2_original, 1-x_original)
        return reaction
731343
def generate(self, x, **kwargs):
    
    assert self.sess is not None, \
        'Cannot use `generate` when no `sess` was provided'
    self.parse_params(**kwargs)

    labels, nb_classes = self.get_or_guess_labels(x, kwargs)

    attack = CWL2(self.sess, self.model, self.batch_size, self.confidence,
                  'y_target' in kwargs, self.learning_rate,
                  self.binary_search_steps, self.max_iterations,
                  self.abort_early, self.initial_const, self.clip_min,
                  self.clip_max, nb_classes,
                  x.get_shape().as_list()[1:])

    def cw_wrap(x_val, y_val):
      return np.array(attack.attack(x_val, y_val), dtype=self.np_dtype)

    wrap = tf.py_func(cw_wrap, [x, labels], self.tf_dtype)
    wrap.set_shape(x.get_shape())

    return wrap
864348
def is_mass_balanced(reaction):
    """"""
    balance = defaultdict(int)
    for metabolite, coefficient in iteritems(reaction.metabolites):
        if metabolite.elements is None or len(metabolite.elements) == 0:
            return False
        for element, amount in iteritems(metabolite.elements):
            balance[element] += coefficient * amount
    return all(amount == 0 for amount in itervalues(balance))
664385
def bbox(self):
        
        mn = amin(self.coordinates, axis=0)
        mx = amax(self.coordinates, axis=0)
        return concatenate((mn, mx))
49550
def gen_psi(self, x):
        
   
        if isinstance(x, np.ndarray):
            x = x[:,None]
        return np.exp(-self.h * (x - self.c)**2)
1340832
def generateXY(self, **kwargs):
        
        self.num_objects = 0
        xycols = self._readCatalog()

        if xycols is not None:
            # convert the catalog into attribute
            self.xypos = xycols[:3]
            # convert optional columns if they are present
            if self.numcols > 3:
                self.xypos.append(np.asarray(xycols[3], dtype=int)) # source ID
            if self.numcols > 4:
                self.sharp = xycols[4]
            if self.numcols > 5:
                self.round1 = xycols[5]
            if self.numcols > 6:
                self.round2 = xycols[6]
            self.num_objects = len(xycols[0])

        if self.numcols < 3: # account for flux column
            self.xypos.append(np.zeros(self.num_objects, dtype=float))
            self.flux_col = False

        if self.numcols < 4: # add source ID column
            self.xypos.append(np.arange(self.num_objects)+self.start_id)

        if self.use_sharp_round:
            for i in range(len(self.xypos), 7):
                self.xypos.append(np.zeros(self.num_objects, dtype=float))
            self.sharp_col = False

        if self.pars['xyunits'] == 'degrees':
            self.radec = [x.copy() for x in self.xypos]
            if self.wcs is not None:
                self.xypos[:2] = list(self.wcs.all_world2pix(np.array(self.xypos[:2]).T, self.origin).T)
47855
def charge_balance(model):
    

    compound_charge = {}
    for compound in model.compounds:
        if compound.charge is not None:
            compound_charge[compound.id] = compound.charge

    for reaction in model.reactions:
        charge = reaction_charge(reaction.equation, compound_charge)
        yield reaction, charge
1258046
def frac(x, context=None):
    
    return _apply_function_in_current_context(
        BigFloat,
        mpfr.mpfr_frac,
        (BigFloat._implicit_convert(x),),
        context,
    )
997056
def p_expr_BXOR_expr(p):
    
    p[0] = make_binary(p.lineno(2), 'BXOR', p[1], p[3], lambda x, y: x ^ y)
559951
def total(self, xbin1=1, xbin2=-2):
        
        return self.hist.integral(xbin1=xbin1, xbin2=xbin2, error=True)
353883
def p_x_commalist(self,t):
    
    if len(t) == 2: t[0] = CommaX([t[1]])
    elif len(t) == 4: t[0] = CommaX(t[1].children+[t[3]])
    else: raise NotImplementedError('unk_len',len(t)) # pragma: no cover
178525
def amean(x, weights=None):
    
    w_arr, x_arr = _preprocess_inputs(x, weights)
    return (w_arr*x_arr).sum(axis=0) / w_arr.sum(axis=0)
1082076
def x_rolls(self, number, count=0, func=sum):
        '''
        '''
        for x in range(number):
            yield self.roll(count, func)
1194807
def generate(self, x, g, **kwargs):
    

    # Parse and save attack-specific parameters
    assert self.parse_params(**kwargs)

    g_feat = self.model.fprop(g)[self.layer]

    # Initialize loop variables
    eta = tf.random_uniform(
        tf.shape(x), -self.eps, self.eps, dtype=self.tf_dtype)
    eta = clip_eta(eta, self.ord, self.eps)

    def cond(i, _):
      return tf.less(i, self.nb_iter)

    def body(i, e):
      new_eta = self.attack_single_step(x, e, g_feat)
      return i + 1, new_eta

    _, eta = tf.while_loop(cond, body, (tf.zeros([]), eta), back_prop=True,
                           maximum_iterations=self.nb_iter)

    # Define adversarial example (and clip if necessary)
    adv_x = x + eta
    if self.clip_min is not None and self.clip_max is not None:
      adv_x = tf.clip_by_value(adv_x, self.clip_min, self.clip_max)

    return adv_x
89142
def qx(mt, x):
    
    if x < len(mt.qx):
        return mt.qx[x]
    else:
        return 0
821214
def evaluate(self, x, *args):
        
        a = (self.amplitude * np.ones_like(x)) * self._flux_unit
        y = units.convert_flux(x, a, units.PHOTLAM)
        return y.value
993647
def mix1(servo1, servo2, mixtype=1, gain=0.5):
    ''''''
    (v1,v2) = mixer(servo1, servo2, mixtype=mixtype, gain=gain)
    return v1