Merge branch 'master' into sort_complex-fix

This commit is contained in:
Zoltán Vörös 2023-01-23 21:53:12 +01:00 committed by GitHub
commit c758859640
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View file

@ -152,6 +152,12 @@ mp_obj_t create_arange(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
if(args[3].u_obj != mp_const_none) {
dtype = (uint8_t)mp_obj_get_int(args[3].u_obj);
}
// bail out, if the range cannot be constructed
if(step == MICROPY_FLOAT_CONST(0.0)) {
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("divide by zero"));
}
ndarray_obj_t *ndarray;
if((stop - start)/step < 0) {
ndarray = ndarray_new_linear_array(0, dtype);

View file

@ -1,4 +1,9 @@
Sun, 21 Jan 2023
version 6.0.6
raise proper exception in arange
Sun, 21 Jan 2023
version 6.0.7

View file

@ -8,4 +8,10 @@ dtypes = (np.uint8, np.int8, np.uint16, np.int16, np.float)
for dtype in dtypes:
print(np.arange(10, dtype=dtype))
print(np.arange(2, 10, dtype=dtype))
print(np.arange(2, 10, 3, dtype=dtype))
print(np.arange(2, 10, 3, dtype=dtype))
# test for ZeroDivisionError exception
try:
np.arange(0, 10, 0)
except ZeroDivisionError as e:
print('ZeroDivisionError: ', e)

View file

@ -13,3 +13,4 @@ array([2, 5, 8], dtype=int16)
array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], dtype=float64)
array([2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], dtype=float64)
array([2.0, 5.0, 8.0], dtype=float64)
ZeroDivisionError: divide by zero