<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def unitcheck(u, nonperiodic=None):
 """Check whether `u` is inside the unit cube. Given a masked array `nonperiodic`, also allows periodic boundaries conditions to exceed the unit cube."""


    if nonperiodic is None:
        # No periodic boundary conditions provided.
        return np.all(u > 0.) and np.all(u < 1.)
    else:
        # Alternating periodic and non-periodic boundary conditions.
        return (np.all(u[nonperiodic] > 0.) and
                np.all(u[nonperiodic] < 1.) and
                np.all(u[~nonperiodic] > -0.5) and
                np.all(u[~nonperiodic] < 1.5))