Repository: numba/numba

Issue:
Broadcasting error with sliced array and ParallelAccelerator
Running this:
```python
import numpy as np
from numba import jit

@jit(nopython=True, parallel=True)
def test(x1, x2):
    x1 = x1.reshape(x1.size, 1)
    x2 = x2.reshape(1, x2.size)
    return x1 >= x2[:, :-1]

x1 = np.random.rand(5)
x2 = np.random.rand(3)
test(x1, x2)
```
I get
```python
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-15-a9fd360d9c07> in <module>
     10 x1 = np.random.rand(5)
     11 x2 = np.random.rand(3)
---> 12 test(x1, x2)

AssertionError: Sizes of x1.1, $0.24 do not match on <ipython-input-15-a9fd360d9c07> (8)
```
using version 0.44.1. When setting parallel = False I get no error.


Discussion:
Thanks for the report. The immediate problem of the `AssertionError` is fixed on the current master branch by virtue of recent work updating slice analysis, however the above now produces:
```python
  File "<path>/numba/types/functions.py", line 116, in get_impl_key
    return self._impl_keys[sig.args]
numba.errors.LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
(int64, int64)

File "issue4215.py", line 8:
def test(x1, x2):
    <source elided>
    x2 = x2.reshape(1, x2.size)
    return x1 >= x2[:, :-1]
    ^

[1] During: lowering "replacement_slice.13 = call $0.21(zero.11, explicit_neg.12, func=$0.21, args=(Var(zero.11, issue4215.py (8)), Var(explicit_neg.12, issue4215.py (8))), kws=(), vararg=None)" at issue4215.py (8)
```
CC @DrTodd13 
Fixed the issue you were seeing @stuartarchibald and now I see the error reported by @bdch1234.  Looking into that now.
@stuartarchibald @bdch1234 

See Numba documentation section 1.9.1 point 5.

"Multi-dimensional arrays are also supported for the above operations when operands have matching dimension and size. **The full semantics of Numpy broadcast between arrays with mixed dimensionality or size is not supported**, nor is the reduction across a selected dimension."

The error you are seeing is basically ParallelAccelerator saying we don't currently support broadcast.

Resolving patch:
diff --git a/numba/array_analysis.py b/numba/array_analysis.py
--- a/numba/array_analysis.py
+++ b/numba/array_analysis.py
@@ -1283,8 +1283,9 @@ def slice_size(self, index, dsize, equiv_set, scope, stmts):
             # Create a deepcopy of slice calltype so that when we change it below
             # the original isn't changed.  Make the types of the parts of the slice
             # intp.
-            self.calltypes[replacement_slice] = copy.deepcopy(self.calltypes[index_def])
-            self.calltypes[replacement_slice].args = (types.intp, types.intp)
+            new_arg_typs = (types.intp, types.intp)
+            rs_calltype = self.typemap[index_def.func.name].get_call_type(self.context, new_arg_typs, {})
+            self.calltypes[replacement_slice] = rs_calltype
             stmts.append(ir.Assign(value=replacement_slice, target=replacement_slice_var, loc=loc))
             # The type of the replacement slice is the same type as the original.
             self.typemap[replacement_slice_var.name] = self.typemap[index.name]


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
@@ -2619,6 +2619,17 @@ def test_impl():
 
         self.check(test_impl, check_scheduling=False)
 
+    @skip_unsupported
+    def test_parfor_slice21(self):
+        def test_impl(x1, x2):
+            x1 = x1.reshape(x1.size, 1)
+            x2 = x2.reshape(x2.size, 1)
+            return x1 >= x2[:-1, :]
+
+        x1 = np.random.rand(5)
+        x2 = np.random.rand(6)
+        self.check(test_impl, x1, x2)
+
 class TestParforsOptions(TestParforsBase):
 
     def check(self, pyfunc, *args, **kwargs):