code: def multiple_fast_inverse(a):
      """Compute the inverse of a set of arrays.
  
      Parameters
      ----------
      a : array_like of shape (n_samples, n_dim, n_dim)
          Set of square matrices to be inverted. A is changed in place.
  
      Returns
      -------
      a : ndarray
         Yielding the inverse of the inputs.
  
      Raises
      ------
      LinAlgError :
          If `a` is singular.
  
      ValueError :
          If `a` is not square, or not 2-dimensional.
  
      Notes
      -----
      This function is borrowed from scipy.linalg.inv,
      but with some customizations for speed-up.
  
      """
      if a.shape[1] != a.shape[2]:
          raise ValueError(
              "a must have shape (n_samples, n_dim, n_dim)"
          )
      from scipy.linalg.lapack import get_lapack_funcs
  
      a1, n = a[0], a.shape[0]
      getrf, getri, getri_lwork = get_lapack_funcs(
          ("getrf", "getri", "getri_lwork"), (a1,)
      )
      for i in range(n):
          if (
              getrf.module_name[:7] == "clapack"
              and getri.module_name[:7] != "clapack"
          ):
              # ATLAS 3.2.1 has getrf but not getri.
              lu, piv, info = getrf(
                  np.transpose(a[i]), rowmajor=0, overwrite_a=True
              )
              a[i] = np.transpose(lu)
          else:
              a[i], piv, info = getrf(a[i], overwrite_a=True)
          if info == 0:
              if getri.module_name[:7] == "flapack":
                  lwork, _ = getri_lwork(a1.shape[0])
                  # XXX: the following line fixes curious SEGFAULT when
                  # benchmarking 500x500 matrix inverse. This seems to
                  # be a bug in LAPACK ?getri routine because if lwork is
                  # minimal (when using lwork[0] instead of lwork[1]) then
                  # all tests pass. Further investigation is required if
                  # more such SEGFAULTs occur.
                  lwork = int(1.01 * lwork.real)
                  a[i], _ = getri(
                      a[i], piv, lwork=lwork, overwrite_lu=1
                  )
              else:  # clapack
                  a[i], _ = getri(a[i], piv, overwrite_lu=1)
          else:
              raise ValueError("Matrix LU decomposition failed")
      return a
  
file_path: nilearn/nilearn/glm/_utils.py
imports: from warnings import warn
  import numpy
  import scipy.linalg
  from scipy.stats import norm
label_desc: Use image node_id 2 for calling a global function with example usage: multiple_fast_inverse(a) and returns: a