atcollab / at

Accelerator Toolbox
Apache License 2.0
48 stars 31 forks source link

use np.float64 instead of np.float in function get_bunch_length_espread of pyat/at/acceptance/touschek.py module #706

Closed simoneliuzzo closed 7 months ago

simoneliuzzo commented 7 months ago

use np.float64 instead of np.float in function get_bunch_length_espread of pyat/at/acceptance/touschek.py module

This solves an error of deprecation given by numpy (since numpy 1.20). An alternative is to upgrade the package requirement for scikit-learn

simoneliuzzo commented 7 months ago

this pull request would solve issue #705

lfarv commented 7 months ago

The reason for this cast seems to be the fact that fsolve works on an array variable (array of 1 element here). To convert an array of one element into a scalar, the clean solution is:

bl = bl0*fsolve(haissinski, numpy.array([1.0]), args=cst)[0]

Note that the initial value (1.0) should also be an array. Otherwise PyCharm gives a warning: Expected type 'ndarray', got 'tuple[int]' instead

simoneliuzzo commented 7 months ago

Dear @swhite2401,

what is your opinion? You are the author of the code, may be there are good reasons for the cast instead of indexing proposed by @lfarv ?

thank you best regards Simone

swhite2401 commented 7 months ago

Hello, sorry for the late reply, I have been very busy lately. I think I agree with @lfarv on this one, no need to cast. Indexing makes it clear to the reader that fsolve returns an array so it seems more logical to me.

simoneliuzzo commented 7 months ago

The solution proposed by @lfarv is adopted. I tested on my side and it is ok.