test_trigonometric.py 3.54 KB
Newer Older
root's avatar
root committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import unittest

from cupy import testing


class TestTrigonometric(unittest.TestCase):

    @testing.for_all_dtypes(no_complex=True)
    @testing.numpy_cupy_allclose(atol=1e-5)
    def check_unary(self, name, xp, dtype):
        a = testing.shaped_arange((2, 3), xp, dtype)
        return getattr(xp, name)(a)

    @testing.for_all_dtypes(no_complex=True)
    @testing.numpy_cupy_allclose(atol=1e-5)
    def check_binary(self, name, xp, dtype):
        a = testing.shaped_arange((2, 3), xp, dtype)
        b = testing.shaped_reverse_arange((2, 3), xp, dtype)
        return getattr(xp, name)(a, b)

    @testing.for_dtypes(['e', 'f', 'd'])
    @testing.numpy_cupy_allclose(atol=1e-5)
    def check_unary_unit(self, name, xp, dtype):
        a = xp.array([0.2, 0.4, 0.6, 0.8], dtype=dtype)
        return getattr(xp, name)(a)

    def test_sin(self):
        self.check_unary('sin')

    def test_cos(self):
        self.check_unary('cos')

    def test_tan(self):
        self.check_unary('tan')

    def test_arcsin(self):
        self.check_unary_unit('arcsin')

    def test_arccos(self):
        self.check_unary_unit('arccos')

    def test_arctan(self):
        self.check_unary('arctan')

    def test_arctan2(self):
        self.check_binary('arctan2')

    def test_hypot(self):
        self.check_binary('hypot')

    def test_deg2rad(self):
        self.check_unary('deg2rad')

    def test_rad2deg(self):
        self.check_unary('rad2deg')


@testing.with_requires('numpy>=1.21.0')
class TestUnwrap(unittest.TestCase):

    @testing.for_all_dtypes(no_complex=True)
    @testing.numpy_cupy_allclose()
    def test_unwrap_1dim(self, xp, dtype):
        a = testing.shaped_random((5,), xp, dtype)
        return xp.unwrap(a)

    @testing.for_all_dtypes(no_complex=True)
    @testing.numpy_cupy_allclose()
    def test_unwrap_1dim_with_discont(self, xp, dtype):
        a = testing.shaped_random((5,), xp, dtype)
        return xp.unwrap(a, discont=1.0)

    @testing.for_all_dtypes(no_complex=True)
    @testing.numpy_cupy_allclose()
    def test_unwrap_1dim_with_period(self, xp, dtype):
        a = testing.shaped_random((5,), xp, dtype)
        return xp.unwrap(a, period=1.2)

    @testing.for_all_dtypes(no_complex=True)
    @testing.numpy_cupy_allclose()
    def test_unwrap_1dim_with_discont_and_period(self, xp, dtype):
        a = testing.shaped_random((5,), xp, dtype)
        return xp.unwrap(a, discont=1.0, period=1.2)

    @testing.for_all_dtypes(no_complex=True)
    @testing.numpy_cupy_allclose()
    def test_unwrap_2dim_without_axis(self, xp, dtype):
        a = testing.shaped_random((4, 5), xp, dtype)
        return xp.unwrap(a)

    @testing.for_all_dtypes(no_complex=True)
    @testing.numpy_cupy_allclose()
    def test_unwrap_2dim_with_axis(self, xp, dtype):
        a = testing.shaped_random((4, 5), xp, dtype)
        return xp.unwrap(a, axis=1)

    @testing.for_all_dtypes(no_complex=True)
    @testing.numpy_cupy_allclose()
    def test_unwrap_2dim_with_discont(self, xp, dtype):
        a = testing.shaped_random((4, 5), xp, dtype)
        return xp.unwrap(a, discont=5.0, axis=1)

    @testing.for_all_dtypes(no_complex=True)
    @testing.numpy_cupy_allclose()
    def test_unwrap_2dim_with_period(self, xp, dtype):
        a = testing.shaped_random((4, 5), xp, dtype)
        return xp.unwrap(a, axis=1, period=4.5)

    @testing.for_all_dtypes(no_complex=True)
    @testing.numpy_cupy_allclose()
    def test_unwrap_2dim_with_discont_and_period(self, xp, dtype):
        a = testing.shaped_random((4, 5), xp, dtype)
        return xp.unwrap(a, discont=5.0, axis=1, period=4.5)