You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow lambdify to generate functions with out arguments (pyccel#1867)
Add a `use_out` parameter to `pyccel.lambdify` to avoid unnecessary
memory allocation. Auto-generate a docstring for functions generated via
calls to `pyccel.lambdify`.
Copy file name to clipboardExpand all lines: docs/quickstart.md
+16Lines changed: 16 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -482,6 +482,22 @@ In practice `lambdify` uses SymPy's `NumPyPrinter` to generate code which is pas
482
482
Once the file has been copied, `epyccel` calls the `pyccel` command to generate a Python C extension module that contains a single pyccelised function.
483
483
Then finally, it imports this function and returns it to the caller.
484
484
485
+
In order to make functions even faster it may be desirable to avoid unnecessary allocations inside the function. This functionality is similar to using an `out` argument in NumPy. Pyccel makes this functionality possible through the use of the `use_out` argument.
486
+
For example:
487
+
```python
488
+
import numpy as np
489
+
import sympy as sp
490
+
from pyccel import lambdify
491
+
492
+
x = sp.Symbol('x')
493
+
expr = x**2+ x*5
494
+
f = lambdify(expr, {x : 'float[:,:]'}, result_type='float[:,:]')
495
+
x_2d = np.ones((4,2))
496
+
y_2d = np.empty_like(x_2d)
497
+
f(x_2d, y_2d)
498
+
print(y_2d)
499
+
```
500
+
485
501
## Other Features
486
502
487
503
Pyccel's generated code can use parallel multi-threading through [OpenMP](https://en.wikipedia.org/wiki/OpenMP); please read [our documentation](https://github.com/pyccel/pyccel/blob/devel/docs/openmp.md) for more details.
0 commit comments