'Wrap numpy ufuncs, taking care of units.
Parameters
function : callable
ufunc to wrap.
method : str
Ufunc method: ``__call__``, ``at``, ``reduce``, etc.
inputs : tuple
Input arrays.
kwargs : keyword arguments
As passed on, with ``out`` containing possible quantity output.
Returns
result : `~astropy.units.Quantity`
Results of the ufunc, with the unit set properly.'

def __array_ufunc__(self, function, method, *inputs, **kwargs):

    (converters, unit) = converters_and_unit(function, method, *inputs)
    out = kwargs.get(u'out', None)
    if (out is not None):
        if (function.nout == 1):
            out = out[0]
        out_array = check_output(out, unit, inputs, function=function)
        kwargs[u'out'] = ((out_array,) if (function.nout == 1) else out_array)
    arrays = tuple(((converter(input_.value) if converter else getattr(input_, u'value', input_)) for (input_, converter) in zip(inputs, converters)))
    result = super(Quantity, self).__array_ufunc__(function, method, *arrays, **kwargs)
    if ((unit is None) or (result is None) or (result is NotImplemented)):
        return result
    return self._result_as_quantity(result, unit, out)
