Nicholaswogan / NumbaMinpack

Python wrapper of Minpack (root finding) which can be called from within numba functions.
MIT License
32 stars 2 forks source link

Slicing args #6

Closed laubapires closed 1 year ago

laubapires commented 1 year ago

I am using NumbaMinpack to minimize 1 equation, however args has a dimension of 24, but it is a flat numpy array, and in the minimized function I break down each parameter from the 24-dimension array. but I receive the following error. Therefore, is it not possible to slice the args argument afterwards?

    ``
     File "C:\Anaconda3\lib\site-packages\numba\core\decorators.py", line 311, in wrapper
        res.compile()
      File "C:\Anaconda3\lib\site-packages\numba\core\compiler_lock.py", line 35, in _acquire_compile_lock
        return func(*args, **kwargs)
      File "C:\Anaconda3\lib\site-packages\numba\core\ccallback.py", line 68, in compile
        cres = self._compile_uncached()
      File "C:\Anaconda3\lib\site-packages\numba\core\ccallback.py", line 82, in _compile_uncached
        return self._compiler.compile(sig.args, sig.return_type)
      File "C:\Anaconda3\lib\site-packages\numba\core\dispatcher.py", line 129, in compile
        raise retval
      File "C:\Anaconda3\lib\site-packages\numba\core\dispatcher.py", line 139, in _compile_cached
        retval = self._compile_core(args, return_type)
      File "C:\Anaconda3\lib\site-packages\numba\core\dispatcher.py", line 152, in _compile_core
        cres = compiler.compile_extra(self.targetdescr.typing_context,
      File "C:\Anaconda3\lib\site-packages\numba\core\compiler.py", line 742, in compile_extra
        return pipeline.compile_extra(func)
      File "C:\Anaconda3\lib\site-packages\numba\core\compiler.py", line 460, in compile_extra
        return self._compile_bytecode()
      File "C:\Anaconda3\lib\site-packages\numba\core\compiler.py", line 528, in _compile_bytecode
        return self._compile_core()
      File "C:\Anaconda3\lib\site-packages\numba\core\compiler.py", line 507, in _compile_core
        raise e
      File "C:\Anaconda3\lib\site-packages\numba\core\compiler.py", line 494, in _compile_core
        pm.run(self.state)
      File "C:\Anaconda3\lib\site-packages\numba\core\compiler_machinery.py", line 368, in run
        raise patched_exception
      File "C:\Anaconda3\lib\site-packages\numba\core\compiler_machinery.py", line 356, in run
        self._runPass(idx, pass_inst, state)
      File "C:\Anaconda3\lib\site-packages\numba\core\compiler_lock.py", line 35, in _acquire_compile_lock
        return func(*args, **kwargs)
      File "C:\Anaconda3\lib\site-packages\numba\core\compiler_machinery.py", line 311, in _runPass
        mutated |= check(pss.run_pass, internal_state)
      File "C:\Anaconda3\lib\site-packages\numba\core\compiler_machinery.py", line 273, in check
        mangled = func(compiler_state)
      File "C:\Anaconda3\lib\site-packages\numba\core\typed_passes.py", line 110, in run_pass
        typemap, return_type, calltypes, errs = type_inference_stage(
      File "C:\Anaconda3\lib\site-packages\numba\core\typed_passes.py", line 88, in type_inference_stage
        errs = infer.propagate(raise_errors=raise_errors)
      File "C:\Anaconda3\lib\site-packages\numba\core\typeinfer.py", line 1086, in propagate
        raise errors[0]
    numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
    No implementation of function Function(<built-in function getitem>) found for signature:

     >>> getitem(float64*, slice<a:b>)

    There are 22 candidate implementations:
          - Of which 22 did not match due to:
          Overload of function 'getitem': File: <numerous>: Line N/A.
            With argument(s): '(float64*, slice<a:b>)':
           No match.

    During: typing of intrinsic-call at c:\Documents\file.py (96)
    During: typing of static-get-item at c:\Documents\file.py (96)

    File "file.py", line 96:
    def denfit(rho_guess, fvec, args):
        <source elided>

        x     = args[0:ncomp]
        ^

``

laubapires commented 1 year ago

Also include operations such as 'reshape'

def denfit(rho_guess, fvec, args):
    rho_guess = rho_guess[0]

    ncomp = args[-1]
    ncomp = int(ncomp)

    x     = args[0:ncomp]
    m     = args[ncomp:ncomp*2]
    s     = args[ncomp*2:ncomp*3]
    e     = args[ncomp*3:ncomp*4]
    t     = args[ncomp*4]
    p     = args[ncomp*4 + 1]

    k_ij  = args[ncomp*4 + 2:-1]
    k_ij  = k_ij.reshape(ncomp, ncomp)
Nicholaswogan commented 1 year ago

Use the numba.carray command illustrated in the README to convert the input array to a numpy array. Then the slicing will work

Nicholaswogan commented 1 year ago

Actually take a look at the README for this other similar package

https://github.com/Nicholaswogan/numbalsoda