Skip to content

numba@jit compilation fail for function "_error_fun_triangulation" #149

@hejieshi

Description

@hejieshi

Error message:


NumbaWarning:
Compilation is falling back to object mode WITHOUT looplifting enabled because Function "_error_fun_triangulation" failed type inference due to: No implementation of function Function(<function diff at 0x0000023562457EB0>) found for signature:

 >>> diff(array(float64, 3d, C), n=int64, axis=Literal[int](0))

There are 2 candidate implementations:
  - Of which 2 did not match due to:
  Overload in function 'np_diff_impl': File: numba\np\arraymath.py: Line 3531.
    With argument(s): '(array(float64, 3d, C), n=int64, axis=int64)':
   Rejected as the implementation raised a specific error:
     TypingError: got an unexpected keyword argument 'axis'
  raised from C:\Users\DELL\anaconda3\envs\DEEPLABCUT\lib\site-packages\numba\core\typing\templates.py:783

During: resolving callee type: Function(<function diff at 0x0000023562457EB0>)
During: typing of call at C:\Users\DELL\anaconda3\envs\DEEPLABCUT\lib\site-packages\aniposelib\cameras.py (1288)


File "C:\Users\DELL\anaconda3\envs\DEEPLABCUT\lib\site-packages\aniposelib\cameras.py", line 1288:
    def _error_fun_triangulation(self, params, p2ds,
        <source elided>
        # temporal constraint
        errors_smooth = np.diff(p3ds, n=n_deriv_smooth, axis=0).ravel() * scale_smooth
        ^

  @jit(forceobj=True, parallel=True)

 >>> diff(array(float64, 3d, C), int64, Literal[int](0))

Error code:
errors_smooth = np.diff(p3ds, n=n_deriv_smooth, axis=0).ravel() * scale_smooth
After checking, I found that numba's function np_diff_impl does not support the passed axis parameter, because np_diff_impl only supports operations on the last dimension. In order to accommodate np_diff_impl, I changed the code to:
errors_smooth = np.diff(p3ds.transpose(2, 1, 0), n=n_deriv_smooth).transpose(2, 1, 0).ravel() * scale_smooth
However, more errors have been reported. How should I use numba acceleration correctly?
My package version:
aniposelib 0.7.0
numba 0.61.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions