def lstsq(x, y, rcond=None, driver=None, name=None):
    '\n    Computes a solution to\n    the least squares problem of a system of linear equations.\n\n    Args:\n        x (Tensor): A tensor with shape ``(*, M, N)`` , the data type of the input Tensor ``x``\n            should be one of float32, float64.\n        y (Tensor): A tensor with shape ``(*, M, K)`` , the data type of the input Tensor ``y`` \n            should be one of float32, float64.\n        rcond(float, optional): The default value is None. A float pointing number used to determine \n            the effective rank of ``x``. If ``rcond`` is None, it will be set to max(M, N) times the \n            machine precision of x_dtype.\n        driver(str, optional): The default value is None. The name of LAPACK method to be used. For \n            CPU inputs the valid values are ‘gels’, ‘gelsy’, ‘gelsd, ‘gelss’. For CUDA input, the only \n            valid driver is ‘gels’. If ``driver`` is None, ‘gelsy’ is used for CPU inputs and ‘gels’ \n            for CUDA inputs.\n        name(str, optional): The default value is None. Normally there is no need for user to set \n            this property. For more information, please refer to :ref:`api_guide_Name`.\n\n    Returns:\n        Tuple: A tuple of 4 Tensors which is (``solution``, ``residuals``, ``rank``, ``singular_values``). \n        ``solution`` is a tensor with shape ``(*, N, K)``, meaning the least squares solution. ``residuals`` \n        is a tensor with shape ``(*, K)``, meaning the squared residuals of the solutions, which is computed \n        when M > N and every matrix in ``x`` is full-rank, otherwise return an empty tensor. ``rank`` is a tensor \n        with shape ``(*)``, meaning the ranks of the matrices in ``x``, which is computed when ``driver`` in \n        (‘gelsy’, ‘gelsd’, ‘gelss’), otherwise return an empty tensor. ``singular_values`` is a tensor with \n        shape ``(*, min(M, N))``, meaning singular values of the matrices in ``x``, which is computed when \n        ``driver`` in (‘gelsd’, ‘gelss’), otherwise return an empty tensor.\n\n    Examples:\n        .. code-block:: python\n\n            import paddle\n\n            paddle.set_device("cpu")\n            x = paddle.to_tensor([[1, 3], [3, 2], [5, 6.]])\n            y = paddle.to_tensor([[3, 4, 6], [5, 3, 4], [1, 2, 1.]])\n            results = paddle.linalg.lstsq(x, y, driver="gelsd")\n            print(results[0])\n            # [[ 0.78350395, -0.22165027, -0.62371236],\n            # [-0.11340097,  0.78866047,  1.14948535]]\n            print(results[1])\n            # [19.81443405, 10.43814468, 30.56185532])\n            print(results[2])\n            # 2\n            print(results[3])\n            # [9.03455734, 1.54167950]\n\n            x = paddle.to_tensor([[10, 2, 3], [3, 10, 5], [5, 6, 12.]])\n            y = paddle.to_tensor([[4, 2, 9], [2, 0, 3], [2, 5, 3.]])\n            results = paddle.linalg.lstsq(x, y, driver="gels")\n            print(results[0])\n            # [[ 0.39386186,  0.10230173,  0.93606132],\n            # [ 0.10741687, -0.29028133,  0.11892585],\n            # [-0.05115091,  0.51918161, -0.19948854]]\n            print(results[1])\n            # []\n    '
    device = paddle.get_device()
    if (device == 'cpu'):
        if (driver not in (None, 'gels', 'gelss', 'gelsd', 'gelsy')):
            raise ValueError("Only support valid driver is 'gels', 'gelss', 'gelsd', 'gelsy' or None for CPU inputs. But got {}".format(driver))
        driver = ('gelsy' if (driver is None) else driver)
    elif ('gpu' in device):
        if (driver not in (None, 'gels')):
            raise ValueError("Only support valid driver is 'gels' or None for CUDA inputs. But got {}".format(driver))
        driver = ('gels' if (driver is None) else driver)
    else:
        raise RuntimeError('Only support lstsq api for CPU or CUDA device.')
    if ((x.dtype == y.dtype) and (x.dtype in (paddle.float32, paddle.float64))):
        pass
    else:
        raise ValueError("Only support x and y have the same dtype such as 'float32' and 'float64'.")
    if (rcond is None):
        if (x.dtype == paddle.float32):
            rcond = (1e-07 * max(x.shape[(- 2)], x.shape[(- 1)]))
        elif (x.dtype == paddle.float64):
            rcond = (1e-15 * max(x.shape[(- 2)], x.shape[(- 1)]))
    if paddle.in_dynamic_mode():
        (solution, rank, singular_values) = _C_ops.lstsq(x, y, 'rcond', rcond, 'driver', driver)
        if (x.shape[(- 2)] > x.shape[(- 1)]):
            matmul_out = _varbase_creator(dtype=x.dtype)
            _C_ops.matmul(x, solution, matmul_out, 'trans_x', False, 'trans_y', False)
            minus_out = _C_ops.elementwise_sub(matmul_out, y)
            pow_out = _C_ops.pow(minus_out, 'factor', 2)
            residuals = _C_ops.reduce_sum(pow_out, 'dim', [(- 2)], 'keepdim', False, 'reduce_all', False)
        else:
            residuals = paddle.empty(shape=[0], dtype=x.dtype)
        if (driver == 'gels'):
            rank = paddle.empty(shape=[0], dtype=paddle.int32)
            singular_values = paddle.empty(shape=[0], dtype=x.dtype)
        elif (driver == 'gelsy'):
            singular_values = paddle.empty(shape=[0], dtype=x.dtype)
        return (solution, residuals, rank, singular_values)
    helper = LayerHelper('lstsq', **locals())
    check_variable_and_dtype(x, 'dtype', ['float32', 'float64', 'complex64', 'complex128'], 'lstsq')
    check_variable_and_dtype(y, 'dtype', ['float32', 'float64', 'complex64', 'complex128'], 'lstsq')
    solution = helper.create_variable_for_type_inference(dtype=x.dtype)
    residuals = helper.create_variable_for_type_inference(dtype=x.dtype)
    rank = helper.create_variable_for_type_inference(dtype=paddle.int32)
    singular_values = helper.create_variable_for_type_inference(dtype=x.dtype)
    helper.append_op(type='lstsq', inputs={'X': x, 'Y': y}, outputs={'Solution': solution, 'Rank': rank, 'SingularValues': singular_values}, attrs={'rcond': rcond, 'driver': driver})
    matmul_out = helper.create_variable_for_type_inference(dtype=x.dtype)
    minus_out = helper.create_variable_for_type_inference(dtype=x.dtype)
    pow_out = helper.create_variable_for_type_inference(dtype=x.dtype)
    helper.append_op(type='matmul_v2', inputs={'X': x, 'Y': solution}, outputs={'Out': matmul_out}, attrs={'trans_x': False, 'trans_y': False})
    helper.append_op(type='elementwise_sub', inputs={'X': matmul_out, 'Y': y}, outputs={'Out': minus_out})
    helper.append_op(type='pow', inputs={'X': minus_out}, outputs={'Out': pow_out}, attrs={'factor': 2})
    helper.append_op(type='reduce_sum', inputs={'X': pow_out}, outputs={'Out': residuals}, attrs={'dim': [(- 2)], 'keep_dim': False, 'reduce_all': False})
    if (driver == 'gels'):
        rank = paddle.static.data(name='rank', shape=[0])
        singular_values = paddle.static.data(name='singular_values', shape=[0])
    elif (driver == 'gelsy'):
        singular_values = paddle.static.data(name='singular_values', shape=[0])
    return (solution, residuals, rank, singular_values)
