def run_numerical_test(function, n, k, results):
n_grid, k_grid = np.meshgrid(n, k)
if results.shape != n_grid.shape:
raise ValueError('results passed do not match the shape of n/k')
# Test both as scalars
for i, cur_n in enumerate(n):
for j, cur_k in enumerate(k):
np.testing.assert_allclose(function(cur_n, cur_k), results[i, j], err_msg=('n: ' + str(cur_n) + ', k: ' + str(cur_k)))
# Test first as scalar
for i, cur_n in enumerate(n):
np.testing.assert_allclose(function(cur_n, k_grid[:, i]), results[i, :], err_msg=('n: ' + str(cur_n) + ', k: ' + str(k_grid[:, i])))
# Test two as scalar
for j, cur_k in enumerate(k):
np.testing.assert_allclose(function(n_grid[j, :], cur_k), results[:, j], err_msg=('n: ' + str(n_grid[j, :]) + ', k: ' + str(cur_k)))
# Test matrix
np.testing.assert_allclose(function(n_grid, k_grid), results.T, err_msg=('Matrix computation failed!'))
test_bessel_functions.py 文件源码
python
阅读 42
收藏 0
点赞 0
评论 0
评论列表
文章目录