Repository: numba/numba

Issue:
numpy max for arrays of several dimensions not implemented for parallelized code
Hi, 
First of all: GREAT JOB!

I am running into what I think is a bug. This can be reproduced with the following code:

**import numpy as np
import numba as nb

@nb.jit(nopython=True, parallel=True)
def find_maxima_3D_jit():
    package = np.zeros((10, 10, 10)).astype(np.int16)
    for index in range(0, 10):
        z_stack = package[index, :, :]
        B = np.max(z_stack)
    return

find_maxima_3D_jit()**

The program does not crash when any of the following is true:
1- the option parallel=True is removed
2- the function np.max is applied on an array of one dimension: B = np.max(z_stack[0])
3- when the variable z_stack is defined before the loop (for example as a numpy array of zeros)

Thank you for your support!





Discussion:
Thanks for the report, glad you like Numba :) 
The above does demonstrate a bug:
```python
import numpy as np
import numba as nb

@nb.jit(nopython=True, parallel=True)
def find_maxima_3D_jit():
    package = np.zeros((10, 10, 10)).astype(np.int16)
    for index in range(0, 10):
        z_stack = package[index, :, :]
    B = np.max(z_stack)
    return

find_maxima_3D_jit()
```

Gives:
```
  File "<path>/numba/numba/parfors/parfor.py", line 2336, in find_mask_from_size
    result = _find_mask(pass_states.typemap, pass_states.func_ir, arr_def)
  File "<path>/numba/numba/parfors/parfor.py", line 2683, in _find_mask
    raise AssertionError('unreachable')
AssertionError: Failed in nopython mode pipeline (step: convert to parfors)
unreachable
```
cc @DrTodd13 
It also seems that both full slice indexes are needed to trigger the problem.
I think this is due to me adding the assertion because the branch was never exercised. Now, we found a case that will trigger it.

Resolving patch:
diff --git a/numba/parfors/parfor.py b/numba/parfors/parfor.py
--- a/numba/parfors/parfor.py
+++ b/numba/parfors/parfor.py
@@ -2679,8 +2679,6 @@ def _find_mask(typemap, func_ir, arr_def):
                 mask_indices.append(None)
             # Handle integer index
             elif isinstance(index_typ, types.Integer):
-                # The follow is never tested
-                raise AssertionError('unreachable')
                 count_consts += 1
                 mask_indices.append(ind)
 


Test patch:
diff --git a/numba/tests/test_parfors.py b/numba/tests/test_parfors.py
--- a/numba/tests/test_parfors.py
+++ b/numba/tests/test_parfors.py
@@ -3568,6 +3568,22 @@ def foo(src, method, out):
             foo.py_func(src, method, out)
         )
 
+    @skip_parfors_unsupported
+    def test_issue6095_numpy_max(self):
+        @njit(parallel=True)
+        def find_maxima_3D_jit(args):
+            package = args
+            for index in range(0, 10):
+                z_stack = package[index, :, :]
+            return np.max(z_stack)
+
+        np.random.seed(0)
+        args = np.random.random((10, 10, 10))
+        self.assertPreciseEqual(
+            find_maxima_3D_jit(args),
+            find_maxima_3D_jit.py_func(args),
+        )
+
 
 @skip_parfors_unsupported
 class TestParforsDiagnostics(TestParforsBase):