SphericalHarmonics icon indicating copy to clipboard operation
SphericalHarmonics copied to clipboard

`nan`s in calculation of the spherical harmonics

Open stoprightthere opened this issue 2 years ago • 2 comments

There are nans when computing spherical harmonics with the number of degrees > 87 in dimension 3.

Steps to reproduce:

  1. Generate fundamental system cache for dim = 3 and the number of degrees > 87.
  2. Run the code:
import numpy as np
from spherical_harmonics import SphericalHarmonics

X = np.r_[1., 0., 0.].reshape(1, -1)

harmonics_86 = SphericalHarmonics(dimension=3, degrees=86)
hX = harmonics_86(X)

print(np.any(np.isnan(hX)))  # False

harmonics_87 = SphericalHarmonics(dimension=3, degrees=87)

hX = harmonics_87(X)

print(np.any(np.isnan(hX)))  # True

Expected behaviour: No nans

stoprightthere avatar Nov 16 '22 16:11 stoprightthere

The spherical harmonics are only defined on the sphere. I'm not surprised that the input X = np.r_[0., 0., 0.].reshape(1, -1) leads to nans. Can you double-check that this isn't the issue, please?

vdutor avatar Nov 17 '22 17:11 vdutor

I am sorry for the typo. The problem persists with X = np.r_[1., 0., 0.].reshape(1, -1) and I updated the issue.

stoprightthere avatar Nov 17 '22 18:11 stoprightthere