Computes a solution to
the least squares problem of a system of linear equations.

Args:
    x (Tensor): A tensor with shape ``(*, M, N)`` , the data type of the input Tensor ``x``
        should be one of float32, float64.
    y (Tensor): A tensor with shape ``(*, M, K)`` , the data type of the input Tensor ``y`` 
        should be one of float32, float64.
    rcond(float, optional): The default value is None. A float pointing number used to determine 
        the effective rank of ``x``. If ``rcond`` is None, it will be set to max(M, N) times the 
        machine precision of x_dtype.
    driver(str, optional): The default value is None. The name of LAPACK method to be used. For 
        CPU inputs the valid values are ‘gels’, ‘gelsy’, ‘gelsd, ‘gelss’. For CUDA input, the only 
        valid driver is ‘gels’. If ``driver`` is None, ‘gelsy’ is used for CPU inputs and ‘gels’ 
        for CUDA inputs.
    name(str, optional): The default value is None. Normally there is no need for user to set 
        this property. For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tuple: A tuple of 4 Tensors which is (``solution``, ``residuals``, ``rank``, ``singular_values``). 
    ``solution`` is a tensor with shape ``(*, N, K)``, meaning the least squares solution. ``residuals`` 
    is a tensor with shape ``(*, K)``, meaning the squared residuals of the solutions, which is computed 
    when M > N and every matrix in ``x`` is full-rank, otherwise return an empty tensor. ``rank`` is a tensor 
    with shape ``(*)``, meaning the ranks of the matrices in ``x``, which is computed when ``driver`` in 
    (‘gelsy’, ‘gelsd’, ‘gelss’), otherwise return an empty tensor. ``singular_values`` is a tensor with 
    shape ``(*, min(M, N))``, meaning singular values of the matrices in ``x``, which is computed when 
    ``driver`` in (‘gelsd’, ‘gelss’), otherwise return an empty tensor.

