def expm_frechet(A, E, method=None, compute_expm=True, check_finite=True):
 if check_finite:
  A = np.asarray_chkfinite(A)
  E = np.asarray_chkfinite(E)
 else:
  A = np.asarray(A)
  E = np.asarray(E)
 if ((A.ndim != 2) or (A.shape[0] != A.shape[1])):
  raise ValueError('expected A to be a square matrix')
 if ((E.ndim != 2) or (E.shape[0] != E.shape[1])):
  raise ValueError('expected E to be a square matrix')
 if (A.shape != E.shape):
  raise ValueError('expected A and E to be the same shape')
 if (method is None):
  method = 'SPS'
 if (method == 'SPS'):
  (expm_A, expm_frechet_AE) = expm_frechet_algo_64(A, E)
 elif (method == 'blockEnlarge'):
  (expm_A, expm_frechet_AE) = expm_frechet_block_enlarge(A, E)
 else:
  raise ValueError(('Unknown implementation %s' % method))
 if compute_expm:
  return (expm_A, expm_frechet_AE)
 else:
  return expm_frechet_AE

def expm_frechet ( A , E , method = None , compute_expm = True , check_finite = True ) : if check_finite : A = np . asarray_chkfinite ( A ) E = np . asarray_chkfinite ( E ) else : A = np . asarray ( A ) E = np . asarray ( E ) if ( ( A . ndim != 2 ) or ( A . shape [ 0 ] != A . shape [ 1 ] ) ) : raise ValueError ( 'expected A to be a square matrix' ) if ( ( E . ndim != 2 ) or ( E . shape [ 0 ] != E . shape [ 1 ] ) ) : raise ValueError ( 'expected E to be a square matrix' ) if ( A . shape != E . shape ) : raise ValueError ( 'expected A and E to be the same shape' ) if ( method is None ) : method = 'SPS' if ( method == 'SPS' ) : ( expm_A , expm_frechet_AE ) = expm_frechet_algo_64 ( A , E ) elif ( method == 'blockEnlarge' ) : ( expm_A , expm_frechet_AE ) = expm_frechet_block_enlarge ( A , E ) else : raise ValueError ( ( 'Unknown implementation %s' % method ) ) if compute_expm : return ( expm_A , expm_frechet_AE ) else : return expm_frechet_AE
frechet derivative of the matrix exponential of a in the direction e .