Hello!
I'm trying to use numba for faster numpy array's looping. My code:
@nb.njit
def _complicated(heat_list_, raw_array_, x_min_, x_step_, y_min_, y_step_):
array = np.array(raw_array_)
z_val = array[2, :]
x_val = array[0, :]
y_val = array[1, :]
for i in range(len(z_val)):
heat_list_[np.round_((y_val[i] - y_min_) / y_step_)][np.round_((x_val[i] - x_min_) / x_step_)] = z_val[i]
return heat_list_
heat_list_, raw_list_ are numpy.ndarrays
x_min_, x_step_, y_min_, y_step_ are floats
When I run this function, the following error appears:
---------------------------------------------------------------------------
TypingError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_28508/1500348391.py in <module>
----> 1 _complicated(data1.heat_list, data1.raw_array, data1.x_min, data1.x_step, data1.y_min, data1.y_step)
~\miniconda3\envs\pyquac\lib\site-packages\numba\core\dispatcher.py in _compile_for_args(self, *args, **kws)
418 e.patch_message(msg)
419
--> 420 error_rewrite(e, 'typing')
421 except errors.UnsupportedError as e:
422 # Something unsupported is present in the user code, add help info
~\miniconda3\envs\pyquac\lib\site-packages\numba\core\dispatcher.py in error_rewrite(e, issue_type)
359 raise e
360 else:
--> 361 raise e.with_traceback(None)
362
363 argtypes = []
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function array>) found for signature:
>>> array(array(float64, 2d, C))
There are 2 candidate implementations:
- Of which 2 did not match due to:
Overload in function 'array': File: numba\core\typing\npydecl.py: Line 489.
With argument(s): '(array(float64, 2d, C))':
Rejected as the implementation raised a specific error:
TypingError: array(float64, 2d, C) not allowed in a homogeneous sequence
raised from C:\Users\nokol\miniconda3\envs\pyquac\lib\site-packages\numba\core\typing\npydecl.py:457
During: resolving callee type: Function(<built-in function array>)
During: typing of call at C:\Users\nokol\AppData\Local\Temp/ipykernel_28508/1750607535.py (14)
File "..\..\..\..\AppData\Local\Temp\ipykernel_28508\1750607535.py", line 14:
<source missing, REPL/exec in use?>
I don't understand why it happens, since the function itself is simple, and the data types in it are supported by numba.
I would be glad if someone could help me figure it out.
PS
numba version == 0.53.1
python version == 3.9.7
ver 2 I've changed my code a little bit, but I still get an error:
@nb.generated_jit(nopython=True)
def _complicated(heat_list_, raw_array_x, raw_array_y, raw_array_z, x_min_, x_step_, y_min_, y_step_):
for i in range(len(raw_array_y)):
heat_list_[np.round_((raw_array_y[i] - y_min_) / y_step_),
np.round_((raw_array_x[i] - x_min_) / x_step_)] = raw_array_z[i]
return heat_list_
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_17704/3567269810.py in <module>
----> 1 data1.njit_result()
~\AppData\Local\Temp/ipykernel_17704/1768352675.py in njit_result(self)
336
337 if len(self.x_raw) >= 2:
--> 338 return _complicated(self.heat_list, x_val, y_val, z_val,
339 self.x_min, self.x_step, self.y_min, self.y_step, len_of_z)
340 else:
~\miniconda3\envs\pyquac\lib\site-packages\numba\core\dispatcher.py in _compile_for_args(self, *args, **kws)
499 e.patch_message('\n'.join((str(e).rstrip(), help_msg)))
500 # ignore the FULL_TRACEBACKS config, this needs reporting!
--> 501 raise e
502 finally:
503 self._types_active_call = []
~\miniconda3\envs\pyquac\lib\site-packages\numba\core\dispatcher.py in _compile_for_args(self, *args, **kws)
432 return_val = None
433 try:
--> 434 return_val = self.compile(tuple(argtypes))
435 except errors.ForceLiteralArg as e:
436 # Received request for compiler re-entry with the list of arguments
~\miniconda3\envs\pyquac\lib\site-packages\numba\core\dispatcher.py in compile(self, sig)
977 with ev.trigger_event("numba:compile", data=ev_details):
978 try:
--> 979 cres = self._compiler.compile(args, return_type)
980 except errors.ForceLiteralArg as e:
981 def folded(args, kws):
~\miniconda3\envs\pyquac\lib\site-packages\numba\core\dispatcher.py in compile(self, args, return_type)
139
140 def compile(self, args, return_type):
--> 141 status, retval = self._compile_cached(args, return_type)
142 if status:
143 return retval
~\miniconda3\envs\pyquac\lib\site-packages\numba\core\dispatcher.py in _compile_cached(self, args, return_type)
153
154 try:
--> 155 retval = self._compile_core(args, return_type)
156 except errors.TypingError as e:
157 self._failed_cache[key] = e
~\miniconda3\envs\pyquac\lib\site-packages\numba\core\dispatcher.py in _compile_core(self, args, return_type)
165 flags = self._customize_flags(flags)
166
--> 167 impl = self._get_implementation(args, {})
168 cres = compiler.compile_extra(self.targetdescr.typing_context,
169 self.targetdescr.target_context,
~\miniconda3\envs\pyquac\lib\site-packages\numba\core\dispatcher.py in _get_implementation(self, args, kws)
201
202 def _get_implementation(self, args, kws):
--> 203 impl = self.py_func(*args, **kws)
204 # Check the generating function and implementation signatures are
205 # compatible, otherwise compiling would fail later.
~\AppData\Local\Temp/ipykernel_17704/1768352675.py in _complicated(heat_list_, raw_array_x, raw_array_y, raw_array_z, x_min_, x_step_, y_min_, y_step_, len_of_z)
12 def _complicated(heat_list_, raw_array_x, raw_array_y, raw_array_z, x_min_, x_step_, y_min_, y_step_,
13 len_of_z):
---> 14 for i in range(len(raw_array_y)):
15 heat_list_[np.round_((raw_array_y[i] - y_min_) / y_step_),
16 np.round_((raw_array_x[i] - x_min_) / x_step_)] = raw_array_z[i]
TypeError: object of type 'Array' has no len()