parent
							
								
									095d7fb877
								
							
						
					
					
						commit
						ab17c49eba
					
				| @ -0,0 +1,46 @@ | ||||
| # Copyright 2021 Huawei Technologies Co., Ltd | ||||
| # | ||||
| # 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 numpy as np | ||||
| import pytest | ||||
| 
 | ||||
| import mindspore.nn as nn | ||||
| from mindspore import Tensor | ||||
| from mindspore import context | ||||
| from mindspore.ops.operations import _grad_ops as G | ||||
| 
 | ||||
| context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | ||||
| 
 | ||||
| 
 | ||||
| class NetAcoshGrad(nn.Cell): | ||||
|     def __init__(self): | ||||
|         super(NetAcoshGrad, self).__init__() | ||||
|         self.acoshGrad = G.AcoshGrad() | ||||
| 
 | ||||
|     def construct(self, x, dy): | ||||
|         return self.acoshGrad(x, dy) | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.level0 | ||||
| @pytest.mark.platform_x86_cpu | ||||
| @pytest.mark.env_onecard | ||||
| def test_acosh_grad(): | ||||
|     x = np.array([5, 4, 3]).astype('float32') | ||||
|     dy = np.array([1, 0, -1]).astype('float32') | ||||
|     acosh_grad = NetAcoshGrad() | ||||
|     output = acosh_grad(Tensor(x), Tensor(dy)) | ||||
|     print(output) | ||||
|     expect = dy / np.sqrt(x * x - 1) | ||||
|     assert np.allclose(output.asnumpy(), expect) | ||||
| @ -0,0 +1,46 @@ | ||||
| # Copyright 2021 Huawei Technologies Co., Ltd | ||||
| # | ||||
| # 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 numpy as np | ||||
| import pytest | ||||
| 
 | ||||
| import mindspore.nn as nn | ||||
| from mindspore import Tensor | ||||
| from mindspore import context | ||||
| from mindspore.ops import operations as P | ||||
| 
 | ||||
| context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | ||||
| 
 | ||||
| 
 | ||||
| class NetAcosh(nn.Cell): | ||||
|     def __init__(self): | ||||
|         super(NetAcosh, self).__init__() | ||||
|         self.acosh = P.Acosh() | ||||
| 
 | ||||
|     def construct(self, x): | ||||
|         return self.acosh(x) | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.level0 | ||||
| @pytest.mark.platform_x86_cpu | ||||
| @pytest.mark.env_onecard | ||||
| def test_acosh(): | ||||
|     np_array = np.array([1, 2, 3, 4, 5]).astype('float32') | ||||
|     input_x = Tensor(np_array) | ||||
|     net = NetAcosh() | ||||
|     output = net(input_x) | ||||
|     print(output) | ||||
|     expect = np.arccosh(np_array) | ||||
|     assert np.allclose(output.asnumpy(), expect) | ||||
| @ -0,0 +1,46 @@ | ||||
| # Copyright 2021 Huawei Technologies Co., Ltd | ||||
| # | ||||
| # 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 numpy as np | ||||
| import pytest | ||||
| 
 | ||||
| import mindspore.nn as nn | ||||
| from mindspore import Tensor | ||||
| from mindspore import context | ||||
| from mindspore.ops.operations import _grad_ops as G | ||||
| 
 | ||||
| context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | ||||
| 
 | ||||
| 
 | ||||
| class NetAsinhGrad(nn.Cell): | ||||
|     def __init__(self): | ||||
|         super(NetAsinhGrad, self).__init__() | ||||
|         self.asinhGrad = G.AsinhGrad() | ||||
| 
 | ||||
|     def construct(self, x, dy): | ||||
|         return self.asinhGrad(x, dy) | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.level0 | ||||
| @pytest.mark.platform_x86_cpu | ||||
| @pytest.mark.env_onecard | ||||
| def test_asinh_grad(): | ||||
|     x = np.array([-0.5, 0, 0.5]).astype('float32') | ||||
|     dy = np.array([1, 0, -1]).astype('float32') | ||||
|     asinh_grad = NetAsinhGrad() | ||||
|     output = asinh_grad(Tensor(x), Tensor(dy)) | ||||
|     print(output) | ||||
|     expect = dy / np.sqrt(1 + x * x) | ||||
|     assert np.allclose(output.asnumpy(), expect) | ||||
| @ -0,0 +1,46 @@ | ||||
| # Copyright 2021 Huawei Technologies Co., Ltd | ||||
| # | ||||
| # 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 numpy as np | ||||
| import pytest | ||||
| 
 | ||||
| import mindspore.nn as nn | ||||
| from mindspore import Tensor | ||||
| from mindspore import context | ||||
| from mindspore.ops import operations as P | ||||
| 
 | ||||
| context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | ||||
| 
 | ||||
| 
 | ||||
| class NetAsinh(nn.Cell): | ||||
|     def __init__(self): | ||||
|         super(NetAsinh, self).__init__() | ||||
|         self.asinh = P.Asinh() | ||||
| 
 | ||||
|     def construct(self, x): | ||||
|         return self.asinh(x) | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.level0 | ||||
| @pytest.mark.platform_x86_cpu | ||||
| @pytest.mark.env_onecard | ||||
| def test_asinh(): | ||||
|     np_array = np.array([-1, -0.5, 0, 0.5, 1]).astype('float32') | ||||
|     input_x = Tensor(np_array) | ||||
|     net = NetAsinh() | ||||
|     output = net(input_x) | ||||
|     print(output) | ||||
|     expect = np.arcsinh(np_array) | ||||
|     assert np.allclose(output.asnumpy(), expect) | ||||
| @ -0,0 +1,46 @@ | ||||
| # Copyright 2021 Huawei Technologies Co., Ltd | ||||
| # | ||||
| # 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 numpy as np | ||||
| import pytest | ||||
| 
 | ||||
