def get_kernel_GJE(self, reactions=None):
        """ Return the kernel K from GJE routine.
        
        Notes
        -----
        The steady state solution is given by ``reactions = K * indep_variables``
        where ``indep_variables = reactions[-K.shape[1]:]``

        Parameters
        ----------
        reactions : list
          When specified then the reaction list defines the order of flux rows.
          Otherwise the rows are order by the sparsity.

        Returns
        -------
        fluxes, indep_fluxes, kernel : list, list, Matrix
        """
        from sympycore.matrices.linalg import get_rc_map
        self.compute_kernel_GJE(use_cache=True)
        gj, row_operations, leading_rows, leading_cols, zero_rows = self.compute_kernel_GJE_data
        if reactions is None:
            reactions = self.get_sorted_reactions()
        start = time.time()
        kernel = Matrix(len(reactions), len(reactions) - len(leading_cols))
        indep_vars = [r for r in reactions if r in self.independent_variables]
        n = len(indep_vars)
        rows = get_rc_map(gj.data)

        def indep_index(r):
            try:
                return indep_vars.index(r)
            except ValueError:
                pass

        indep_indices = []
        indices = []
        for r in self.reactions:
            indices.append(reactions.index(r))
            indep_indices.append(indep_index(r))

        for i0, j0 in zip(leading_rows, leading_cols):
            i = indices[j0]
            for j1 in rows[i0]:
                if j1 != j0:
                    j = indep_indices[j1]
                    kernel[i, j] = -gj.data[(i0, j1)]

        for j0 in range(len(self.reactions)):
            if j0 not in leading_cols:
                i = indices[j0]
                j = indep_indices[j0]
                kernel[i, j] = 1
        end = time.time()
        self.get_kernel_GJE_elapsed = end - start
        return reactions, indep_vars, kernel
    def get_kernel_GJE(self, reactions=None):
        """ Return the kernel K from GJE routine.
        
        Notes
        -----
        The steady state solution is given by ``reactions = K * indep_variables``
        where ``indep_variables = reactions[-K.shape[1]:]``

        Parameters
        ----------
        reactions : list
          When specified then the reaction list defines the order of flux rows.
          Otherwise the rows are order by the sparsity.

        Returns
        -------
        fluxes, indep_fluxes, kernel : list, list, Matrix
        """
        from sympycore.matrices.linalg import  get_rc_map
        self.compute_kernel_GJE(use_cache=True)
        gj, row_operations, leading_rows, leading_cols, zero_rows = self.compute_kernel_GJE_data
        if reactions is None:
            reactions = self.get_sorted_reactions()
        start = time.time ()
        kernel = Matrix(len(reactions), len(reactions)-len(leading_cols))
        indep_vars = [r for r in reactions if r in self.independent_variables]
        n = len (indep_vars)
        rows = get_rc_map(gj.data)
        def indep_index (r):
            try: return indep_vars.index (r)
            except ValueError: pass
        indep_indices = []
        indices = []
        for r in self.reactions:
            indices.append(reactions.index(r))
            indep_indices.append(indep_index (r))

        for i0,j0 in zip(leading_rows, leading_cols):
            i = indices[j0]
            for j1 in rows[i0]:
                if j1!=j0:
                    j = indep_indices[j1]
                    kernel[i,j] = -gj.data[(i0,j1)]

        for j0 in range (len (self.reactions)):
            if j0 not in leading_cols:
                i = indices[j0]
                j = indep_indices[j0]
                kernel[i,j] = 1
        end = time.time()
        self.get_kernel_GJE_elapsed = end-start
        return reactions, indep_vars, kernel
 def get_sorted_reactions(self):
     from sympycore.matrices.linalg import  get_rc_map
     self.compute_kernel_GJE(use_cache=True)
     start = time.time ()
     gj, row_operations, leading_rows, leading_cols, zero_rows = self.compute_kernel_GJE_data
     l = []
     rows = get_rc_map(gj.data)
     for i0,j0 in zip (leading_rows, leading_cols):
         row = rows[i0]
         row.remove (j0)
         if row:
             l.append ((len(row),-min(row), self.reactions[j0]))
         else:
             l.append ((len(row),0, self.reactions[j0]))
     reactions = [s for i,i1,s in sorted(l, reverse=True)]
     reactions += [s for s in self.reactions if s not in reactions]
     end = time.time ()
     self.get_sorted_reactions_elapsed = end-start
     return reactions
 def get_sorted_reactions(self):
     from sympycore.matrices.linalg import get_rc_map
     self.compute_kernel_GJE(use_cache=True)
     start = time.time()
     gj, row_operations, leading_rows, leading_cols, zero_rows = self.compute_kernel_GJE_data
     l = []
     rows = get_rc_map(gj.data)
     for i0, j0 in zip(leading_rows, leading_cols):
         row = rows[i0]
         row.remove(j0)
         if row:
             l.append((len(row), -min(row), self.reactions[j0]))
         else:
             l.append((len(row), 0, self.reactions[j0]))
     reactions = [s for i, i1, s in sorted(l, reverse=True)]
     reactions += [s for s in self.reactions if s not in reactions]
     end = time.time()
     self.get_sorted_reactions_elapsed = end - start
     return reactions