Skip to content

Instantly share code, notes, and snippets.

@kmuehlbauer
Created October 16, 2022 07:07
Show Gist options
  • Save kmuehlbauer/81b99492c964a67912cd7910cde8f816 to your computer and use it in GitHub Desktop.
Save kmuehlbauer/81b99492c964a67912cd7910cde8f816 to your computer and use it in GitHub Desktop.
scipy RegularGridInterpolator - new
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "9fd25b3f-ba2b-41a4-b015-15ad2e9532b5",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from scipy.interpolate import RegularGridInterpolator\n",
"import cProfile\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "45344f99-62dd-4952-a63d-e865142fc6b5",
"metadata": {},
"outputs": [],
"source": [
"def create_test_data(descending=False):\n",
" # create points, values, xi\n",
" \n",
" if descending:\n",
" ll = (12, 55)\n",
" ur = (2, 45)\n",
" else:\n",
" ll = (2, 45)\n",
" ur = (12, 55)\n",
"\n",
" x = np.linspace(ll[0], ur[0], 1001)\n",
" y = np.linspace(ll[1], ur[1], 501)\n",
" X, Y = np.meshgrid(x, y)\n",
"\n",
" # points\n",
" grid = np.stack((X, Y), axis=-1)\n",
" grd_dim0 = np.take(grid[..., 0], 0, axis=0)\n",
" grd_dim1 = np.take(grid[..., 1], 0, axis=1)\n",
" points = grd_dim0, grd_dim1\n",
"\n",
" # values\n",
" values = (X + Y).T\n",
"\n",
" # xi\n",
" np.random.seed(42)\n",
" xt = np.random.uniform(ll[0], ur[0], 10000)\n",
" yt = np.random.uniform(ll[1], ur[1], 10000)\n",
" xi = np.stack((xt, yt), axis=-1)\n",
" \n",
" return points, values, xi"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4ba9d082-94ad-40f2-9612-085359bb1a0c",
"metadata": {},
"outputs": [],
"source": [
"# test function\n",
"def test_ipol_xi(points, values, xi, iterations=1):\n",
" \"\"\"Simulate evaluation of values, hence effectively re-creating the interpolator.\n",
" \"\"\"\n",
" for i in range(iterations):\n",
" interp = RegularGridInterpolator(points, values, method=\"linear\",\n",
" bounds_error=False,\n",
" fill_value=np.nan)\n",
" valip = interp(xi)"
]
},
{
"cell_type": "markdown",
"id": "df2f8c5a-f83a-4827-b761-f5bce071b3c7",
"metadata": {},
"source": [
"# Normal Test, one iteration"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ec8a50cb-c228-4255-a2b5-6027298ebcd6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 157 function calls in 0.007 seconds\n",
"\n",
" Ordered by: standard name\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.000 0.000 0.007 0.007 4049209860.py:2(test_ipol_xi)\n",
" 2 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(all)\n",
" 2 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(any)\n",
" 1 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(can_cast)\n",
" 2 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(diff)\n",
" 1 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(flip)\n",
" 2 0.000 0.000 0.003 0.001 <__array_function__ internals>:177(searchsorted)\n",
" 2 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(where)\n",
" 1 0.000 0.000 0.007 0.007 <string>:1(<module>)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:212(__init__)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:225(<listcomp>)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:230(_check_dimensionality)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:242(_check_values)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:252(_check_fill_value)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:261(_check_points)\n",
" 1 0.000 0.000 0.007 0.007 _rgi.py:276(__call__)\n",
" 1 0.000 0.000 0.001 0.001 _rgi.py:351(_prepare_xi)\n",
" 1 0.002 0.002 0.002 0.002 _rgi.py:377(_evaluate_linear)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:382(<listcomp>)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:383(<listcomp>)\n",
" 1 0.001 0.001 0.004 0.004 _rgi.py:488(_find_indices)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:509(_find_out_of_bounds)\n",
" 4 0.000 0.000 0.000 0.000 _ufunc_config.py:131(geterr)\n",
" 4 0.000 0.000 0.000 0.000 _ufunc_config.py:32(seterr)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:425(__init__)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:429(__enter__)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:434(__exit__)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:1315(_searchsorted_dispatcher)\n",
" 2 0.000 0.000 0.002 0.001 fromnumeric.py:1319(searchsorted)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:2302(_any_dispatcher)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:2307(any)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:2401(_all_dispatcher)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:2406(all)\n",
" 2 0.000 0.000 0.002 0.001 fromnumeric.py:51(_wrapfunc)\n",
" 4 0.000 0.000 0.000 0.000 fromnumeric.py:69(_wrapreduction)\n",
" 4 0.000 0.000 0.000 0.000 fromnumeric.py:70(<dictcomp>)\n",
" 2 0.000 0.000 0.000 0.000 function_base.py:1315(_diff_dispatcher)\n",
" 2 0.000 0.000 0.000 0.000 function_base.py:1319(diff)\n",
" 1 0.000 0.000 0.000 0.000 function_base.py:248(_flip_dispatcher)\n",
" 1 0.000 0.000 0.000 0.000 function_base.py:252(flip)\n",
" 1 0.000 0.000 0.000 0.000 index_tricks.py:758(__getitem__)\n",
" 2 0.000 0.000 0.000 0.000 multiarray.py:341(where)\n",
" 1 0.000 0.000 0.000 0.000 multiarray.py:498(can_cast)\n",
" 1 0.000 0.000 0.000 0.000 numeric.py:1347(normalize_axis_tuple)\n",
" 1 0.000 0.000 0.000 0.000 numeric.py:1397(<listcomp>)\n",
" 2 0.000 0.000 0.000 0.000 numerictypes.py:282(issubclass_)\n",
" 1 0.000 0.000 0.000 0.000 numerictypes.py:356(issubdtype)\n",
" 1 0.000 0.000 0.007 0.007 {built-in method builtins.exec}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method builtins.getattr}\n",
" 5 0.000 0.000 0.000 0.000 {built-in method builtins.hasattr}\n",
" 3 0.000 0.000 0.000 0.000 {built-in method builtins.issubclass}\n",
" 10 0.000 0.000 0.000 0.000 {built-in method builtins.len}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method numpy.asanyarray}\n",
" 9 0.000 0.000 0.000 0.000 {built-in method numpy.asarray}\n",
" 12 0.000 0.000 0.003 0.000 {built-in method numpy.core._multiarray_umath.implement_array_function}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method numpy.core._multiarray_umath.normalize_axis_index}\n",
" 8 0.000 0.000 0.000 0.000 {built-in method numpy.geterrobj}\n",
" 4 0.000 0.000 0.000 0.000 {built-in method numpy.seterrobj}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method numpy.zeros}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method scipy.interpolate.interpnd._ndim_coords_from_arrays}\n",
" 6 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
" 4 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects}\n",
" 4 0.000 0.000 0.000 0.000 {method 'reduce' of 'numpy.ufunc' objects}\n",
" 2 0.000 0.000 0.000 0.000 {method 'reshape' of 'numpy.ndarray' objects}\n",
" 2 0.002 0.001 0.002 0.001 {method 'searchsorted' of 'numpy.ndarray' objects}\n",
"\n",
"\n"
]
}
],
"source": [
"points, values, xi = create_test_data()\n",
"cProfile.run('test_ipol_xi(points, values, xi, 1)')"
]
},
{
"cell_type": "markdown",
"id": "dc45be5a-24c6-4779-819f-0a2ea70f4c64",
"metadata": {},
"source": [
"# Descending dimensions, one iteration"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f652ab2a-0d08-4c8b-b4c6-2ef3ac572bcf",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 189 function calls in 0.007 seconds\n",
"\n",
" Ordered by: standard name\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.000 0.000 0.007 0.007 4049209860.py:2(test_ipol_xi)\n",
" 4 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(all)\n",
" 2 0.000 0.000 0.001 0.000 <__array_function__ internals>:177(any)\n",
" 1 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(can_cast)\n",
" 2 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(diff)\n",
" 3 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(flip)\n",
" 2 0.000 0.000 0.003 0.001 <__array_function__ internals>:177(searchsorted)\n",
" 2 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(where)\n",
" 1 0.000 0.000 0.007 0.007 <string>:1(<module>)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:212(__init__)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:225(<listcomp>)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:230(_check_dimensionality)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:242(_check_values)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:252(_check_fill_value)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:261(_check_points)\n",
" 1 0.000 0.000 0.006 0.006 _rgi.py:276(__call__)\n",
" 1 0.000 0.000 0.001 0.001 _rgi.py:351(_prepare_xi)\n",
" 1 0.001 0.001 0.001 0.001 _rgi.py:377(_evaluate_linear)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:382(<listcomp>)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:383(<listcomp>)\n",
" 1 0.001 0.001 0.004 0.004 _rgi.py:488(_find_indices)\n",
" 1 0.001 0.001 0.001 0.001 _rgi.py:509(_find_out_of_bounds)\n",
" 4 0.000 0.000 0.000 0.000 _ufunc_config.py:131(geterr)\n",
" 4 0.000 0.000 0.000 0.000 _ufunc_config.py:32(seterr)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:425(__init__)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:429(__enter__)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:434(__exit__)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:1315(_searchsorted_dispatcher)\n",
" 2 0.000 0.000 0.003 0.001 fromnumeric.py:1319(searchsorted)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:2302(_any_dispatcher)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:2307(any)\n",
" 4 0.000 0.000 0.000 0.000 fromnumeric.py:2401(_all_dispatcher)\n",
" 4 0.000 0.000 0.000 0.000 fromnumeric.py:2406(all)\n",
" 2 0.000 0.000 0.003 0.001 fromnumeric.py:51(_wrapfunc)\n",
" 6 0.000 0.000 0.001 0.000 fromnumeric.py:69(_wrapreduction)\n",
" 6 0.000 0.000 0.000 0.000 fromnumeric.py:70(<dictcomp>)\n",
" 2 0.000 0.000 0.000 0.000 function_base.py:1315(_diff_dispatcher)\n",
" 2 0.000 0.000 0.000 0.000 function_base.py:1319(diff)\n",
" 3 0.000 0.000 0.000 0.000 function_base.py:248(_flip_dispatcher)\n",
" 3 0.000 0.000 0.000 0.000 function_base.py:252(flip)\n",
" 5 0.000 0.000 0.000 0.000 index_tricks.py:758(__getitem__)\n",
" 2 0.000 0.000 0.000 0.000 multiarray.py:341(where)\n",
" 1 0.000 0.000 0.000 0.000 multiarray.py:498(can_cast)\n",
" 1 0.000 0.000 0.000 0.000 numeric.py:1347(normalize_axis_tuple)\n",
" 1 0.000 0.000 0.000 0.000 numeric.py:1397(<listcomp>)\n",
" 2 0.000 0.000 0.000 0.000 numerictypes.py:282(issubclass_)\n",
" 1 0.000 0.000 0.000 0.000 numerictypes.py:356(issubdtype)\n",
" 1 0.000 0.000 0.007 0.007 {built-in method builtins.exec}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method builtins.getattr}\n",
" 7 0.000 0.000 0.000 0.000 {built-in method builtins.hasattr}\n",
" 3 0.000 0.000 0.000 0.000 {built-in method builtins.issubclass}\n",
" 10 0.000 0.000 0.000 0.000 {built-in method builtins.len}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method numpy.asanyarray}\n",
" 7 0.000 0.000 0.000 0.000 {built-in method numpy.asarray}\n",
" 16 0.000 0.000 0.003 0.000 {built-in method numpy.core._multiarray_umath.implement_array_function}\n",
" 4 0.000 0.000 0.000 0.000 {built-in method numpy.core._multiarray_umath.normalize_axis_index}\n",
" 8 0.000 0.000 0.000 0.000 {built-in method numpy.geterrobj}\n",
" 4 0.000 0.000 0.000 0.000 {built-in method numpy.seterrobj}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method numpy.zeros}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method scipy.interpolate.interpnd._ndim_coords_from_arrays}\n",
" 8 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
" 6 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects}\n",
" 6 0.000 0.000 0.000 0.000 {method 'reduce' of 'numpy.ufunc' objects}\n",
" 2 0.000 0.000 0.000 0.000 {method 'reshape' of 'numpy.ndarray' objects}\n",
" 2 0.002 0.001 0.002 0.001 {method 'searchsorted' of 'numpy.ndarray' objects}\n",
"\n",
"\n"
]
}
],
"source": [
"points, values, xi = create_test_data(descending=True)\n",
"cProfile.run('test_ipol_xi(points, values, xi, 1)')"
]
},
{
"cell_type": "markdown",
"id": "4f2fd3cf-354c-4124-b77c-9135da92af1a",
"metadata": {},
"source": [
"# Normal test, 1000 iterations"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "e03df216-6061-4884-8eff-97ccdd4d037c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 153004 function calls in 2.352 seconds\n",
"\n",
" Ordered by: standard name\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.006 0.006 2.352 2.352 4049209860.py:2(test_ipol_xi)\n",
" 2000 0.002 0.000 0.016 0.000 <__array_function__ internals>:177(all)\n",
" 2000 0.003 0.000 0.169 0.000 <__array_function__ internals>:177(any)\n",
" 1000 0.001 0.000 0.005 0.000 <__array_function__ internals>:177(can_cast)\n",
" 2000 0.002 0.000 0.021 0.000 <__array_function__ internals>:177(diff)\n",
" 1000 0.001 0.000 0.010 0.000 <__array_function__ internals>:177(flip)\n",
" 2000 0.002 0.000 1.229 0.001 <__array_function__ internals>:177(searchsorted)\n",
" 2000 0.002 0.000 0.028 0.000 <__array_function__ internals>:177(where)\n",
" 1 0.000 0.000 2.352 2.352 <string>:1(<module>)\n",
" 1000 0.007 0.000 0.085 0.000 _rgi.py:212(__init__)\n",
" 1000 0.001 0.000 0.002 0.000 _rgi.py:225(<listcomp>)\n",
" 1000 0.003 0.000 0.004 0.000 _rgi.py:230(_check_dimensionality)\n",
" 1000 0.002 0.000 0.008 0.000 _rgi.py:242(_check_values)\n",
" 1000 0.002 0.000 0.008 0.000 _rgi.py:252(_check_fill_value)\n",
" 1000 0.010 0.000 0.048 0.000 _rgi.py:261(_check_points)\n",
" 1000 0.012 0.000 2.261 0.002 _rgi.py:276(__call__)\n",
" 1000 0.015 0.000 0.227 0.000 _rgi.py:351(_prepare_xi)\n",
" 1000 0.469 0.000 0.498 0.000 _rgi.py:377(_evaluate_linear)\n",
" 1000 0.015 0.000 0.015 0.000 _rgi.py:382(<listcomp>)\n",
" 1000 0.014 0.000 0.014 0.000 _rgi.py:383(<listcomp>)\n",
" 1000 0.218 0.000 1.504 0.002 _rgi.py:488(_find_indices)\n",
" 1000 0.057 0.000 0.059 0.000 _rgi.py:509(_find_out_of_bounds)\n",
" 4000 0.007 0.000 0.007 0.000 _ufunc_config.py:131(geterr)\n",
" 4000 0.009 0.000 0.021 0.000 _ufunc_config.py:32(seterr)\n",
" 2000 0.002 0.000 0.002 0.000 _ufunc_config.py:425(__init__)\n",
" 2000 0.003 0.000 0.015 0.000 _ufunc_config.py:429(__enter__)\n",
" 2000 0.003 0.000 0.011 0.000 _ufunc_config.py:434(__exit__)\n",
" 2000 0.000 0.000 0.000 0.000 fromnumeric.py:1315(_searchsorted_dispatcher)\n",
" 2000 0.003 0.000 1.225 0.001 fromnumeric.py:1319(searchsorted)\n",
" 2000 0.000 0.000 0.000 0.000 fromnumeric.py:2302(_any_dispatcher)\n",
" 2000 0.003 0.000 0.159 0.000 fromnumeric.py:2307(any)\n",
" 2000 0.000 0.000 0.000 0.000 fromnumeric.py:2401(_all_dispatcher)\n",
" 2000 0.002 0.000 0.013 0.000 fromnumeric.py:2406(all)\n",
" 2000 0.003 0.000 1.222 0.001 fromnumeric.py:51(_wrapfunc)\n",
" 4000 0.009 0.000 0.167 0.000 fromnumeric.py:69(_wrapreduction)\n",
" 4000 0.002 0.000 0.002 0.000 fromnumeric.py:70(<dictcomp>)\n",
" 2000 0.000 0.000 0.000 0.000 function_base.py:1315(_diff_dispatcher)\n",
" 2000 0.016 0.000 0.018 0.000 function_base.py:1319(diff)\n",
" 1000 0.000 0.000 0.000 0.000 function_base.py:248(_flip_dispatcher)\n",
" 1000 0.004 0.000 0.007 0.000 function_base.py:252(flip)\n",
" 1000 0.000 0.000 0.000 0.000 index_tricks.py:758(__getitem__)\n",
" 2000 0.000 0.000 0.000 0.000 multiarray.py:341(where)\n",
" 1000 0.000 0.000 0.000 0.000 multiarray.py:498(can_cast)\n",
" 1000 0.003 0.000 0.003 0.000 numeric.py:1347(normalize_axis_tuple)\n",
" 1000 0.000 0.000 0.000 0.000 numeric.py:1397(<listcomp>)\n",
" 2000 0.002 0.000 0.003 0.000 numerictypes.py:282(issubclass_)\n",
" 1000 0.002 0.000 0.005 0.000 numerictypes.py:356(issubdtype)\n",
" 1 0.000 0.000 2.352 2.352 {built-in method builtins.exec}\n",
" 2000 0.001 0.000 0.001 0.000 {built-in method builtins.getattr}\n",
" 5000 0.001 0.000 0.001 0.000 {built-in method builtins.hasattr}\n",
" 3000 0.001 0.000 0.001 0.000 {built-in method builtins.issubclass}\n",
" 10000 0.002 0.000 0.002 0.000 {built-in method builtins.len}\n",
" 2000 0.000 0.000 0.000 0.000 {built-in method numpy.asanyarray}\n",
" 9000 0.002 0.000 0.002 0.000 {built-in method numpy.asarray}\n",
" 12000 0.040 0.000 1.463 0.000 {built-in method numpy.core._multiarray_umath.implement_array_function}\n",
" 2000 0.001 0.000 0.001 0.000 {built-in method numpy.core._multiarray_umath.normalize_axis_index}\n",
" 8000 0.002 0.000 0.002 0.000 {built-in method numpy.geterrobj}\n",
" 4000 0.003 0.000 0.003 0.000 {built-in method numpy.seterrobj}\n",
" 1000 0.002 0.000 0.002 0.000 {built-in method numpy.zeros}\n",
" 1000 0.001 0.000 0.001 0.000 {built-in method scipy.interpolate.interpnd._ndim_coords_from_arrays}\n",
" 6000 0.001 0.000 0.001 0.000 {method 'append' of 'list' objects}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
" 4000 0.001 0.000 0.001 0.000 {method 'items' of 'dict' objects}\n",
" 4000 0.155 0.000 0.155 0.000 {method 'reduce' of 'numpy.ufunc' objects}\n",
" 2000 0.002 0.000 0.002 0.000 {method 'reshape' of 'numpy.ndarray' objects}\n",
" 2000 1.218 0.001 1.218 0.001 {method 'searchsorted' of 'numpy.ndarray' objects}\n",
"\n",
"\n"
]
}
],
"source": [
"points, values, xi = create_test_data()\n",
"cProfile.run('test_ipol_xi(points, values, xi, 1000)')"
]
},
{
"cell_type": "markdown",
"id": "fa9a331a-5d59-4494-97e1-9ce0eb252f60",
"metadata": {},
"source": [
"# Descending Dimensions, 1000 iterations"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "1db116aa-a12e-4946-ab09-722b614f4c1c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 185004 function calls in 2.327 seconds\n",
"\n",
" Ordered by: standard name\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.006 0.006 2.327 2.327 4049209860.py:2(test_ipol_xi)\n",
" 4000 0.003 0.000 0.026 0.000 <__array_function__ internals>:177(all)\n",
" 2000 0.003 0.000 0.167 0.000 <__array_function__ internals>:177(any)\n",
" 1000 0.001 0.000 0.004 0.000 <__array_function__ internals>:177(can_cast)\n",
" 2000 0.001 0.000 0.021 0.000 <__array_function__ internals>:177(diff)\n",
" 3000 0.002 0.000 0.016 0.000 <__array_function__ internals>:177(flip)\n",
" 2000 0.002 0.000 1.214 0.001 <__array_function__ internals>:177(searchsorted)\n",
" 2000 0.002 0.000 0.026 0.000 <__array_function__ internals>:177(where)\n",
" 1 0.000 0.000 2.327 2.327 <string>:1(<module>)\n",
" 1000 0.006 0.000 0.106 0.000 _rgi.py:212(__init__)\n",
" 1000 0.002 0.000 0.009 0.000 _rgi.py:225(<listcomp>)\n",
" 1000 0.003 0.000 0.004 0.000 _rgi.py:230(_check_dimensionality)\n",
" 1000 0.002 0.000 0.007 0.000 _rgi.py:242(_check_values)\n",
" 1000 0.002 0.000 0.008 0.000 _rgi.py:252(_check_fill_value)\n",
" 1000 0.015 0.000 0.062 0.000 _rgi.py:261(_check_points)\n",
" 1000 0.012 0.000 2.215 0.002 _rgi.py:276(__call__)\n",
" 1000 0.015 0.000 0.223 0.000 _rgi.py:351(_prepare_xi)\n",
" 1000 0.457 0.000 0.484 0.000 _rgi.py:377(_evaluate_linear)\n",
" 1000 0.014 0.000 0.014 0.000 _rgi.py:382(<listcomp>)\n",
" 1000 0.013 0.000 0.013 0.000 _rgi.py:383(<listcomp>)\n",
" 1000 0.207 0.000 1.475 0.001 _rgi.py:488(_find_indices)\n",
" 1000 0.056 0.000 0.058 0.000 _rgi.py:509(_find_out_of_bounds)\n",
" 4000 0.007 0.000 0.007 0.000 _ufunc_config.py:131(geterr)\n",
" 4000 0.009 0.000 0.020 0.000 _ufunc_config.py:32(seterr)\n",
" 2000 0.001 0.000 0.001 0.000 _ufunc_config.py:425(__init__)\n",
" 2000 0.002 0.000 0.015 0.000 _ufunc_config.py:429(__enter__)\n",
" 2000 0.002 0.000 0.011 0.000 _ufunc_config.py:434(__exit__)\n",
" 2000 0.000 0.000 0.000 0.000 fromnumeric.py:1315(_searchsorted_dispatcher)\n",
" 2000 0.003 0.000 1.210 0.001 fromnumeric.py:1319(searchsorted)\n",
" 2000 0.000 0.000 0.000 0.000 fromnumeric.py:2302(_any_dispatcher)\n",
" 2000 0.003 0.000 0.157 0.000 fromnumeric.py:2307(any)\n",
" 4000 0.001 0.000 0.001 0.000 fromnumeric.py:2401(_all_dispatcher)\n",
" 4000 0.004 0.000 0.020 0.000 fromnumeric.py:2406(all)\n",
" 2000 0.002 0.000 1.207 0.001 fromnumeric.py:51(_wrapfunc)\n",
" 6000 0.011 0.000 0.170 0.000 fromnumeric.py:69(_wrapreduction)\n",
" 6000 0.003 0.000 0.003 0.000 fromnumeric.py:70(<dictcomp>)\n",
" 2000 0.000 0.000 0.000 0.000 function_base.py:1315(_diff_dispatcher)\n",
" 2000 0.015 0.000 0.017 0.000 function_base.py:1319(diff)\n",
" 3000 0.001 0.000 0.001 0.000 function_base.py:248(_flip_dispatcher)\n",
" 3000 0.007 0.000 0.012 0.000 function_base.py:252(flip)\n",
" 5000 0.001 0.000 0.001 0.000 index_tricks.py:758(__getitem__)\n",
" 2000 0.000 0.000 0.000 0.000 multiarray.py:341(where)\n",
" 1000 0.000 0.000 0.000 0.000 multiarray.py:498(can_cast)\n",
" 1000 0.002 0.000 0.004 0.000 numeric.py:1347(normalize_axis_tuple)\n",
" 1000 0.001 0.000 0.001 0.000 numeric.py:1397(<listcomp>)\n",
" 2000 0.002 0.000 0.003 0.000 numerictypes.py:282(issubclass_)\n",
" 1000 0.002 0.000 0.005 0.000 numerictypes.py:356(issubdtype)\n",
" 1 0.000 0.000 2.327 2.327 {built-in method builtins.exec}\n",
" 2000 0.001 0.000 0.001 0.000 {built-in method builtins.getattr}\n",
" 7000 0.001 0.000 0.001 0.000 {built-in method builtins.hasattr}\n",
" 3000 0.001 0.000 0.001 0.000 {built-in method builtins.issubclass}\n",
" 10000 0.002 0.000 0.002 0.000 {built-in method builtins.len}\n",
" 2000 0.000 0.000 0.000 0.000 {built-in method numpy.asanyarray}\n",
" 7000 0.002 0.000 0.002 0.000 {built-in method numpy.asarray}\n",
" 16000 0.041 0.000 1.457 0.000 {built-in method numpy.core._multiarray_umath.implement_array_function}\n",
" 4000 0.001 0.000 0.001 0.000 {built-in method numpy.core._multiarray_umath.normalize_axis_index}\n",
" 8000 0.002 0.000 0.002 0.000 {built-in method numpy.geterrobj}\n",
" 4000 0.003 0.000 0.003 0.000 {built-in method numpy.seterrobj}\n",
" 1000 0.002 0.000 0.002 0.000 {built-in method numpy.zeros}\n",
" 1000 0.001 0.000 0.001 0.000 {built-in method scipy.interpolate.interpnd._ndim_coords_from_arrays}\n",
" 8000 0.001 0.000 0.001 0.000 {method 'append' of 'list' objects}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
" 6000 0.001 0.000 0.001 0.000 {method 'items' of 'dict' objects}\n",
" 6000 0.156 0.000 0.156 0.000 {method 'reduce' of 'numpy.ufunc' objects}\n",
" 2000 0.002 0.000 0.002 0.000 {method 'reshape' of 'numpy.ndarray' objects}\n",
" 2000 1.204 0.001 1.204 0.001 {method 'searchsorted' of 'numpy.ndarray' objects}\n",
"\n",
"\n"
]
}
],
"source": [
"points, values, xi = create_test_data(descending=True)\n",
"cProfile.run('test_ipol_xi(points, values, xi, 1000)')"
]
},
{
"cell_type": "markdown",
"id": "5960760a-fdd5-4171-b072-2958ef413601",
"metadata": {},
"source": [
"# Subclass RegularGridInterpolator"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "e14defc0-a2c3-4ee5-bb15-c8ea8a5e1eac",
"metadata": {},
"outputs": [],
"source": [
"class RegularGridInterpolatorValues(RegularGridInterpolator):\n",
" def __init__(self, points, xi, **kwargs):\n",
" # create fake values for initialization\n",
" values = np.zeros(tuple([len(pt) for pt in points]))\n",
" super().__init__(points, values, **kwargs)\n",
" self._is_initialized = False\n",
" # precompute values\n",
" self.xi, self.xi_shape, self.ndim, self.nans, self.out_of_bounds = self._prepare_xi(xi)\n",
" self.indices, self.norm_distances = self._find_indices(xi.T)\n",
" self._is_initialized = True\n",
"\n",
" def _prepare_xi(self, xi):\n",
" if not self._is_initialized:\n",
" return super()._prepare_xi(xi)\n",
" else:\n",
" # just give back precomputed values\n",
" return self.xi, self.xi_shape, self.ndim, self.nans, self.out_of_bounds\n",
"\n",
" def _find_indices(self, xi):\n",
" if not self._is_initialized:\n",
" return super()._find_indices(xi)\n",
" else:\n",
" # just give back pre-computed values\n",
" return self.indices, self.norm_distances\n",
"\n",
" def __call__(self, values, method=None):\n",
" valiues = self._check_values(values)\n",
" # check fillvalue\n",
" self._check_fill_value(values, self.fill_value)\n",
" # check dimensionality\n",
" self._check_dimensionality(self.grid, values)\n",
" # flip, if needed\n",
" self.values = np.flip(values, axis=self._descending_dimensions)\n",
" return super().__call__(self.xi, method=method)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "f05f1c3f-b916-4858-a9ff-00344ce08d8d",
"metadata": {},
"outputs": [],
"source": [
"def test_ipol_values(points, values, xi, iterations=1):\n",
" \"\"\"Subclassed interpolator, only need instantiating once.\n",
" \"\"\"\n",
" interp = RegularGridInterpolatorValues(points, xi, method=\"linear\",\n",
" bounds_error=False,\n",
" fill_value=np.nan)\n",
" for i in range(iterations):\n",
" valip2 = interp(values)\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "1f8b68ea-1d2c-4e5e-b554-2fad6cc93ee9",
"metadata": {},
"source": [
"# Normal tests, 1000 iterations"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "87df25b9-776b-4244-b165-5edaac011781",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 53146 function calls in 0.432 seconds\n",
"\n",
" Ordered by: standard name\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1001 0.000 0.000 0.001 0.000 3175201396.py:12(_prepare_xi)\n",
" 1001 0.000 0.000 0.003 0.000 3175201396.py:19(_find_indices)\n",
" 1 0.000 0.000 0.004 0.004 3175201396.py:2(__init__)\n",
" 1000 0.004 0.000 0.427 0.000 3175201396.py:26(__call__)\n",
" 1 0.000 0.000 0.000 0.000 3175201396.py:4(<listcomp>)\n",
" 1 0.001 0.001 0.432 0.432 3429582310.py:1(test_ipol_values)\n",
" 2 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(all)\n",
" 1001 0.001 0.000 0.013 0.000 <__array_function__ internals>:177(any)\n",
" 1001 0.001 0.000 0.003 0.000 <__array_function__ internals>:177(can_cast)\n",
" 2 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(diff)\n",
" 1001 0.001 0.000 0.007 0.000 <__array_function__ internals>:177(flip)\n",
" 2 0.000 0.000 0.002 0.001 <__array_function__ internals>:177(searchsorted)\n",
" 2 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(where)\n",
" 1 0.000 0.000 0.432 0.432 <string>:1(<module>)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:212(__init__)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:225(<listcomp>)\n",
" 1001 0.003 0.000 0.003 0.000 _rgi.py:230(_check_dimensionality)\n",
" 1001 0.001 0.000 0.006 0.000 _rgi.py:242(_check_values)\n",
" 1001 0.002 0.000 0.006 0.000 _rgi.py:252(_check_fill_value)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:261(_check_points)\n",
" 1000 0.008 0.000 0.402 0.000 _rgi.py:276(__call__)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:351(_prepare_xi)\n",
" 1000 0.351 0.000 0.379 0.000 _rgi.py:377(_evaluate_linear)\n",
" 1000 0.014 0.000 0.014 0.000 _rgi.py:382(<listcomp>)\n",
" 1000 0.013 0.000 0.013 0.000 _rgi.py:383(<listcomp>)\n",
" 1 0.001 0.001 0.003 0.003 _rgi.py:488(_find_indices)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:509(_find_out_of_bounds)\n",
" 4 0.000 0.000 0.000 0.000 _ufunc_config.py:131(geterr)\n",
" 4 0.000 0.000 0.000 0.000 _ufunc_config.py:32(seterr)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:425(__init__)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:429(__enter__)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:434(__exit__)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:1315(_searchsorted_dispatcher)\n",
" 2 0.000 0.000 0.002 0.001 fromnumeric.py:1319(searchsorted)\n",
" 1001 0.000 0.000 0.000 0.000 fromnumeric.py:2302(_any_dispatcher)\n",
" 1001 0.001 0.000 0.009 0.000 fromnumeric.py:2307(any)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:2401(_all_dispatcher)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:2406(all)\n",
" 2 0.000 0.000 0.002 0.001 fromnumeric.py:51(_wrapfunc)\n",
" 1003 0.002 0.000 0.008 0.000 fromnumeric.py:69(_wrapreduction)\n",
" 1003 0.001 0.000 0.001 0.000 fromnumeric.py:70(<dictcomp>)\n",
" 2 0.000 0.000 0.000 0.000 function_base.py:1315(_diff_dispatcher)\n",
" 2 0.000 0.000 0.000 0.000 function_base.py:1319(diff)\n",
" 1001 0.000 0.000 0.000 0.000 function_base.py:248(_flip_dispatcher)\n",
" 1001 0.003 0.000 0.005 0.000 function_base.py:252(flip)\n",
" 1001 0.000 0.000 0.000 0.000 index_tricks.py:758(__getitem__)\n",
" 2 0.000 0.000 0.000 0.000 multiarray.py:341(where)\n",
" 1001 0.000 0.000 0.000 0.000 multiarray.py:498(can_cast)\n",
" 1001 0.002 0.000 0.002 0.000 numeric.py:1347(normalize_axis_tuple)\n",
" 1001 0.000 0.000 0.000 0.000 numeric.py:1397(<listcomp>)\n",
" 2002 0.001 0.000 0.002 0.000 numerictypes.py:282(issubclass_)\n",
" 1001 0.001 0.000 0.004 0.000 numerictypes.py:356(issubdtype)\n",
" 1 0.000 0.000 0.432 0.432 {built-in method builtins.exec}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method builtins.getattr}\n",
" 5005 0.001 0.000 0.001 0.000 {built-in method builtins.hasattr}\n",
" 3003 0.001 0.000 0.001 0.000 {built-in method builtins.issubclass}\n",
" 6011 0.001 0.000 0.001 0.000 {built-in method builtins.len}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method numpy.asanyarray}\n",
" 7005 0.002 0.000 0.002 0.000 {built-in method numpy.asarray}\n",
" 3011 0.005 0.000 0.022 0.000 {built-in method numpy.core._multiarray_umath.implement_array_function}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method numpy.core._multiarray_umath.normalize_axis_index}\n",
" 8 0.000 0.000 0.000 0.000 {built-in method numpy.geterrobj}\n",
" 4 0.000 0.000 0.000 0.000 {built-in method numpy.seterrobj}\n",
" 2 0.001 0.000 0.001 0.000 {built-in method numpy.zeros}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method scipy.interpolate.interpnd._ndim_coords_from_arrays}\n",
" 6 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
" 1003 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects}\n",
" 1003 0.005 0.000 0.005 0.000 {method 'reduce' of 'numpy.ufunc' objects}\n",
" 1001 0.001 0.000 0.001 0.000 {method 'reshape' of 'numpy.ndarray' objects}\n",
" 2 0.002 0.001 0.002 0.001 {method 'searchsorted' of 'numpy.ndarray' objects}\n",
"\n",
"\n"
]
}
],
"source": [
"points, values, xi = create_test_data()\n",
"cProfile.run('test_ipol_values(points, values, xi, 1000)')"
]
},
{
"cell_type": "markdown",
"id": "0571fd48-51a4-43ad-a5df-0ced1d2d61eb",
"metadata": {},
"source": [
"# Descending Dimensions, 1000 iterations"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "cc508de1-076a-435a-8d56-ed43229f243c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 57178 function calls in 0.385 seconds\n",
"\n",
" Ordered by: standard name\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1001 0.000 0.000 0.001 0.000 3175201396.py:12(_prepare_xi)\n",
" 1001 0.000 0.000 0.002 0.000 3175201396.py:19(_find_indices)\n",
" 1 0.000 0.000 0.003 0.003 3175201396.py:2(__init__)\n",
" 1000 0.003 0.000 0.381 0.000 3175201396.py:26(__call__)\n",
" 1 0.000 0.000 0.000 0.000 3175201396.py:4(<listcomp>)\n",
" 1 0.001 0.001 0.385 0.385 3429582310.py:1(test_ipol_values)\n",
" 4 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(all)\n",
" 1001 0.001 0.000 0.011 0.000 <__array_function__ internals>:177(any)\n",
" 1001 0.001 0.000 0.003 0.000 <__array_function__ internals>:177(can_cast)\n",
" 2 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(diff)\n",
" 1003 0.001 0.000 0.009 0.000 <__array_function__ internals>:177(flip)\n",
" 2 0.000 0.000 0.001 0.001 <__array_function__ internals>:177(searchsorted)\n",
" 2 0.000 0.000 0.000 0.000 <__array_function__ internals>:177(where)\n",
" 1 0.000 0.000 0.385 0.385 <string>:1(<module>)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:212(__init__)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:225(<listcomp>)\n",
" 1001 0.002 0.000 0.003 0.000 _rgi.py:230(_check_dimensionality)\n",
" 1001 0.001 0.000 0.005 0.000 _rgi.py:242(_check_values)\n",
" 1001 0.002 0.000 0.005 0.000 _rgi.py:252(_check_fill_value)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:261(_check_points)\n",
" 1000 0.007 0.000 0.356 0.000 _rgi.py:276(__call__)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:351(_prepare_xi)\n",
" 1000 0.312 0.000 0.336 0.000 _rgi.py:377(_evaluate_linear)\n",
" 1000 0.013 0.000 0.013 0.000 _rgi.py:382(<listcomp>)\n",
" 1000 0.011 0.000 0.011 0.000 _rgi.py:383(<listcomp>)\n",
" 1 0.000 0.000 0.002 0.002 _rgi.py:488(_find_indices)\n",
" 1 0.000 0.000 0.000 0.000 _rgi.py:509(_find_out_of_bounds)\n",
" 4 0.000 0.000 0.000 0.000 _ufunc_config.py:131(geterr)\n",
" 4 0.000 0.000 0.000 0.000 _ufunc_config.py:32(seterr)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:425(__init__)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:429(__enter__)\n",
" 2 0.000 0.000 0.000 0.000 _ufunc_config.py:434(__exit__)\n",
" 2 0.000 0.000 0.000 0.000 fromnumeric.py:1315(_searchsorted_dispatcher)\n",
" 2 0.000 0.000 0.001 0.001 fromnumeric.py:1319(searchsorted)\n",
" 1001 0.000 0.000 0.000 0.000 fromnumeric.py:2302(_any_dispatcher)\n",
" 1001 0.001 0.000 0.008 0.000 fromnumeric.py:2307(any)\n",
" 4 0.000 0.000 0.000 0.000 fromnumeric.py:2401(_all_dispatcher)\n",
" 4 0.000 0.000 0.000 0.000 fromnumeric.py:2406(all)\n",
" 2 0.000 0.000 0.001 0.001 fromnumeric.py:51(_wrapfunc)\n",
" 1005 0.002 0.000 0.007 0.000 fromnumeric.py:69(_wrapreduction)\n",
" 1005 0.001 0.000 0.001 0.000 fromnumeric.py:70(<dictcomp>)\n",
" 2 0.000 0.000 0.000 0.000 function_base.py:1315(_diff_dispatcher)\n",
" 2 0.000 0.000 0.000 0.000 function_base.py:1319(diff)\n",
" 1003 0.000 0.000 0.000 0.000 function_base.py:248(_flip_dispatcher)\n",
" 1003 0.003 0.000 0.007 0.000 function_base.py:252(flip)\n",
" 3005 0.000 0.000 0.000 0.000 index_tricks.py:758(__getitem__)\n",
" 2 0.000 0.000 0.000 0.000 multiarray.py:341(where)\n",
" 1001 0.000 0.000 0.000 0.000 multiarray.py:498(can_cast)\n",
" 1001 0.002 0.000 0.003 0.000 numeric.py:1347(normalize_axis_tuple)\n",
" 1001 0.001 0.000 0.001 0.000 numeric.py:1397(<listcomp>)\n",
" 2002 0.001 0.000 0.002 0.000 numerictypes.py:282(issubclass_)\n",
" 1001 0.001 0.000 0.003 0.000 numerictypes.py:356(issubdtype)\n",
" 1 0.000 0.000 0.385 0.385 {built-in method builtins.exec}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method builtins.getattr}\n",
" 5007 0.001 0.000 0.001 0.000 {built-in method builtins.hasattr}\n",
" 3003 0.001 0.000 0.001 0.000 {built-in method builtins.issubclass}\n",
" 6011 0.001 0.000 0.001 0.000 {built-in method builtins.len}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method numpy.asanyarray}\n",
" 7003 0.001 0.000 0.001 0.000 {built-in method numpy.asarray}\n",
" 3015 0.004 0.000 0.021 0.000 {built-in method numpy.core._multiarray_umath.implement_array_function}\n",
" 2004 0.000 0.000 0.000 0.000 {built-in method numpy.core._multiarray_umath.normalize_axis_index}\n",
" 8 0.000 0.000 0.000 0.000 {built-in method numpy.geterrobj}\n",
" 4 0.000 0.000 0.000 0.000 {built-in method numpy.seterrobj}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method numpy.zeros}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method scipy.interpolate.interpnd._ndim_coords_from_arrays}\n",
" 8 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
" 1005 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects}\n",
" 1005 0.004 0.000 0.004 0.000 {method 'reduce' of 'numpy.ufunc' objects}\n",
" 1001 0.001 0.000 0.001 0.000 {method 'reshape' of 'numpy.ndarray' objects}\n",
" 2 0.001 0.001 0.001 0.001 {method 'searchsorted' of 'numpy.ndarray' objects}\n",
"\n",
"\n"
]
}
],
"source": [
"points, values, xi = create_test_data(descending=True)\n",
"cProfile.run('test_ipol_values(points, values, xi, 1000)')"
]
},
{
"cell_type": "markdown",
"id": "76489ffa-da42-40f4-98e0-8a04ffb073b0",
"metadata": {},
"source": [
"# Comparison"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "948c2bb4-5c15-4ac1-9459-f8c047a3115b",
"metadata": {},
"outputs": [],
"source": [
"interp = RegularGridInterpolator(points, values, method=\"linear\",\n",
" bounds_error=False,\n",
" fill_value=np.nan)\n",
"valip = interp(xi)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "f2ddb81a-d320-4181-96ea-cad29f267acb",
"metadata": {},
"outputs": [],
"source": [
"interp = RegularGridInterpolatorValues(points, xi, method=\"linear\",\n",
" bounds_error=False,\n",
" fill_value=np.nan)\n",
"valip2 = interp(values)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "1c16676e-e83a-422d-9b65-ce3be77c5de8",
"metadata": {},
"outputs": [],
"source": [
"np.testing.assert_array_equal(valip2, valip)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment