Repository: nv-legate/cunumeric

Issue:
NumPy and cuNumeric behave differently in some cases found in test_append.py and test_array_creation.py
NumPy and cuNumeric behave differently for the following cases.

case-1
`np.arange(-10)`  
In Numpy, returns [] successfully. In cuNumeric, raise ValueError

case-2
`np.arange(2, -10)` 
In Numpy, returns [] successfully. In cuNumeric, raise ValueError

case-3
`np.arrange(1, -10, -2.5)` 
In Numpy, returns array([ 1. , -1.5, -4. , -6.5, -9. ]. In cuNumeric, returns array([ 1, -1, -3, -5, -7])

case-4
`a = [[1, 2, 3], [4, 5, 6]]
b = [[10, 20, 30]]
print (np.append(a, b, axis=1))`
In Numpy, raise ValueError. In cuNumeric, raise AssertionError

case-5
`num.full((2, 3), [10, 20, 30])`
In NumPy, returns [[10 20 30], [10 20 30]]. In cuNumeric, raise AssertionError. From API guide, I found cuNumeric.full only supports fill_value which is scalar. But I think ValueError may be better. 

case-6
`x = num.array([[1, 2, 3], [4, 5, 6]])
num.full_like(x, [10, 20, 30])
`
In NumPy, returns [[10 20 30], [10 20 30]]. In cuNumeric, raise AssertionError. From API guide, I found cuNumeric.full_like only supports fill_value which is scalar. But I think ValueError may be better. 


Discussion:

Resolving patch:
diff --git a/cunumeric/module.py b/cunumeric/module.py
--- a/cunumeric/module.py
+++ b/cunumeric/module.py
@@ -663,12 +663,12 @@ def arange(
         step = 1
 
     if dtype is None:
-        dtype = np.array([stop]).dtype
+        dtype = np.find_common_type([], [type(start), type(stop), type(step)])
     else:
         dtype = np.dtype(dtype)
 
     N = math.ceil((stop - start) / step)
-    result = ndarray((N,), dtype)
+    result = ndarray((_builtin_max(0, N),), dtype)
     result._thunk.arange(start, stop, step)
     return result
 


Test patch:
diff --git a/tests/integration/test_array_creation.py b/tests/integration/test_array_creation.py
--- a/tests/integration/test_array_creation.py
+++ b/tests/integration/test_array_creation.py
@@ -191,11 +191,12 @@ def test_full_like_bad_filled_value():
     (0,),
     (10,),
     (3.5,),
-    pytest.param((-10), marks=pytest.mark.xfail),
+    (3.0, 8, None),
+    (-10,),
     (2, 10),
-    pytest.param((2, -10), marks=pytest.mark.xfail),
+    (2, -10),
     (-2.5, 10.0),
-    pytest.param((1, -10, -2.5), marks=pytest.mark.xfail),
+    (1, -10, -2.5),
     (1.0, -10.0, -2.5),
     (-10, 10, 10),
     (-10, 10, -100),
diff --git a/tests/integration/test_diag_indices.py b/tests/integration/test_diag_indices.py
--- a/tests/integration/test_diag_indices.py
+++ b/tests/integration/test_diag_indices.py
@@ -20,9 +20,10 @@
 import cunumeric as num
 
 
-def test_diag_indices_default_ndim():
-    a_np = np.diag_indices(10)
-    a_num = num.diag_indices(10)
+@pytest.mark.parametrize("n", [10, -10.5, -1])
+def test_diag_indices_default_ndim(n):
+    a_np = np.diag_indices(n)
+    a_num = num.diag_indices(n)
     assert np.array_equal(a_np, a_num)
 
 
@@ -42,11 +43,6 @@ def test_diag_indices(n, ndim):
 
 
 class TestDiagIndicesErrors:
-    @pytest.mark.parametrize("n", [-10.5, -1])
-    def test_negative_n(self, n):
-        with pytest.raises(ValueError):
-            num.diag_indices(n)
-
     @pytest.mark.xfail
     @pytest.mark.parametrize("n", [-10.5, -1])
     def test_negative_n_DIVERGENCE(self, n):