def test_legendre(): allTrue = True for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.eval_legendre(order, x) valueCpp = NumCpp.legendre_p_Scaler1(order, x) if np.round(valuePy, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False assert allTrue allTrue = True for order in range(ORDER_MAX): shapeInput = np.random.randint(10, 100, [ 2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_legendre(order, x) valueCpp = NumCpp.legendre_p_Array1(order, cArray) if not np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)): allTrue = False assert allTrue allTrue = True for order in range(ORDER_MAX): x = np.random.rand(1).item() degree = np.random.randint(order, ORDER_MAX) valuePy = sp.lpmn(order, degree, x)[0][order, degree] valueCpp = NumCpp.legendre_p_Scaler2(order, degree, x) if np.round(valuePy, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False assert allTrue allTrue = True for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.lqn(order, x)[0][order] valueCpp = NumCpp.legendre_q_Scaler(order, x) if np.round(valuePy, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False assert allTrue
def test_legendre(): if NumCpp.NO_USE_BOOST and not NumCpp.STL_SPECIAL_FUNCTIONS: return for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.eval_legendre(order, x) valueCpp = NumCpp.legendre_p_Scaler1(order, x) assert np.round(valuePy, DECIMALS_ROUND) == np.round(valueCpp, DECIMALS_ROUND) for order in range(ORDER_MAX): shapeInput = np.random.randint(10, 100, [ 2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_legendre(order, x) valueCpp = NumCpp.legendre_p_Array1(order, cArray) assert np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)) if not NumCpp.NO_USE_BOOST: for order in range(ORDER_MAX): x = np.random.rand(1).item() degree = np.random.randint(order, ORDER_MAX) valuePy = sp.lpmn(order, degree, x)[0][order, degree] valueCpp = NumCpp.legendre_p_Scaler2(order, degree, x) assert np.round(valuePy, DECIMALS_ROUND) == np.round(valueCpp, DECIMALS_ROUND), \ f'order={order}, degree={degree}, x={x}' for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.lqn(order, x)[0][order] valueCpp = NumCpp.legendre_q_Scaler(order, x) assert np.round(valuePy, DECIMALS_ROUND) == np.round( valueCpp, DECIMALS_ROUND)
def lqn_(n, x): return lqn(n.astype('l'), x)[0][-1]
def testFunctions(): print(colored('Testing Polynomial functions', 'magenta')) ORDER_MAX = 5 DECIMALS_ROUND = 7 print(colored('Testing chebyshev_t_Scaler', 'cyan')) allTrue = True for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.eval_chebyt(order, x) valueCpp = NumCpp.chebyshev_t_Scaler(order, x) if np.round(valuePy, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(f'valuePy = {valuePy}, valueCpp = {valueCpp}') print(colored('Testing chebyshev_t_Array', 'cyan')) allTrue = True for order in range(ORDER_MAX): shapeInput = np.random.randint(10, 100, [ 2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_chebyt(order, x) valueCpp = NumCpp.chebyshev_t_Array(order, cArray) if not np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing chebyshev_u_Scaler', 'cyan')) allTrue = True for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.eval_chebyu(order, x) valueCpp = NumCpp.chebyshev_u_Scaler(order, x) if np.round(valuePy, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(f'valuePy = {valuePy}, valueCpp = {valueCpp}') print(colored('Testing chebyshev_u_Array', 'cyan')) allTrue = True for order in range(ORDER_MAX): shapeInput = np.random.randint(10, 100, [ 2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_chebyu(order, x) valueCpp = NumCpp.chebyshev_u_Array(order, cArray) if not np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing hermite_Scaler', 'cyan')) allTrue = True for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.eval_hermite(order, x) valueCpp = NumCpp.hermite_Scaler(order, x) if np.round(valuePy, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(f'valuePy = {valuePy}, valueCpp = {valueCpp}') print(colored('Testing hermite_Array', 'cyan')) allTrue = True for order in range(ORDER_MAX): shapeInput = np.random.randint(10, 100, [ 2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_hermite(order, x) valueCpp = NumCpp.hermite_Array(order, cArray) if not np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing laguerre_Scaler1', 'cyan')) allTrue = True for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.eval_laguerre(order, x) valueCpp = NumCpp.laguerre_Scaler1(order, x) if np.round(valuePy, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(f'valuePy = {valuePy}, valueCpp = {valueCpp}') print(colored('Testing laguerre_Array1', 'cyan')) allTrue = True for order in range(ORDER_MAX): shapeInput = np.random.randint(10, 100, [ 2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_laguerre(order, x) valueCpp = NumCpp.laguerre_Array1(order, cArray) if not np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing laguerre_Scaler2', 'cyan')) allTrue = True for order in range(ORDER_MAX): degree = np.random.randint(0, 10, [ 1, ]).item() x = np.random.rand(1).item() valuePy = sp.eval_genlaguerre(degree, order, x) valueCpp = NumCpp.laguerre_Scaler2(order, degree, x) if np.round(valuePy, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(f'valuePy = {valuePy}, valueCpp = {valueCpp}') print(colored('Testing laguerre_Array2', 'cyan')) allTrue = True for order in range(ORDER_MAX): degree = np.random.randint(0, 10, [ 1, ]).item() shapeInput = np.random.randint(10, 100, [ 2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_genlaguerre(degree, order, x) valueCpp = NumCpp.laguerre_Array2(order, degree, cArray) if not np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing legendre_p_Scaler1', 'cyan')) allTrue = True for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.eval_legendre(order, x) valueCpp = NumCpp.legendre_p_Scaler1(order, x) if np.round(valuePy, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(f'valuePy = {valuePy}, valueCpp = {valueCpp}') print(colored('Testing legendre_p_Array1', 'cyan')) allTrue = True for order in range(ORDER_MAX): shapeInput = np.random.randint(10, 100, [ 2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_legendre(order, x) valueCpp = NumCpp.legendre_p_Array1(order, cArray) if not np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing legendre_p_Scaler2', 'cyan')) allTrue = True for order in range(ORDER_MAX): x = np.random.rand(1).item() degree = np.random.randint(order, ORDER_MAX) valuePy = sp.lpmn(order, degree, x)[0][order, degree] valueCpp = NumCpp.legendre_p_Scaler2(order, degree, x) if np.round(valuePy, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(f'valuePy = {valuePy}, valueCpp = {valueCpp}') print(colored('Testing legendre_q_Scaler', 'cyan')) allTrue = True for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.lqn(order, x)[0][order] valueCpp = NumCpp.legendre_q_Scaler(order, x) if np.round(valuePy, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(f'valuePy = {valuePy}, valueCpp = {valueCpp}') print(colored('Testing spherical_harmonic', 'cyan')) allTrue = True for order in range(ORDER_MAX): degree = np.random.randint(order, ORDER_MAX) theta = np.random.rand(1).item() * np.pi * 2 phi = np.random.rand(1).item() * np.pi valuePy = sp.sph_harm(order, degree, theta, phi) valueCpp = NumCpp.spherical_harmonic(order, degree, theta, phi) if (np.round(valuePy.real, DECIMALS_ROUND) != np.round( valueCpp[0], DECIMALS_ROUND) or np.round(valuePy.imag, DECIMALS_ROUND) != np.round( valueCpp[1], DECIMALS_ROUND)): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(f'valuePy = {valuePy}, valueCpp = {valueCpp}') print(colored('Testing spherical_harmonic_r', 'cyan')) allTrue = True for order in range(ORDER_MAX): degree = np.random.randint(order, ORDER_MAX) theta = np.random.rand(1).item() * np.pi * 2 phi = np.random.rand(1).item() * np.pi valuePy = sp.sph_harm(order, degree, theta, phi) valueCpp = NumCpp.spherical_harmonic_r(order, degree, theta, phi) if np.round(valuePy.real, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(f'valuePy = {valuePy}, valueCpp = {valueCpp}') print(colored('Testing spherical_harmonic_i', 'cyan')) allTrue = True for order in range(ORDER_MAX): degree = np.random.randint(order, ORDER_MAX) theta = np.random.rand(1).item() * np.pi * 2 phi = np.random.rand(1).item() * np.pi valuePy = sp.sph_harm(order, degree, theta, phi) valueCpp = NumCpp.spherical_harmonic_i(order, degree, theta, phi) if np.round(valuePy.imag, DECIMALS_ROUND) != np.round( valueCpp, DECIMALS_ROUND): allTrue = False if allTrue: print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(f'valuePy = {valuePy}, valueCpp = {valueCpp}')
def lqn_(n, x): return lqn(n.astype("l"), x)[0][-1]