Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cupy.vectorize currently does not support "excluded" option #8166

Open
matthewjmuscat opened this issue Feb 5, 2024 · 0 comments · May be fixed by #8287
Open

cupy.vectorize currently does not support "excluded" option #8166

matthewjmuscat opened this issue Feb 5, 2024 · 0 comments · May be fixed by #8287
Labels

Comments

@matthewjmuscat
Copy link

Description

At the moment I am trying to use cp.vectorize to improve the performance over np.vectorize. However the function that I am trying to vectorize accepts an array like argument that I want to be consistent for each function call, so I dont want to vectorize over this argument, here is a minimal working example:

import numpy as np
from bisect import bisect_left

def myfunc(a,b):
    return bisect_left(a, b)

vfunc = np.vectorize(myfunc, excluded = ['a'])
vfunc(a= np.array([1,2,3,4]),b=np.array([1.5,2.5]))

In other words, I would like the following code to work as expected:

import cupy as cp
from bisect import bisect_left

def myfunc(a,b):
    return bisect_left(a, b)

vfunc = cp.vectorize(myfunc, excluded = ['a'])
vfunc(a= cp.array([1,2,3,4]),b=cp.array([1.5,2.5]))

Note that help(cp.vectorize) produces the following output:

Help on class vectorize in module cupy._functional.vectorize:
class vectorize(builtins.object)
| vectorize(pyfunc, otypes=None, doc=None, excluded=None, cache=False, signature=None)
|
| Generalized function class.
|
| .. seealso:: :class:numpy.vectorize
|
| Methods defined here:
|
| call(self, *args)
| Call self as a function.
|
| init(self, pyfunc, otypes=None, doc=None, excluded=None, cache=False, signature=None)
| Args:
| pyfunc (callable): The target python function.
| otypes (str or list of dtypes, optional): The output data type.
| doc (str or None): The docstring for the function.
| excluded: Currently not supported.
| cache: Currently Ignored.
| signature: Currently not supported.

I would like to request that the excluded option be implemented.

In the meantime, I tried to workaround this by vectorizing a function with arbitrary number of arguments *args, but cp.vectorize does not support this either:

import cupy as cp
from bisect import bisect_left

def myfunc(b, *a):
    return bisect_left(a, b)
testlist = [4,5,6,7,8]
vfunc = cp.vectorize(myfunc)
vfunc(cp.array([1,2,3,4]),*testlist)

Output:

NotImplementedError: *args is not supported currently.

Any other potential workarounds would be greatly appreciated!

Additional Information

No response

@matthewjmuscat matthewjmuscat added the cat:feature New features/APIs label Feb 5, 2024
@RyanI70I RyanI70I linked a pull request Apr 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants