{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numba" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import interpolation" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "grid = (\n", " (0.0, 1.0, 10),\n", " (0.0, 1.0, 10)\n", ")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "C = np.random.random((10,10))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "N = 1000000" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "S = np.random.random((N,2))" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "from interpolation import mlinterp" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.39887696, 0.46464487, 0.2931475 , ..., 0.05132932, 0.59298413,\n", " 0.68548968])" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mlinterp(grid, C, S)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "d = mlinterp.inspect_llvm()\n", "d[[*d.keys()]]" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/pablo/anaconda3/lib/python3.6/site-packages/numba/pretty_annotate.py:26: FutureWarning: The pretty_annotate functionality is experimental and might change API\n", " FutureWarning)\n" ] }, { "data": { "text/html": [ "\n", "\n", "
\n", " \n", "\n", "\n", "\n", " \n", " \n", "\n",
" \n",
" \n",
" \n",
" \n",
" |
\n",
" \n",
" label 0\n",
" \n",
" | \n",
"
\n",
" 47:\n",
" N = u.shape[0]\n",
"
\n",
" \n",
" \n",
" grid = arg(0, name=grid) :: tuple((float64, float64, int64) x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" c = arg(1, name=c) :: array(float64, 2d, C)\n",
" \n",
" | \n",
"
\n",
" \n",
" u = arg(2, name=u) :: array(float64, 2d, C)\n",
" \n",
" | \n",
"
\n",
" \n",
" $0.2 = getattr(value=u, attr=shape) :: tuple(int64 x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" $const0.3 = const(int, 0) :: int64\n",
" \n",
" | \n",
"
\n",
" \n",
" $0.4 = static_getitem(value=$0.2, index=0, index_var=$const0.3) :: int64\n",
" \n",
" | \n",
"
\n",
" \n",
" del $const0.3\n",
" \n",
" | \n",
"
\n",
" \n",
" del $0.2\n",
" \n",
" | \n",
"
\n",
" \n",
" N = $0.4 :: int64\n",
" \n",
" | \n",
"
\n",
" \n",
" del $0.4\n",
" \n",
" | \n",
"
\n",
" 48:\n",
" res = np.zeros(N)\n",
"
\n",
" \n",
" \n",
" $0.5 = global(np: <module 'numpy' from '/opt/pablo/anaconda3/lib/python3.6/site-packages/numpy/__init__.py'>) :: Module(<module 'numpy' from '/opt/pablo/anaconda3/lib/python3.6/site-packages/numpy/__init__.py'>)\n",
" \n",
" | \n",
"
\n",
" \n",
" $0.6 = getattr(value=$0.5, attr=zeros) :: Function(<built-in function zeros>)\n",
" \n",
" | \n",
"
\n",
" \n",
" del $0.5\n",
" \n",
" | \n",
"
\n",
" \n",
" $0.8 = call $0.6(N, func=$0.6, args=[Var(N, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (47))], kws=(), vararg=None) :: (int64,) -> array(float64, 1d, C)\n",
" \n",
" | \n",
"
\n",
" \n",
" del $0.6\n",
" \n",
" | \n",
"
\n",
" \n",
" res = $0.8 :: array(float64, 1d, C)\n",
" \n",
" | \n",
"
\n",
" \n",
" del $0.8\n",
" \n",
" | \n",
"
\n",
" \n",
" jump 20\n",
" \n",
" | \n",
"
\n",
" \n",
" label 20\n",
" \n",
" | \n",
"
\n",
" 49:\n",
" for n in range(N):\n",
"
\n",
" \n",
" \n",
" jump 22\n",
" \n",
" | \n",
"
\n",
" \n",
" label 22\n",
" \n",
" | \n",
"
\n",
" \n",
" $22.1 = global(range: <class 'range'>) :: Function(<class 'range'>)\n",
" \n",
" | \n",
"
\n",
" \n",
" $22.3 = call $22.1(N, func=$22.1, args=[Var(N, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (47))], kws=(), vararg=None) :: (int64,) -> range_state_int64\n",
" \n",
" | \n",
"
\n",
" \n",
" del N\n",
" \n",
" | \n",
"
\n",
" \n",
" del $22.1\n",
" \n",
" | \n",
"
\n",
" \n",
" $22.4 = getiter(value=$22.3) :: range_iter_int64\n",
" \n",
" | \n",
"
\n",
" \n",
" del $22.3\n",
" \n",
" | \n",
"
\n",
" \n",
" $phi30.1 = $22.4 :: range_iter_int64\n",
" \n",
" | \n",
"
\n",
" \n",
" del $22.4\n",
" \n",
" | \n",
"
\n",
" \n",
" jump 30\n",
" \n",
" | \n",
"
\n",
" \n",
" label 30\n",
" \n",
" | \n",
"
\n",
" \n",
" $30.2 = iternext(value=$phi30.1) :: pair<int64, bool>\n",
" \n",
" | \n",
"
\n",
" \n",
" $30.3 = pair_first(value=$30.2) :: int64\n",
" \n",
" | \n",
"
\n",
" \n",
" $30.4 = pair_second(value=$30.2) :: bool\n",
" \n",
" | \n",
"
\n",
" \n",
" del $30.2\n",
" \n",
" | \n",
"
\n",
" \n",
" $phi32.1 = $30.3 :: int64\n",
" \n",
" | \n",
"
\n",
" \n",
" $phi96.1 = $30.3 :: int64\n",
" \n",
" | \n",
"
\n",
" \n",
" del $phi96.1\n",
" \n",
" | \n",
"
\n",
" \n",
" del $30.3\n",
" \n",
" | \n",
"
\n",
" \n",
" $phi96.2 = $phi30.1 :: range_iter_int64\n",
" \n",
" | \n",
"
\n",
" \n",
" del $phi96.2\n",
" \n",
" | \n",
"
\n",
" \n",
" branch $30.4, 32, 96\n",
" \n",
" | \n",
"
\n",
" \n",
" label 32\n",
" \n",
" | \n",
"
\n",
" \n",
" del $30.4\n",
" \n",
" | \n",
"
\n",
" \n",
" n = $phi32.1 :: int64\n",
" \n",
" | \n",
"
\n",
" \n",
" del $phi32.1\n",
" \n",
" | \n",
"
\n",
" 50:\n",
" uu = extract_row(u, n, grid)\n",
"
\n",
" \n",
" \n",
" $32.2 = global(extract_row: CPUDispatcher(<function extract_row at 0x7ff2779c18c8>)) :: type(CPUDispatcher(<function extract_row at 0x7ff2779c18c8>))\n",
" \n",
" | \n",
"
\n",
" \n",
" $32.6 = call $32.2(u, n, grid, func=$32.2, args=[Var(u, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (47)), Var(n, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (49)), Var(grid, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (47))], kws=(), vararg=None) :: (array(float64, 2d, C), int64, tuple((float64, float64, int64) x 2)) -> tuple(float64 x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.2\n",
" \n",
" | \n",
"
\n",
" \n",
" uu = $32.6 :: tuple(float64 x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.6\n",
" \n",
" | \n",
"
\n",
" 51:\n",
" # get indices and barycentric coordinates\n",
"
\n",
" \n",
" 52:\n",
" tmp = fmap(get_index, grid, uu)\n",
"
\n",
" \n",
" \n",
" $32.7 = global(fmap: <function fmap at 0x7ff277be11e0>) :: Function(<function fmap at 0x7ff277be11e0>)\n",
" \n",
" | \n",
"
\n",
" \n",
" $32.8 = global(get_index: CPUDispatcher(<function get_index at 0x7ff277be17b8>)) :: type(CPUDispatcher(<function get_index at 0x7ff277be17b8>))\n",
" \n",
" | \n",
"
\n",
" \n",
" $32.11 = call $32.7($32.8, grid, uu, func=$32.7, args=[Var($32.8, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (52)), Var(grid, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (47)), Var(uu, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (50))], kws=(), vararg=None) :: (type(CPUDispatcher(<function get_index at 0x7ff277be17b8>)), tuple((float64, float64, int64) x 2), tuple(float64 x 2)) -> tuple((int64, float64) x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" del uu\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.8\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.7\n",
" \n",
" | \n",
"
\n",
" \n",
" tmp = $32.11 :: tuple((int64, float64) x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.11\n",
" \n",
" | \n",
"
\n",
" 53:\n",
" indices, barycenters = funzip(tmp)\n",
"
\n",
" \n",
" \n",
" $32.12 = global(funzip: CPUDispatcher(<function funzip at 0x7ff2779c1268>)) :: type(CPUDispatcher(<function funzip at 0x7ff2779c1268>))\n",
" \n",
" | \n",
"
\n",
" \n",
" $32.14 = call $32.12(tmp, func=$32.12, args=[Var(tmp, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (52))], kws=(), vararg=None) :: (tuple((int64, float64) x 2),) -> (tuple(int64 x 2), tuple(float64 x 2))\n",
" \n",
" | \n",
"
\n",
" \n",
" del tmp\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.12\n",
" \n",
" | \n",
"
\n",
" \n",
" $32.17 = exhaust_iter(value=$32.14, count=2) :: (tuple(int64 x 2), tuple(float64 x 2))\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.14\n",
" \n",
" | \n",
"
\n",
" \n",
" $32.15 = static_getitem(value=$32.17, index=0, index_var=None) :: tuple(int64 x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" $32.16 = static_getitem(value=$32.17, index=1, index_var=None) :: tuple(float64 x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.17\n",
" \n",
" | \n",
"
\n",
" \n",
" indices = $32.15 :: tuple(int64 x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.15\n",
" \n",
" | \n",
"
\n",
" \n",
" barycenters = $32.16 :: tuple(float64 x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.16\n",
" \n",
" | \n",
"
\n",
" 54:\n",
" coeffs = get_coeffs(c, indices)\n",
"
\n",
" \n",
" \n",
" $32.18 = global(get_coeffs: CPUDispatcher(<function get_coeffs at 0x7ff2779c12f0>)) :: type(CPUDispatcher(<function get_coeffs at 0x7ff2779c12f0>))\n",
" \n",
" | \n",
"
\n",
" \n",
" $32.21 = call $32.18(c, indices, func=$32.18, args=[Var(c, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (47)), Var(indices, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (53))], kws=(), vararg=None) :: (array(float64, 2d, C), tuple(int64 x 2)) -> tuple(tuple(float64 x 2) x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" del indices\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.18\n",
" \n",
" | \n",
"
\n",
" \n",
" coeffs = $32.21 :: tuple(tuple(float64 x 2) x 2)\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.21\n",
" \n",
" | \n",
"
\n",
" 55:\n",
" res[n] = tensor_reduction(coeffs, barycenters)\n",
"
\n",
" \n",
" \n",
" $32.22 = global(tensor_reduction: CPUDispatcher(<function tensor_reduction at 0x7ff2779c1840>)) :: type(CPUDispatcher(<function tensor_reduction at 0x7ff2779c1840>))\n",
" \n",
" | \n",
"
\n",
" \n",
" $32.25 = call $32.22(coeffs, barycenters, func=$32.22, args=[Var(coeffs, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (54)), Var(barycenters, /home/pablo/Mobilhome/econforge/interpolation.py/interpolation/multilinear/mlinterp.py (53))], kws=(), vararg=None) :: (tuple(tuple(float64 x 2) x 2), tuple(float64 x 2)) -> float64\n",
" \n",
" | \n",
"
\n",
" \n",
" del coeffs\n",
" \n",
" | \n",
"
\n",
" \n",
" del barycenters\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.22\n",
" \n",
" | \n",
"
\n",
" \n",
" res[n] = $32.25 :: (array(float64, 1d, C), int64, float64) -> none\n",
" \n",
" | \n",
"
\n",
" \n",
" del n\n",
" \n",
" | \n",
"
\n",
" \n",
" del $32.25\n",
" \n",
" | \n",
"
\n",
" \n",
" jump 30\n",
" \n",
" | \n",
"
\n",
" \n",
" label 96\n",
" \n",
" | \n",
"
\n",
" \n",
" del u\n",
" \n",
" | \n",
"
\n",
" \n",
" del grid\n",
" \n",
" | \n",
"
\n",
" \n",
" del c\n",
" \n",
" | \n",
"
\n",
" \n",
" del $phi32.1\n",
" \n",
" | \n",
"
\n",
" \n",
" del $phi30.1\n",
" \n",
" | \n",
"
\n",
" \n",
" del $30.4\n",
" \n",
" | \n",
"
\n",
" \n",
" jump 98\n",
" \n",
" | \n",
"
\n",
" \n",
" label 98\n",
" \n",
" | \n",
"
\n",
" 56:\n",
" return res\n",
"
\n",
" \n",
" \n",
" $98.2 = cast(value=res) :: array(float64, 1d, C)\n",
" \n",
" | \n",
"
\n",
" \n",
" del res\n",
" \n",
" | \n",
"
\n",
" \n",
" return $98.2\n",
" \n",
" | \n",
"