-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d7dadd
commit 9862490
Showing
2 changed files
with
46 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import paddle | ||
import pytest | ||
|
||
from ppsci import loss | ||
|
||
__all__ = [] | ||
|
||
|
||
def test_non_tensor_return_type(): | ||
"""Test for biharmonic equation.""" | ||
|
||
def loss_func_return_tensor(input_dict, label_dict, weight_dict): | ||
return (0.5 * (input_dict["x"] - label_dict["x"]) ** 2).sum() | ||
|
||
def loss_func_reuturn_builtin_float(input_dict, label_dict, weight_dict): | ||
return (0.5 * (input_dict["x"] - label_dict["x"]) ** 2).sum().item() | ||
|
||
wrapped_loss1 = loss.FunctionalLoss(loss_func_return_tensor) | ||
wrapped_loss2 = loss.FunctionalLoss(loss_func_reuturn_builtin_float) | ||
|
||
input_dict = {"x": paddle.randn([10, 1])} | ||
label_dict = {"x": paddle.zeros([10, 1])} | ||
|
||
wrapped_loss1(input_dict, label_dict) | ||
with pytest.raises(AssertionError): | ||
wrapped_loss2(input_dict, label_dict) | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main() |