Recursive helper for mdot

def _mdot_r(a, b):
    """Recursive helper for mdot"""
    if type(a) == tuple:
        if len(a) > 1:
            a = mdot(*a)
        else:
            a = a[0]
    if type(b) == tuple:
        if len(b) > 1:
            b = mdot(*b)
        else:
            b = b[0]
    return np.dot(a, b)