Examples:
    .. code-block:: python

        import paddle

        paddle.set_device("cpu")
        x = paddle.to_tensor([[1, 3], [3, 2], [5, 6.]])
        y = paddle.to_tensor([[3, 4, 6], [5, 3, 4], [1, 2, 1.]])
        results = paddle.linalg.lstsq(x, y, driver="gelsd")
        print(results[0])
        # [[ 0.78350395, -0.22165027, -0.62371236],
        # [-0.11340097,  0.78866047,  1.14948535]]
        print(results[1])
        # [19.81443405, 10.43814468, 30.56185532])
        print(results[2])
        # 2
        print(results[3])
        # [9.03455734, 1.54167950]

        x = paddle.to_tensor([[10, 2, 3], [3, 10, 5], [5, 6, 12.]])
        y = paddle.to_tensor([[4, 2, 9], [2, 0, 3], [2, 5, 3.]])
        results = paddle.linalg.lstsq(x, y, driver="gels")
        print(results[0])
        # [[ 0.39386186,  0.10230173,  0.93606132],
        # [ 0.10741687, -0.29028133,  0.11892585],
        # [-0.05115091,  0.51918161, -0.19948854]]
        print(results[1])
        # []
def lstsq(x, y, rcond=None, driver=None, name=None):
    '\n    Computes a solution to\n    the least squares problem of a system of linear equations.\n\n    Args:\n        x (Tensor): A tensor with shape ``(*, M, N)`` , the data type of the input Tensor ``x``\n            should be one of float32, float64.\n        y (Tensor): A tensor with shape ``(*, M, K)`` , the data type of the input Tensor ``y`` \n            should be one of float32, float64.\n        rcond(float, optional): The default value is None. A float pointing number used to determine \n            the effective rank of ``x``. If ``rcond`` is None, it will be set to max(M, N) times the \n            machine precision of x_dtype.\n        driver(str, optional): The default value is None. The name of LAPACK method to be used. For \n            CPU inputs the valid values are ‘gels’, ‘gelsy’, ‘gelsd, ‘gelss’. For CUDA input, the only \n            valid driver is ‘gels’. If ``driver`` is None, ‘gelsy’ is used for CPU inputs and ‘gels’ \n            for CUDA inputs.\n        name(str, optional): The default value is None. Normally there is no need for user to set \n            this property. For more information, please refer to :ref:`api_guide_Name`.\n\n    Returns:\n        Tuple: A tuple of 4 Tensors which is (``solution``, ``residuals``, ``rank``, ``singular_values``). \n        ``solution`` is a tensor with shape ``(*, N, K)``, meaning the least squares solution. ``residuals`` \n        is a tensor with shape ``(*, K)``, meaning the squared residuals of the solutions, which is computed \n        when M > N and every matrix in ``x`` is full-rank, otherwise return an empty tensor. ``rank`` is a tensor \n        with shape ``(*)``, meaning the ranks of the matrices in ``x``, which is computed when ``driver`` in \n        (‘gelsy’, ‘gelsd’, ‘gelss’), otherwise return an empty tensor. ``singular_values`` is a tensor with \n        shape ``(*, min(M, N))``, meaning singular values of the matrices in ``x``, which is computed when \n        ``driver`` in (‘gelsd’, ‘gelss’), otherwise return an empty tensor.\n\n    Examples:\n        .. code-block:: python\n\n            import paddle\n\n            paddle.set_device("cpu")\n            x = paddle.to_tensor([[1, 3], [3, 2], [5, 6.]])\n            y = paddle.to_tensor([[3, 4, 6], [5, 3, 4], [1, 2, 1.]])\n            results = paddle.linalg.lstsq(x, y, driver="gelsd")\n            print(results[0])\n            # [[ 0.78350395, -0.22165027, -0.62371236],\n            # [-0.11340097,  0.78866047,  1.14948535]]\n            print(results[1])\n            # [19.81443405, 10.43814468, 30.56185532])\n            print(results[2])\n            # 2\n            print(results[3])\n            # [9.03455734, 1.54167950]\n\n            x = paddle.to_tensor([[10, 2, 3], [3, 10, 5], [5, 6, 12.]])\n            y = paddle.to_tensor([[4, 2, 9], [2, 0, 3], [2, 5, 3.]])\n            results = paddle.linalg.lstsq(x, y, driver="gels")\n            print(results[0])\n            # [[ 0.39386186,  0.10230173,  0.93606132],\n            # [ 0.10741687, -0.29028133,  0.11892585],\n            # [-0.05115091,  0.51918161, -0.19948854]]\n            print(results[1])\n            # []\n    '
    device = paddle.get_device()
    if (device == 'cpu'):
        if (driver not in (None, 'gels', 'gelss', 'gelsd', 'gelsy')):
            raise ValueError("Only support valid driver is 'gels', 'gelss', 'gelsd', 'gelsy' or None for CPU inputs. But got {}".format(driver))
        driver = ('gelsy' if (driver is None) else driver)
    elif ('gpu' in device):
        if (driver not in (None, 'gels')):
            raise ValueError("Only support valid driver is 'gels' or None for CUDA inputs. But got {}".format(driver))
        driver = ('gels' if (driver is None) else driver)
    else:
        raise RuntimeError('Only support lstsq api for CPU or CUDA device.')
    if ((x.dtype == y.dtype) and (x.dtype in (paddle.float32, paddle.float64))):
        pass
    else:
        raise ValueError("Only support x and y have the same dtype such as 'float32' and 'float64'.")
    if (rcond is None):
        if (x.dtype == paddle.float32):
            rcond = (1e-07 * max(x.shape[(- 2)], x.shape[(- 1)]))
        elif (x.dtype == paddle.float64):
            rcond = (1e-15 * max(x.shape[(- 2)], x.shape[(- 1)]))
    if paddle.in_dynamic_mode():
        (solution, rank, singular_values) = _C_ops.lstsq(x, y, 'rcond', rcond, 'driver', driver)
        if (x.shape[(- 2)] > x.shape[(- 1)]):
            matmul_out = _varbase_creator(dtype=x.dtype)
            _C_ops.matmul(x, solution, matmul_out, 'trans_x', False, 'trans_y', False)
            minus_out = _C_ops.elementwise_sub(matmul_out, y)
            pow_out = _C_ops.pow(minus_out, 'factor', 2)
            residuals = _C_ops.reduce_sum(pow_out, 'dim', [(- 2)], 'keepdim', False, 'reduce_all', False)
        else:
            residuals = paddle.empty(shape=[0], dtype=x.dtype)
        if (driver == 'gels'):
            rank = paddle.empty(shape=[0], dtype=paddle.int32)
            singular_values = paddle.empty(shape=[0], dtype=x.dtype)
        elif (driver == 'gelsy'):
            singular_values = paddle.empty(shape=[0], dtype=x.dtype)
        return (solution, residuals, rank, singular_values)
    helper = LayerHelper('lstsq', **locals())
    check_variable_and_dtype(x, 'dtype', ['float32', 'float64', 'complex64', 'complex128'], 'lstsq')
    check_variable_and_dtype(y, 'dtype', ['float32', 'float64', 'complex64', 'complex128'], 'lstsq')
    solution = helper.create_variable_for_type_inference(dtype=x.dtype)
    residuals = helper.create_variable_for_type_inference(dtype=x.dtype)
    rank = helper.create_variable_for_type_inference(dtype=paddle.int32)
    singular_values = helper.create_variable_for_type_inference(dtype=x.dtype)
    helper.append_op(type='lstsq', inputs={'X': x, 'Y': y}, outputs={'Solution': solution, 'Rank': rank, 'SingularValues': singular_values}, attrs={'rcond': rcond, 'driver': driver})
    matmul_out = helper.create_variable_for_type_inference(dtype=x.dtype)
    minus_out = helper.create_variable_for_type_inference(dtype=x.dtype)
    pow_out = helper.create_variable_for_type_inference(dtype=x.dtype)
    helper.append_op(type='matmul_v2', inputs={'X': x, 'Y': solution}, outputs={'Out': matmul_out}, attrs={'trans_x': False, 'trans_y': False})
    helper.append_op(type='elementwise_sub', inputs={'X': matmul_out, 'Y': y}, outputs={'Out': minus_out})
    helper.append_op(type='pow', inputs={'X': minus_out}, outputs={'Out': pow_out}, attrs={'factor': 2})
    helper.append_op(type='reduce_sum', inputs={'X': pow_out}, outputs={'Out': residuals}, attrs={'dim': [(- 2)], 'keep_dim': False, 'reduce_all': False})
    if (driver == 'gels'):
        rank = paddle.static.data(name='rank', shape=[0])
        singular_values = paddle.static.data(name='singular_values', shape=[0])
    elif (driver == 'gelsy'):
        singular_values = paddle.static.data(name='singular_values', shape=[0])
    return (solution, residuals, rank, singular_values)