def _replace_nan(a, val):
is_new = not isinstance(a, np.ndarray)<EOL>if is_new:<EOL><INDENT>a = np.array(a)<EOL><DEDENT>if not issubclass(a.dtype.type, np.inexact):<EOL><INDENT>return a, None<EOL><DEDENT>if not is_new:<EOL><INDENT>a = np.array(a, subok=True)<EOL><DEDENT>mask = np.isnan(a)<EOL>np.copyto(a, val, where=mask)<EOL>return a, mask<EOL>
If `a` is of inexact type, make a copy of `a`, replace NaNs with
the `val` value, and return the copy together with a boolean mask
marking the locations where NaNs were present. If `a` is not of
inexact type, do nothing and return `a` together with a mask of None.

Parameters
----------
a : array-like
    Input array.
val : float
    NaN values are set to val before doing the operation.

Returns
-------
y : ndarray
    If `a` is of inexact type, return a copy of `a` with the NaNs
    replaced by the fill value, otherwise return `a`.
mask: {bool, None}
    If `a` is of inexact type, return a boolean mask marking locations of
    NaNs, otherwise return None.