code: def F(x, dim, dfd=np.inf, dfn=1):
      """
      EC densities for F and Chi^2 (dfd=inf) random fields.
      """
      m = float(dfd)
      n = float(dfn)
      D = float(dim)
      if dim > 0:
          x = np.asarray(x, np.float64)
          k = K(dim=dim, dfd=dfd, dfn=dfn)(x)
          if np.isfinite(m):
              f = x * n / m
              t = -np.log(1 + f) * (m + n - 2.0) / 2.0
              t += np.log(f) * (n - D) / 2.0
              t += gammaln((m + n - D) / 2.0) - gammaln(m / 2.0)
          else:
              f = x * n
              t = np.log(f / 2.0) * (n - D) / 2.0 - f / 2.0
          t -= (
              np.log(2 * np.pi) * D / 2.0
              + np.log(2) * (D - 2) / 2.0
              + gammaln(n / 2.0)
          )
          k *= np.exp(t)
          return k
      else:
          if np.isfinite(m):
              return scipy.stats.f.sf(x, dfn, dfd)
          else:
              return scipy.stats.chi.sf(x, dfn)
  
imports: import numpy
  import scipy.stats
  from scipy.special import gammaln, hermitenorm
  import pytest
  from numpy.testing import assert_almost_equal
  from ..None import rft
label_desc: Use image node_id 3 for calling a global function with example usage: F(x, dim, dfd, dfn) and returns: k, scipy, scipy