What happens when you use this?

eval is generally used only for defining output for SymPy arguments, but I
believe what you are doing should work, since lambdify should map MyClip to
itself.  You might have to do something to make sure it is included in the
namespace.

Aaron Meurer

On Wed, Feb 3, 2016 at 4:10 PM, Vladimir Perić <[email protected]>
wrote:

> Hi,
>
> I'm trying to write a symbolic numpy.clip function[1], to be used in
> expressions (it's ok if it doesn't get simplified) and in lambdify
> (and consequently evaluated by numpy). Doing this in pure numpy would
> be trivial, but it doesn't work well with my current code (and would
> be inelegant).
>
> I've tried something like this, in the hope that the function will
> remain unevaluated except when an numpy array is passed to it, but
> it's not working: (inspired by [2])
>
> class MyClip(sympy.Function):
>     @classmethod
>     def eval(cls, arg1, arg2, arg3):
>         if isinstance(arg1, np.ndarray):
>             return np.clip(arg1, arg2, arg3)
>
> Am I missing something obvious here, or not specifying "eval" in the
> correct way? Perhaps my whole approach is wrong, but I cannot see a
> better solution.
>
> Thanks for any help!
>
> [1] Clip limits the values in an array: given an interval, values
> outside the interval are clipped to the interval edges: np.clip(a,
> a_min, a_max)
> [2] How to define a symbolic function:
> https://groups.google.com/forum/#!topic/sympy/sk4K-VWBRRQ
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/CAFu6gYbqsROfy9WnZ5VaocVjdcV3-Te3dQO3f_ZQ2UHdRa6YDQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6KPeZWqi1-qrOj8D7VS%3D21ObMB3stQK23%3DUXhG9Rcu3OA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to