| import mindspore.nn as nn | ||||
| from mindspore import Tensor | ||||
| from mindspore import context | ||||
| from mindspore.ops import operations as P | ||||
| 
 | ||||
| context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | ||||
| 
 | ||||
| 
 | ||||
| class NetAtan2(nn.Cell): | ||||
|     def __init__(self): | ||||
|         super(NetAtan2, self).__init__() | ||||
|         self.atan2 = P.Atan2() | ||||
| 
 | ||||
|     def construct(self, x, y): | ||||
|         return self.atan2(x, y) | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.level0 | ||||
| @pytest.mark.platform_x86_cpu | ||||
| @pytest.mark.env_onecard | ||||
| def test_atan2(): | ||||
|     np_array = np.array([1, 2, 3, 4, 5]).astype('float32') | ||||
|     input_x = Tensor(np_array) | ||||
|     net = NetAtan2() | ||||
|     output = net(input_x, input_x) | ||||
|     print(output) | ||||
|     expect = np.arctan2(np_array, np_array) | ||||
|     assert np.allclose(output.asnumpy(), expect) | ||||
| @ -0,0 +1,46 @@ | ||||
| # Copyright 2021 Huawei Technologies Co., Ltd | ||||
| # | ||||
| # 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 numpy as np | ||||
| import pytest | ||||
| 
 | ||||
| import mindspore.nn as nn | ||||
| from mindspore import Tensor | ||||
| from mindspore import context | ||||
| from mindspore.ops import operations as P | ||||
| 
 | ||||
| context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | ||||
| 
 | ||||
| 
 | ||||
| class NetAtanh(nn.Cell): | ||||
|     def __init__(self): | ||||
|         super(NetAtanh, self).__init__() | ||||
|         self.atanh = P.Atanh() | ||||
| 
 | ||||
|     def construct(self, x): | ||||
|         return self.atanh(x) | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.level0 | ||||
| @pytest.mark.platform_x86_cpu | ||||
| @pytest.mark.env_onecard | ||||
| def test_atanh(): | ||||
|     np_array = np.array([-0.5, 0, 0.5]).astype('float32') | ||||
|     input_x = Tensor(np_array) | ||||
|     net = NetAtanh() | ||||
|     output = net(input_x) | ||||
|     print(output) | ||||
|     expect = np.arctanh(np_array) | ||||
|     assert np.allclose(output.asnumpy(), expect) | ||||
| @ -0,0 +1,46 @@ | ||||
| # Copyright 2021 Huawei Technologies Co., Ltd | ||||
| # | ||||
| # 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 numpy as np | ||||
| import pytest | ||||
| 
 | ||||
| import mindspore.nn as nn | ||||
| from mindspore import Tensor | ||||
| from mindspore import context | ||||
| from mindspore.ops import operations as P | ||||
| 
 | ||||
| context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | ||||
| 
 | ||||
| 
 | ||||
| class NetCosh(nn.Cell): | ||||
|     def __init__(self): | ||||
|         super(NetCosh, self).__init__() | ||||
|         self.cosh = P.Cosh() | ||||
| 
 | ||||
|     def construct(self, x): | ||||
|         return self.cosh(x) | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.level0 | ||||
| @pytest.mark.platform_x86_cpu | ||||
| @pytest.mark.env_onecard | ||||
| def test_cosh(): | ||||
|     np_array = np.array([-1, -0.5, 0, 0.5, 1]).astype('float32') | ||||
|     input_x = Tensor(np_array) | ||||
|     net = NetCosh() | ||||
|     output = net(input_x) | ||||
|     print(output) | ||||
|     expect = np.cosh(np_array) | ||||
|     assert np.allclose(output.asnumpy(), expect) | ||||
| @ -0,0 +1,46 @@ | ||||
| # Copyright 2021 Huawei Technologies Co., Ltd | ||||
| # | ||||
| # 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 numpy as np | ||||
| import pytest | ||||
| 
 | ||||
| import mindspore.nn as nn | ||||
| from mindspore import Tensor | ||||
| from mindspore import context | ||||
| from mindspore.ops import operations as P | ||||
| 
 | ||||
| context.set_context(mode=context.GRAPH_MODE, device_target="CPU") | ||||
| 
 | ||||
| 
 | ||||
| class NetSinh(nn.Cell): | ||||
|     def __init__(self): | ||||
|         super(NetSinh, self).__init__() | ||||
|         self.sinh = P.Sinh() | ||||
| 
 | ||||
|     def construct(self, x): | ||||
|         return self.sinh(x) | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.level0 | ||||
| @pytest.mark.platform_x86_cpu | ||||
| @pytest.mark.env_onecard | ||||
| def test_sinh(): | ||||
|     np_array = np.array([-1, -0.5, 0, 0.5, 1]).astype('float32') | ||||
|     input_x = Tensor(np_array) | ||||
|     net = NetSinh() | ||||
|     output = net(input_x) | ||||
|     print(output) | ||||
|     expect = np.sinh(np_array) | ||||
|     assert np.allclose(output.asnumpy(), expect) | ||||
					Loading…
					
					
				
		Reference in new issue