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

'Bad token in signature' with @guvectorize #6690

Open
2 tasks done
yohplala opened this issue Feb 5, 2021 · 13 comments · May be fixed by #6694
Open
2 tasks done

'Bad token in signature' with @guvectorize #6690

yohplala opened this issue Feb 5, 2021 · 13 comments · May be fixed by #6694
Labels
bug - failure to compile Bugs: failed to compile valid code

Comments

@yohplala
Copy link

yohplala commented Feb 5, 2021

  • I have tried using the version 0.51.2 of Numba
  • I have included a self contained code sample to reproduce the problem

Hi,
I am sorry, I am aware it is more a 'usage' question or perhaps a 'feature request'.
I have posted the question on SO here, but it does not meet much success.

Please, can we setup a constant number of columns for a result array in function signature?
I have tried this way, but get here below error message.

import numpy as np
from numba import guvectorize

@guvectorize('void(float64[:], float64, uint32[:,2])', '(m),()->(m,2)', nopython=True)
def array_copy(data, delta, result):
    for i, val in np.ndenumerate(data):
        # Open i.
        i, = i
        result[i,:] = [i, int(val)+delta]

data = np.arange(3, dtype='float64')
res = np.zeros((data.shape[0], 2), dtype='uint32')
array_copy(data, 3, res)
Traceback (most recent call last):

  File "<ipython-input-17-63f8983bbf61>", line 5, in <module>
    def array_copy(data, delta, result):

  File "/home/pierre/anaconda3/lib/python3.8/site-packages/numba/np/ufunc/decorators.py", line 177, in wrap
    guvec = GUVectorize(func, signature, **kws)

  File "/home/pierre/anaconda3/lib/python3.8/site-packages/numba/np/ufunc/decorators.py", line 49, in __new__
    return imp(func, signature, identity=identity, cache=cache,

  File "/home/pierre/anaconda3/lib/python3.8/site-packages/numba/np/ufunc/ufuncbuilder.py", line 298, in __init__
    self.sin, self.sout = parse_signature(signature)

  File "/home/pierre/anaconda3/lib/python3.8/site-packages/numba/np/ufunc/sigparse.py", line 49, in parse_signature
    outputs = list(parse(outs))

  File "/home/pierre/anaconda3/lib/python3.8/site-packages/numba/np/ufunc/sigparse.py", line 35, in parse
    raise ValueError('bad token in signature "%s"' % tok[1])

ValueError: bad token in signature "2"
@esc esc added the needtriage label Feb 5, 2021
@esc
Copy link
Member

esc commented Feb 5, 2021

@yohplala thank you for asking about this. As far as I can tell this feature is not yet supported by Numba.

@sklam
Copy link
Member

sklam commented Feb 8, 2021

@esc
Copy link
Member

esc commented Feb 8, 2021

Also, important to note that: uint32[:,2] isn't valid code in this case.

@yohplala
Copy link
Author

yohplala commented Feb 8, 2021

Also, important to note that: uint32[:,2] isn't valid code in this case.

Thanks for the tip. What would be valid code then?

@esc
Copy link
Member

esc commented Feb 9, 2021

@yohplala I am not sure, but it may be that uint32[:,:] is the only legitmate answer, but maybe the following helps:

In [1]: from numba import uint32

In [2]: uint32[:,2]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-2-c343ab4fd798> in <module>
----> 1 uint32[:,2]

~/git/numba/numba/core/types/abstract.py in __getitem__(self, args)
    183         """
    184         from numba.core.types import Array
--> 185         ndim, layout = self._determine_array_spec(args)
    186         return Array(dtype=self, ndim=ndim, layout=layout)
    187

~/git/numba/numba/core/types/abstract.py in _determine_array_spec(self, args)
    208         else:
    209             # Raise a KeyError to not be handled by collection constructors (e.g. list).
--> 210             raise KeyError(f"Can only index numba types with slices with no start or stop, got {args}.")
    211
    212         return ndim, layout

KeyError: 'Can only index numba types with slices with no start or stop, got (slice(None, None, None), 2).'

In [3]: uint32[:,:]
Out[3]: array(uint32, 2d, A)

@esc
Copy link
Member

esc commented Feb 9, 2021

@yohplala so, to follow up, from what I know, the shape of the array is not part of the type specification, only the dimensionality.

@yohplala
Copy link
Author

yohplala commented Feb 9, 2021

thanks a lot for your help @esc !

@github-actions
Copy link

This issue is marked as stale as it has had no activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with any updates and confirm that this issue still needs to be addressed.

@github-actions github-actions bot added the stale Marker label for stale issues. label May 28, 2021
@yohplala
Copy link
Author

I confirm the issue is still open. A PR appears to have been proposed, but not merged yet.

@esc
Copy link
Member

esc commented May 28, 2021

@yohplala thank you for following up on this, do you happen to know the ID of the PR being proposed?

@yohplala
Copy link
Author

Hi @esc , it is just mentionned above : #6694

@esc esc added bug - failure to compile Bugs: failed to compile valid code and removed needtriage stale Marker label for stale issues. labels May 28, 2021
@esc
Copy link
Member

esc commented May 28, 2021

@yohplala thank you kindly, I had missed that. I have relabelled this issue accordingly now and thank you very much for bringing this to our attention!

@yohplala
Copy link
Author

@yohplala thank you kindly, I had missed that. I have relabelled this issue accordingly now and thank you very much for bringing this to our attention!

No worries, thank you for helping @esc !
I only responded to the bot pinging us :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - failure to compile Bugs: failed to compile valid code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants