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

[Divide by 0 Error] add lu check #49974

Merged
merged 2 commits into from
Feb 1, 2023

Conversation

gouzil
Copy link
Member

@gouzil gouzil commented Jan 21, 2023

@luotao1 luotao1 added the contributor External developers label Jan 21, 2023
@luotao1 luotao1 mentioned this pull request Jan 21, 2023
Comment on lines 1 to 37
# 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()
Copy link
Contributor

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即可

Comment on lines 2161 to 2163
if x.size == 0:
raise ValueError("input size should not be 0")

Copy link
Contributor

Choose a reason for hiding this comment

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

这个判断放到C++端吧。放到python端会影响到API性能

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

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

LGTM

@luotao1 luotao1 merged commit f71796b into PaddlePaddle:develop Feb 1, 2023
pangengzheng pushed a commit to pangengzheng/Paddle that referenced this pull request Feb 2, 2023
* [Divide by 0 Error] add lu check

* [Divide by 0 Error] lu check migrate to c++
@gouzil gouzil deleted the fix-lu-divide-by-0 branch March 24, 2023 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants