Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError: index 0 is out of bounds for axis 0 with size 0 #31

Open
cool-RR opened this issue May 2, 2020 · 2 comments
Open

IndexError: index 0 is out of bounds for axis 0 with size 0 #31

cool-RR opened this issue May 2, 2020 · 2 comments

Comments

@cool-RR
Copy link

cool-RR commented May 2, 2020

Running this code under Python 3.8 produced the following traceback. Note that it seems that max_n=10**7 is related to this bug, because it didn't happen before I used that.

Traceback (most recent call last):
  File "heapz.py", line 115, in <module>
    best, others = big_o.big_o(heapify, data_generator_heapify, max_n=10**6)
  File "C:\Program Files\Python38\lib\site-packages\big_o\big_o.py", line 157, in big_o
    return infer_big_o_class(ns, time, classes, verbose=verbose)
  File "C:\Program Files\Python38\lib\site-packages\big_o\big_o.py", line 97, in infer_big_o_class
    residuals = inst.fit(ns, time)
  File "C:\Program Files\Python38\lib\site-packages\big_o\complexities.py", line 38, in fit
    return residuals[0]
IndexError: index 0 is out of bounds for axis 0 with size 0
@lucasalavapena
Copy link

I did some debugging and testing. Like you mentioned this happens at larger max_n, as in the error message it also happens with max_n=10**7. I tried remove different classes and I think the error seems to occur specifically for the Cubic class, for others not. If you follow the error precisely, you see that coeff, residuals, rank, s = np.linalg.lstsq(x, y, rcond=-1) (here) we get an empty numpy vector for the residual for the Cubic case when max_n is large, the reason being that the rank of x is too small (see the relevant numpy docs) and thus numpy gives one an empty array. I think you should be able to compute the residual doing something like np.linalg.norm(y - x @ coeff) which would still work in this case, however, doing that give different residual from numpy.

Why this specifically happens for the Cubic case, I cannot tell you. I tried this also for another case that I made up and again for large max_n specifically the Cubic case has this problem.

@Tachyon5
Copy link

Did this get resolved? Seems like @lucasalavapena got to the bottom of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants