-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fix cholesky doc, test=develop #25250
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8e02ef7
add cholesky, test=develop
ForFishes 3c1e7c3
add inverse, dot, test=develop
ForFishes 840b0cb
fix inverse doc, test=develop
ForFishes 44d2e63
fix the dynamic mode, test=develop
ForFishes f50a742
fix the doc, test=develop
ForFishes 3976928
fix doc ,test=develop
ForFishes f9428a6
Merge branch 'develop' into fix_doc
ForFishes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1064,78 +1064,58 @@ def logsumexp(x, dim=None, keepdim=False, out=None, name=None): | |
return layers.log(sum_out, name) | ||
|
||
|
||
def inverse(input, out=None, name=None): | ||
def inverse(x, name=None): | ||
""" | ||
:alias_main: paddle.inverse | ||
:alias: paddle.inverse,paddle.tensor.inverse,paddle.tensor.math.inverse | ||
:alias: paddle.inverse, paddle.tensor.inverse, paddle.tensor.math.inverse | ||
|
||
Takes the inverse of the square matrix. A square matrix is a matrix with | ||
the same number of rows and columns. The input can be a square matrix | ||
(2-D Tensor) or batches of square matrices. | ||
|
||
Args: | ||
input (Variable): The input Variable which holds a Tensor. The last two | ||
x (Variable): The input Variable which holds a Tensor. The last two | ||
dimensions should be equal. When the number of dimensions is | ||
greater than 2, it is treated as batches of square matrix. The data | ||
type can be float32 and float64. | ||
out (Variable, optional): Optional output which can be any created | ||
Variable that meets the requirements to store the result of operation. | ||
If out is None, a new Varibale will be create to store the result. | ||
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: | ||
Variable: A Tensor holds the inverse of input. The shape and data type | ||
is the same as input. | ||
Variable: A Tensor holds the inverse of x. The shape and data type | ||
is the same as x. | ||
|
||
Examples: | ||
.. code-block:: python | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 示例代码只保留动态图版本即可。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok,fixed it |
||
|
||
import numpy as np | ||
import paddle | ||
import paddle.fluid as fluid | ||
|
||
mat_np = np.array([[2, 0], [0, 2]]).astype("float32") | ||
|
||
# example for static graph | ||
input = fluid.data("input", shape=[2, 2], dtype="float32") | ||
out = paddle.inverse(input) | ||
|
||
place = fluid.CPUPlace() | ||
exe = fluid.Executor(place) | ||
results = exe.run(feed={"input": mat_np }, | ||
fetch_list=[out.name]) | ||
print(results[0]) # [[0.5, 0], [0, 0.5]] | ||
|
||
# example for dynamic graph | ||
with fluid.dygraph.guard(): | ||
mat = fluid.dygraph.to_variable(mat_np) | ||
inv = paddle.inverse(mat) | ||
print(inv) # [[0.5, 0], [0, 0.5]] | ||
paddle.enable_imperative() | ||
mat = paddle.imperative.to_variable(mat_np) | ||
inv = paddle.inverse(mat) | ||
print(inv) # [[0.5, 0], [0, 0.5]] | ||
""" | ||
if in_dygraph_mode(): | ||
return core.ops.inverse(input) | ||
return core.ops.inverse(x) | ||
|
||
def _check_input(input): | ||
check_variable_and_dtype(input, 'input', | ||
def _check_input(x): | ||
check_variable_and_dtype(x, 'x', | ||
['float32', 'float64'], 'inverse') | ||
if len(input.shape) < 2: | ||
if len(x.shape) < 2: | ||
raise ValueError( | ||
"The input of inverse is expected to be a Tensor whose number " | ||
"of dimensions is no less than 2. But reviced: %d, " | ||
"input's shape: %s." % (len(input.shape), input.shape)) | ||
|
||
if out is not None: | ||
check_variable_and_dtype(out, 'out', input.dtype, 'inverse') | ||
"x's shape: %s." % (len(x.shape), x.shape)) | ||
|
||
_check_input(input) | ||
_check_input(x) | ||
|
||
helper = LayerHelper('inverse', **locals()) | ||
if out is None: | ||
out = helper.create_variable_for_type_inference(dtype=input.dtype) | ||
out = helper.create_variable_for_type_inference(dtype=x.dtype) | ||
helper.append_op( | ||
type='inverse', inputs={'Input': [input] }, outputs={'Output': [out]}) | ||
type='inverse', inputs={'Input': [x] }, outputs={'Output': [out]}) | ||
return out | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The input Variable which holds a Tensor. --> The input tensor.
现在概念上是不是Variable holds tensor,还不明确。。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, fixed it.