code: def _fragment_2_1(X, T, s):
      """
      A helper function for expm_2009.
  
      Notes
      -----
      The argument X is modified in-place, but this modification is not the same
      as the returned value of the function.
      This function also takes pains to do things in ways that are compatible
      with sparse matrices, for example by avoiding fancy indexing
      and by using methods of the matrices whenever possible instead of
      using functions of the numpy or scipy libraries themselves.
  
      """
      # Form X = r_m(2^-s T)
      # Replace diag(X) by exp(2^-s diag(T)).
      n = X.shape[0]
      diag_T = np.ravel(T.diagonal().copy())
  
      # Replace diag(X) by exp(2^-s diag(T)).
      scale = 2**-s
      exp_diag = np.exp(scale * diag_T)
      for k in range(n):
          X[k, k] = exp_diag[k]
  
      for i in range(s - 1, -1, -1):
          X = X.dot(X)
  
          # Replace diag(X) by exp(2^-i diag(T)).
          scale = 2**-i
          exp_diag = np.exp(scale * diag_T)
          for k in range(n):
              X[k, k] = exp_diag[k]
  
          # Replace (first) superdiagonal of X by explicit formula
          # for superdiagonal of exp(2^-i T) from Eq (10.42) of
          # the author's 2008 textbook
          # Functions of Matrices: Theory and Computation.
          for k in range(n - 1):
              lam_1 = scale * diag_T[k]
              lam_2 = scale * diag_T[k + 1]
              t_12 = scale * T[k, k + 1]
              value = _eq_10_42(lam_1, lam_2, t_12)
              X[k, k + 1] = value
  
      # Return the updated X matrix.
      return X
  
imports: from __future__ import division, print_function, absolute_import
  import math
  import numpy
  import scipy.special
  from scipy.linalg.basic import solve, solve_triangular
  from scipy.sparse.base import isspmatrix
  from scipy.sparse.construct import eye
  from scipy.sparse.linalg import spsolve
  import scipy.sparse
  import scipy.sparse.linalg
  from scipy.sparse.linalg.interface import LinearOperator
label_desc: Use image node_id 14 for calling a global function with example usage: _fragment_2_1(X, T, s) and returns: X