Mar-24-2022, 06:50 PM
I try to optimize and speed up the code. With numba, it started to work much better, but still takes hours because of a lot of data that should be iterated in nested cycles. How to be with these loops? How can these get optimized?
@njit
def function_gam(et0, y30, ph0b, ot, y70):
ht = ot[0] * et0 * np.cos(y30) / np.sqrt(ph0b) + ot[1] * -et0 * np.sin(y30) / np.sqrt(ph0b) + y70 * np.sqrt(1 / ph0b) * et0 * np.sin(y30) + funct_labt(y30, ot, y70) * (np.sqrt(1 / ph0b) * (1 + et0 * np.cos(y30) * (1 + et0 * np.cos(y30)**2) / ph0b**2))
return ht
@njit
def funct_labt(y30, ot, y70):
y80 = ot[1] * et0 *(np.sin(y30)) / np.sqrt(ph0b) - y70 * (ph0b * et0 * (np.sin(y30)) / (1 + et0 * np.cos(y30)))**2 + (-ot[0] * et0 *(np.cos(y30)) / np.sqrt(ph0b))
return y80
tol = E-10
for i in z30:# iteratation through values for variable z30
for o in zres: # iteratation through values for array zres which includes 2 interconnected variales. The values of the first are in zres[0], for the other - in zres[1]
for l in z70: # iteratation through values for variable z70
ht0 = function_gam(et0, i, ph0b, o, l)
if np.isclose(ht0, 0): # only these combinations of variables values are collected that satisfy the condition ht == 0
lh0 = i, o[0], o[1], l
print(lh0)
