Cannot use @numba.vectorize on a jitclass method

0 views
Skip to first unread message

parth...@gmail.com

unread,
Sep 20, 2016, 4:54:06 PM9/20/16
to Numba Public Discussion - Public
On 0.26.0 it is not possible to decorate jitclass method with numba.vectorize. Is there a plan to add this capability?

Siu Kwan Lam

unread,
Sep 21, 2016, 9:33:01 AM9/21/16
to Numba Public Discussion - Public
There are some details that I am not understanding.  Would your usecase require a jitclass instance be stored in arrays?  Or, would the `self` argument not participate in the vectorizing?  Alternatively, would calling a vectorize-ed function inside the jitclass method satisfy your usecase?

On Tue, Sep 20, 2016 at 3:54 PM <parth...@gmail.com> wrote:
On 0.26.0 it is not possible to decorate jitclass method with numba.vectorize. Is there a plan to add this capability?

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.
To post to this group, send email to numba...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/3b0a826d-33f0-4a3f-8c12-3efaf0f7b5d6%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
--
Siu Kwan Lam
Software Engineer
Continuum Analytics

Parth Patel

unread,
Sep 21, 2016, 12:37:10 PM9/21/16
to Numba Public Discussion - Public
This is a class for 2d interpolation. It has various properties that stores some samples x, y, f(x, y) to use for interpolation. It has one method (interp_single) that takes in a single x, y pair and returns interpolated f(x,y). I would like to vectorize this method so that I can compute interpolated data for arrays of x and y.

Simple solution for python class using numpy.vectorize is following.
Inside init method: self.interp_vec = numpy.vectorize(self.interp_single)
object.interp_vec(x_array, y_array) returns array of interpolated values.

However, same trick doesn't work using jitclass and numba.vectorize. I don't know how to declare this method interp_vec in jitclass's spec list.

It would be ideal if I could decorate a jitclass method with numba.vectorize.

Thanks,
Parth

Siu Kwan Lam

unread,
Sep 22, 2016, 9:30:53 AM9/22/16
to Numba Public Discussion - Public
Interesting, your are applying `numpy.vectorize` to a bound method so that `numpy.vectorize` does not see the `self` arg.  For now, I am afraid that is not easy to support in numba.

As a workaround, `interp_vec` can be a wrapper that calls the vectorized function.  Does `self.interp_single` depends on properties stored in `self`?  If so, it may need more restructuring.  

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.
To post to this group, send email to numba...@continuum.io.

Parth Patel

unread,
Sep 22, 2016, 10:56:26 AM9/22/16
to numba...@continuum.io
Yes, self.interp_single depends on several properties of the object. 

One way I could resolve this issue is the following. 
- write a separate method interp_single whose arguments are not just single float x and y, but the raw data (set of pre calculated x, y, f(x,y) ). 
- The problem with this approach is that vectorize decorator requires me to have all its arguments be scalars. 

Is it possible to tell numba.vectorize that first two arguments are scalars and last argument is a tuple. I want it to vectorize using only first two arguments, and the last argument will be fixed in size. 

Thanks,
Parth 

On Thu, Sep 22, 2016 at 9:30 AM, Siu Kwan Lam <s...@continuum.io> wrote:
Interesting, your are applying `numpy.vectorize` to a bound method so that `numpy.vectorize` does not see the `self` arg.  For now, I am afraid that is not easy to support in numba.

As a workaround, `interp_vec` can be a wrapper that calls the vectorized function.  Does `self.interp_single` depends on properties stored in `self`?  If so, it may need more restructuring.  

On Wed, Sep 21, 2016 at 11:37 AM Parth Patel <parth...@gmail.com> wrote:
This is a class for 2d interpolation. It has various properties that stores some samples x, y, f(x, y) to use for interpolation. It has one method (interp_single) that takes in a single x, y pair and returns interpolated f(x,y). I would like to vectorize this method so that I can compute interpolated data for arrays of x and y.

Simple solution for python class using numpy.vectorize is following.
Inside init method: self.interp_vec = numpy.vectorize(self.interp_single)
object.interp_vec(x_array, y_array) returns array of interpolated values.

However, same trick doesn't work using jitclass and numba.vectorize. I don't know how to declare this method interp_vec in jitclass's spec list.

It would be ideal if I could decorate a jitclass method with numba.vectorize.

Thanks,
Parth

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+unsubscribe@continuum.io.
--
Siu Kwan Lam
Software Engineer
Continuum Analytics

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+unsubscribe@continuum.io.

To post to this group, send email to numba...@continuum.io.

Siu Kwan Lam

unread,
Sep 22, 2016, 12:41:09 PM9/22/16
to numba...@continuum.io
Numeric scalars will be broadcasted as if it is an array of the same number but without the memory cost.  The tuple is a problem.  Can it be unpacked?

On Thu, Sep 22, 2016 at 9:56 AM Parth Patel <parth...@gmail.com> wrote:
Yes, self.interp_single depends on several properties of the object. 

One way I could resolve this issue is the following. 
- write a separate method interp_single whose arguments are not just single float x and y, but the raw data (set of pre calculated x, y, f(x,y) ). 
- The problem with this approach is that vectorize decorator requires me to have all its arguments be scalars. 

Is it possible to tell numba.vectorize that first two arguments are scalars and last argument is a tuple. I want it to vectorize using only first two arguments, and the last argument will be fixed in size. 

Thanks,
Parth 

On Thu, Sep 22, 2016 at 9:30 AM, Siu Kwan Lam <s...@continuum.io> wrote:
Interesting, your are applying `numpy.vectorize` to a bound method so that `numpy.vectorize` does not see the `self` arg.  For now, I am afraid that is not easy to support in numba.

As a workaround, `interp_vec` can be a wrapper that calls the vectorized function.  Does `self.interp_single` depends on properties stored in `self`?  If so, it may need more restructuring.  

On Wed, Sep 21, 2016 at 11:37 AM Parth Patel <parth...@gmail.com> wrote:
This is a class for 2d interpolation. It has various properties that stores some samples x, y, f(x, y) to use for interpolation. It has one method (interp_single) that takes in a single x, y pair and returns interpolated f(x,y). I would like to vectorize this method so that I can compute interpolated data for arrays of x and y.

Simple solution for python class using numpy.vectorize is following.
Inside init method: self.interp_vec = numpy.vectorize(self.interp_single)
object.interp_vec(x_array, y_array) returns array of interpolated values.

However, same trick doesn't work using jitclass and numba.vectorize. I don't know how to declare this method interp_vec in jitclass's spec list.

It would be ideal if I could decorate a jitclass method with numba.vectorize.

Thanks,
Parth

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.
--
Siu Kwan Lam
Software Engineer
Continuum Analytics

--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.

To post to this group, send email to numba...@continuum.io.
--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.

To post to this group, send email to numba...@continuum.io.
Reply all
Reply to author
Forward
0 new messages