vector icon indicating copy to clipboard operation
vector copied to clipboard

Awkward Records with vector behavior and non-vector coordinates don't work with numba

Open Saransh-cpp opened this issue 1 year ago • 0 comments

Vector Version

v1.1.1

Python Version

3.11

OS / Environment

MacOS

Describe the bug

In [1]: import vector; import numba as nb

In [2]: vec = vector.zip({"pt": [1, 2 ,3], "phi": [1, 2, 3], "eta": [1, 2, 3], "
   ...: mass": [1, 2, 3], "charge": [1, 2, 3]})

In [3]: @nb.njit
   ...: def return_charge(vec):
   ...:     return vec.charge

In [4]: return_charge(vec)  # works fine
Out[4]: <Array [1, 2, 3] type='3 * int64'>

In [5]: @nb.njit
   ...: def return_charge(vec):
   ...:     return vec[0].charge 

In [6]: return_charge(vec)  # errors out
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
<ipython-input-8-74cedf343dae> in <cell line: 0>()
----> 1 return_charge(vec)  # errors out

/opt/homebrew/lib/python3.11/site-packages/numba/core/dispatcher.py in _compile_for_args(self, *args, **kws)
    466                 e.patch_message(msg)
    467 
--> 468             error_rewrite(e, 'typing')
    469         except errors.UnsupportedError as e:
    470             # Something unsupported is present in the user code, add help info

/opt/homebrew/lib/python3.11/site-packages/numba/core/dispatcher.py in error_rewrite(e, issue_type)
    407                 raise e
    408             else:
--> 409                 raise e.with_traceback(None)
    410 
    411         argtypes = []

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'charge' of type MomentumObject4DType(AzimuthalObjectRhoPhi(int64 x 2), LongitudinalObjectEta(int64 x 1), TemporalObjectTau(int64 x 1))

File "<ipython-input-7-37c9d458f596>", line 3:
def return_charge(vec):
    return vec[0].charge
    ^

During: typing of get attribute at <ipython-input-7-37c9d458f596> (3)

File "<ipython-input-7-37c9d458f596>", line 3:
def return_charge(vec):
    return vec[0].charge
    ^

In [7]: @nb.njit
   ...: def return_charge(vec):
   ...:     return vec.charge[0] 

In [8]: return_charge(vec)  # works fine
Out[8]: 1

Any additional but relevant log output

No response

Saransh-cpp avatar Jan 22 '24 20:01 Saransh-cpp