Open
Description
This is a good function to implement fully in LPython. It works for:
- any type
- any array rank and some combination of ranks
- it automatically broadcasts
If we can fully implement this as regular LPython code, without any extra "clip
specific" logic in AST2ASR, this will be enough to implement large parts of NumPy.
So we can use this function as a "testbed", and implement all missing features in LPython.
I suggest we try to implement some small subset, then we try to make the function work for more combination of types and ranks, then we try to implement some generalizations in LPython to make this easier, such as "generics" (any type) and rank agnostic generics, to make the code simpler, and iteratively improve, until this function can be implemented relatively easily.
See also:
- NumPy implementation: https://github.com/numpy/numpy/blob/f982384166f3fc8ab06f1fbfa42a3165e3903486/numpy/core/src/umath/clip.cpp, https://github.com/numpy/numpy/blob/bb95cf015165bcf85f99ba0d28a7a6e727ca955b/numpy/core/src/multiarray/calculation.c#L844
- Numba implementation:
numpy.clip
acceptnumpy.array
fora_min
,a_max
numba/numba#7958