_rbfinterp_common.py 973 B

1234567891011121314151617181920212223242526272829303132
  1. # Impl routines common for all backends
  2. from itertools import combinations_with_replacement
  3. from math import comb
  4. def _monomial_powers_impl(ndim, degree):
  5. """Return the powers for each monomial in a polynomial.
  6. Parameters
  7. ----------
  8. ndim : int
  9. Number of variables in the polynomial.
  10. degree : int
  11. Degree of the polynomial.
  12. Returns
  13. -------
  14. (nmonos, ndim) int ndarray
  15. Array where each row contains the powers for each variable in a
  16. monomial.
  17. """
  18. nmonos = comb(degree + ndim, ndim)
  19. out = [[0]*ndim for _ in range(nmonos)]
  20. count = 0
  21. for deg in range(degree + 1):
  22. for mono in combinations_with_replacement(range(ndim), deg):
  23. # `mono` is a tuple of variables in the current monomial with
  24. # multiplicity indicating power (e.g., (0, 1, 1) represents x*y**2)
  25. for var in mono:
  26. out[count][var] += 1
  27. count += 1
  28. return out