-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Divide by 0 Error] add lu check #49974
Conversation
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
import numpy as np | ||
|
||
import paddle | ||
|
||
|
||
class TestSparseEmbeddingAPIError(unittest.TestCase): | ||
def test_errors(self): | ||
with paddle.fluid.dygraph.guard(): | ||
# The size of input in sparse_embedding should not be 0. | ||
def test_0_size(): | ||
array = np.array([], dtype=np.float32) | ||
x = paddle.to_tensor( | ||
np.reshape(array, [0, 0, 0]), dtype='float32' | ||
) | ||
paddle.linalg.lu(x, get_infos=True) | ||
|
||
self.assertRaises(ValueError, test_0_size) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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.
这个单测不需要新建文件。放到python/paddle/fluid/tests/unittests/test_lu_op.py即可
python/paddle/tensor/linalg.py
Outdated
if x.size == 0: | ||
raise ValueError("input size should not be 0") | ||
|
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.
这个判断放到C++端吧。放到python端会影响到API性能
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.
LGTM
* [Divide by 0 Error] add lu check * [Divide by 0 Error] lu check migrate to c++
PR types
Others
PR changes
Others
Describe