'Method for compatibility with NumPy\'s ufuncs and dot
functions.'

def __numpy_ufunc__(self, func, method, pos, inputs, **kwargs):

    if any((((not isinstance(x, spmatrix)) and (np.asarray(x).dtype == object)) for x in inputs)):
        with_self = list(inputs)
        with_self[pos] = np.asarray(self, dtype=object)
        return getattr(func, method)(*with_self, **kwargs)
    out = kwargs.pop('out', None)
    if ((method != '__call__') or kwargs):
        return NotImplemented
    without_self = list(inputs)
    del without_self[pos]
    without_self = tuple(without_self)
    if (func is np.multiply):
        result = self.multiply(*without_self)
    elif (func is np.add):
        result = self.__add__(*without_self)
    elif (func is np.dot):
        if (pos == 0):
            result = self.__mul__(inputs[1])
        else:
            result = self.__rmul__(inputs[0])
    elif (func is np.subtract):
        if (pos == 0):
            result = self.__sub__(inputs[1])
        else:
            result = self.__rsub__(inputs[0])
    elif (func is np.divide):
        true_divide = (sys.version_info[0] >= 3)
        rdivide = (pos == 1)
        result = self._divide(true_divide=true_divide, rdivide=rdivide, *without_self)
    elif (func is np.true_divide):
        rdivide = (pos == 1)
        result = self._divide(true_divide=True, rdivide=rdivide, *without_self)
    elif (func is np.maximum):
        result = self.maximum(*without_self)
    elif (func is np.minimum):
        result = self.minimum(*without_self)
    elif (func is np.absolute):
        result = abs(self)
    elif (func in _ufuncs_with_fixed_point_at_zero):
        func_name = func.__name__
        if hasattr(self, func_name):
            result = getattr(self, func_name)()
        else:
            result = getattr(self.tocsr(), func_name)()
    else:
        return NotImplemented
    if (out is not None):
        if ((not isinstance(out, spmatrix)) and isinstance(result, spmatrix)):
            out[...] = result.todense()
        else:
            out[...] = result
        result = out
    return result
