Skip to content

Commit

Permalink
Rename make_cfunc() -> cfunc().
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Feb 15, 2024
1 parent 247a959 commit d11689e
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 75 deletions.
2 changes: 1 addition & 1 deletion doc/notebooks/NeuralODEs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
"outputs": [],
"source": [
"# Assemble the r.h.s. for scipy-integration\n",
"rhs = hy.make_cfunc(fn = [it[1] for it in dyn], compact_mode=True, vars = state + list(phi.flatten())+ list(varphi.flatten()))"
"rhs = hy.cfunc(fn = [it[1] for it in dyn], compact_mode=True, vars = state + list(phi.flatten())+ list(varphi.flatten()))"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
"\n",
"# Introduce a compiled function\n",
"# for the evaluation of the Hamiltonian.\n",
"H_cf = hy.make_cfunc([H], vars=[x, y, lx, ly, u])\n",
"H_cf = hy.cfunc([H], vars=[x, y, lx, ly, u])\n",
"\n",
"def _hamiltonian(x,y,lx,ly,p):\n",
" sw_v = switching_function(x,y,lx,ly,p)\n",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/Outer Solar System.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"metadata": {},
"outputs": [],
"source": [
"en_cf = hy.make_cfunc([hy.model.nbody_energy(6, masses = masses, Gconst = G)],\n",
"en_cf = hy.cfunc([hy.model.nbody_energy(6, masses = masses, Gconst = G)],\n",
" # NOTE: the variables for the compiled function\n",
" # are taken from the definition of the ODE system.\n",
" vars=[_[0] for _ in sys])"
Expand Down
4 changes: 2 additions & 2 deletions doc/notebooks/Periodic orbits in the CR3BP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"source": [
"# Introduce a compiled function for the evaluation\n",
"# of the dynamics equation for px.\n",
"px_dyn_cf = hy.make_cfunc([f[3]], vars=x)\n",
"px_dyn_cf = hy.cfunc([f[3]], vars=x)\n",
"\n",
"def compute_L_points(mu):\n",
" \"\"\"Computes The exact position of the Lagrangian points. To do so it finds the zeros of the\n",
Expand Down Expand Up @@ -651,7 +651,7 @@
"source": [
"# Introduce a compiled function for the evaluation\n",
"# of the dynamics equations.\n",
"dyn_cf = hy.make_cfunc(f, vars=x)\n",
"dyn_cf = hy.cfunc(f, vars=x)\n",
"\n",
"def corrector(ta, x0):\n",
" \"\"\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@
"f = np.array(f)\n",
"\n",
"# We compile the r.h.s. of the dynamics into compiled functions as to later be able to evaluate their numerical values magnitude.\n",
"cf_f = hy.make_cfunc(f, vars=x)\n",
"cf_px = hy.make_cfunc([f[3]], vars=[x[0],x[1],x[2],x[4]]) # x,y,z,py"
"cf_f = hy.cfunc(f, vars=x)\n",
"cf_px = hy.cfunc([f[3]], vars=[x[0],x[1],x[2],x[4]]) # x,y,z,py"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/arbitrary_precision.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@
"sym_func = x**2-y**2\n",
"\n",
"# Compile it.\n",
"cf = hy.make_cfunc([sym_func], [x, y],\n",
"cf = hy.cfunc([sym_func], [x, y],\n",
" fp_type=real, prec=prec)"
]
},
Expand Down
18 changes: 9 additions & 9 deletions doc/notebooks/compiled_functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"id": "68861247-8ac9-42a3-bf58-b893282ccdf7",
"metadata": {},
"source": [
"We can now proceed to JIT compile ``sym_func`` via the ``make_cfunc()`` function. ``make_cfunc()`` takes two mandatory input arguments:\n",
"We can now proceed to JIT compile ``sym_func`` via the ``cfunc()`` function. ``cfunc()`` takes two mandatory input arguments:\n",
"\n",
"- the list of symbolic expressions representing the outputs of the vector function, and\n",
"- the list of symbolic variables representing the inputs of the function.\n",
Expand All @@ -72,15 +72,15 @@
"metadata": {},
"outputs": [],
"source": [
"cf = hy.make_cfunc([sym_func], [x, y])"
"cf = hy.cfunc([sym_func], [x, y])"
]
},
{
"cell_type": "markdown",
"id": "8df3f92c-49b2-459d-bb0a-33e2e000812c",
"metadata": {},
"source": [
"The value returned by ``make_cfunc()`` is a callable function object which accepts as input a NumPy array representing the values to use in the evaluation of ``sym_func``:"
"The value returned by ``cfunc()`` is a callable function object which accepts as input a NumPy array representing the values to use in the evaluation of ``sym_func``:"
]
},
{
Expand Down Expand Up @@ -163,7 +163,7 @@
}
],
"source": [
"cf2 = hy.make_cfunc([sym_func], vars=[y,x])\n",
"cf2 = hy.cfunc([sym_func], vars=[y,x])\n",
"\n",
"# Evaluate for x=1 and y=5.\n",
"cf2([5,1])"
Expand Down Expand Up @@ -205,9 +205,9 @@
"id": "43f895e7-2da5-440d-84f8-1932d5a9d1fc",
"metadata": {},
"source": [
"``make_cfunc()`` accepts several additional keyword arguments, the most important of which is the boolean flag ``compact_mode`` (defaulting to ``False``). Similarly to the [adaptive Taylor integrators](<./Customising the adaptive integrator.ipynb>), you should enable ``compact_mode`` if you want to compile extremely large symbolic expressions that result in excessively long compilation times. The downside of ``compact_mode`` is a slight performance degradation due to the different code generation model adopted during the JIT compilation process.\n",
"``cfunc()`` accepts several additional keyword arguments, the most important of which is the boolean flag ``compact_mode`` (defaulting to ``False``). Similarly to the [adaptive Taylor integrators](<./Customising the adaptive integrator.ipynb>), you should enable ``compact_mode`` if you want to compile extremely large symbolic expressions that result in excessively long compilation times. The downside of ``compact_mode`` is a slight performance degradation due to the different code generation model adopted during the JIT compilation process.\n",
"\n",
"The function object returned by ``make_cfunc()`` also accepts several optional keyword arguments. It is possible, for instance, to pass as ``outputs`` argument a pre-allocated NumPy array into which the result of the evaluation will be written. This is useful to avoid the overhead of allocating new memory for the return value, if such memory is already available:"
"The function object returned by ``cfunc()`` also accepts several optional keyword arguments. It is possible, for instance, to pass as ``outputs`` argument a pre-allocated NumPy array into which the result of the evaluation will be written. This is useful to avoid the overhead of allocating new memory for the return value, if such memory is already available:"
]
},
{
Expand Down Expand Up @@ -273,7 +273,7 @@
"sym_func_par = hy.par[0]*x**2-hy.par[1]*y**2+hy.par[2]\n",
"\n",
"# Compile it.\n",
"cf_par = hy.make_cfunc([sym_func_par], [x, y])\n",
"cf_par = hy.cfunc([sym_func_par], [x, y])\n",
"\n",
"# Evaluate, specifying the parameter values\n",
"cf_par([1,5], pars=[-1, -2, -3])"
Expand Down Expand Up @@ -315,7 +315,7 @@
"sym_func_tm = x**2-y**2+hy.time\n",
"\n",
"# Compile it.\n",
"cf_tm = hy.make_cfunc([sym_func_tm], [x, y])\n",
"cf_tm = hy.cfunc([sym_func_tm], [x, y])\n",
"\n",
"# Evaluate for x=1, y=5 and time=6.\n",
"cf_tm([1,5], time=6)"
Expand Down Expand Up @@ -538,7 +538,7 @@
"metadata": {},
"outputs": [],
"source": [
"Ham_cf = hy.make_cfunc([Ham_sym], vars=[px,py,pz,x,y,z])"
"Ham_cf = hy.cfunc([Ham_sym], vars=[px,py,pz,x,y,z])"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions doc/notebooks/computing_derivatives.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@
}
],
"source": [
"grad_diff_cf = hy.make_cfunc(grad_diff, sym_vars)\n",
"grad_diff_cf = hy.cfunc(grad_diff, sym_vars)\n",
"grad_diff_cf.decomposition[8:-8]"
]
},
Expand Down Expand Up @@ -582,7 +582,7 @@
}
],
"source": [
"grad_diff_tensors_cf = hy.make_cfunc(grad_diff_tensors, sym_vars)\n",
"grad_diff_tensors_cf = hy.cfunc(grad_diff_tensors, sym_vars)\n",
"grad_diff_tensors_cf.decomposition[8:-8]"
]
},
Expand Down Expand Up @@ -621,7 +621,7 @@
" grad_diff_tensors = [t[1] for t in hy.diff_tensors([sp_func],\n",
" diff_args=hy.diff_args.vars,\n",
" diff_order=1).get_derivatives(1)]\n",
" grad_diff_tensors_cf = hy.make_cfunc(grad_diff_tensors, sym_vars)\n",
" grad_diff_tensors_cf = hy.cfunc(grad_diff_tensors, sym_vars)\n",
" nops.append(len(grad_diff_tensors_cf.decomposition) - 2*nvars)\n",
"\n",
"%matplotlib inline\n",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/elp2000.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
" thresh=thr)\n",
"\n",
" # Compile the function for the evaluation of moon_x/y/z.\n",
" moon_cf = hy.make_cfunc([moon_x, moon_y, moon_z], [tm], compact_mode=True)\n",
" moon_cf = hy.cfunc([moon_x, moon_y, moon_z], [tm], compact_mode=True)\n",
" \n",
" # Run the evaluation.\n",
" elp2000_states = moon_cf(dates.reshape((1,-1)))\n",
Expand Down
8 changes: 4 additions & 4 deletions doc/notebooks/ex_system_revisited.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
"metadata": {},
"outputs": [],
"source": [
"f_cf = hy.make_cfunc([x+y+1., x+y+z], [x, y, z])"
"f_cf = hy.cfunc([x+y+1., x+y+z], [x, y, z])"
]
},
{
Expand Down Expand Up @@ -608,7 +608,7 @@
"metadata": {},
"outputs": [],
"source": [
"f_cf_fix = hy.make_cfunc([hy.fix(x+y)+1., hy.fix(x+y)+z],\n",
"f_cf_fix = hy.cfunc([hy.fix(x+y)+1., hy.fix(x+y)+z],\n",
" [x, y, z])"
]
},
Expand Down Expand Up @@ -711,7 +711,7 @@
}
],
"source": [
"g_cf = hy.make_cfunc([2.0 * (x + y + z)], [x, y, z])\n",
"g_cf = hy.cfunc([2.0 * (x + y + z)], [x, y, z])\n",
"g_cf.decomposition"
]
},
Expand Down Expand Up @@ -741,7 +741,7 @@
}
],
"source": [
"g_cf_fix = hy.make_cfunc([2.0 * hy.fix(x + y + z)],\n",
"g_cf_fix = hy.cfunc([2.0 * hy.fix(x + y + z)],\n",
" [x, y, z])\n",
"g_cf_fix.decomposition"
]
Expand Down
4 changes: 2 additions & 2 deletions doc/notebooks/ffnn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
}
],
"source": [
"cf = hy.make_cfunc(ffnn, [x, y])\n",
"cf = hy.cfunc(ffnn, [x, y])\n",
"print(cf)"
]
},
Expand Down Expand Up @@ -251,7 +251,7 @@
}
],
"source": [
"cf = hy.make_cfunc(ffnn, [x, y])\n",
"cf = hy.cfunc(ffnn, [x, y])\n",
"print(cf)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions doc/notebooks/lagrangian_propagator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
"metadata": {},
"outputs": [],
"source": [
"cf = hy.make_cfunc(pos_vel,\n",
"cf = hy.cfunc(pos_vel,\n",
" # Specify the order in which the input\n",
" # variables are passed to the compiled\n",
" # function.\n",
Expand Down Expand Up @@ -373,7 +373,7 @@
"metadata": {},
"outputs": [],
"source": [
"cf_stm = hy.make_cfunc(jac.flatten(),\n",
"cf_stm = hy.cfunc(jac.flatten(),\n",
" # Specify the order in which the input\n",
" # variables are passed to the compiled\n",
" # function.\n",
Expand Down
6 changes: 3 additions & 3 deletions doc/notebooks/projection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"source": [
"# Define a compiled function for the computation\n",
"# of the energy in an N-body system from its state vector.\n",
"en_cfunc = hy.make_cfunc([hy.model.nbody_energy(6, masses=masses, Gconst=G)],\n",
"en_cfunc = hy.cfunc([hy.model.nbody_energy(6, masses=masses, Gconst=G)],\n",
" vars=state_vars)"
]
},
Expand Down Expand Up @@ -511,7 +511,7 @@
"metadata": {},
"outputs": [],
"source": [
"objfun_cfunc = hy.make_cfunc([dist2_ex] + grad_dist2_ex, vars=state_vars)"
"objfun_cfunc = hy.cfunc([dist2_ex] + grad_dist2_ex, vars=state_vars)"
]
},
{
Expand Down Expand Up @@ -561,7 +561,7 @@
"\n",
"# The compiled function for the computation of the gradient\n",
"# of the constraint.\n",
"grad_cstr_cfunc = hy.make_cfunc(grad_cstr, vars=state_vars)"
"grad_cstr_cfunc = hy.cfunc(grad_cstr, vars=state_vars)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/single_precision.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"source": [
"x, v = hy.make_vars(\"x\", \"v\")\n",
"\n",
"cf_en = hy.make_cfunc([en], fp_type=np.single,\n",
"cf_en = hy.cfunc([en], fp_type=np.single,\n",
" vars=[x, v])"
]
},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/torch_and_heyoka.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"metadata": {},
"outputs": [],
"source": [
"model_heyoka_compiled=hk.make_cfunc(model_heyoka, [inp_1, inp_2, inp_3, inp_4])"
"model_heyoka_compiled=hk.cfunc(model_heyoka, [inp_1, inp_2, inp_3, inp_4])"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/vsop2013.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
" thresh=thr)[:3]\n",
"\n",
" # Compile the function for the evaluation of venus_x/y/z.\n",
" venus_cf = hy.make_cfunc([venus_x, venus_y, venus_z], [tm], compact_mode=True)\n",
" venus_cf = hy.cfunc([venus_x, venus_y, venus_z], [tm], compact_mode=True)\n",
" \n",
" # Run the evaluation.\n",
" vsop_states = venus_cf(dates.reshape((1,-1)))\n",
Expand Down
2 changes: 1 addition & 1 deletion heyoka/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def taylor_add_jet(sys, order, **kwargs):
return getattr(core, "_taylor_add_jet{}".format(fp_suffix))(sys, order, **kwargs)


def make_cfunc(fn, vars, **kwargs):
def cfunc(fn, vars, **kwargs):
from . import core

fp_type = kwargs.pop("fp_type", float)
Expand Down
Loading

0 comments on commit d11689e

Please sign in to comment.