def checked_add_with_arr(arr, b, arr_mask=None, b_mask=None):
<EOL>b2 = np.broadcast_to(b, arr.shape)<EOL>if b_mask is not None:<EOL><INDENT>b2_mask = np.broadcast_to(b_mask, arr.shape)<EOL><DEDENT>else:<EOL><INDENT>b2_mask = None<EOL><DEDENT>if arr_mask is not None and b2_mask is not None:<EOL><INDENT>not_nan = np.logical_not(arr_mask | b2_mask)<EOL><DEDENT>elif arr_mask is not None:<EOL><INDENT>not_nan = np.logical_not(arr_mask)<EOL><DEDENT>elif b_mask is not None:<EOL><INDENT>not_nan = np.logical_not(b2_mask)<EOL><DEDENT>else:<EOL><INDENT>not_nan = np.empty(arr.shape, dtype=bool)<EOL>not_nan.fill(True)<EOL><DEDENT>mask1 = b2 > <NUM_LIT:0><EOL>mask2 = b2 < <NUM_LIT:0><EOL>if not mask1.any():<EOL><INDENT>to_raise = ((np.iinfo(np.int64).min - b2 > arr) & not_nan).any()<EOL><DEDENT>elif not mask2.any():<EOL><INDENT>to_raise = ((np.iinfo(np.int64).max - b2 < arr) & not_nan).any()<EOL><DEDENT>else:<EOL><INDENT>to_raise = (((np.iinfo(np.int64).max -<EOL>b2[mask1] < arr[mask1]) & not_nan[mask1]).any() or<EOL>((np.iinfo(np.int64).min -<EOL>b2[mask2] > arr[mask2]) & not_nan[mask2]).any())<EOL><DEDENT>if to_raise:<EOL><INDENT>raise OverflowError("<STR_LIT>")<EOL><DEDENT>return arr + b<EOL>
Perform array addition that checks for underflow and overflow.

Performs the addition of an int64 array and an int64 integer (or array)
but checks that they do not result in overflow first. For elements that
are indicated to be NaN, whether or not there is overflow for that element
is automatically ignored.

Parameters
----------
arr : array addend.
b : array or scalar addend.
arr_mask : boolean array or None
    array indicating which elements to exclude from checking
b_mask : boolean array or boolean or None
    array or scalar indicating which element(s) to exclude from checking

Returns
-------
sum : An array for elements x + b for each element x in arr if b is
      a scalar or an array for elements x + y for each element pair
      (x, y) in (arr, b).

Raises
------
OverflowError if any x + y exceeds the maximum or minimum int64 value.