Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new API/OP: paddle.linalg.triangular_solve #36714

Merged
merged 6 commits into from
Oct 29, 2021

Conversation

zhwesky2010
Copy link
Contributor

@zhwesky2010 zhwesky2010 commented Oct 25, 2021

PR types

New features

PR changes

APIs

Describe

Computes the solution of a system of equations with a triangular coefficient matrix x and
multiple right-hand sides y .

Input x and y is 2D matrices or batches of 2D matrices. If the inputs are batches, the outputs
is also batches.

Args:

x (Tensor): The input triangular coefficient matrix. Its shape should be [*, M, M], where * is zero or
    more batch dimensions. Its data type should be float32 or float64.
y (Tensor): Multiple right-hand sides of system of equations. Its shape should be [*, M, K], where * is 
    zero or more batch dimensions. Its data type should be float32 or float64.
upper (bool, optional): Whether to solve the upper-triangular system of equations (default) or the lower-triangular 
    system of equations. Default: True.
transpose (bool, optional): whether x should be transposed before calculation. Default: False.
unitriangular (bool, optional): whether x is unit triangular. If True, the diagonal elements of x are assumed 
    to be 1 and not referenced from x . Default: False.
name(str, optional): Name for the operation (optional, default is None).

Returns:

Tensor: The solution of the system of equations. Its data type should be the same as that of `x`.

Examples:

# A · X = b
#
# a square system of linear equations:
# x1 +   x2  +   x3 = 0
#      2*x2  +   x3 = -9
#               -x3 = 5

import paddle

x = paddle.to_tensor([[1, 1, 1], 
                      [0, 2, 1],
                      [0, 0,-1]], dtype="float64")
y = paddle.to_tensor([[0], [-9], [5]], dtype="float64")
out = paddle.linalg.triangular_solve(x, y, upper=True, transpose=False, unitriangular=False)

print(out)
# [7, -2, -5]

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@zhwesky2010 zhwesky2010 changed the title add new API/OP: paddle.linalg.triangular_solve add new API/OP: paddle.linalg.triangular_solve Oct 25, 2021
Avin0323
Avin0323 previously approved these changes Oct 28, 2021
Copy link
Contributor

@Avin0323 Avin0323 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for PR-CI-OP-benchmark.

Comment on lines 54 to 55
int M = b->dims()[b_dim_size - 2];
int N = b->dims()[b_dim_size - 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tensor->dims()[] wll return int64_t, use static_cast ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thx

Comment on lines 183 to 184
int M = b->dims()[b_dim_size - 2];
int N = b->dims()[b_dim_size - 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tensor->dims()[] wll return int64_t, use static_cast ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thx

Copy link
Contributor

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@TCChenlong TCChenlong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

# -x3 = 5

import paddle
import numpy as np
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numpy没用到。

Copy link
Contributor Author

@zhwesky2010 zhwesky2010 Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下个PR顺带删掉~ thx

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG API

Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@raindrops2sea raindrops2sea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhwesky2010 zhwesky2010 merged commit 92d6a04 into PaddlePaddle:develop Oct 29, 2021
ghost pushed a commit to piotrekobi/Paddle that referenced this pull request Nov 3, 2021
* add new API: paddle.linalg.triangular_solve

* add new API/OP: paddle.linalg.triangular_solve

* add new API/OP: paddle.linalg.triangular_solve

* fix comment
DDDivano added a commit to PaddlePaddle/PaddleTest that referenced this pull request Nov 24, 2021
ignore test_triangular_solve.py because PaddlePaddle/Paddle#36714 havn't cherry-pick yet.
zhwesky2010 added a commit to zhwesky2010/Paddle that referenced this pull request Nov 25, 2021
* add new API: paddle.linalg.triangular_solve

* add new API/OP: paddle.linalg.triangular_solve

* add new API/OP: paddle.linalg.triangular_solve

* fix comment
lanxianghit pushed a commit that referenced this pull request Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants