ZTWHHH commited on
Commit
1f76e58
·
verified ·
1 Parent(s): 8ac3b62

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/discard_block_engine.inl +184 -0
  2. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/linear_congruential_engine.inl +155 -0
  3. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/linear_congruential_engine_discard.h +109 -0
  4. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/linear_feedback_shift_engine.inl +151 -0
  5. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/linear_feedback_shift_engine_wordmask.h +53 -0
  6. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/mod.h +101 -0
  7. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/normal_distribution.inl +189 -0
  8. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/normal_distribution_base.h +160 -0
  9. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/random_core_access.h +63 -0
  10. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/subtract_with_carry_engine.inl +201 -0
  11. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/uniform_int_distribution.inl +198 -0
  12. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/uniform_real_distribution.inl +198 -0
  13. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/xor_combine_engine.inl +183 -0
  14. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/xor_combine_engine_max.h +216 -0
  15. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/discard_block_engine.h +239 -0
  16. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/linear_congruential_engine.h +288 -0
  17. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/linear_feedback_shift_engine.h +216 -0
  18. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/normal_distribution.h +257 -0
  19. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/subtract_with_carry_engine.h +246 -0
  20. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/uniform_int_distribution.h +260 -0
  21. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/uniform_real_distribution.h +258 -0
  22. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/xor_combine_engine.h +253 -0
  23. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/type_traits/is_execution_policy.h +67 -0
  24. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/type_traits/is_trivially_relocatable.h +313 -0
  25. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/type_traits/void_t.h +58 -0
  26. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_dlpack/LICENSE +201 -0
  27. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_dlpack/dlpack.h +332 -0
  28. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/catrig.h +732 -0
  29. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/catrigf.h +446 -0
  30. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/cexp.h +175 -0
  31. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/cexpf.h +155 -0
  32. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/clog.h +205 -0
  33. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/clogf.h +194 -0
  34. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/complex.h +676 -0
  35. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/complex_inl.h +167 -0
  36. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/csinh.h +194 -0
  37. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/csinhf.h +135 -0
  38. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/ctanh.h +193 -0
  39. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/ctanhf.h +118 -0
  40. vllm/lib/python3.10/site-packages/cupy/_indexing/__init__.py +2 -0
  41. vllm/lib/python3.10/site-packages/cupy/_indexing/__pycache__/__init__.cpython-310.pyc +0 -0
  42. vllm/lib/python3.10/site-packages/cupy/_indexing/__pycache__/generate.cpython-310.pyc +0 -0
  43. vllm/lib/python3.10/site-packages/cupy/_indexing/__pycache__/indexing.cpython-310.pyc +0 -0
  44. vllm/lib/python3.10/site-packages/cupy/_indexing/__pycache__/insert.cpython-310.pyc +0 -0
  45. vllm/lib/python3.10/site-packages/cupy/_indexing/__pycache__/iterate.cpython-310.pyc +0 -0
  46. vllm/lib/python3.10/site-packages/cupy/_indexing/generate.py +588 -0
  47. vllm/lib/python3.10/site-packages/cupy/_indexing/indexing.py +223 -0
  48. vllm/lib/python3.10/site-packages/cupy/_indexing/insert.py +260 -0
  49. vllm/lib/python3.10/site-packages/cupy/_indexing/iterate.py +155 -0
  50. vllm/lib/python3.10/site-packages/cupy/array_api/__init__.py +388 -0
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/discard_block_engine.inl ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/random/discard_block_engine.h>
30
+
31
+ THRUST_NAMESPACE_BEGIN
32
+
33
+ namespace random
34
+ {
35
+
36
+ template <typename Engine, size_t p, size_t r>
37
+ _CCCL_HOST_DEVICE discard_block_engine<Engine, p, r>::discard_block_engine()
38
+ : m_e()
39
+ , m_n(0)
40
+ {}
41
+
42
+ template <typename Engine, size_t p, size_t r>
43
+ _CCCL_HOST_DEVICE discard_block_engine<Engine, p, r>::discard_block_engine(result_type s)
44
+ : m_e(s)
45
+ , m_n(0)
46
+ {}
47
+
48
+ template <typename Engine, size_t p, size_t r>
49
+ _CCCL_HOST_DEVICE discard_block_engine<Engine, p, r>::discard_block_engine(const base_type& urng)
50
+ : m_e(urng)
51
+ , m_n(0)
52
+ {}
53
+
54
+ template <typename Engine, size_t p, size_t r>
55
+ _CCCL_HOST_DEVICE void discard_block_engine<Engine, p, r>::seed()
56
+ {
57
+ m_e.seed();
58
+ m_n = 0;
59
+ }
60
+
61
+ template <typename Engine, size_t p, size_t r>
62
+ _CCCL_HOST_DEVICE void discard_block_engine<Engine, p, r>::seed(result_type s)
63
+ {
64
+ m_e.seed(s);
65
+ m_n = 0;
66
+ }
67
+
68
+ template <typename Engine, size_t p, size_t r>
69
+ _CCCL_HOST_DEVICE typename discard_block_engine<Engine, p, r>::result_type
70
+ discard_block_engine<Engine, p, r>::operator()(void)
71
+ {
72
+ if (m_n >= used_block)
73
+ {
74
+ m_e.discard(block_size - m_n);
75
+ // for(; m_n < block_size; ++m_n)
76
+ // m_e();
77
+ m_n = 0;
78
+ }
79
+
80
+ ++m_n;
81
+
82
+ return m_e();
83
+ }
84
+
85
+ template <typename Engine, size_t p, size_t r>
86
+ _CCCL_HOST_DEVICE void discard_block_engine<Engine, p, r>::discard(unsigned long long z)
87
+ {
88
+ // XXX this should be accelerated
89
+ for (; z > 0; --z)
90
+ {
91
+ this->operator()();
92
+ } // end for
93
+ }
94
+
95
+ template <typename Engine, size_t p, size_t r>
96
+ _CCCL_HOST_DEVICE const typename discard_block_engine<Engine, p, r>::base_type&
97
+ discard_block_engine<Engine, p, r>::base() const
98
+ {
99
+ return m_e;
100
+ }
101
+
102
+ template <typename Engine, size_t p, size_t r>
103
+ template <typename CharT, typename Traits>
104
+ std::basic_ostream<CharT, Traits>&
105
+ discard_block_engine<Engine, p, r>::stream_out(std::basic_ostream<CharT, Traits>& os) const
106
+ {
107
+ using ostream_type = std::basic_ostream<CharT, Traits>;
108
+ using ios_base = typename ostream_type::ios_base;
109
+
110
+ // save old flags & fill character
111
+ const typename ios_base::fmtflags flags = os.flags();
112
+ const CharT fill = os.fill();
113
+
114
+ const CharT space = os.widen(' ');
115
+ os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
116
+ os.fill(space);
117
+
118
+ // output the base engine followed by n
119
+ os << m_e << space << m_n;
120
+
121
+ // restore flags & fill character
122
+ os.flags(flags);
123
+ os.fill(fill);
124
+
125
+ return os;
126
+ }
127
+
128
+ template <typename Engine, size_t p, size_t r>
129
+ template <typename CharT, typename Traits>
130
+ std::basic_istream<CharT, Traits>& discard_block_engine<Engine, p, r>::stream_in(std::basic_istream<CharT, Traits>& is)
131
+ {
132
+ using istream_type = std::basic_istream<CharT, Traits>;
133
+ using ios_base = typename istream_type::ios_base;
134
+
135
+ // save old flags
136
+ const typename ios_base::fmtflags flags = is.flags();
137
+
138
+ is.flags(ios_base::skipws);
139
+
140
+ // input the base engine and then n
141
+ is >> m_e >> m_n;
142
+
143
+ // restore old flags
144
+ is.flags(flags);
145
+ return is;
146
+ }
147
+
148
+ template <typename Engine, size_t p, size_t r>
149
+ _CCCL_HOST_DEVICE bool discard_block_engine<Engine, p, r>::equal(const discard_block_engine<Engine, p, r>& rhs) const
150
+ {
151
+ return (m_e == rhs.m_e) && (m_n == rhs.m_n);
152
+ }
153
+
154
+ template <typename Engine, size_t p, size_t r, typename CharT, typename Traits>
155
+ std::basic_ostream<CharT, Traits>&
156
+ operator<<(std::basic_ostream<CharT, Traits>& os, const discard_block_engine<Engine, p, r>& e)
157
+ {
158
+ return thrust::random::detail::random_core_access::stream_out(os, e);
159
+ }
160
+
161
+ template <typename Engine, size_t p, size_t r, typename CharT, typename Traits>
162
+ std::basic_istream<CharT, Traits>&
163
+ operator>>(std::basic_istream<CharT, Traits>& is, discard_block_engine<Engine, p, r>& e)
164
+ {
165
+ return thrust::random::detail::random_core_access::stream_in(is, e);
166
+ }
167
+
168
+ template <typename Engine, size_t p, size_t r>
169
+ _CCCL_HOST_DEVICE bool
170
+ operator==(const discard_block_engine<Engine, p, r>& lhs, const discard_block_engine<Engine, p, r>& rhs)
171
+ {
172
+ return thrust::random::detail::random_core_access::equal(lhs, rhs);
173
+ }
174
+
175
+ template <typename Engine, size_t p, size_t r>
176
+ _CCCL_HOST_DEVICE bool
177
+ operator!=(const discard_block_engine<Engine, p, r>& lhs, const discard_block_engine<Engine, p, r>& rhs)
178
+ {
179
+ return !(lhs == rhs);
180
+ }
181
+
182
+ } // namespace random
183
+
184
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/linear_congruential_engine.inl ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/random/detail/mod.h>
30
+ #include <thrust/random/detail/random_core_access.h>
31
+ #include <thrust/random/linear_congruential_engine.h>
32
+
33
+ THRUST_NAMESPACE_BEGIN
34
+
35
+ namespace random
36
+ {
37
+
38
+ template <typename UIntType, UIntType a, UIntType c, UIntType m>
39
+ _CCCL_HOST_DEVICE linear_congruential_engine<UIntType, a, c, m>::linear_congruential_engine(result_type s)
40
+ {
41
+ seed(s);
42
+ } // end linear_congruential_engine::linear_congruential_engine()
43
+
44
+ template <typename UIntType, UIntType a, UIntType c, UIntType m>
45
+ _CCCL_HOST_DEVICE void linear_congruential_engine<UIntType, a, c, m>::seed(result_type s)
46
+ {
47
+ if ((detail::mod<UIntType, 1, 0, m>(c) == 0) && (detail::mod<UIntType, 1, 0, m>(s) == 0))
48
+ {
49
+ m_x = detail::mod<UIntType, 1, 0, m>(1);
50
+ }
51
+ else
52
+ {
53
+ m_x = detail::mod<UIntType, 1, 0, m>(s);
54
+ }
55
+ } // end linear_congruential_engine::seed()
56
+
57
+ template <typename UIntType, UIntType a, UIntType c, UIntType m>
58
+ _CCCL_HOST_DEVICE typename linear_congruential_engine<UIntType, a, c, m>::result_type
59
+ linear_congruential_engine<UIntType, a, c, m>::operator()(void)
60
+ {
61
+ m_x = detail::mod<UIntType, a, c, m>(m_x);
62
+ return m_x;
63
+ } // end linear_congruential_engine::operator()()
64
+
65
+ template <typename UIntType, UIntType a, UIntType c, UIntType m>
66
+ _CCCL_HOST_DEVICE void linear_congruential_engine<UIntType, a, c, m>::discard(unsigned long long z)
67
+ {
68
+ thrust::random::detail::linear_congruential_engine_discard::discard(*this, z);
69
+ } // end linear_congruential_engine::discard()
70
+
71
+ template <typename UIntType, UIntType a, UIntType c, UIntType m>
72
+ template <typename CharT, typename Traits>
73
+ std::basic_ostream<CharT, Traits>&
74
+ linear_congruential_engine<UIntType, a, c, m>::stream_out(std::basic_ostream<CharT, Traits>& os) const
75
+ {
76
+ using ostream_type = std::basic_ostream<CharT, Traits>;
77
+ using ios_base = typename ostream_type::ios_base;
78
+
79
+ // save old flags & fill character
80
+ const typename ios_base::fmtflags flags = os.flags();
81
+ const CharT fill = os.fill();
82
+
83
+ os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
84
+ os.fill(os.widen(' '));
85
+
86
+ // output one word of state
87
+ os << m_x;
88
+
89
+ // restore flags & fill character
90
+ os.flags(flags);
91
+ os.fill(fill);
92
+
93
+ return os;
94
+ }
95
+
96
+ template <typename UIntType, UIntType a, UIntType c, UIntType m>
97
+ template <typename CharT, typename Traits>
98
+ std::basic_istream<CharT, Traits>&
99
+ linear_congruential_engine<UIntType, a, c, m>::stream_in(std::basic_istream<CharT, Traits>& is)
100
+ {
101
+ using istream_type = std::basic_istream<CharT, Traits>;
102
+ using ios_base = typename istream_type::ios_base;
103
+
104
+ // save old flags
105
+ const typename ios_base::fmtflags flags = is.flags();
106
+
107
+ is.flags(ios_base::dec);
108
+
109
+ // input one word of state
110
+ is >> m_x;
111
+
112
+ // restore flags
113
+ is.flags(flags);
114
+
115
+ return is;
116
+ }
117
+
118
+ template <typename UIntType, UIntType a, UIntType c, UIntType m>
119
+ _CCCL_HOST_DEVICE bool
120
+ linear_congruential_engine<UIntType, a, c, m>::equal(const linear_congruential_engine<UIntType, a, c, m>& rhs) const
121
+ {
122
+ return m_x == rhs.m_x;
123
+ }
124
+
125
+ template <typename UIntType_, UIntType_ a_, UIntType_ c_, UIntType_ m_>
126
+ _CCCL_HOST_DEVICE bool operator==(const linear_congruential_engine<UIntType_, a_, c_, m_>& lhs,
127
+ const linear_congruential_engine<UIntType_, a_, c_, m_>& rhs)
128
+ {
129
+ return detail::random_core_access::equal(lhs, rhs);
130
+ }
131
+
132
+ template <typename UIntType, UIntType a, UIntType c, UIntType m>
133
+ _CCCL_HOST_DEVICE bool operator!=(const linear_congruential_engine<UIntType, a, c, m>& lhs,
134
+ const linear_congruential_engine<UIntType, a, c, m>& rhs)
135
+ {
136
+ return !(lhs == rhs);
137
+ }
138
+
139
+ template <typename UIntType_, UIntType_ a_, UIntType_ c_, UIntType_ m_, typename CharT, typename Traits>
140
+ std::basic_ostream<CharT, Traits>&
141
+ operator<<(std::basic_ostream<CharT, Traits>& os, const linear_congruential_engine<UIntType_, a_, c_, m_>& e)
142
+ {
143
+ return detail::random_core_access::stream_out(os, e);
144
+ }
145
+
146
+ template <typename UIntType_, UIntType_ a_, UIntType_ c_, UIntType_ m_, typename CharT, typename Traits>
147
+ std::basic_istream<CharT, Traits>&
148
+ operator>>(std::basic_istream<CharT, Traits>& is, linear_congruential_engine<UIntType_, a_, c_, m_>& e)
149
+ {
150
+ return detail::random_core_access::stream_in(is, e);
151
+ }
152
+
153
+ } // namespace random
154
+
155
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/linear_congruential_engine_discard.h ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/random/detail/mod.h>
30
+
31
+ #include <cstdint>
32
+
33
+ THRUST_NAMESPACE_BEGIN
34
+
35
+ namespace random
36
+ {
37
+
38
+ namespace detail
39
+ {
40
+
41
+ template <typename UIntType, UIntType a, unsigned long long c, UIntType m>
42
+ struct linear_congruential_engine_discard_implementation
43
+ {
44
+ _CCCL_HOST_DEVICE static void discard(UIntType& state, unsigned long long z)
45
+ {
46
+ for (; z > 0; --z)
47
+ {
48
+ state = detail::mod<UIntType, a, c, m>(state);
49
+ }
50
+ }
51
+ }; // end linear_congruential_engine_discard
52
+
53
+ // specialize for small integers and c == 0
54
+ // XXX figure out a robust implementation of this for any unsigned integer type later
55
+ template <std::uint32_t a, std::uint32_t m>
56
+ struct linear_congruential_engine_discard_implementation<std::uint32_t, a, 0, m>
57
+ {
58
+ _CCCL_HOST_DEVICE static void discard(std::uint32_t& state, unsigned long long z)
59
+ {
60
+ const std::uint32_t modulus = m;
61
+
62
+ // XXX we need to use unsigned long long here or we will encounter overflow in the
63
+ // multiplies below
64
+ // figure out a robust implementation of this later
65
+ unsigned long long multiplier = a;
66
+ unsigned long long multiplier_to_z = 1;
67
+
68
+ // see http://en.wikipedia.org/wiki/Modular_exponentiation
69
+ while (z > 0)
70
+ {
71
+ if (z & 1)
72
+ {
73
+ // multiply in this bit's contribution while using modulus to keep result small
74
+ multiplier_to_z = (multiplier_to_z * multiplier) % modulus;
75
+ }
76
+
77
+ // move to the next bit of the exponent, square (and mod) the base accordingly
78
+ z >>= 1;
79
+ multiplier = (multiplier * multiplier) % modulus;
80
+ }
81
+
82
+ state = static_cast<std::uint32_t>((multiplier_to_z * state) % modulus);
83
+ }
84
+ }; // end linear_congruential_engine_discard
85
+
86
+ struct linear_congruential_engine_discard
87
+ {
88
+ template <typename LinearCongruentialEngine>
89
+ _CCCL_HOST_DEVICE static void discard(LinearCongruentialEngine& lcg, unsigned long long z)
90
+ {
91
+ using result_type = typename LinearCongruentialEngine::result_type;
92
+ const result_type c = LinearCongruentialEngine::increment;
93
+ const result_type a = LinearCongruentialEngine::multiplier;
94
+ const result_type m = LinearCongruentialEngine::modulus;
95
+
96
+ // XXX WAR unused variable warnings
97
+ (void) c;
98
+ (void) a;
99
+ (void) m;
100
+
101
+ linear_congruential_engine_discard_implementation<result_type, a, c, m>::discard(lcg.m_x, z);
102
+ }
103
+ }; // end linear_congruential_engine_discard
104
+
105
+ } // namespace detail
106
+
107
+ } // namespace random
108
+
109
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/linear_feedback_shift_engine.inl ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/random/linear_feedback_shift_engine.h>
30
+
31
+ THRUST_NAMESPACE_BEGIN
32
+
33
+ namespace random
34
+ {
35
+
36
+ template <typename UIntType, size_t w, size_t k, size_t q, size_t s>
37
+ _CCCL_HOST_DEVICE linear_feedback_shift_engine<UIntType, w, k, q, s>::linear_feedback_shift_engine(result_type value)
38
+ {
39
+ seed(value);
40
+ } // end linear_feedback_shift_engine::linear_feedback_shift_engine()
41
+
42
+ template <typename UIntType, size_t w, size_t k, size_t q, size_t s>
43
+ _CCCL_HOST_DEVICE void linear_feedback_shift_engine<UIntType, w, k, q, s>::seed(result_type value)
44
+ {
45
+ m_value = value;
46
+ } // end linear_feedback_shift_engine::seed()
47
+
48
+ template <typename UIntType, size_t w, size_t k, size_t q, size_t s>
49
+ _CCCL_HOST_DEVICE typename linear_feedback_shift_engine<UIntType, w, k, q, s>::result_type
50
+ linear_feedback_shift_engine<UIntType, w, k, q, s>::operator()(void)
51
+ {
52
+ const UIntType b = (((m_value << q) ^ m_value) & wordmask) >> (k - s);
53
+ const UIntType mask = ((~static_cast<UIntType>(0)) << (w - k)) & wordmask;
54
+ m_value = ((m_value & mask) << s) ^ b;
55
+ return m_value;
56
+ } // end linear_feedback_shift_engine::operator()()
57
+
58
+ template <typename UIntType, size_t w, size_t k, size_t q, size_t s>
59
+ _CCCL_HOST_DEVICE void linear_feedback_shift_engine<UIntType, w, k, q, s>::discard(unsigned long long z)
60
+ {
61
+ for (; z > 0; --z)
62
+ {
63
+ this->operator()();
64
+ } // end for
65
+ } // end linear_feedback_shift_engine::discard()
66
+
67
+ template <typename UIntType, size_t w, size_t k, size_t q, size_t s>
68
+ template <typename CharT, typename Traits>
69
+ std::basic_ostream<CharT, Traits>&
70
+ linear_feedback_shift_engine<UIntType, w, k, q, s>::stream_out(std::basic_ostream<CharT, Traits>& os) const
71
+ {
72
+ using ostream_type = std::basic_ostream<CharT, Traits>;
73
+ using ios_base = typename ostream_type::ios_base;
74
+
75
+ // save old flags & fill character
76
+ const typename ios_base::fmtflags flags = os.flags();
77
+ const CharT fill = os.fill();
78
+
79
+ os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
80
+ os.fill(os.widen(' '));
81
+
82
+ // output one word of state
83
+ os << m_value;
84
+
85
+ // restore flags & fill character
86
+ os.flags(flags);
87
+ os.fill(fill);
88
+
89
+ return os;
90
+ }
91
+
92
+ template <typename UIntType, size_t w, size_t k, size_t q, size_t s>
93
+ template <typename CharT, typename Traits>
94
+ std::basic_istream<CharT, Traits>&
95
+ linear_feedback_shift_engine<UIntType, w, k, q, s>::stream_in(std::basic_istream<CharT, Traits>& is)
96
+ {
97
+ using istream_type = std::basic_istream<CharT, Traits>;
98
+ using ios_base = typename istream_type::ios_base;
99
+
100
+ // save old flags
101
+ const typename ios_base::fmtflags flags = is.flags();
102
+
103
+ is.flags(ios_base::skipws);
104
+
105
+ // input one word of state
106
+ is >> m_value;
107
+
108
+ // restore flags
109
+ is.flags(flags);
110
+
111
+ return is;
112
+ }
113
+
114
+ template <typename UIntType, size_t w, size_t k, size_t q, size_t s>
115
+ _CCCL_HOST_DEVICE bool linear_feedback_shift_engine<UIntType, w, k, q, s>::equal(
116
+ const linear_feedback_shift_engine<UIntType, w, k, q, s>& rhs) const
117
+ {
118
+ return m_value == rhs.m_value;
119
+ }
120
+
121
+ template <typename UIntType, size_t w, size_t k, size_t q, size_t s>
122
+ _CCCL_HOST_DEVICE bool operator==(const linear_feedback_shift_engine<UIntType, w, k, q, s>& lhs,
123
+ const linear_feedback_shift_engine<UIntType, w, k, q, s>& rhs)
124
+ {
125
+ return thrust::random::detail::random_core_access::equal(lhs, rhs);
126
+ }
127
+
128
+ template <typename UIntType, size_t w, size_t k, size_t q, size_t s>
129
+ _CCCL_HOST_DEVICE bool operator!=(const linear_feedback_shift_engine<UIntType, w, k, q, s>& lhs,
130
+ const linear_feedback_shift_engine<UIntType, w, k, q, s>& rhs)
131
+ {
132
+ return !(lhs == rhs);
133
+ }
134
+
135
+ template <typename UIntType_, size_t w_, size_t k_, size_t q_, size_t s_, typename CharT, typename Traits>
136
+ std::basic_ostream<CharT, Traits>&
137
+ operator<<(std::basic_ostream<CharT, Traits>& os, const linear_feedback_shift_engine<UIntType_, w_, k_, q_, s_>& e)
138
+ {
139
+ return thrust::random::detail::random_core_access::stream_out(os, e);
140
+ }
141
+
142
+ template <typename UIntType_, size_t w_, size_t k_, size_t q_, size_t s_, typename CharT, typename Traits>
143
+ std::basic_istream<CharT, Traits>&
144
+ operator>>(std::basic_istream<CharT, Traits>& is, linear_feedback_shift_engine<UIntType_, w_, k_, q_, s_>& e)
145
+ {
146
+ return thrust::random::detail::random_core_access::stream_in(is, e);
147
+ }
148
+
149
+ } // namespace random
150
+
151
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/linear_feedback_shift_engine_wordmask.h ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ THRUST_NAMESPACE_BEGIN
30
+
31
+ namespace random
32
+ {
33
+
34
+ namespace detail
35
+ {
36
+
37
+ template <typename T, int w, int i = w - 1>
38
+ struct linear_feedback_shift_engine_wordmask
39
+ {
40
+ static const T value = (T(1u) << i) | linear_feedback_shift_engine_wordmask<T, w, i - 1>::value;
41
+ }; // end linear_feedback_shift_engine_wordmask
42
+
43
+ template <typename T, int w>
44
+ struct linear_feedback_shift_engine_wordmask<T, w, 0>
45
+ {
46
+ static const T value = 0;
47
+ }; // end linear_feedback_shift_engine_wordmask
48
+
49
+ } // namespace detail
50
+
51
+ } // namespace random
52
+
53
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/mod.h ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ THRUST_NAMESPACE_BEGIN
30
+
31
+ namespace random
32
+ {
33
+
34
+ namespace detail
35
+ {
36
+
37
+ template <typename T, T a, T c, T m, bool = (m == 0)>
38
+ struct static_mod
39
+ {
40
+ static const T q = m / a;
41
+ static const T r = m % a;
42
+
43
+ _CCCL_HOST_DEVICE T operator()(T x) const
44
+ {
45
+ _CCCL_IF_CONSTEXPR (a == 1)
46
+ {
47
+ x %= m;
48
+ }
49
+ else
50
+ {
51
+ T t1 = a * (x % q);
52
+ T t2 = r * (x / q);
53
+ if (t1 >= t2)
54
+ {
55
+ x = t1 - t2;
56
+ }
57
+ else
58
+ {
59
+ x = m - t2 + t1;
60
+ }
61
+ }
62
+
63
+ _CCCL_IF_CONSTEXPR (c != 0)
64
+ {
65
+ const T d = m - x;
66
+ if (d > c)
67
+ {
68
+ x += c;
69
+ }
70
+ else
71
+ {
72
+ x = c - d;
73
+ }
74
+ }
75
+
76
+ return x;
77
+ }
78
+ }; // end static_mod
79
+
80
+ // Rely on machine overflow handling
81
+ template <typename T, T a, T c, T m>
82
+ struct static_mod<T, a, c, m, true>
83
+ {
84
+ _CCCL_HOST_DEVICE T operator()(T x) const
85
+ {
86
+ return a * x + c;
87
+ }
88
+ }; // end static_mod
89
+
90
+ template <typename T, T a, T c, T m>
91
+ _CCCL_HOST_DEVICE T mod(T x)
92
+ {
93
+ static_mod<T, a, c, m> f;
94
+ return f(x);
95
+ } // end static_mod
96
+
97
+ } // namespace detail
98
+
99
+ } // namespace random
100
+
101
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/normal_distribution.inl ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/detail/integer_traits.h>
30
+ #include <thrust/random/normal_distribution.h>
31
+ #include <thrust/random/uniform_real_distribution.h>
32
+
33
+ #include <cuda/std/limits>
34
+
35
+ #include <cstdint>
36
+
37
+ THRUST_NAMESPACE_BEGIN
38
+
39
+ namespace random
40
+ {
41
+
42
+ template <typename RealType>
43
+ _CCCL_HOST_DEVICE normal_distribution<RealType>::normal_distribution(RealType a, RealType b)
44
+ : super_t()
45
+ , m_param(a, b)
46
+ {} // end normal_distribution::normal_distribution()
47
+
48
+ template <typename RealType>
49
+ _CCCL_HOST_DEVICE normal_distribution<RealType>::normal_distribution(const param_type& parm)
50
+ : super_t()
51
+ , m_param(parm)
52
+ {} // end normal_distribution::normal_distribution()
53
+
54
+ template <typename RealType>
55
+ _CCCL_HOST_DEVICE void normal_distribution<RealType>::reset()
56
+ {
57
+ super_t::reset();
58
+ } // end normal_distribution::reset()
59
+
60
+ template <typename RealType>
61
+ template <typename UniformRandomNumberGenerator>
62
+ _CCCL_HOST_DEVICE typename normal_distribution<RealType>::result_type
63
+ normal_distribution<RealType>::operator()(UniformRandomNumberGenerator& urng)
64
+ {
65
+ return operator()(urng, m_param);
66
+ } // end normal_distribution::operator()()
67
+
68
+ template <typename RealType>
69
+ template <typename UniformRandomNumberGenerator>
70
+ _CCCL_HOST_DEVICE typename normal_distribution<RealType>::result_type
71
+ normal_distribution<RealType>::operator()(UniformRandomNumberGenerator& urng, const param_type& parm)
72
+ {
73
+ return super_t::sample(urng, parm.first, parm.second);
74
+ } // end normal_distribution::operator()()
75
+
76
+ template <typename RealType>
77
+ _CCCL_HOST_DEVICE typename normal_distribution<RealType>::param_type normal_distribution<RealType>::param() const
78
+ {
79
+ return m_param;
80
+ } // end normal_distribution::param()
81
+
82
+ template <typename RealType>
83
+ _CCCL_HOST_DEVICE void normal_distribution<RealType>::param(const param_type& parm)
84
+ {
85
+ m_param = parm;
86
+ } // end normal_distribution::param()
87
+
88
+ template <typename RealType>
89
+ _CCCL_HOST_DEVICE typename normal_distribution<RealType>::result_type normal_distribution<RealType>::min
90
+ THRUST_PREVENT_MACRO_SUBSTITUTION() const
91
+ {
92
+ return ::cuda::std::numeric_limits<RealType>::lowest();
93
+ } // end normal_distribution::min()
94
+
95
+ template <typename RealType>
96
+ _CCCL_HOST_DEVICE typename normal_distribution<RealType>::result_type normal_distribution<RealType>::max
97
+ THRUST_PREVENT_MACRO_SUBSTITUTION() const
98
+ {
99
+ return ::cuda::std::numeric_limits<RealType>::max();
100
+ } // end normal_distribution::max()
101
+
102
+ template <typename RealType>
103
+ _CCCL_HOST_DEVICE typename normal_distribution<RealType>::result_type normal_distribution<RealType>::mean() const
104
+ {
105
+ return m_param.first;
106
+ } // end normal_distribution::mean()
107
+
108
+ template <typename RealType>
109
+ _CCCL_HOST_DEVICE typename normal_distribution<RealType>::result_type normal_distribution<RealType>::stddev() const
110
+ {
111
+ return m_param.second;
112
+ } // end normal_distribution::stddev()
113
+
114
+ template <typename RealType>
115
+ _CCCL_HOST_DEVICE bool normal_distribution<RealType>::equal(const normal_distribution& rhs) const
116
+ {
117
+ return m_param == rhs.param();
118
+ }
119
+
120
+ template <typename RealType>
121
+ template <typename CharT, typename Traits>
122
+ std::basic_ostream<CharT, Traits>& normal_distribution<RealType>::stream_out(std::basic_ostream<CharT, Traits>& os) const
123
+ {
124
+ using ostream_type = std::basic_ostream<CharT, Traits>;
125
+ using ios_base = typename ostream_type::ios_base;
126
+
127
+ // save old flags and fill character
128
+ const typename ios_base::fmtflags flags = os.flags();
129
+ const CharT fill = os.fill();
130
+
131
+ const CharT space = os.widen(' ');
132
+ os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
133
+ os.fill(space);
134
+
135
+ os << mean() << space << stddev();
136
+
137
+ // restore old flags and fill character
138
+ os.flags(flags);
139
+ os.fill(fill);
140
+ return os;
141
+ }
142
+
143
+ template <typename RealType>
144
+ template <typename CharT, typename Traits>
145
+ std::basic_istream<CharT, Traits>& normal_distribution<RealType>::stream_in(std::basic_istream<CharT, Traits>& is)
146
+ {
147
+ using istream_type = std::basic_istream<CharT, Traits>;
148
+ using ios_base = typename istream_type::ios_base;
149
+
150
+ // save old flags
151
+ const typename ios_base::fmtflags flags = is.flags();
152
+
153
+ is.flags(ios_base::skipws);
154
+
155
+ is >> m_param.first >> m_param.second;
156
+
157
+ // restore old flags
158
+ is.flags(flags);
159
+ return is;
160
+ }
161
+
162
+ template <typename RealType>
163
+ _CCCL_HOST_DEVICE bool operator==(const normal_distribution<RealType>& lhs, const normal_distribution<RealType>& rhs)
164
+ {
165
+ return thrust::random::detail::random_core_access::equal(lhs, rhs);
166
+ }
167
+
168
+ template <typename RealType>
169
+ _CCCL_HOST_DEVICE bool operator!=(const normal_distribution<RealType>& lhs, const normal_distribution<RealType>& rhs)
170
+ {
171
+ return !(lhs == rhs);
172
+ }
173
+
174
+ template <typename RealType, typename CharT, typename Traits>
175
+ std::basic_ostream<CharT, Traits>&
176
+ operator<<(std::basic_ostream<CharT, Traits>& os, const normal_distribution<RealType>& d)
177
+ {
178
+ return thrust::random::detail::random_core_access::stream_out(os, d);
179
+ }
180
+
181
+ template <typename RealType, typename CharT, typename Traits>
182
+ std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, normal_distribution<RealType>& d)
183
+ {
184
+ return thrust::random::detail::random_core_access::stream_in(is, d);
185
+ }
186
+
187
+ } // namespace random
188
+
189
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/normal_distribution_base.h ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*
18
+ * Copyright Jens Maurer 2000-2001
19
+ * Distributed under the Boost Software License, Version 1.0. (See
20
+ * accompanying file LICENSE_1_0.txt or copy at
21
+ * http://www.boost.org/LICENSE_1_0.txt)
22
+ */
23
+
24
+ #pragma once
25
+
26
+ #include <thrust/detail/config.h>
27
+
28
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
29
+ # pragma GCC system_header
30
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
31
+ # pragma clang system_header
32
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
33
+ # pragma system_header
34
+ #endif // no system header
35
+ #include <thrust/pair.h>
36
+ #include <thrust/random/uniform_real_distribution.h>
37
+
38
+ #include <cmath>
39
+ #include <limits>
40
+
41
+ THRUST_NAMESPACE_BEGIN
42
+ namespace random
43
+ {
44
+ namespace detail
45
+ {
46
+
47
+ // this version samples the normal distribution directly
48
+ // and uses the non-standard math function erfcinv
49
+ template <typename RealType>
50
+ class normal_distribution_nvcc
51
+ {
52
+ protected:
53
+ template <typename UniformRandomNumberGenerator>
54
+ _CCCL_HOST_DEVICE RealType sample(UniformRandomNumberGenerator& urng, const RealType mean, const RealType stddev)
55
+ {
56
+ using uint_type = typename UniformRandomNumberGenerator::result_type;
57
+ constexpr uint_type urng_range = UniformRandomNumberGenerator::max - UniformRandomNumberGenerator::min;
58
+
59
+ // Constants for conversion
60
+ constexpr RealType S1 = static_cast<RealType>(1. / static_cast<double>(urng_range));
61
+ constexpr RealType S2 = S1 / 2;
62
+
63
+ RealType S3 = static_cast<RealType>(-1.4142135623730950488016887242097); // -sqrt(2)
64
+
65
+ // Get the integer value
66
+ uint_type u = urng() - UniformRandomNumberGenerator::min;
67
+
68
+ // Ensure the conversion to float will give a value in the range [0,0.5)
69
+ if (u > (urng_range / 2))
70
+ {
71
+ u = urng_range - u;
72
+ S3 = -S3;
73
+ }
74
+
75
+ // Convert to floating point in [0,0.5)
76
+ RealType p = u * S1 + S2;
77
+
78
+ // Apply inverse error function
79
+ return mean + stddev * S3 * erfcinv(2 * p);
80
+ }
81
+
82
+ // no-op
83
+ _CCCL_HOST_DEVICE void reset() {}
84
+ };
85
+
86
+ // this version samples the normal distribution using
87
+ // Marsaglia's "polar method"
88
+ template <typename RealType>
89
+ class normal_distribution_portable
90
+ {
91
+ protected:
92
+ normal_distribution_portable()
93
+ : m_r1()
94
+ , m_r2()
95
+ , m_cached_rho()
96
+ , m_valid(false)
97
+ {}
98
+
99
+ normal_distribution_portable(const normal_distribution_portable& other)
100
+ : m_r1(other.m_r1)
101
+ , m_r2(other.m_r2)
102
+ , m_cached_rho(other.m_cached_rho)
103
+ , m_valid(other.m_valid)
104
+ {}
105
+
106
+ void reset()
107
+ {
108
+ m_valid = false;
109
+ }
110
+
111
+ // note that we promise to call this member function with the same mean and stddev
112
+ template <typename UniformRandomNumberGenerator>
113
+ _CCCL_HOST_DEVICE RealType sample(UniformRandomNumberGenerator& urng, const RealType mean, const RealType stddev)
114
+ {
115
+ // implementation from Boost
116
+ // allow for Koenig lookup
117
+ using std::cos;
118
+ using std::log;
119
+ using std::sin;
120
+ using std::sqrt;
121
+
122
+ if (!m_valid)
123
+ {
124
+ uniform_real_distribution<RealType> u01;
125
+ m_r1 = u01(urng);
126
+ m_r2 = u01(urng);
127
+ m_cached_rho = sqrt(-RealType(2) * log(RealType(1) - m_r2));
128
+
129
+ m_valid = true;
130
+ }
131
+ else
132
+ {
133
+ m_valid = false;
134
+ }
135
+
136
+ const RealType pi = RealType(3.14159265358979323846);
137
+
138
+ RealType result = m_cached_rho * (m_valid ? cos(RealType(2) * pi * m_r1) : sin(RealType(2) * pi * m_r1));
139
+
140
+ return mean + stddev * result;
141
+ }
142
+
143
+ private:
144
+ RealType m_r1, m_r2, m_cached_rho;
145
+ bool m_valid;
146
+ };
147
+
148
+ template <typename RealType>
149
+ struct normal_distribution_base
150
+ {
151
+ #if _CCCL_HAS_CUDA_COMPILER && !_CCCL_CUDA_COMPILER(NVHPC)
152
+ using type = normal_distribution_nvcc<RealType>;
153
+ #else
154
+ using type = normal_distribution_portable<RealType>;
155
+ #endif
156
+ };
157
+
158
+ } // namespace detail
159
+ } // namespace random
160
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/random_core_access.h ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ THRUST_NAMESPACE_BEGIN
30
+
31
+ namespace random
32
+ {
33
+
34
+ namespace detail
35
+ {
36
+
37
+ struct random_core_access
38
+ {
39
+ template <typename OStream, typename EngineOrDistribution>
40
+ static OStream& stream_out(OStream& os, const EngineOrDistribution& x)
41
+ {
42
+ return x.stream_out(os);
43
+ }
44
+
45
+ template <typename IStream, typename EngineOrDistribution>
46
+ static IStream& stream_in(IStream& is, EngineOrDistribution& x)
47
+ {
48
+ return x.stream_in(is);
49
+ }
50
+
51
+ template <typename EngineOrDistribution>
52
+ _CCCL_HOST_DEVICE static bool equal(const EngineOrDistribution& lhs, const EngineOrDistribution& rhs)
53
+ {
54
+ return lhs.equal(rhs);
55
+ }
56
+
57
+ }; // end random_core_access
58
+
59
+ } // namespace detail
60
+
61
+ } // namespace random
62
+
63
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/subtract_with_carry_engine.inl ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/random/detail/mod.h>
30
+ #include <thrust/random/detail/random_core_access.h>
31
+ #include <thrust/random/linear_congruential_engine.h>
32
+ #include <thrust/random/subtract_with_carry_engine.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+ namespace random
37
+ {
38
+
39
+ template <typename UIntType, size_t w, size_t s, size_t r>
40
+ _CCCL_HOST_DEVICE subtract_with_carry_engine<UIntType, w, s, r>::subtract_with_carry_engine(result_type value)
41
+ {
42
+ seed(value);
43
+ } // end subtract_with_carry_engine::subtract_with_carry_engine()
44
+
45
+ template <typename UIntType, size_t w, size_t s, size_t r>
46
+ _CCCL_HOST_DEVICE void subtract_with_carry_engine<UIntType, w, s, r>::seed(result_type value)
47
+ {
48
+ thrust::random::linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> e(
49
+ value == 0u ? default_seed : value);
50
+
51
+ // initialize state
52
+ for (size_t i = 0; i < long_lag; ++i)
53
+ {
54
+ m_x[i] = detail::mod<UIntType, 1, 0, modulus>(e());
55
+ } // end for i
56
+
57
+ m_carry = (m_x[long_lag - 1] == 0);
58
+ m_k = 0;
59
+ } // end subtract_with_carry_engine::seed()
60
+
61
+ template <typename UIntType, size_t w, size_t s, size_t r>
62
+ _CCCL_HOST_DEVICE typename subtract_with_carry_engine<UIntType, w, s, r>::result_type
63
+ subtract_with_carry_engine<UIntType, w, s, r>::operator()(void)
64
+ {
65
+ // XXX we probably need to cache these m_x[m_k] in a register
66
+ // maybe we need to cache the use of all member variables
67
+ int short_index = m_k - short_lag;
68
+ if (short_index < 0)
69
+ {
70
+ short_index += long_lag;
71
+ }
72
+ result_type xi;
73
+ if (m_x[short_index] >= m_x[m_k] + m_carry)
74
+ {
75
+ // x(n) >= 0
76
+ xi = m_x[short_index] - m_x[m_k] - m_carry;
77
+ m_carry = 0;
78
+ }
79
+ else
80
+ {
81
+ // x(n) < 0
82
+ xi = modulus - m_x[m_k] - m_carry + m_x[short_index];
83
+ m_carry = 1;
84
+ }
85
+ m_x[m_k] = xi;
86
+ ++m_k;
87
+ if (m_k >= long_lag)
88
+ {
89
+ m_k = 0;
90
+ }
91
+ return xi;
92
+ } // end subtract_with_carry_engine::operator()()
93
+
94
+ template <typename UIntType, size_t w, size_t s, size_t r>
95
+ _CCCL_HOST_DEVICE void subtract_with_carry_engine<UIntType, w, s, r>::discard(unsigned long long z)
96
+ {
97
+ for (; z > 0; --z)
98
+ {
99
+ this->operator()();
100
+ } // end for
101
+ } // end subtract_with_carry_engine::discard()
102
+
103
+ template <typename UIntType, size_t w, size_t s, size_t r>
104
+ template <typename CharT, typename Traits>
105
+ std::basic_ostream<CharT, Traits>&
106
+ subtract_with_carry_engine<UIntType, w, s, r>::stream_out(std::basic_ostream<CharT, Traits>& os) const
107
+ {
108
+ using ostream_type = std::basic_ostream<CharT, Traits>;
109
+ using ios_base = typename ostream_type::ios_base;
110
+
111
+ const typename ios_base::fmtflags flags = os.flags();
112
+ const CharT fill = os.fill();
113
+ const CharT space = os.widen(' ');
114
+ os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
115
+ os.fill(space);
116
+
117
+ const UIntType long_lag_ = r;
118
+
119
+ for (size_t i = 0; i < r; ++i)
120
+ {
121
+ os << m_x[(i + m_k) % long_lag_] << space;
122
+ }
123
+ os << m_carry;
124
+
125
+ os.flags(flags);
126
+ os.fill(fill);
127
+ return os;
128
+ }
129
+
130
+ template <typename UIntType, size_t w, size_t s, size_t r>
131
+ template <typename CharType, typename Traits>
132
+ std::basic_istream<CharType, Traits>&
133
+ subtract_with_carry_engine<UIntType, w, s, r>::stream_in(std::basic_istream<CharType, Traits>& is)
134
+ {
135
+ using istream_type = std::basic_istream<CharType, Traits>;
136
+ using ios_base = typename istream_type::ios_base;
137
+
138
+ const typename ios_base::fmtflags flags = is.flags();
139
+ is.flags(ios_base::dec | ios_base::skipws);
140
+
141
+ for (size_t i = 0; i < r; ++i)
142
+ {
143
+ is >> m_x[i];
144
+ }
145
+ is >> m_carry;
146
+
147
+ m_k = 0;
148
+
149
+ is.flags(flags);
150
+ return is;
151
+ }
152
+
153
+ template <typename UIntType, size_t w, size_t s, size_t r>
154
+ _CCCL_HOST_DEVICE bool
155
+ subtract_with_carry_engine<UIntType, w, s, r>::equal(const subtract_with_carry_engine<UIntType, w, s, r>& rhs) const
156
+ {
157
+ const UIntType long_lag_ = r;
158
+
159
+ bool result = true;
160
+ for (size_t i = 0; i < r; ++i)
161
+ {
162
+ result &= (m_x[(i + m_k) % long_lag_] == rhs.m_x[(i + rhs.m_k) % long_lag_]);
163
+ }
164
+
165
+ // XXX not sure if this last check is necessary
166
+ result &= (m_carry == rhs.m_carry);
167
+
168
+ return result;
169
+ }
170
+
171
+ template <typename UIntType, size_t w, size_t s, size_t r, typename CharT, typename Traits>
172
+ std::basic_ostream<CharT, Traits>&
173
+ operator<<(std::basic_ostream<CharT, Traits>& os, const subtract_with_carry_engine<UIntType, w, s, r>& e)
174
+ {
175
+ return thrust::random::detail::random_core_access::stream_out(os, e);
176
+ }
177
+
178
+ template <typename UIntType, size_t w, size_t s, size_t r, typename CharType, typename Traits>
179
+ std::basic_istream<CharType, Traits>&
180
+ operator>>(std::basic_istream<CharType, Traits>& is, subtract_with_carry_engine<UIntType, w, s, r>& e)
181
+ {
182
+ return thrust::random::detail::random_core_access::stream_in(is, e);
183
+ }
184
+
185
+ template <typename UIntType, size_t w, size_t s, size_t r>
186
+ _CCCL_HOST_DEVICE bool operator==(const subtract_with_carry_engine<UIntType, w, s, r>& lhs,
187
+ const subtract_with_carry_engine<UIntType, w, s, r>& rhs)
188
+ {
189
+ return thrust::random::detail::random_core_access::equal(lhs, rhs);
190
+ }
191
+
192
+ template <typename UIntType, size_t w, size_t s, size_t r>
193
+ _CCCL_HOST_DEVICE bool operator!=(const subtract_with_carry_engine<UIntType, w, s, r>& lhs,
194
+ const subtract_with_carry_engine<UIntType, w, s, r>& rhs)
195
+ {
196
+ return !(lhs == rhs);
197
+ }
198
+
199
+ } // namespace random
200
+
201
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/uniform_int_distribution.inl ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/detail/type_traits.h>
30
+ #include <thrust/random/uniform_int_distribution.h>
31
+ #include <thrust/random/uniform_real_distribution.h>
32
+
33
+ THRUST_NAMESPACE_BEGIN
34
+
35
+ namespace random
36
+ {
37
+
38
+ template <typename IntType>
39
+ _CCCL_HOST_DEVICE uniform_int_distribution<IntType>::uniform_int_distribution(IntType a, IntType b)
40
+ : m_param(a, b)
41
+ {} // end uniform_int_distribution::uniform_int_distribution()
42
+
43
+ template <typename IntType>
44
+ _CCCL_HOST_DEVICE uniform_int_distribution<IntType>::uniform_int_distribution(const param_type& parm)
45
+ : m_param(parm)
46
+ {} // end uniform_int_distribution::uniform_int_distribution()
47
+
48
+ template <typename IntType>
49
+ _CCCL_HOST_DEVICE void uniform_int_distribution<IntType>::reset()
50
+ {} // end uniform_int_distribution::reset()
51
+
52
+ template <typename IntType>
53
+ template <typename UniformRandomNumberGenerator>
54
+ _CCCL_HOST_DEVICE typename uniform_int_distribution<IntType>::result_type
55
+ uniform_int_distribution<IntType>::operator()(UniformRandomNumberGenerator& urng)
56
+ {
57
+ return operator()(urng, m_param);
58
+ } // end uniform_int_distribution::operator()()
59
+
60
+ template <typename IntType>
61
+ template <typename UniformRandomNumberGenerator>
62
+ _CCCL_HOST_DEVICE typename uniform_int_distribution<IntType>::result_type
63
+ uniform_int_distribution<IntType>::operator()(UniformRandomNumberGenerator& urng, const param_type& parm)
64
+ {
65
+ // XXX this implementation is somewhat hacky and will skip
66
+ // values if the range of the RNG is smaller than the range of the distribution
67
+ // we should improve this implementation in a later version
68
+
69
+ using float_type = typename thrust::detail::largest_available_float::type;
70
+
71
+ const float_type real_min(static_cast<float_type>(parm.first));
72
+ const float_type real_max(static_cast<float_type>(parm.second));
73
+
74
+ // add one to the right end of the interval because it is half-open
75
+ // XXX adding 1.0 to a potentially large floating point number seems like a bad idea
76
+ uniform_real_distribution<float_type> real_dist(real_min, real_max + float_type(1));
77
+
78
+ return static_cast<result_type>(real_dist(urng));
79
+ } // end uniform_int_distribution::operator()()
80
+
81
+ template <typename IntType>
82
+ _CCCL_HOST_DEVICE typename uniform_int_distribution<IntType>::result_type uniform_int_distribution<IntType>::a() const
83
+ {
84
+ return m_param.first;
85
+ } // end uniform_int_distribution<IntType>::a()
86
+
87
+ template <typename IntType>
88
+ _CCCL_HOST_DEVICE typename uniform_int_distribution<IntType>::result_type uniform_int_distribution<IntType>::b() const
89
+ {
90
+ return m_param.second;
91
+ } // end uniform_int_distribution::b()
92
+
93
+ template <typename IntType>
94
+ _CCCL_HOST_DEVICE typename uniform_int_distribution<IntType>::param_type uniform_int_distribution<IntType>::param() const
95
+ {
96
+ return m_param;
97
+ } // end uniform_int_distribution::param()
98
+
99
+ template <typename IntType>
100
+ _CCCL_HOST_DEVICE void uniform_int_distribution<IntType>::param(const param_type& parm)
101
+ {
102
+ m_param = parm;
103
+ } // end uniform_int_distribution::param()
104
+
105
+ template <typename IntType>
106
+ _CCCL_HOST_DEVICE typename uniform_int_distribution<IntType>::result_type uniform_int_distribution<IntType>::min
107
+ THRUST_PREVENT_MACRO_SUBSTITUTION() const
108
+ {
109
+ return a();
110
+ } // end uniform_int_distribution::min()
111
+
112
+ template <typename IntType>
113
+ _CCCL_HOST_DEVICE typename uniform_int_distribution<IntType>::result_type uniform_int_distribution<IntType>::max
114
+ THRUST_PREVENT_MACRO_SUBSTITUTION() const
115
+ {
116
+ return b();
117
+ } // end uniform_int_distribution::max()
118
+
119
+ template <typename IntType>
120
+ _CCCL_HOST_DEVICE bool uniform_int_distribution<IntType>::equal(const uniform_int_distribution& rhs) const
121
+ {
122
+ return param() == rhs.param();
123
+ }
124
+
125
+ template <typename IntType>
126
+ template <typename CharT, typename Traits>
127
+ std::basic_ostream<CharT, Traits>&
128
+ uniform_int_distribution<IntType>::stream_out(std::basic_ostream<CharT, Traits>& os) const
129
+ {
130
+ using ostream_type = std::basic_ostream<CharT, Traits>;
131
+ using ios_base = typename ostream_type::ios_base;
132
+
133
+ // save old flags and fill character
134
+ const typename ios_base::fmtflags flags = os.flags();
135
+ const CharT fill = os.fill();
136
+
137
+ const CharT space = os.widen(' ');
138
+ os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
139
+ os.fill(space);
140
+
141
+ os << a() << space << b();
142
+
143
+ // restore old flags and fill character
144
+ os.flags(flags);
145
+ os.fill(fill);
146
+ return os;
147
+ }
148
+
149
+ template <typename IntType>
150
+ template <typename CharT, typename Traits>
151
+ std::basic_istream<CharT, Traits>& uniform_int_distribution<IntType>::stream_in(std::basic_istream<CharT, Traits>& is)
152
+ {
153
+ using istream_type = std::basic_istream<CharT, Traits>;
154
+ using ios_base = typename istream_type::ios_base;
155
+
156
+ // save old flags
157
+ const typename ios_base::fmtflags flags = is.flags();
158
+
159
+ is.flags(ios_base::skipws);
160
+
161
+ is >> m_param.first >> m_param.second;
162
+
163
+ // restore old flags
164
+ is.flags(flags);
165
+ return is;
166
+ }
167
+
168
+ template <typename IntType>
169
+ _CCCL_HOST_DEVICE bool
170
+ operator==(const uniform_int_distribution<IntType>& lhs, const uniform_int_distribution<IntType>& rhs)
171
+ {
172
+ return thrust::random::detail::random_core_access::equal(lhs, rhs);
173
+ }
174
+
175
+ template <typename IntType>
176
+ _CCCL_HOST_DEVICE bool
177
+ operator!=(const uniform_int_distribution<IntType>& lhs, const uniform_int_distribution<IntType>& rhs)
178
+ {
179
+ return !(lhs == rhs);
180
+ }
181
+
182
+ template <typename IntType, typename CharT, typename Traits>
183
+ std::basic_ostream<CharT, Traits>&
184
+ operator<<(std::basic_ostream<CharT, Traits>& os, const uniform_int_distribution<IntType>& d)
185
+ {
186
+ return thrust::random::detail::random_core_access::stream_out(os, d);
187
+ }
188
+
189
+ template <typename IntType, typename CharT, typename Traits>
190
+ std::basic_istream<CharT, Traits>&
191
+ operator>>(std::basic_istream<CharT, Traits>& is, uniform_int_distribution<IntType>& d)
192
+ {
193
+ return thrust::random::detail::random_core_access::stream_in(is, d);
194
+ }
195
+
196
+ } // namespace random
197
+
198
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/uniform_real_distribution.inl ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/random/uniform_real_distribution.h>
30
+
31
+ THRUST_NAMESPACE_BEGIN
32
+
33
+ namespace random
34
+ {
35
+
36
+ template <typename RealType>
37
+ _CCCL_HOST_DEVICE uniform_real_distribution<RealType>::uniform_real_distribution(RealType a, RealType b)
38
+ : m_param(a, b)
39
+ {} // end uniform_real_distribution::uniform_real_distribution()
40
+
41
+ template <typename RealType>
42
+ _CCCL_HOST_DEVICE uniform_real_distribution<RealType>::uniform_real_distribution(const param_type& parm)
43
+ : m_param(parm)
44
+ {} // end uniform_real_distribution::uniform_real_distribution()
45
+
46
+ template <typename RealType>
47
+ _CCCL_HOST_DEVICE void uniform_real_distribution<RealType>::reset()
48
+ {} // end uniform_real_distribution::reset()
49
+
50
+ template <typename RealType>
51
+ template <typename UniformRandomNumberGenerator>
52
+ _CCCL_HOST_DEVICE typename uniform_real_distribution<RealType>::result_type
53
+ uniform_real_distribution<RealType>::operator()(UniformRandomNumberGenerator& urng)
54
+ {
55
+ return operator()(urng, m_param);
56
+ } // end uniform_real::operator()()
57
+
58
+ template <typename RealType>
59
+ template <typename UniformRandomNumberGenerator>
60
+ _CCCL_HOST_DEVICE typename uniform_real_distribution<RealType>::result_type
61
+ uniform_real_distribution<RealType>::operator()(UniformRandomNumberGenerator& urng, const param_type& parm)
62
+ {
63
+ // call the urng & map its result to [0,1)
64
+ result_type result = static_cast<result_type>(urng() - UniformRandomNumberGenerator::min);
65
+
66
+ // adding one to the denominator ensures that the interval is half-open at 1.0
67
+ // XXX adding 1.0 to a potentially large floating point number seems like a bad idea
68
+ // XXX OTOH adding 1 to what is potentially UINT_MAX also seems like a bad idea
69
+ // XXX we could statically check if 1u + (max - min) is representable and do that, otherwise use the current
70
+ // implementation
71
+ result /=
72
+ (result_type(1) + static_cast<result_type>(UniformRandomNumberGenerator::max - UniformRandomNumberGenerator::min));
73
+
74
+ return (result * (parm.second - parm.first)) + parm.first;
75
+ } // end uniform_real::operator()()
76
+
77
+ template <typename RealType>
78
+ _CCCL_HOST_DEVICE typename uniform_real_distribution<RealType>::result_type
79
+ uniform_real_distribution<RealType>::a() const
80
+ {
81
+ return m_param.first;
82
+ } // end uniform_real::a()
83
+
84
+ template <typename RealType>
85
+ _CCCL_HOST_DEVICE typename uniform_real_distribution<RealType>::result_type
86
+ uniform_real_distribution<RealType>::b() const
87
+ {
88
+ return m_param.second;
89
+ } // end uniform_real_distribution::b()
90
+
91
+ template <typename RealType>
92
+ _CCCL_HOST_DEVICE typename uniform_real_distribution<RealType>::param_type
93
+ uniform_real_distribution<RealType>::param() const
94
+ {
95
+ return m_param;
96
+ ;
97
+ } // end uniform_real_distribution::param()
98
+
99
+ template <typename RealType>
100
+ _CCCL_HOST_DEVICE void uniform_real_distribution<RealType>::param(const param_type& parm)
101
+ {
102
+ m_param = parm;
103
+ } // end uniform_real_distribution::param()
104
+
105
+ template <typename RealType>
106
+ _CCCL_HOST_DEVICE typename uniform_real_distribution<RealType>::result_type uniform_real_distribution<RealType>::min
107
+ THRUST_PREVENT_MACRO_SUBSTITUTION() const
108
+ {
109
+ return a();
110
+ } // end uniform_real_distribution::min()
111
+
112
+ template <typename RealType>
113
+ _CCCL_HOST_DEVICE typename uniform_real_distribution<RealType>::result_type uniform_real_distribution<RealType>::max
114
+ THRUST_PREVENT_MACRO_SUBSTITUTION() const
115
+ {
116
+ return b();
117
+ } // end uniform_real_distribution::max()
118
+
119
+ template <typename RealType>
120
+ _CCCL_HOST_DEVICE bool uniform_real_distribution<RealType>::equal(const uniform_real_distribution& rhs) const
121
+ {
122
+ return m_param == rhs.param();
123
+ }
124
+
125
+ template <typename RealType>
126
+ template <typename CharT, typename Traits>
127
+ std::basic_ostream<CharT, Traits>&
128
+ uniform_real_distribution<RealType>::stream_out(std::basic_ostream<CharT, Traits>& os) const
129
+ {
130
+ using ostream_type = std::basic_ostream<CharT, Traits>;
131
+ using ios_base = typename ostream_type::ios_base;
132
+
133
+ // save old flags and fill character
134
+ const typename ios_base::fmtflags flags = os.flags();
135
+ const CharT fill = os.fill();
136
+
137
+ const CharT space = os.widen(' ');
138
+ os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
139
+ os.fill(space);
140
+
141
+ os << a() << space << b();
142
+
143
+ // restore old flags and fill character
144
+ os.flags(flags);
145
+ os.fill(fill);
146
+ return os;
147
+ }
148
+
149
+ template <typename RealType>
150
+ template <typename CharT, typename Traits>
151
+ std::basic_istream<CharT, Traits>& uniform_real_distribution<RealType>::stream_in(std::basic_istream<CharT, Traits>& is)
152
+ {
153
+ using istream_type = std::basic_istream<CharT, Traits>;
154
+ using ios_base = typename istream_type::ios_base;
155
+
156
+ // save old flags
157
+ const typename ios_base::fmtflags flags = is.flags();
158
+
159
+ is.flags(ios_base::skipws);
160
+
161
+ is >> m_param.first >> m_param.second;
162
+
163
+ // restore old flags
164
+ is.flags(flags);
165
+ return is;
166
+ }
167
+
168
+ template <typename RealType>
169
+ _CCCL_HOST_DEVICE bool
170
+ operator==(const uniform_real_distribution<RealType>& lhs, const uniform_real_distribution<RealType>& rhs)
171
+ {
172
+ return thrust::random::detail::random_core_access::equal(lhs, rhs);
173
+ }
174
+
175
+ template <typename RealType>
176
+ _CCCL_HOST_DEVICE bool
177
+ operator!=(const uniform_real_distribution<RealType>& lhs, const uniform_real_distribution<RealType>& rhs)
178
+ {
179
+ return !(lhs == rhs);
180
+ }
181
+
182
+ template <typename RealType, typename CharT, typename Traits>
183
+ std::basic_ostream<CharT, Traits>&
184
+ operator<<(std::basic_ostream<CharT, Traits>& os, const uniform_real_distribution<RealType>& d)
185
+ {
186
+ return thrust::random::detail::random_core_access::stream_out(os, d);
187
+ }
188
+
189
+ template <typename RealType, typename CharT, typename Traits>
190
+ std::basic_istream<CharT, Traits>&
191
+ operator>>(std::basic_istream<CharT, Traits>& is, uniform_real_distribution<RealType>& d)
192
+ {
193
+ return thrust::random::detail::random_core_access::stream_in(is, d);
194
+ }
195
+
196
+ } // namespace random
197
+
198
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/xor_combine_engine.inl ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/random/detail/random_core_access.h>
30
+ #include <thrust/random/xor_combine_engine.h>
31
+
32
+ THRUST_NAMESPACE_BEGIN
33
+
34
+ namespace random
35
+ {
36
+
37
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
38
+ _CCCL_HOST_DEVICE xor_combine_engine<Engine1, s1, Engine2, s2>::xor_combine_engine()
39
+ : m_b1()
40
+ , m_b2()
41
+ {} // end xor_combine_engine::xor_combine_engine()
42
+
43
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
44
+ _CCCL_HOST_DEVICE
45
+ xor_combine_engine<Engine1, s1, Engine2, s2>::xor_combine_engine(const base1_type& urng1, const base2_type& urng2)
46
+ : m_b1(urng1)
47
+ , m_b2(urng2)
48
+ {} // end xor_combine_engine::xor_combine_engine()
49
+
50
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
51
+ _CCCL_HOST_DEVICE xor_combine_engine<Engine1, s1, Engine2, s2>::xor_combine_engine(result_type s)
52
+ : m_b1(s)
53
+ , m_b2(s)
54
+ {} // end xor_combine_engine::xor_combine_engine()
55
+
56
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
57
+ _CCCL_HOST_DEVICE void xor_combine_engine<Engine1, s1, Engine2, s2>::seed()
58
+ {
59
+ m_b1.seed();
60
+ m_b2.seed();
61
+ } // end xor_combine_engine::seed()
62
+
63
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
64
+ _CCCL_HOST_DEVICE void xor_combine_engine<Engine1, s1, Engine2, s2>::seed(result_type s)
65
+ {
66
+ m_b1.seed(s);
67
+ m_b2.seed(s);
68
+ } // end xor_combine_engine::seed()
69
+
70
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
71
+ _CCCL_HOST_DEVICE const typename xor_combine_engine<Engine1, s1, Engine2, s2>::base1_type&
72
+ xor_combine_engine<Engine1, s1, Engine2, s2>::base1() const
73
+ {
74
+ return m_b1;
75
+ } // end xor_combine_engine::base1()
76
+
77
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
78
+ _CCCL_HOST_DEVICE const typename xor_combine_engine<Engine1, s1, Engine2, s2>::base2_type&
79
+ xor_combine_engine<Engine1, s1, Engine2, s2>::base2() const
80
+ {
81
+ return m_b2;
82
+ } // end xor_combine_engine::base2()
83
+
84
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
85
+ _CCCL_HOST_DEVICE typename xor_combine_engine<Engine1, s1, Engine2, s2>::result_type
86
+ xor_combine_engine<Engine1, s1, Engine2, s2>::operator()(void)
87
+ {
88
+ return (result_type(m_b1() - base1_type::min) << shift1) ^ (result_type(m_b2() - base2_type::min) << shift2);
89
+ } // end xor_combine_engine::operator()()
90
+
91
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
92
+ _CCCL_HOST_DEVICE void xor_combine_engine<Engine1, s1, Engine2, s2>::discard(unsigned long long z)
93
+ {
94
+ for (; z > 0; --z)
95
+ {
96
+ this->operator()();
97
+ } // end for
98
+ } // end xor_combine_engine::discard()
99
+
100
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
101
+ template <typename CharT, typename Traits>
102
+ std::basic_ostream<CharT, Traits>&
103
+ xor_combine_engine<Engine1, s1, Engine2, s2>::stream_out(std::basic_ostream<CharT, Traits>& os) const
104
+ {
105
+ using ostream_type = std::basic_ostream<CharT, Traits>;
106
+ using ios_base = typename ostream_type::ios_base;
107
+
108
+ // save old flags and fill character
109
+ const typename ios_base::fmtflags flags = os.flags();
110
+ const CharT fill = os.fill();
111
+
112
+ const CharT space = os.widen(' ');
113
+ os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
114
+ os.fill(space);
115
+
116
+ // output each base engine in turn
117
+ os << base1() << space << base2();
118
+
119
+ // restore old flags and fill character
120
+ os.flags(flags);
121
+ os.fill(fill);
122
+ return os;
123
+ }
124
+
125
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
126
+ template <typename CharT, typename Traits>
127
+ std::basic_istream<CharT, Traits>&
128
+ xor_combine_engine<Engine1, s1, Engine2, s2>::stream_in(std::basic_istream<CharT, Traits>& is)
129
+ {
130
+ using istream_type = std::basic_istream<CharT, Traits>;
131
+ using ios_base = typename istream_type::ios_base;
132
+
133
+ // save old flags
134
+ const typename ios_base::fmtflags flags = is.flags();
135
+
136
+ is.flags(ios_base::skipws);
137
+
138
+ // input each base engine in turn
139
+ is >> m_b1 >> m_b2;
140
+
141
+ // restore old flags
142
+ is.flags(flags);
143
+ return is;
144
+ }
145
+
146
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
147
+ _CCCL_HOST_DEVICE bool
148
+ xor_combine_engine<Engine1, s1, Engine2, s2>::equal(const xor_combine_engine<Engine1, s1, Engine2, s2>& rhs) const
149
+ {
150
+ return (m_b1 == rhs.m_b1) && (m_b2 == rhs.m_b2);
151
+ }
152
+
153
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2, typename CharT, typename Traits>
154
+ std::basic_ostream<CharT, Traits>&
155
+ operator<<(std::basic_ostream<CharT, Traits>& os, const xor_combine_engine<Engine1, s1, Engine2, s2>& e)
156
+ {
157
+ return thrust::random::detail::random_core_access::stream_out(os, e);
158
+ }
159
+
160
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2, typename CharT, typename Traits>
161
+ std::basic_istream<CharT, Traits>&
162
+ operator>>(std::basic_istream<CharT, Traits>& is, xor_combine_engine<Engine1, s1, Engine2, s2>& e)
163
+ {
164
+ return thrust::random::detail::random_core_access::stream_in(is, e);
165
+ }
166
+
167
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
168
+ _CCCL_HOST_DEVICE bool operator==(const xor_combine_engine<Engine1, s1, Engine2, s2>& lhs,
169
+ const xor_combine_engine<Engine1, s1, Engine2, s2>& rhs)
170
+ {
171
+ return thrust::random::detail::random_core_access::equal(lhs, rhs);
172
+ }
173
+
174
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2>
175
+ _CCCL_HOST_DEVICE bool operator!=(const xor_combine_engine<Engine1, s1, Engine2, s2>& lhs,
176
+ const xor_combine_engine<Engine1, s1, Engine2, s2>& rhs)
177
+ {
178
+ return !(lhs == rhs);
179
+ }
180
+
181
+ } // namespace random
182
+
183
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/detail/xor_combine_engine_max.h ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/detail/mpl/math.h>
30
+ #include <thrust/detail/type_traits.h>
31
+
32
+ #include <cstddef>
33
+ #include <limits>
34
+
35
+ THRUST_NAMESPACE_BEGIN
36
+
37
+ namespace random
38
+ {
39
+
40
+ namespace detail
41
+ {
42
+
43
+ namespace math = thrust::detail::mpl::math;
44
+
45
+ namespace detail
46
+ {
47
+
48
+ // two cases for this function avoids compile-time warnings of overflow
49
+ template <typename UIntType, UIntType w, UIntType lhs, UIntType rhs, bool shift_will_overflow>
50
+ struct lshift_w
51
+ {
52
+ static const UIntType value = 0;
53
+ };
54
+
55
+ template <typename UIntType, UIntType w, UIntType lhs, UIntType rhs>
56
+ struct lshift_w<UIntType, w, lhs, rhs, false>
57
+ {
58
+ static const UIntType value = lhs << rhs;
59
+ };
60
+
61
+ } // namespace detail
62
+
63
+ template <typename UIntType, UIntType w, UIntType lhs, UIntType rhs>
64
+ struct lshift_w
65
+ {
66
+ static const bool shift_will_overflow = rhs >= w;
67
+
68
+ static const UIntType value = detail::lshift_w<UIntType, w, lhs, rhs, shift_will_overflow>::value;
69
+ };
70
+
71
+ template <typename UIntType, UIntType lhs, UIntType rhs>
72
+ struct lshift : lshift_w<UIntType, std::numeric_limits<UIntType>::digits, lhs, rhs>
73
+ {};
74
+
75
+ template <typename UIntType, int p>
76
+ struct two_to_the_power : lshift<UIntType, 1, p>
77
+ {};
78
+
79
+ template <typename result_type, result_type a, result_type b, int d>
80
+ class xor_combine_engine_max_aux_constants
81
+ {
82
+ public:
83
+ static const result_type two_to_the_d = two_to_the_power<result_type, d>::value;
84
+ static const result_type c = lshift<result_type, a, d>::value;
85
+
86
+ static const result_type t = math::max<result_type, c, b>::value;
87
+
88
+ static const result_type u = math::min<result_type, c, b>::value;
89
+
90
+ static const result_type p = math::log2<u>::value;
91
+ static const result_type two_to_the_p = two_to_the_power<result_type, p>::value;
92
+
93
+ static const result_type k = math::div<result_type, t, two_to_the_p>::value;
94
+ };
95
+
96
+ template <typename result_type, result_type, result_type, int>
97
+ struct xor_combine_engine_max_aux;
98
+
99
+ template <typename result_type, result_type a, result_type b, int d>
100
+ struct xor_combine_engine_max_aux_case4
101
+ {
102
+ using constants = xor_combine_engine_max_aux_constants<result_type, a, b, d>;
103
+
104
+ static const result_type k_plus_1_times_two_to_the_p =
105
+ lshift<result_type, math::plus<result_type, constants::k, 1>::value, constants::p>::value;
106
+
107
+ static const result_type M =
108
+ xor_combine_engine_max_aux<result_type,
109
+ math::div<result_type,
110
+ math::mod<result_type, constants::u, constants::two_to_the_p>::value,
111
+ constants::two_to_the_p>::value,
112
+ math::mod<result_type, constants::t, constants::two_to_the_p>::value,
113
+ d>::value;
114
+
115
+ static const result_type value = math::plus<result_type, k_plus_1_times_two_to_the_p, M>::value;
116
+ };
117
+
118
+ template <typename result_type, result_type a, result_type b, int d>
119
+ struct xor_combine_engine_max_aux_case3
120
+ {
121
+ using constants = xor_combine_engine_max_aux_constants<result_type, a, b, d>;
122
+
123
+ static const result_type k_plus_1_times_two_to_the_p =
124
+ lshift<result_type, math::plus<result_type, constants::k, 1>::value, constants::p>::value;
125
+
126
+ static const result_type M =
127
+ xor_combine_engine_max_aux<result_type,
128
+ math::div<result_type,
129
+ math::mod<result_type, constants::t, constants::two_to_the_p>::value,
130
+ constants::two_to_the_p>::value,
131
+ math::mod<result_type, constants::u, constants::two_to_the_p>::value,
132
+ d>::value;
133
+
134
+ static const result_type value = math::plus<result_type, k_plus_1_times_two_to_the_p, M>::value;
135
+ };
136
+
137
+ template <typename result_type, result_type a, result_type b, int d>
138
+ struct xor_combine_engine_max_aux_case2
139
+ {
140
+ using constants = xor_combine_engine_max_aux_constants<result_type, a, b, d>;
141
+
142
+ static const result_type k_plus_1_times_two_to_the_p =
143
+ lshift<result_type, math::plus<result_type, constants::k, 1>::value, constants::p>::value;
144
+
145
+ static const result_type value = math::minus<result_type, k_plus_1_times_two_to_the_p, 1>::value;
146
+ };
147
+
148
+ template <typename result_type, result_type a, result_type b, int d>
149
+ struct xor_combine_engine_max_aux_case1
150
+ {
151
+ static const result_type c = lshift<result_type, a, d>::value;
152
+
153
+ static const result_type value = math::plus<result_type, c, b>::value;
154
+ };
155
+
156
+ template <typename result_type, result_type a, result_type b, int d>
157
+ struct xor_combine_engine_max_aux_2
158
+ {
159
+ using constants = xor_combine_engine_max_aux_constants<result_type, a, b, d>;
160
+
161
+ static const result_type value = thrust::detail::eval_if<
162
+ // if k is odd...
163
+ math::is_odd<result_type, constants::k>::value,
164
+ thrust::detail::identity_<
165
+ thrust::detail::integral_constant<result_type, xor_combine_engine_max_aux_case2<result_type, a, b, d>::value>>,
166
+ thrust::detail::eval_if<
167
+ // otherwise if a * 2^3 >= b, then case 3
168
+ a * constants::two_to_the_d >= b,
169
+ thrust::detail::identity_<
170
+ thrust::detail::integral_constant<result_type, xor_combine_engine_max_aux_case3<result_type, a, b, d>::value>>,
171
+ // otherwise, case 4
172
+ thrust::detail::identity_<
173
+ thrust::detail::integral_constant<result_type, xor_combine_engine_max_aux_case4<result_type, a, b, d>::value>>>>::
174
+ type::value;
175
+ };
176
+
177
+ template <typename result_type,
178
+ result_type a,
179
+ result_type b,
180
+ int d,
181
+ bool use_case1 = (a == 0) || (b < two_to_the_power<result_type, d>::value)>
182
+ struct xor_combine_engine_max_aux_1 : xor_combine_engine_max_aux_case1<result_type, a, b, d>
183
+ {};
184
+
185
+ template <typename result_type, result_type a, result_type b, int d>
186
+ struct xor_combine_engine_max_aux_1<result_type, a, b, d, false> : xor_combine_engine_max_aux_2<result_type, a, b, d>
187
+ {};
188
+
189
+ template <typename result_type, result_type a, result_type b, int d>
190
+ struct xor_combine_engine_max_aux : xor_combine_engine_max_aux_1<result_type, a, b, d>
191
+ {};
192
+
193
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2, typename result_type>
194
+ struct xor_combine_engine_max
195
+ {
196
+ static const size_t w = std::numeric_limits<result_type>::digits;
197
+
198
+ static const result_type m1 = math::
199
+ min<result_type, result_type(Engine1::max - Engine1::min), two_to_the_power<result_type, w - s1>::value - 1>::value;
200
+
201
+ static const result_type m2 = math::
202
+ min<result_type, result_type(Engine2::max - Engine2::min), two_to_the_power<result_type, w - s2>::value - 1>::value;
203
+
204
+ static const result_type s = s1 - s2;
205
+
206
+ static const result_type M = xor_combine_engine_max_aux<result_type, m1, m2, s>::value;
207
+
208
+ // the value is M(m1,m2,s) lshift_w s2
209
+ static const result_type value = lshift_w<result_type, w, M, s2>::value;
210
+ }; // end xor_combine_engine_max
211
+
212
+ } // namespace detail
213
+
214
+ } // namespace random
215
+
216
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/discard_block_engine.h ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file discard_block_engine.h
18
+ * \brief A random number engine which adapts a base engine and produces
19
+ * numbers by discarding all but a contiguous blocks of its values.
20
+ */
21
+
22
+ #pragma once
23
+
24
+ #include <thrust/detail/config.h>
25
+
26
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
27
+ # pragma GCC system_header
28
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
29
+ # pragma clang system_header
30
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
31
+ # pragma system_header
32
+ #endif // no system header
33
+
34
+ #include <thrust/random/detail/random_core_access.h>
35
+
36
+ #include <cstdint>
37
+ #include <iostream>
38
+
39
+ THRUST_NAMESPACE_BEGIN
40
+
41
+ namespace random
42
+ {
43
+
44
+ /*! \addtogroup random_number_engine_adaptors Random Number Engine Adaptor Class Templates
45
+ * \ingroup random
46
+ * \{
47
+ */
48
+
49
+ /*! \class discard_block_engine
50
+ * \brief A \p discard_block_engine adapts an existing base random number engine and produces
51
+ * random values by discarding some of the values returned by its base engine.
52
+ * Each cycle of the compound engine begins by returning \c r values successively produced
53
+ * by the base engine and ends by discarding <tt>p-r</tt> such values. The engine's state
54
+ * is the state of its base engine followed by the number of calls to <tt>operator()</tt>
55
+ * that have occurred since the beginning of the current cycle.
56
+ *
57
+ * \tparam Engine The type of the base random number engine to adapt.
58
+ * \tparam p The discard cycle length.
59
+ * \tparam r The number of values to return of the base engine. Because <tt>p-r</tt> will be
60
+ * discarded, <tt>r <= p</tt>.
61
+ *
62
+ * The following code snippet shows an example of using a \p discard_block_engine instance:
63
+ *
64
+ * \code
65
+ * #include <thrust/random/linear_congruential_engine.h>
66
+ * #include <thrust/random/discard_block_engine.h>
67
+ * #include <iostream>
68
+ *
69
+ * int main()
70
+ * {
71
+ * // create a discard_block_engine from minstd_rand, with a cycle length of 13
72
+ * // keep every first 10 values, and discard the next 3
73
+ * thrust::discard_block_engine<thrust::minstd_rand, 13, 10> rng;
74
+ *
75
+ * // print a random number to standard output
76
+ * std::cout << rng() << std::endl;
77
+ *
78
+ * return 0;
79
+ * }
80
+ * \endcode
81
+ */
82
+ template <typename Engine, size_t p, size_t r>
83
+ class discard_block_engine
84
+ {
85
+ public:
86
+ // types
87
+
88
+ /*! \typedef base_type
89
+ * \brief The type of the adapted base random number engine.
90
+ */
91
+ using base_type = Engine;
92
+
93
+ /*! \typedef result_type
94
+ * \brief The type of the unsigned integer produced by this \p linear_congruential_engine.
95
+ */
96
+ using result_type = typename base_type::result_type;
97
+
98
+ // engine characteristics
99
+
100
+ /*! The length of the production cycle.
101
+ */
102
+ static const size_t block_size = p;
103
+
104
+ /*! The number of used numbers per production cycle.
105
+ */
106
+ static const size_t used_block = r;
107
+
108
+ /*! The smallest value this \p discard_block_engine may potentially produce.
109
+ */
110
+ static const result_type min = base_type::min;
111
+
112
+ /*! The largest value this \p discard_block_engine may potentially produce.
113
+ */
114
+ static const result_type max = base_type::max;
115
+
116
+ // constructors and seeding functions
117
+
118
+ /*! This constructor constructs a new \p discard_block_engine and constructs
119
+ * its \p base_type engine using its null constructor.
120
+ */
121
+ _CCCL_HOST_DEVICE discard_block_engine();
122
+
123
+ /*! This constructor constructs a new \p discard_block_engine using
124
+ * a given \p base_type engine to initialize its adapted base engine.
125
+ *
126
+ * \param urng A \p base_type to use to initialize this \p discard_block_engine's
127
+ * adapted base engine.
128
+ */
129
+ _CCCL_HOST_DEVICE explicit discard_block_engine(const base_type& urng);
130
+
131
+ /*! This constructor initializes a new \p discard_block_engine with a given seed.
132
+ *
133
+ * \param s The seed used to initialize this \p discard_block_engine's adapted base engine.
134
+ */
135
+ _CCCL_HOST_DEVICE explicit discard_block_engine(result_type s);
136
+
137
+ /*! This method initializes the state of this \p discard_block_engine's adapted base engine
138
+ * by using its \p default_seed value.
139
+ */
140
+ _CCCL_HOST_DEVICE void seed();
141
+
142
+ /*! This method initializes the state of this \p discard_block_engine's adapted base engine
143
+ * by using the given seed.
144
+ *
145
+ * \param s The seed with which to initialize this \p discard_block_engine's adapted base engine.
146
+ */
147
+ _CCCL_HOST_DEVICE void seed(result_type s);
148
+
149
+ // generating functions
150
+
151
+ /*! This member function produces a new random value and updates this \p discard_block_engine's state.
152
+ * \return A new random number.
153
+ */
154
+ _CCCL_HOST_DEVICE result_type operator()(void);
155
+
156
+ /*! This member function advances this \p discard_block_engine's state a given number of times
157
+ * and discards the results.
158
+ *
159
+ * \param z The number of random values to discard.
160
+ * \note This function is provided because an implementation may be able to accelerate it.
161
+ */
162
+ _CCCL_HOST_DEVICE void discard(unsigned long long z);
163
+
164
+ // property functions
165
+
166
+ /*! This member function returns a const reference to this \p discard_block_engine's
167
+ * adapted base engine.
168
+ *
169
+ * \return A const reference to the base engine this \p discard_block_engine adapts.
170
+ */
171
+ _CCCL_HOST_DEVICE const base_type& base() const;
172
+
173
+ /*! \cond
174
+ */
175
+
176
+ private:
177
+ base_type m_e;
178
+ unsigned int m_n;
179
+
180
+ friend struct thrust::random::detail::random_core_access;
181
+
182
+ _CCCL_HOST_DEVICE bool equal(const discard_block_engine& rhs) const;
183
+
184
+ template <typename CharT, typename Traits>
185
+ std::basic_ostream<CharT, Traits>& stream_out(std::basic_ostream<CharT, Traits>& os) const;
186
+
187
+ template <typename CharT, typename Traits>
188
+ std::basic_istream<CharT, Traits>& stream_in(std::basic_istream<CharT, Traits>& is);
189
+ /*! \endcond
190
+ */
191
+ }; // end discard_block_engine
192
+
193
+ /*! This function checks two \p discard_block_engines for equality.
194
+ * \param lhs The first \p discard_block_engine to test.
195
+ * \param rhs The second \p discard_block_engine to test.
196
+ * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise.
197
+ */
198
+ template <typename Engine, size_t p, size_t r>
199
+ _CCCL_HOST_DEVICE bool
200
+ operator==(const discard_block_engine<Engine, p, r>& lhs, const discard_block_engine<Engine, p, r>& rhs);
201
+
202
+ /*! This function checks two \p discard_block_engines for inequality.
203
+ * \param lhs The first \p discard_block_engine to test.
204
+ * \param rhs The second \p discard_block_engine to test.
205
+ * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise.
206
+ */
207
+ template <typename Engine, size_t p, size_t r>
208
+ _CCCL_HOST_DEVICE bool
209
+ operator!=(const discard_block_engine<Engine, p, r>& lhs, const discard_block_engine<Engine, p, r>& rhs);
210
+
211
+ /*! This function streams a discard_block_engine to a \p std::basic_ostream.
212
+ * \param os The \p basic_ostream to stream out to.
213
+ * \param e The \p discard_block_engine to stream out.
214
+ * \return \p os
215
+ */
216
+ template <typename Engine, size_t p, size_t r, typename CharT, typename Traits>
217
+ std::basic_ostream<CharT, Traits>&
218
+ operator<<(std::basic_ostream<CharT, Traits>& os, const discard_block_engine<Engine, p, r>& e);
219
+
220
+ /*! This function streams a discard_block_engine in from a std::basic_istream.
221
+ * \param is The \p basic_istream to stream from.
222
+ * \param e The \p discard_block_engine to stream in.
223
+ * \return \p is
224
+ */
225
+ template <typename Engine, size_t p, size_t r, typename CharT, typename Traits>
226
+ std::basic_istream<CharT, Traits>&
227
+ operator>>(std::basic_istream<CharT, Traits>& is, discard_block_engine<Engine, p, r>& e);
228
+
229
+ /*! \} // end random_number_engine_adaptors
230
+ */
231
+
232
+ } // namespace random
233
+
234
+ // import names into thrust::
235
+ using random::discard_block_engine;
236
+
237
+ THRUST_NAMESPACE_END
238
+
239
+ #include <thrust/random/detail/discard_block_engine.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/linear_congruential_engine.h ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file linear_congruential_engine.h
18
+ * \brief A linear congruential pseudorandom number engine.
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <thrust/detail/config.h>
24
+
25
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
26
+ # pragma GCC system_header
27
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
28
+ # pragma clang system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
30
+ # pragma system_header
31
+ #endif // no system header
32
+ #include <thrust/random/detail/linear_congruential_engine_discard.h>
33
+ #include <thrust/random/detail/random_core_access.h>
34
+
35
+ #include <cstdint>
36
+ #include <iostream>
37
+
38
+ THRUST_NAMESPACE_BEGIN
39
+
40
+ namespace random
41
+ {
42
+
43
+ /*! \addtogroup random_number_engine_templates Random Number Engine Class Templates
44
+ * \ingroup random
45
+ * \{
46
+ */
47
+
48
+ /*! \class linear_congruential_engine
49
+ * \brief A \p linear_congruential_engine random number engine produces unsigned integer
50
+ * random numbers using a linear congruential random number generation algorithm.
51
+ *
52
+ * The generation algorithm has the form <tt>x_i = (a * x_{i-1} + c) mod m</tt>.
53
+ *
54
+ * \tparam UIntType The type of unsigned integer to produce.
55
+ * \tparam a The multiplier used in the generation algorithm.
56
+ * \tparam c The increment used in the generation algorithm.
57
+ * \tparam m The modulus used in the generation algorithm.
58
+ *
59
+ * \note Inexperienced users should not use this class template directly. Instead, use
60
+ * \p minstd_rand or \p minstd_rand0.
61
+ *
62
+ * The following code snippet shows examples of use of a \p linear_congruential_engine instance:
63
+ *
64
+ * \code
65
+ * #include <thrust/random/linear_congruential_engine.h>
66
+ * #include <iostream>
67
+ *
68
+ * int main()
69
+ * {
70
+ * // create a minstd_rand object, which is an instance of linear_congruential_engine
71
+ * thrust::minstd_rand rng1;
72
+ *
73
+ * // output some random values to cout
74
+ * std::cout << rng1() << std::endl;
75
+ *
76
+ * // a random value is printed
77
+ *
78
+ * // create a new minstd_rand from a seed
79
+ * thrust::minstd_rand rng2(13);
80
+ *
81
+ * // discard some random values
82
+ * rng2.discard(13);
83
+ *
84
+ * // stream the object to an iostream
85
+ * std::cout << rng2 << std::endl;
86
+ *
87
+ * // rng2's current state is printed
88
+ *
89
+ * // print the minimum and maximum values that minstd_rand can produce
90
+ * std::cout << thrust::minstd_rand::min << std::endl;
91
+ * std::cout << thrust::minstd_rand::max << std::endl;
92
+ *
93
+ * // the range of minstd_rand is printed
94
+ *
95
+ * // save the state of rng2 to a different object
96
+ * thrust::minstd_rand rng3 = rng2;
97
+ *
98
+ * // compare rng2 and rng3
99
+ * std::cout << (rng2 == rng3) << std::endl;
100
+ *
101
+ * // 1 is printed
102
+ *
103
+ * // re-seed rng2 with a different seed
104
+ * rng2.seed(7);
105
+ *
106
+ * // compare rng2 and rng3
107
+ * std::cout << (rng2 == rng3) << std::endl;
108
+ *
109
+ * // 0 is printed
110
+ *
111
+ * return 0;
112
+ * }
113
+ *
114
+ * \endcode
115
+ *
116
+ * \see thrust::random::minstd_rand
117
+ * \see thrust::random::minstd_rand0
118
+ */
119
+ template <typename UIntType, UIntType a, UIntType c, UIntType m>
120
+ class linear_congruential_engine
121
+ {
122
+ public:
123
+ // types
124
+
125
+ /*! \typedef result_type
126
+ * \brief The type of the unsigned integer produced by this \p linear_congruential_engine.
127
+ */
128
+ using result_type = UIntType;
129
+
130
+ // engine characteristics
131
+
132
+ /*! The multiplier used in the generation algorithm.
133
+ */
134
+ static const result_type multiplier = a;
135
+
136
+ /*! The increment used in the generation algorithm.
137
+ */
138
+ static const result_type increment = c;
139
+
140
+ /*! The modulus used in the generation algorithm.
141
+ */
142
+ static const result_type modulus = m;
143
+
144
+ /*! The smallest value this \p linear_congruential_engine may potentially produce.
145
+ */
146
+ #ifndef _CCCL_DOXYGEN_INVOKED // Doxygen breaks on the ternary :shrug:
147
+ static const result_type min = c == 0u ? 1u : 0u;
148
+ #else
149
+ static const result_type min = 0u;
150
+ #endif // _CCCL_DOXYGEN_INVOKED
151
+
152
+ /*! The largest value this \p linear_congruential_engine may potentially produce.
153
+ */
154
+ static const result_type max = m - 1u;
155
+
156
+ /*! The default seed of this \p linear_congruential_engine.
157
+ */
158
+ static const result_type default_seed = 1u;
159
+
160
+ // constructors and seeding functions
161
+
162
+ /*! This constructor, which optionally accepts a seed, initializes a new
163
+ * \p linear_congruential_engine.
164
+ *
165
+ * \param s The seed used to initialize this \p linear_congruential_engine's state.
166
+ */
167
+ _CCCL_HOST_DEVICE explicit linear_congruential_engine(result_type s = default_seed);
168
+
169
+ /*! This method initializes this \p linear_congruential_engine's state, and optionally accepts
170
+ * a seed value.
171
+ *
172
+ * \param s The seed used to initializes this \p linear_congruential_engine's state.
173
+ */
174
+ _CCCL_HOST_DEVICE void seed(result_type s = default_seed);
175
+
176
+ // generating functions
177
+
178
+ /*! This member function produces a new random value and updates this \p linear_congruential_engine's state.
179
+ * \return A new random number.
180
+ */
181
+ _CCCL_HOST_DEVICE result_type operator()(void);
182
+
183
+ /*! This member function advances this \p linear_congruential_engine's state a given number of times
184
+ * and discards the results.
185
+ *
186
+ * \param z The number of random values to discard.
187
+ * \note This function is provided because an implementation may be able to accelerate it.
188
+ */
189
+ _CCCL_HOST_DEVICE void discard(unsigned long long z);
190
+
191
+ /*! \cond
192
+ */
193
+
194
+ private:
195
+ result_type m_x;
196
+
197
+ static void transition(result_type& state);
198
+
199
+ friend struct thrust::random::detail::random_core_access;
200
+
201
+ friend struct thrust::random::detail::linear_congruential_engine_discard;
202
+
203
+ _CCCL_HOST_DEVICE bool equal(const linear_congruential_engine& rhs) const;
204
+
205
+ template <typename CharT, typename Traits>
206
+ std::basic_ostream<CharT, Traits>& stream_out(std::basic_ostream<CharT, Traits>& os) const;
207
+
208
+ template <typename CharT, typename Traits>
209
+ std::basic_istream<CharT, Traits>& stream_in(std::basic_istream<CharT, Traits>& is);
210
+
211
+ /*! \endcond
212
+ */
213
+ }; // end linear_congruential_engine
214
+
215
+ /*! This function checks two \p linear_congruential_engines for equality.
216
+ * \param lhs The first \p linear_congruential_engine to test.
217
+ * \param rhs The second \p linear_congruential_engine to test.
218
+ * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise.
219
+ */
220
+ template <typename UIntType_, UIntType_ a_, UIntType_ c_, UIntType_ m_>
221
+ _CCCL_HOST_DEVICE bool operator==(const linear_congruential_engine<UIntType_, a_, c_, m_>& lhs,
222
+ const linear_congruential_engine<UIntType_, a_, c_, m_>& rhs);
223
+
224
+ /*! This function checks two \p linear_congruential_engines for inequality.
225
+ * \param lhs The first \p linear_congruential_engine to test.
226
+ * \param rhs The second \p linear_congruential_engine to test.
227
+ * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise.
228
+ */
229
+ template <typename UIntType_, UIntType_ a_, UIntType_ c_, UIntType_ m_>
230
+ _CCCL_HOST_DEVICE bool operator!=(const linear_congruential_engine<UIntType_, a_, c_, m_>& lhs,
231
+ const linear_congruential_engine<UIntType_, a_, c_, m_>& rhs);
232
+
233
+ /*! This function streams a linear_congruential_engine to a \p std::basic_ostream.
234
+ * \param os The \p basic_ostream to stream out to.
235
+ * \param e The \p linear_congruential_engine to stream out.
236
+ * \return \p os
237
+ */
238
+ template <typename UIntType_, UIntType_ a_, UIntType_ c_, UIntType_ m_, typename CharT, typename Traits>
239
+ std::basic_ostream<CharT, Traits>&
240
+ operator<<(std::basic_ostream<CharT, Traits>& os, const linear_congruential_engine<UIntType_, a_, c_, m_>& e);
241
+
242
+ /*! This function streams a linear_congruential_engine in from a std::basic_istream.
243
+ * \param is The \p basic_istream to stream from.
244
+ * \param e The \p linear_congruential_engine to stream in.
245
+ * \return \p is
246
+ */
247
+ template <typename UIntType_, UIntType_ a_, UIntType_ c_, UIntType_ m_, typename CharT, typename Traits>
248
+ std::basic_istream<CharT, Traits>&
249
+ operator>>(std::basic_istream<CharT, Traits>& is, linear_congruential_engine<UIntType_, a_, c_, m_>& e);
250
+
251
+ /*! \} // random_number_engine_templates
252
+ */
253
+
254
+ /*! \addtogroup predefined_random
255
+ * \{
256
+ */
257
+
258
+ // XXX the type N2111 used here was uint_fast32_t
259
+
260
+ /*! \typedef minstd_rand0
261
+ * \brief A random number engine with predefined parameters which implements a version of
262
+ * the Minimal Standard random number generation algorithm.
263
+ * \note The 10000th consecutive invocation of a default-constructed object of type \p minstd_rand0
264
+ * shall produce the value \c 1043618065 .
265
+ */
266
+ using minstd_rand0 = linear_congruential_engine<std::uint32_t, 16807, 0, 2147483647>;
267
+
268
+ /*! \typedef minstd_rand
269
+ * \brief A random number engine with predefined parameters which implements a version of
270
+ * the Minimal Standard random number generation algorithm.
271
+ * \note The 10000th consecutive invocation of a default-constructed object of type \p minstd_rand
272
+ * shall produce the value \c 399268537 .
273
+ */
274
+ using minstd_rand = linear_congruential_engine<std::uint32_t, 48271, 0, 2147483647>;
275
+
276
+ /*! \} // predefined_random
277
+ */
278
+
279
+ } // namespace random
280
+
281
+ // import names into thrust::
282
+ using random::linear_congruential_engine;
283
+ using random::minstd_rand;
284
+ using random::minstd_rand0;
285
+
286
+ THRUST_NAMESPACE_END
287
+
288
+ #include <thrust/random/detail/linear_congruential_engine.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/linear_feedback_shift_engine.h ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file linear_feedback_shift_engine.h
18
+ * \brief A linear feedback shift pseudorandom number generator.
19
+ */
20
+
21
+ /*
22
+ * Copyright Jens Maurer 2002
23
+ *
24
+ * Distributed under the Boost Software License, Version 1.0.
25
+ * (See accompanying NOTICE file for the complete license)
26
+ *
27
+ * For more information, see http://www.boost.org
28
+ */
29
+
30
+ #pragma once
31
+
32
+ #include <thrust/detail/config.h>
33
+
34
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
35
+ # pragma GCC system_header
36
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
37
+ # pragma clang system_header
38
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
39
+ # pragma system_header
40
+ #endif // no system header
41
+ #include <thrust/random/detail/linear_feedback_shift_engine_wordmask.h>
42
+ #include <thrust/random/detail/random_core_access.h>
43
+
44
+ #include <cstddef> // for size_t
45
+ #include <iostream>
46
+
47
+ THRUST_NAMESPACE_BEGIN
48
+
49
+ namespace random
50
+ {
51
+
52
+ /*! \addtogroup random_number_engine_templates
53
+ * \{
54
+ */
55
+
56
+ /*! \class linear_feedback_shift_engine
57
+ * \brief A \p linear_feedback_shift_engine random number engine produces
58
+ * unsigned integer random values using a linear feedback shift random number
59
+ * generation algorithm.
60
+ *
61
+ * \tparam UIntType The type of unsigned integer to produce.
62
+ * \tparam w The word size of the produced values (<tt>w <= sizeof(UIntType)</tt>).
63
+ * \tparam k The k parameter of Tausworthe's 1965 algorithm.
64
+ * \tparam q The q exponent of Tausworthe's 1965 algorithm.
65
+ * \tparam s The step size of Tausworthe's 1965 algorithm.
66
+ *
67
+ * \note linear_feedback_shift_engine is based on the Boost Template Library's linear_feedback_shift.
68
+ */
69
+ template <typename UIntType, size_t w, size_t k, size_t q, size_t s>
70
+ class linear_feedback_shift_engine
71
+ {
72
+ public:
73
+ // types
74
+
75
+ /*! \typedef result_type
76
+ * \brief The type of the unsigned integer produced by this \p linear_feedback_shift_engine.
77
+ */
78
+ using result_type = UIntType;
79
+
80
+ // engine characteristics
81
+
82
+ /*! The word size of the produced values.
83
+ */
84
+ static const size_t word_size = w;
85
+
86
+ /*! A constant used in the generation algorithm.
87
+ */
88
+ static const size_t exponent1 = k;
89
+
90
+ /*! A constant used in the generation algorithm.
91
+ */
92
+ static const size_t exponent2 = q;
93
+
94
+ /*! The step size used in the generation algorithm.
95
+ */
96
+ static const size_t step_size = s;
97
+
98
+ /*! \cond
99
+ */
100
+
101
+ private:
102
+ static const result_type wordmask = detail::linear_feedback_shift_engine_wordmask<result_type, w>::value;
103
+ /*! \endcond
104
+ */
105
+
106
+ public:
107
+ /*! The smallest value this \p linear_feedback_shift_engine may potentially produce.
108
+ */
109
+ static const result_type min = 0;
110
+
111
+ /*! The largest value this \p linear_feedback_shift_engine may potentially produce.
112
+ */
113
+ static const result_type max = wordmask;
114
+
115
+ /*! The default seed of this \p linear_feedback_shift_engine.
116
+ */
117
+ static const result_type default_seed = 341u;
118
+
119
+ // constructors and seeding functions
120
+
121
+ /*! This constructor, which optionally accepts a seed, initializes a new
122
+ * \p linear_feedback_shift_engine.
123
+ *
124
+ * \param value The seed used to initialize this \p linear_feedback_shift_engine's state.
125
+ */
126
+ _CCCL_HOST_DEVICE explicit linear_feedback_shift_engine(result_type value = default_seed);
127
+
128
+ /*! This method initializes this \p linear_feedback_shift_engine's state, and optionally accepts
129
+ * a seed value.
130
+ *
131
+ * \param value The seed used to initializes this \p linear_feedback_shift_engine's state.
132
+ */
133
+ _CCCL_HOST_DEVICE void seed(result_type value = default_seed);
134
+
135
+ // generating functions
136
+
137
+ /*! This member function produces a new random value and updates this \p linear_feedback_shift_engine's state.
138
+ * \return A new random number.
139
+ */
140
+ _CCCL_HOST_DEVICE result_type operator()(void);
141
+
142
+ /*! This member function advances this \p linear_feedback_shift_engine's state a given number of times
143
+ * and discards the results.
144
+ *
145
+ * \param z The number of random values to discard.
146
+ * \note This function is provided because an implementation may be able to accelerate it.
147
+ */
148
+ _CCCL_HOST_DEVICE void discard(unsigned long long z);
149
+
150
+ /*! \cond
151
+ */
152
+
153
+ private:
154
+ result_type m_value;
155
+
156
+ friend struct thrust::random::detail::random_core_access;
157
+
158
+ _CCCL_HOST_DEVICE bool equal(const linear_feedback_shift_engine& rhs) const;
159
+
160
+ template <typename CharT, typename Traits>
161
+ std::basic_ostream<CharT, Traits>& stream_out(std::basic_ostream<CharT, Traits>& os) const;
162
+
163
+ template <typename CharT, typename Traits>
164
+ std::basic_istream<CharT, Traits>& stream_in(std::basic_istream<CharT, Traits>& is);
165
+
166
+ /*! \endcond
167
+ */
168
+ }; // end linear_feedback_shift_engine
169
+
170
+ /*! This function checks two \p linear_feedback_shift_engines for equality.
171
+ * \param lhs The first \p linear_feedback_shift_engine to test.
172
+ * \param rhs The second \p linear_feedback_shift_engine to test.
173
+ * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise.
174
+ */
175
+ template <typename UIntType_, size_t w_, size_t k_, size_t q_, size_t s_>
176
+ _CCCL_HOST_DEVICE bool operator==(const linear_feedback_shift_engine<UIntType_, w_, k_, q_, s_>& lhs,
177
+ const linear_feedback_shift_engine<UIntType_, w_, k_, q_, s_>& rhs);
178
+
179
+ /*! This function checks two \p linear_feedback_shift_engines for inequality.
180
+ * \param lhs The first \p linear_feedback_shift_engine to test.
181
+ * \param rhs The second \p linear_feedback_shift_engine to test.
182
+ * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise.
183
+ */
184
+ template <typename UIntType_, size_t w_, size_t k_, size_t q_, size_t s_>
185
+ _CCCL_HOST_DEVICE bool operator!=(const linear_feedback_shift_engine<UIntType_, w_, k_, q_, s_>& lhs,
186
+ const linear_feedback_shift_engine<UIntType_, w_, k_, q_, s_>& rhs);
187
+
188
+ /*! This function streams a linear_feedback_shift_engine to a \p std::basic_ostream.
189
+ * \param os The \p basic_ostream to stream out to.
190
+ * \param e The \p linear_feedback_shift_engine to stream out.
191
+ * \return \p os
192
+ */
193
+ template <typename UIntType_, size_t w_, size_t k_, size_t q_, size_t s_, typename CharT, typename Traits>
194
+ std::basic_ostream<CharT, Traits>&
195
+ operator<<(std::basic_ostream<CharT, Traits>& os, const linear_feedback_shift_engine<UIntType_, w_, k_, q_, s_>& e);
196
+
197
+ /*! This function streams a linear_feedback_shift_engine in from a std::basic_istream.
198
+ * \param is The \p basic_istream to stream from.
199
+ * \param e The \p linear_feedback_shift_engine to stream in.
200
+ * \return \p is
201
+ */
202
+ template <typename UIntType_, size_t w_, size_t k_, size_t q_, size_t s_, typename CharT, typename Traits>
203
+ std::basic_istream<CharT, Traits>&
204
+ operator>>(std::basic_istream<CharT, Traits>& is, linear_feedback_shift_engine<UIntType_, w_, k_, q_, s_>& e);
205
+
206
+ /*! \} // end random_number_engine_templates
207
+ */
208
+
209
+ } // namespace random
210
+
211
+ // import names into thrust::
212
+ using random::linear_feedback_shift_engine;
213
+
214
+ THRUST_NAMESPACE_END
215
+
216
+ #include <thrust/random/detail/linear_feedback_shift_engine.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/normal_distribution.h ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file normal_distribution.h
18
+ * \brief A normal (Gaussian) distribution of real-valued numbers.
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <thrust/detail/config.h>
24
+
25
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
26
+ # pragma GCC system_header
27
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
28
+ # pragma clang system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
30
+ # pragma system_header
31
+ #endif // no system header
32
+ #include <thrust/pair.h>
33
+ #include <thrust/random/detail/normal_distribution_base.h>
34
+ #include <thrust/random/detail/random_core_access.h>
35
+
36
+ #include <iostream>
37
+
38
+ THRUST_NAMESPACE_BEGIN
39
+
40
+ namespace random
41
+ {
42
+
43
+ /*! \addtogroup random_number_distributions
44
+ * \{
45
+ */
46
+
47
+ /*! \class normal_distribution
48
+ * \brief A \p normal_distribution random number distribution produces floating point
49
+ * Normally distributed random numbers.
50
+ *
51
+ * \tparam RealType The type of floating point number to produce.
52
+ *
53
+ * The following code snippet demonstrates examples of using a \p normal_distribution with a
54
+ * random number engine to produce random values drawn from the Normal distribution with a given
55
+ * mean and variance:
56
+ *
57
+ * \code
58
+ * #include <thrust/random/linear_congruential_engine.h>
59
+ * #include <thrust/random/normal_distribution.h>
60
+ *
61
+ * int main()
62
+ * {
63
+ * // create a minstd_rand object to act as our source of randomness
64
+ * thrust::minstd_rand rng;
65
+ *
66
+ * // create a normal_distribution to produce floats from the Normal distribution
67
+ * // with mean 2.0 and standard deviation 3.5
68
+ * thrust::random::normal_distribution<float> dist(2.0f, 3.5f);
69
+ *
70
+ * // write a random number to standard output
71
+ * std::cout << dist(rng) << std::endl;
72
+ *
73
+ * // write the mean of the distribution, just in case we forgot
74
+ * std::cout << dist.mean() << std::endl;
75
+ *
76
+ * // 2.0 is printed
77
+ *
78
+ * // and the standard deviation
79
+ * std::cout << dist.stddev() << std::endl;
80
+ *
81
+ * // 3.5 is printed
82
+ *
83
+ * return 0;
84
+ * }
85
+ * \endcode
86
+ */
87
+ template <typename RealType = double>
88
+ class normal_distribution : public detail::normal_distribution_base<RealType>::type
89
+ {
90
+ private:
91
+ using super_t = typename detail::normal_distribution_base<RealType>::type;
92
+
93
+ public:
94
+ // types
95
+
96
+ /*! \typedef result_type
97
+ * \brief The type of the floating point number produced by this \p normal_distribution.
98
+ */
99
+ using result_type = RealType;
100
+
101
+ /*! \typedef param_type
102
+ * \brief The type of the object encapsulating this \p normal_distribution's parameters.
103
+ */
104
+ using param_type = thrust::pair<RealType, RealType>;
105
+
106
+ // constructors and reset functions
107
+
108
+ /*! This constructor creates a new \p normal_distribution from two values defining the
109
+ * half-open interval of the distribution.
110
+ *
111
+ * \param mean The mean (expected value) of the distribution. Defaults to \c 0.0.
112
+ * \param stddev The standard deviation of the distribution. Defaults to \c 1.0.
113
+ */
114
+ _CCCL_HOST_DEVICE explicit normal_distribution(RealType mean = 0.0, RealType stddev = 1.0);
115
+
116
+ /*! This constructor creates a new \p normal_distribution from a \p param_type object
117
+ * encapsulating the range of the distribution.
118
+ *
119
+ * \param parm A \p param_type object encapsulating the parameters (i.e., the mean and standard deviation) of the
120
+ * distribution.
121
+ */
122
+ _CCCL_HOST_DEVICE explicit normal_distribution(const param_type& parm);
123
+
124
+ /*! Calling this member function guarantees that subsequent uses of this
125
+ * \p normal_distribution do not depend on values produced by any random
126
+ * number generator prior to invoking this function.
127
+ */
128
+ _CCCL_HOST_DEVICE void reset();
129
+
130
+ // generating functions
131
+
132
+ /*! This method produces a new Normal random integer drawn from this \p normal_distribution's
133
+ * range using a \p UniformRandomNumberGenerator as a source of randomness.
134
+ *
135
+ * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness.
136
+ */
137
+ template <typename UniformRandomNumberGenerator>
138
+ _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator& urng);
139
+
140
+ /*! This method produces a new Normal random integer as if by creating a new \p normal_distribution
141
+ * from the given \p param_type object, and calling its <tt>operator()</tt> method with the given
142
+ * \p UniformRandomNumberGenerator as a source of randomness.
143
+ *
144
+ * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness.
145
+ * \param parm A \p param_type object encapsulating the parameters of the \p normal_distribution
146
+ * to draw from.
147
+ */
148
+ template <typename UniformRandomNumberGenerator>
149
+ _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator& urng, const param_type& parm);
150
+
151
+ // property functions
152
+
153
+ /*! This method returns the value of the parameter with which this \p normal_distribution
154
+ * was constructed.
155
+ *
156
+ * \return The mean (expected value) of this \p normal_distribution's output.
157
+ */
158
+ _CCCL_HOST_DEVICE result_type mean() const;
159
+
160
+ /*! This method returns the value of the parameter with which this \p normal_distribution
161
+ * was constructed.
162
+ *
163
+ * \return The standard deviation of this \p uniform_real_distribution's output.
164
+ */
165
+ _CCCL_HOST_DEVICE result_type stddev() const;
166
+
167
+ /*! This method returns a \p param_type object encapsulating the parameters with which this
168
+ * \p normal_distribution was constructed.
169
+ *
170
+ * \return A \p param_type object encapsulating the parameters (i.e., the mean and standard deviation) of this \p
171
+ * normal_distribution.
172
+ */
173
+ _CCCL_HOST_DEVICE param_type param() const;
174
+
175
+ /*! This method changes the parameters of this \p normal_distribution using the values encapsulated
176
+ * in a given \p param_type object.
177
+ *
178
+ * \param parm A \p param_type object encapsulating the new parameters (i.e., the mean and variance) of this \p
179
+ * normal_distribution.
180
+ */
181
+ _CCCL_HOST_DEVICE void param(const param_type& parm);
182
+
183
+ /*! This method returns the smallest floating point number this \p normal_distribution can potentially produce.
184
+ *
185
+ * \return The lower bound of this \p normal_distribution's half-open interval.
186
+ */
187
+ _CCCL_HOST_DEVICE result_type min THRUST_PREVENT_MACRO_SUBSTITUTION() const;
188
+
189
+ /*! This method returns the smallest number larger than largest floating point number this \p
190
+ * uniform_real_distribution can potentially produce.
191
+ *
192
+ * \return The upper bound of this \p normal_distribution's half-open interval.
193
+ */
194
+ _CCCL_HOST_DEVICE result_type max THRUST_PREVENT_MACRO_SUBSTITUTION() const;
195
+
196
+ /*! \cond
197
+ */
198
+
199
+ private:
200
+ param_type m_param;
201
+
202
+ friend struct thrust::random::detail::random_core_access;
203
+
204
+ _CCCL_HOST_DEVICE bool equal(const normal_distribution& rhs) const;
205
+
206
+ template <typename CharT, typename Traits>
207
+ std::basic_ostream<CharT, Traits>& stream_out(std::basic_ostream<CharT, Traits>& os) const;
208
+
209
+ template <typename CharT, typename Traits>
210
+ std::basic_istream<CharT, Traits>& stream_in(std::basic_istream<CharT, Traits>& is);
211
+ /*! \endcond
212
+ */
213
+ }; // end normal_distribution
214
+
215
+ /*! This function checks two \p normal_distributions for equality.
216
+ * \param lhs The first \p normal_distribution to test.
217
+ * \param rhs The second \p normal_distribution to test.
218
+ * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise.
219
+ */
220
+ template <typename RealType>
221
+ _CCCL_HOST_DEVICE bool operator==(const normal_distribution<RealType>& lhs, const normal_distribution<RealType>& rhs);
222
+
223
+ /*! This function checks two \p normal_distributions for inequality.
224
+ * \param lhs The first \p normal_distribution to test.
225
+ * \param rhs The second \p normal_distribution to test.
226
+ * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise.
227
+ */
228
+ template <typename RealType>
229
+ _CCCL_HOST_DEVICE bool operator!=(const normal_distribution<RealType>& lhs, const normal_distribution<RealType>& rhs);
230
+
231
+ /*! This function streams a normal_distribution to a \p std::basic_ostream.
232
+ * \param os The \p basic_ostream to stream out to.
233
+ * \param d The \p normal_distribution to stream out.
234
+ * \return \p os
235
+ */
236
+ template <typename RealType, typename CharT, typename Traits>
237
+ std::basic_ostream<CharT, Traits>&
238
+ operator<<(std::basic_ostream<CharT, Traits>& os, const normal_distribution<RealType>& d);
239
+
240
+ /*! This function streams a normal_distribution in from a std::basic_istream.
241
+ * \param is The \p basic_istream to stream from.
242
+ * \param d The \p normal_distribution to stream in.
243
+ * \return \p is
244
+ */
245
+ template <typename RealType, typename CharT, typename Traits>
246
+ std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, normal_distribution<RealType>& d);
247
+
248
+ /*! \} // end random_number_distributions
249
+ */
250
+
251
+ } // namespace random
252
+
253
+ using random::normal_distribution;
254
+
255
+ THRUST_NAMESPACE_END
256
+
257
+ #include <thrust/random/detail/normal_distribution.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/subtract_with_carry_engine.h ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file subtract_with_carry_engine.h
18
+ * \brief A subtract-with-carry pseudorandom number generator
19
+ * based on Marsaglia & Zaman.
20
+ */
21
+
22
+ #pragma once
23
+
24
+ #include <thrust/detail/config.h>
25
+
26
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
27
+ # pragma GCC system_header
28
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
29
+ # pragma clang system_header
30
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
31
+ # pragma system_header
32
+ #endif // no system header
33
+
34
+ #include <thrust/random/detail/random_core_access.h>
35
+
36
+ #include <cstddef> // for size_t
37
+ #include <cstdint>
38
+ #include <iostream>
39
+
40
+ THRUST_NAMESPACE_BEGIN
41
+
42
+ namespace random
43
+ {
44
+
45
+ /*! \addtogroup random_number_engine_templates
46
+ * \{
47
+ */
48
+
49
+ /*! \class subtract_with_carry_engine
50
+ * \brief A \p subtract_with_carry_engine random number engine produces unsigned
51
+ * integer random numbers using the subtract with carry algorithm of Marsaglia & Zaman.
52
+ *
53
+ * The generation algorithm is performed as follows:
54
+ * -# Let <tt>Y = X_{i-s}- X_{i-r} - c</tt>.
55
+ * -# Set <tt>X_i</tt> to <tt>y = T mod m</tt>. Set \c c to \c 1 if <tt>Y < 0</tt>, otherwise set \c c to \c 0.
56
+ *
57
+ * This algorithm corresponds to a modular linear function of the form
58
+ *
59
+ * <tt>TA(x_i) = (a * x_i) mod b</tt>, where \c b is of the form <tt>m^r - m^s + 1</tt> and
60
+ * <tt>a = b - (b-1)/m</tt>.
61
+ *
62
+ * \tparam UIntType The type of unsigned integer to produce.
63
+ * \tparam w The word size of the produced values (<tt> w <= sizeof(UIntType)</tt>).
64
+ * \tparam s The short lag of the generation algorithm.
65
+ * \tparam r The long lag of the generation algorithm.
66
+ *
67
+ * \note Inexperienced users should not use this class template directly. Instead, use
68
+ * \p ranlux24_base or \p ranlux48_base, which are instances of \p subtract_with_carry_engine.
69
+ *
70
+ * \see thrust::random::ranlux24_base
71
+ * \see thrust::random::ranlux48_base
72
+ */
73
+ template <typename UIntType, size_t w, size_t s, size_t r>
74
+ class subtract_with_carry_engine
75
+ {
76
+ /*! \cond
77
+ */
78
+
79
+ private:
80
+ static const UIntType modulus = UIntType(1) << w;
81
+ /*! \endcond
82
+ */
83
+
84
+ public:
85
+ // types
86
+
87
+ /*! \typedef result_type
88
+ * \brief The type of the unsigned integer produced by this \p subtract_with_carry_engine.
89
+ */
90
+ using result_type = UIntType;
91
+
92
+ // engine characteristics
93
+
94
+ /*! The word size of the produced values.
95
+ */
96
+ static const size_t word_size = w;
97
+
98
+ /*! The size of the short lag used in the generation algorithm.
99
+ */
100
+ static const size_t short_lag = s;
101
+
102
+ /*! The size of the long lag used in the generation algorithm.
103
+ */
104
+ static const size_t long_lag = r;
105
+
106
+ /*! The smallest value this \p subtract_with_carry_engine may potentially produce.
107
+ */
108
+ static const result_type min = 0;
109
+
110
+ /*! The largest value this \p subtract_with_carry_engine may potentially produce.
111
+ */
112
+ static const result_type max = modulus - 1;
113
+
114
+ /*! The default seed of this \p subtract_with_carry_engine.
115
+ */
116
+ static const result_type default_seed = 19780503u;
117
+
118
+ // constructors and seeding functions
119
+
120
+ /*! This constructor, which optionally accepts a seed, initializes a new
121
+ * \p subtract_with_carry_engine.
122
+ *
123
+ * \param value The seed used to initialize this \p subtract_with_carry_engine's state.
124
+ */
125
+ _CCCL_HOST_DEVICE explicit subtract_with_carry_engine(result_type value = default_seed);
126
+
127
+ /*! This method initializes this \p subtract_with_carry_engine's state, and optionally accepts
128
+ * a seed value.
129
+ *
130
+ * \param value The seed used to initializes this \p subtract_with_carry_engine's state.
131
+ */
132
+ _CCCL_HOST_DEVICE void seed(result_type value = default_seed);
133
+
134
+ // generating functions
135
+
136
+ /*! This member function produces a new random value and updates this \p subtract_with_carry_engine's state.
137
+ * \return A new random number.
138
+ */
139
+ _CCCL_HOST_DEVICE result_type operator()(void);
140
+
141
+ /*! This member function advances this \p subtract_with_carry_engine's state a given number of times
142
+ * and discards the results.
143
+ *
144
+ * \param z The number of random values to discard.
145
+ * \note This function is provided because an implementation may be able to accelerate it.
146
+ */
147
+ _CCCL_HOST_DEVICE void discard(unsigned long long z);
148
+
149
+ /*! \cond
150
+ */
151
+
152
+ private:
153
+ result_type m_x[long_lag];
154
+ unsigned int m_k;
155
+ int m_carry;
156
+
157
+ friend struct thrust::random::detail::random_core_access;
158
+
159
+ _CCCL_HOST_DEVICE bool equal(const subtract_with_carry_engine& rhs) const;
160
+
161
+ template <typename CharT, typename Traits>
162
+ std::basic_ostream<CharT, Traits>& stream_out(std::basic_ostream<CharT, Traits>& os) const;
163
+
164
+ template <typename CharT, typename Traits>
165
+ std::basic_istream<CharT, Traits>& stream_in(std::basic_istream<CharT, Traits>& is);
166
+
167
+ /*! \endcond
168
+ */
169
+ }; // end subtract_with_carry_engine
170
+
171
+ /*! This function checks two \p subtract_with_carry_engines for equality.
172
+ * \param lhs The first \p subtract_with_carry_engine to test.
173
+ * \param rhs The second \p subtract_with_carry_engine to test.
174
+ * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise.
175
+ */
176
+ template <typename UIntType_, size_t w_, size_t s_, size_t r_>
177
+ _CCCL_HOST_DEVICE bool operator==(const subtract_with_carry_engine<UIntType_, w_, s_, r_>& lhs,
178
+ const subtract_with_carry_engine<UIntType_, w_, s_, r_>& rhs);
179
+
180
+ /*! This function checks two \p subtract_with_carry_engines for inequality.
181
+ * \param lhs The first \p subtract_with_carry_engine to test.
182
+ * \param rhs The second \p subtract_with_carry_engine to test.
183
+ * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise.
184
+ */
185
+ template <typename UIntType_, size_t w_, size_t s_, size_t r_>
186
+ _CCCL_HOST_DEVICE bool operator!=(const subtract_with_carry_engine<UIntType_, w_, s_, r_>& lhs,
187
+ const subtract_with_carry_engine<UIntType_, w_, s_, r_>& rhs);
188
+
189
+ /*! This function streams a subtract_with_carry_engine to a \p std::basic_ostream.
190
+ * \param os The \p basic_ostream to stream out to.
191
+ * \param e The \p subtract_with_carry_engine to stream out.
192
+ * \return \p os
193
+ */
194
+ template <typename UIntType_, size_t w_, size_t s_, size_t r_, typename CharT, typename Traits>
195
+ std::basic_ostream<CharT, Traits>&
196
+ operator<<(std::basic_ostream<CharT, Traits>& os, const subtract_with_carry_engine<UIntType_, w_, s_, r_>& e);
197
+
198
+ /*! This function streams a subtract_with_carry_engine in from a std::basic_istream.
199
+ * \param is The \p basic_istream to stream from.
200
+ * \param e The \p subtract_with_carry_engine to stream in.
201
+ * \return \p is
202
+ */
203
+ template <typename UIntType_, size_t w_, size_t s_, size_t r_, typename CharT, typename Traits>
204
+ std::basic_istream<CharT, Traits>&
205
+ operator>>(std::basic_istream<CharT, Traits>& is, subtract_with_carry_engine<UIntType_, w_, s_, r_>& e);
206
+
207
+ /*! \} // end random_number_engine_templates
208
+ */
209
+
210
+ /*! \addtogroup predefined_random
211
+ * \{
212
+ */
213
+
214
+ // XXX N2111 uses uint_fast32_t here
215
+
216
+ /*! \typedef ranlux24_base
217
+ * \brief A random number engine with predefined parameters which implements the
218
+ * base engine of the \p ranlux24 random number engine.
219
+ * \note The 10000th consecutive invocation of a default-constructed object of type \p ranlux24_base
220
+ * shall produce the value \c 7937952 .
221
+ */
222
+ using ranlux24_base = subtract_with_carry_engine<std::uint32_t, 24, 10, 24>;
223
+
224
+ // XXX N2111 uses uint_fast64_t here
225
+
226
+ /*! \typedef ranlux48_base
227
+ * \brief A random number engine with predefined parameters which implements the
228
+ * base engine of the \p ranlux48 random number engine.
229
+ * \note The 10000th consecutive invocation of a default-constructed object of type \p ranlux48_base
230
+ * shall produce the value \c 192113843633948 .
231
+ */
232
+ using ranlux48_base = subtract_with_carry_engine<std::uint64_t, 48, 5, 12>;
233
+
234
+ /*! \} // end predefined_random
235
+ */
236
+
237
+ } // namespace random
238
+
239
+ // import names into thrust::
240
+ using random::ranlux24_base;
241
+ using random::ranlux48_base;
242
+ using random::subtract_with_carry_engine;
243
+
244
+ THRUST_NAMESPACE_END
245
+
246
+ #include <thrust/random/detail/subtract_with_carry_engine.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/uniform_int_distribution.h ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file uniform_int_distribution.h
18
+ * \brief A uniform distribution of integer-valued numbers
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <thrust/detail/config.h>
24
+
25
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
26
+ # pragma GCC system_header
27
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
28
+ # pragma clang system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
30
+ # pragma system_header
31
+ #endif // no system header
32
+ #include <thrust/detail/integer_traits.h>
33
+ #include <thrust/pair.h>
34
+ #include <thrust/random/detail/random_core_access.h>
35
+
36
+ #include <iostream>
37
+
38
+ THRUST_NAMESPACE_BEGIN
39
+
40
+ namespace random
41
+ {
42
+
43
+ /*! \addtogroup random_number_distributions Random Number Distributions Class Templates
44
+ * \ingroup random
45
+ * \{
46
+ */
47
+
48
+ /*! \class uniform_int_distribution
49
+ * \brief A \p uniform_int_distribution random number distribution produces signed or unsigned integer
50
+ * uniform random numbers from a given range.
51
+ *
52
+ * \tparam IntType The type of integer to produce.
53
+ *
54
+ * The following code snippet demonstrates examples of using a \p uniform_int_distribution with a
55
+ * random number engine to produce random integers drawn from a given range:
56
+ *
57
+ * \code
58
+ * #include <thrust/random/linear_congruential_engine.h>
59
+ * #include <thrust/random/uniform_int_distribution.h>
60
+ *
61
+ * int main()
62
+ * {
63
+ * // create a minstd_rand object to act as our source of randomness
64
+ * thrust::minstd_rand rng;
65
+ *
66
+ * // create a uniform_int_distribution to produce ints from [-7,13]
67
+ * thrust::uniform_int_distribution<int> dist(-7,13);
68
+ *
69
+ * // write a random number from the range [-7,13] to standard output
70
+ * std::cout << dist(rng) << std::endl;
71
+ *
72
+ * // write the range of the distribution, just in case we forgot
73
+ * std::cout << dist.min() << std::endl;
74
+ *
75
+ * // -7 is printed
76
+ *
77
+ * std::cout << dist.max() << std::endl;
78
+ *
79
+ * // 13 is printed
80
+ *
81
+ * // write the parameters of the distribution (which happen to be the bounds) to standard output
82
+ * std::cout << dist.a() << std::endl;
83
+ *
84
+ * // -7 is printed
85
+ *
86
+ * std::cout << dist.b() << std::endl;
87
+ *
88
+ * // 13 is printed
89
+ *
90
+ * return 0;
91
+ * }
92
+ * \endcode
93
+ */
94
+ template <typename IntType = int>
95
+ class uniform_int_distribution
96
+ {
97
+ public:
98
+ // types
99
+
100
+ /*! \typedef result_type
101
+ * \brief The type of the integer produced by this \p uniform_int_distribution.
102
+ */
103
+ using result_type = IntType;
104
+
105
+ /*! \typedef param_type
106
+ * \brief The type of the object encapsulating this \p uniform_int_distribution's parameters.
107
+ */
108
+ using param_type = thrust::pair<IntType, IntType>;
109
+
110
+ // constructors and reset functions
111
+
112
+ /*! This constructor creates a new \p uniform_int_distribution from two values defining the
113
+ * range of the distribution.
114
+ *
115
+ * \param a The smallest integer to potentially produce. Defaults to \c 0.
116
+ * \param b The largest integer to potentially produce. Defaults to the largest representable integer in
117
+ * the platform.
118
+ */
119
+ _CCCL_HOST_DEVICE explicit uniform_int_distribution(
120
+ IntType a = 0, IntType b = THRUST_NS_QUALIFIER::detail::integer_traits<IntType>::const_max);
121
+
122
+ /*! This constructor creates a new \p uniform_int_distribution from a \p param_type object
123
+ * encapsulating the range of the distribution.
124
+ *
125
+ * \param parm A \p param_type object encapsulating the parameters (i.e., the range) of the distribution.
126
+ */
127
+ _CCCL_HOST_DEVICE explicit uniform_int_distribution(const param_type& parm);
128
+
129
+ /*! This does nothing. It is included to conform to the requirements of the RandomDistribution concept.
130
+ */
131
+ _CCCL_HOST_DEVICE void reset();
132
+
133
+ // generating functions
134
+
135
+ /*! This method produces a new uniform random integer drawn from this \p uniform_int_distribution's
136
+ * range using a \p UniformRandomNumberGenerator as a source of randomness.
137
+ *
138
+ * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness.
139
+ */
140
+ template <typename UniformRandomNumberGenerator>
141
+ _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator& urng);
142
+
143
+ /*! This method produces a new uniform random integer as if by creating a new \p uniform_int_distribution
144
+ * from the given \p param_type object, and calling its <tt>operator()</tt> method with the given
145
+ * \p UniformRandomNumberGenerator as a source of randomness.
146
+ *
147
+ * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness.
148
+ * \param parm A \p param_type object encapsulating the parameters of the \p uniform_int_distribution
149
+ * to draw from.
150
+ */
151
+ template <typename UniformRandomNumberGenerator>
152
+ _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator& urng, const param_type& parm);
153
+
154
+ // property functions
155
+
156
+ /*! This method returns the value of the parameter with which this \p uniform_int_distribution
157
+ * was constructed.
158
+ *
159
+ * \return The lower bound of this \p uniform_int_distribution's range.
160
+ */
161
+ _CCCL_HOST_DEVICE result_type a() const;
162
+
163
+ /*! This method returns the value of the parameter with which this \p uniform_int_distribution
164
+ * was constructed.
165
+ *
166
+ * \return The upper bound of this \p uniform_int_distribution's range.
167
+ */
168
+ _CCCL_HOST_DEVICE result_type b() const;
169
+
170
+ /*! This method returns a \p param_type object encapsulating the parameters with which this
171
+ * \p uniform_int_distribution was constructed.
172
+ *
173
+ * \return A \p param_type object enapsulating the range of this \p uniform_int_distribution.
174
+ */
175
+ _CCCL_HOST_DEVICE param_type param() const;
176
+
177
+ /*! This method changes the parameters of this \p uniform_int_distribution using the values encapsulated
178
+ * in a given \p param_type object.
179
+ *
180
+ * \param parm A \p param_type object encapsulating the new range of this \p uniform_int_distribution.
181
+ */
182
+ _CCCL_HOST_DEVICE void param(const param_type& parm);
183
+
184
+ /*! This method returns the smallest integer this \p uniform_int_distribution can potentially produce.
185
+ *
186
+ * \return The lower bound of this \p uniform_int_distribution's range.
187
+ */
188
+ _CCCL_HOST_DEVICE result_type min THRUST_PREVENT_MACRO_SUBSTITUTION() const;
189
+
190
+ /*! This method returns the largest integer this \p uniform_int_distribution can potentially produce.
191
+ *
192
+ * \return The upper bound of this \p uniform_int_distribution's range.
193
+ */
194
+ _CCCL_HOST_DEVICE result_type max THRUST_PREVENT_MACRO_SUBSTITUTION() const;
195
+
196
+ /*! \cond
197
+ */
198
+
199
+ private:
200
+ param_type m_param;
201
+
202
+ friend struct thrust::random::detail::random_core_access;
203
+
204
+ _CCCL_HOST_DEVICE bool equal(const uniform_int_distribution& rhs) const;
205
+
206
+ template <typename CharT, typename Traits>
207
+ std::basic_ostream<CharT, Traits>& stream_out(std::basic_ostream<CharT, Traits>& os) const;
208
+
209
+ template <typename CharT, typename Traits>
210
+ std::basic_istream<CharT, Traits>& stream_in(std::basic_istream<CharT, Traits>& is);
211
+ /*! \endcond
212
+ */
213
+ }; // end uniform_int_distribution
214
+
215
+ /*! This function checks two \p uniform_int_distributions for equality.
216
+ * \param lhs The first \p uniform_int_distribution to test.
217
+ * \param rhs The second \p uniform_int_distribution to test.
218
+ * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise.
219
+ */
220
+ template <typename IntType>
221
+ _CCCL_HOST_DEVICE bool
222
+ operator==(const uniform_int_distribution<IntType>& lhs, const uniform_int_distribution<IntType>& rhs);
223
+
224
+ /*! This function checks two \p uniform_int_distributions for inequality.
225
+ * \param lhs The first \p uniform_int_distribution to test.
226
+ * \param rhs The second \p uniform_int_distribution to test.
227
+ * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise.
228
+ */
229
+ template <typename IntType>
230
+ _CCCL_HOST_DEVICE bool
231
+ operator!=(const uniform_int_distribution<IntType>& lhs, const uniform_int_distribution<IntType>& rhs);
232
+
233
+ /*! This function streams a uniform_int_distribution to a \p std::basic_ostream.
234
+ * \param os The \p basic_ostream to stream out to.
235
+ * \param d The \p uniform_int_distribution to stream out.
236
+ * \return \p os
237
+ */
238
+ template <typename IntType, typename CharT, typename Traits>
239
+ std::basic_ostream<CharT, Traits>&
240
+ operator<<(std::basic_ostream<CharT, Traits>& os, const uniform_int_distribution<IntType>& d);
241
+
242
+ /*! This function streams a uniform_int_distribution in from a std::basic_istream.
243
+ * \param is The \p basic_istream to stream from.
244
+ * \param d The \p uniform_int_distribution to stream in.
245
+ * \return \p is
246
+ */
247
+ template <typename IntType, typename CharT, typename Traits>
248
+ std::basic_istream<CharT, Traits>&
249
+ operator>>(std::basic_istream<CharT, Traits>& is, uniform_int_distribution<IntType>& d);
250
+
251
+ /*! \} // end random_number_distributions
252
+ */
253
+
254
+ } // namespace random
255
+
256
+ using random::uniform_int_distribution;
257
+
258
+ THRUST_NAMESPACE_END
259
+
260
+ #include <thrust/random/detail/uniform_int_distribution.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/uniform_real_distribution.h ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file uniform_real_distribution.h
18
+ * \brief A uniform distribution of real-valued numbers
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <thrust/detail/config.h>
24
+
25
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
26
+ # pragma GCC system_header
27
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
28
+ # pragma clang system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
30
+ # pragma system_header
31
+ #endif // no system header
32
+ #include <thrust/pair.h>
33
+ #include <thrust/random/detail/random_core_access.h>
34
+
35
+ #include <iostream>
36
+
37
+ THRUST_NAMESPACE_BEGIN
38
+
39
+ namespace random
40
+ {
41
+
42
+ /*! \addtogroup random_number_distributions
43
+ * \{
44
+ */
45
+
46
+ /*! \class uniform_real_distribution
47
+ * \brief A \p uniform_real_distribution random number distribution produces floating point
48
+ * uniform random numbers from a half-open interval.
49
+ *
50
+ * \tparam RealType The type of floating point number to produce.
51
+ *
52
+ * The following code snippet demonstrates examples of using a \p uniform_real_distribution with a
53
+ * random number engine to produce random integers drawn from a given range:
54
+ *
55
+ * \code
56
+ * #include <thrust/random/linear_congruential_engine.h>
57
+ * #include <thrust/random/uniform_real_distribution.h>
58
+ *
59
+ * int main()
60
+ * {
61
+ * // create a minstd_rand object to act as our source of randomness
62
+ * thrust::minstd_rand rng;
63
+ *
64
+ * // create a uniform_real_distribution to produce floats from [-7,13)
65
+ * thrust::uniform_real_distribution<float> dist(-7,13);
66
+ *
67
+ * // write a random number from the range [-7,13) to standard output
68
+ * std::cout << dist(rng) << std::endl;
69
+ *
70
+ * // write the range of the distribution, just in case we forgot
71
+ * std::cout << dist.min() << std::endl;
72
+ *
73
+ * // -7.0 is printed
74
+ *
75
+ * std::cout << dist.max() << std::endl;
76
+ *
77
+ * // 13.0 is printed
78
+ *
79
+ * // write the parameters of the distribution (which happen to be the bounds) to standard output
80
+ * std::cout << dist.a() << std::endl;
81
+ *
82
+ * // -7.0 is printed
83
+ *
84
+ * std::cout << dist.b() << std::endl;
85
+ *
86
+ * // 13.0 is printed
87
+ *
88
+ * return 0;
89
+ * }
90
+ * \endcode
91
+ */
92
+ template <typename RealType = double>
93
+ class uniform_real_distribution
94
+ {
95
+ public:
96
+ // types
97
+
98
+ /*! \typedef result_type
99
+ * \brief The type of the floating point number produced by this \p uniform_real_distribution.
100
+ */
101
+ using result_type = RealType;
102
+
103
+ /*! \typedef param_type
104
+ * \brief The type of the object encapsulating this \p uniform_real_distribution's parameters.
105
+ */
106
+ using param_type = thrust::pair<RealType, RealType>;
107
+
108
+ // constructors and reset functions
109
+
110
+ /*! This constructor creates a new \p uniform_real_distribution from two values defining the
111
+ * half-open interval of the distribution.
112
+ *
113
+ * \param a The smallest floating point number to potentially produce. Defaults to \c 0.0.
114
+ * \param b The smallest number larger than the largest floating point number to potentially produce. Defaults to
115
+ * \c 1.0.
116
+ */
117
+ _CCCL_HOST_DEVICE explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
118
+
119
+ /*! This constructor creates a new \p uniform_real_distribution from a \p param_type object
120
+ * encapsulating the range of the distribution.
121
+ *
122
+ * \param parm A \p param_type object encapsulating the parameters (i.e., the range) of the distribution.
123
+ */
124
+ _CCCL_HOST_DEVICE explicit uniform_real_distribution(const param_type& parm);
125
+
126
+ /*! This does nothing. It is included to conform to the requirements of the RandomDistribution concept.
127
+ */
128
+ _CCCL_HOST_DEVICE void reset();
129
+
130
+ // generating functions
131
+
132
+ /*! This method produces a new uniform random integer drawn from this \p uniform_real_distribution's
133
+ * range using a \p UniformRandomNumberGenerator as a source of randomness.
134
+ *
135
+ * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness.
136
+ */
137
+ template <typename UniformRandomNumberGenerator>
138
+ _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator& urng);
139
+
140
+ /*! This method produces a new uniform random integer as if by creating a new \p uniform_real_distribution
141
+ * from the given \p param_type object, and calling its <tt>operator()</tt> method with the given
142
+ * \p UniformRandomNumberGenerator as a source of randomness.
143
+ *
144
+ * \param urng The \p UniformRandomNumberGenerator to use as a source of randomness.
145
+ * \param parm A \p param_type object encapsulating the parameters of the \p uniform_real_distribution
146
+ * to draw from.
147
+ */
148
+ template <typename UniformRandomNumberGenerator>
149
+ _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator& urng, const param_type& parm);
150
+
151
+ // property functions
152
+
153
+ /*! This method returns the value of the parameter with which this \p uniform_real_distribution
154
+ * was constructed.
155
+ *
156
+ * \return The lower bound of this \p uniform_real_distribution's half-open interval.
157
+ */
158
+ _CCCL_HOST_DEVICE result_type a() const;
159
+
160
+ /*! This method returns the value of the parameter with which this \p uniform_real_distribution
161
+ * was constructed.
162
+ *
163
+ * \return The upper bound of this \p uniform_real_distribution's half-open interval.
164
+ */
165
+ _CCCL_HOST_DEVICE result_type b() const;
166
+
167
+ /*! This method returns a \p param_type object encapsulating the parameters with which this
168
+ * \p uniform_real_distribution was constructed.
169
+ *
170
+ * \return A \p param_type object enapsulating the half-open interval of this \p uniform_real_distribution.
171
+ */
172
+ _CCCL_HOST_DEVICE param_type param() const;
173
+
174
+ /*! This method changes the parameters of this \p uniform_real_distribution using the values encapsulated
175
+ * in a given \p param_type object.
176
+ *
177
+ * \param parm A \p param_type object encapsulating the new half-open interval of this \p uniform_real_distribution.
178
+ */
179
+ _CCCL_HOST_DEVICE void param(const param_type& parm);
180
+
181
+ /*! This method returns the smallest floating point number this \p uniform_real_distribution can potentially produce.
182
+ *
183
+ * \return The lower bound of this \p uniform_real_distribution's half-open interval.
184
+ */
185
+ _CCCL_HOST_DEVICE result_type min THRUST_PREVENT_MACRO_SUBSTITUTION() const;
186
+
187
+ /*! This method returns the smallest number larger than largest floating point number this \p
188
+ * uniform_real_distribution can potentially produce.
189
+ *
190
+ * \return The upper bound of this \p uniform_real_distribution's half-open interval.
191
+ */
192
+ _CCCL_HOST_DEVICE result_type max THRUST_PREVENT_MACRO_SUBSTITUTION() const;
193
+
194
+ /*! \cond
195
+ */
196
+
197
+ private:
198
+ param_type m_param;
199
+
200
+ friend struct thrust::random::detail::random_core_access;
201
+
202
+ _CCCL_HOST_DEVICE bool equal(const uniform_real_distribution& rhs) const;
203
+
204
+ template <typename CharT, typename Traits>
205
+ std::basic_ostream<CharT, Traits>& stream_out(std::basic_ostream<CharT, Traits>& os) const;
206
+
207
+ template <typename CharT, typename Traits>
208
+ std::basic_istream<CharT, Traits>& stream_in(std::basic_istream<CharT, Traits>& is);
209
+ /*! \endcond
210
+ */
211
+ }; // end uniform_real_distribution
212
+
213
+ /*! This function checks two \p uniform_real_distributions for equality.
214
+ * \param lhs The first \p uniform_real_distribution to test.
215
+ * \param rhs The second \p uniform_real_distribution to test.
216
+ * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise.
217
+ */
218
+ template <typename RealType>
219
+ _CCCL_HOST_DEVICE bool
220
+ operator==(const uniform_real_distribution<RealType>& lhs, const uniform_real_distribution<RealType>& rhs);
221
+
222
+ /*! This function checks two \p uniform_real_distributions for inequality.
223
+ * \param lhs The first \p uniform_real_distribution to test.
224
+ * \param rhs The second \p uniform_real_distribution to test.
225
+ * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise.
226
+ */
227
+ template <typename RealType>
228
+ _CCCL_HOST_DEVICE bool
229
+ operator!=(const uniform_real_distribution<RealType>& lhs, const uniform_real_distribution<RealType>& rhs);
230
+
231
+ /*! This function streams a uniform_real_distribution to a \p std::basic_ostream.
232
+ * \param os The \p basic_ostream to stream out to.
233
+ * \param d The \p uniform_real_distribution to stream out.
234
+ * \return \p os
235
+ */
236
+ template <typename RealType, typename CharT, typename Traits>
237
+ std::basic_ostream<CharT, Traits>&
238
+ operator<<(std::basic_ostream<CharT, Traits>& os, const uniform_real_distribution<RealType>& d);
239
+
240
+ /*! This function streams a uniform_real_distribution in from a std::basic_istream.
241
+ * \param is The \p basic_istream to stream from.
242
+ * \param d The \p uniform_real_distribution to stream in.
243
+ * \return \p is
244
+ */
245
+ template <typename RealType, typename CharT, typename Traits>
246
+ std::basic_istream<CharT, Traits>&
247
+ operator>>(std::basic_istream<CharT, Traits>& is, uniform_real_distribution<RealType>& d);
248
+
249
+ /*! \} // end random_number_distributions
250
+ */
251
+
252
+ } // namespace random
253
+
254
+ using random::uniform_real_distribution;
255
+
256
+ THRUST_NAMESPACE_END
257
+
258
+ #include <thrust/random/detail/uniform_real_distribution.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random/xor_combine_engine.h ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file xor_combine_engine.h
18
+ * \brief A pseudorandom number generator which produces pseudorandom
19
+ * numbers from two integer base engines by merging their
20
+ * pseudorandom numbers with bitwise exclusive-or.
21
+ */
22
+
23
+ #pragma once
24
+
25
+ #include <thrust/detail/config.h>
26
+
27
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
28
+ # pragma GCC system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
30
+ # pragma clang system_header
31
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
32
+ # pragma system_header
33
+ #endif // no system header
34
+
35
+ #include <thrust/detail/type_traits.h>
36
+ #include <thrust/random/detail/random_core_access.h>
37
+ #include <thrust/random/detail/xor_combine_engine_max.h>
38
+
39
+ #include <cstddef> // for size_t
40
+ #include <iostream>
41
+
42
+ THRUST_NAMESPACE_BEGIN
43
+
44
+ namespace random
45
+ {
46
+
47
+ /*! \addtogroup random_number_engine_adaptors
48
+ * \{
49
+ */
50
+
51
+ /*! \class xor_combine_engine
52
+ * \brief An \p xor_combine_engine adapts two existing base random number engines and
53
+ * produces random values by combining the values produced by each.
54
+ *
55
+ * \tparam Engine1 The type of the first base random number engine to adapt.
56
+ * \tparam s1 The size of the first shift to use in the generation algorithm.
57
+ * \tparam Engine2 The type of the second base random number engine to adapt.
58
+ * \tparam s2 The second of the second shift to use in the generation algorithm. Defaults to \c 0.
59
+ *
60
+ * The following code snippet shows an example of using an \p xor_combine_engine instance:
61
+ *
62
+ * \code
63
+ * #include <thrust/random/linear_congruential_engine.h>
64
+ * #include <thrust/random/xor_combine_engine.h>
65
+ * #include <iostream>
66
+ *
67
+ * int main()
68
+ * {
69
+ * // create an xor_combine_engine from minstd_rand and minstd_rand0
70
+ * // use a shift of 0 for each
71
+ * thrust::xor_combine_engine<thrust::minstd_rand,0,thrust::minstd_rand0,0> rng;
72
+ *
73
+ * // print a random number to standard output
74
+ * std::cout << rng() << std::endl;
75
+ *
76
+ * return 0;
77
+ * }
78
+ * \endcode
79
+ */
80
+ template <typename Engine1, size_t s1, typename Engine2, size_t s2 = 0u>
81
+ class xor_combine_engine
82
+ {
83
+ public:
84
+ // types
85
+
86
+ /*! \typedef base1_type
87
+ * \brief The type of the first adapted base random number engine.
88
+ */
89
+ using base1_type = Engine1;
90
+
91
+ /*! \typedef base2_type
92
+ * \brief The type of the second adapted base random number engine.
93
+ */
94
+ using base2_type = Engine2;
95
+
96
+ /*! \typedef result_type
97
+ * \brief The type of the unsigned integer produced by this \p xor_combine_engine.
98
+ */
99
+ using result_type = typename thrust::detail::eval_if<
100
+ (sizeof(typename base2_type::result_type) > sizeof(typename base1_type::result_type)),
101
+ thrust::detail::identity_<typename base2_type::result_type>,
102
+ thrust::detail::identity_<typename base1_type::result_type>>::type;
103
+
104
+ /*! The size of the first shift used in the generation algorithm.
105
+ */
106
+ static const size_t shift1 = s1;
107
+
108
+ /*! The size of the second shift used in the generation algorithm.
109
+ */
110
+ static const size_t shift2 = s2;
111
+
112
+ /*! The smallest value this \p xor_combine_engine may potentially produce.
113
+ */
114
+ static const result_type min = 0;
115
+
116
+ /*! The largest value this \p xor_combine_engine may potentially produce.
117
+ */
118
+ static const result_type max = detail::xor_combine_engine_max<Engine1, s1, Engine2, s2, result_type>::value;
119
+
120
+ // constructors and seeding functions
121
+
122
+ /*! This constructor constructs a new \p xor_combine_engine and constructs
123
+ * its adapted engines using their null constructors.
124
+ */
125
+ _CCCL_HOST_DEVICE xor_combine_engine();
126
+
127
+ /*! This constructor constructs a new \p xor_combine_engine using
128
+ * given \p base1_type and \p base2_type engines to initialize its adapted base engines.
129
+ *
130
+ * \param urng1 A \p base1_type to use to initialize this \p xor_combine_engine's
131
+ * first adapted base engine.
132
+ * \param urng2 A \p base2_type to use to initialize this \p xor_combine_engine's
133
+ * first adapted base engine.
134
+ */
135
+ _CCCL_HOST_DEVICE xor_combine_engine(const base1_type& urng1, const base2_type& urng2);
136
+
137
+ /*! This constructor initializes a new \p xor_combine_engine with a given seed.
138
+ *
139
+ * \param s The seed used to initialize this \p xor_combine_engine's adapted base engines.
140
+ */
141
+ _CCCL_HOST_DEVICE xor_combine_engine(result_type s);
142
+
143
+ /*! This method initializes the state of this \p xor_combine_engine's adapted base engines
144
+ * by using their \p default_seed values.
145
+ */
146
+ _CCCL_HOST_DEVICE void seed();
147
+
148
+ /*! This method initializes the state of this \p xor_combine_engine's adapted base engines
149
+ * by using the given seed.
150
+ *
151
+ * \param s The seed with which to initialize this \p xor_combine_engine's adapted base engines.
152
+ */
153
+ _CCCL_HOST_DEVICE void seed(result_type s);
154
+
155
+ // generating functions
156
+
157
+ /*! This member function produces a new random value and updates this \p xor_combine_engine's state.
158
+ * \return A new random number.
159
+ */
160
+ _CCCL_HOST_DEVICE result_type operator()(void);
161
+
162
+ /*! This member function advances this \p xor_combine_engine's state a given number of times
163
+ * and discards the results.
164
+ *
165
+ * \param z The number of random values to discard.
166
+ * \note This function is provided because an implementation may be able to accelerate it.
167
+ */
168
+ _CCCL_HOST_DEVICE void discard(unsigned long long z);
169
+
170
+ // property functions
171
+
172
+ /*! This member function returns a const reference to this \p xor_combine_engine's
173
+ * first adapted base engine.
174
+ *
175
+ * \return A const reference to the first base engine this \p xor_combine_engine adapts.
176
+ */
177
+ _CCCL_HOST_DEVICE const base1_type& base1() const;
178
+
179
+ /*! This member function returns a const reference to this \p xor_combine_engine's
180
+ * second adapted base engine.
181
+ *
182
+ * \return A const reference to the second base engine this \p xor_combine_engine adapts.
183
+ */
184
+ _CCCL_HOST_DEVICE const base2_type& base2() const;
185
+
186
+ /*! \cond
187
+ */
188
+
189
+ private:
190
+ base1_type m_b1;
191
+ base2_type m_b2;
192
+
193
+ friend struct thrust::random::detail::random_core_access;
194
+
195
+ _CCCL_HOST_DEVICE bool equal(const xor_combine_engine& rhs) const;
196
+
197
+ template <typename CharT, typename Traits>
198
+ std::basic_istream<CharT, Traits>& stream_in(std::basic_istream<CharT, Traits>& is);
199
+
200
+ template <typename CharT, typename Traits>
201
+ std::basic_ostream<CharT, Traits>& stream_out(std::basic_ostream<CharT, Traits>& os) const;
202
+
203
+ /*! \endcond
204
+ */
205
+ }; // end xor_combine_engine
206
+
207
+ /*! This function checks two \p xor_combine_engines for equality.
208
+ * \param lhs The first \p xor_combine_engine to test.
209
+ * \param rhs The second \p xor_combine_engine to test.
210
+ * \return \c true if \p lhs is equal to \p rhs; \c false, otherwise.
211
+ */
212
+ template <typename Engine1_, size_t s1_, typename Engine2_, size_t s2_>
213
+ _CCCL_HOST_DEVICE bool operator==(const xor_combine_engine<Engine1_, s1_, Engine2_, s2_>& lhs,
214
+ const xor_combine_engine<Engine1_, s1_, Engine2_, s2_>& rhs);
215
+
216
+ /*! This function checks two \p xor_combine_engines for inequality.
217
+ * \param lhs The first \p xor_combine_engine to test.
218
+ * \param rhs The second \p xor_combine_engine to test.
219
+ * \return \c true if \p lhs is not equal to \p rhs; \c false, otherwise.
220
+ */
221
+ template <typename Engine1_, size_t s1_, typename Engine2_, size_t s2_>
222
+ _CCCL_HOST_DEVICE bool operator!=(const xor_combine_engine<Engine1_, s1_, Engine2_, s2_>& lhs,
223
+ const xor_combine_engine<Engine1_, s1_, Engine2_, s2_>& rhs);
224
+
225
+ /*! This function streams a xor_combine_engine to a \p std::basic_ostream.
226
+ * \param os The \p basic_ostream to stream out to.
227
+ * \param e The \p xor_combine_engine to stream out.
228
+ * \return \p os
229
+ */
230
+ template <typename Engine1_, size_t s1_, typename Engine2_, size_t s2_, typename CharT, typename Traits>
231
+ std::basic_ostream<CharT, Traits>&
232
+ operator<<(std::basic_ostream<CharT, Traits>& os, const xor_combine_engine<Engine1_, s1_, Engine2_, s2_>& e);
233
+
234
+ /*! This function streams a xor_combine_engine in from a std::basic_istream.
235
+ * \param is The \p basic_istream to stream from.
236
+ * \param e The \p xor_combine_engine to stream in.
237
+ * \return \p is
238
+ */
239
+ template <typename Engine1_, size_t s1_, typename Engine2_, size_t s2_, typename CharT, typename Traits>
240
+ std::basic_istream<CharT, Traits>&
241
+ operator>>(std::basic_istream<CharT, Traits>& is, xor_combine_engine<Engine1_, s1_, Engine2_, s2_>& e);
242
+
243
+ /*! \} // end random_number_engine_adaptors
244
+ */
245
+
246
+ } // namespace random
247
+
248
+ // import names into thrust::
249
+ using random::xor_combine_engine;
250
+
251
+ THRUST_NAMESPACE_END
252
+
253
+ #include <thrust/random/detail/xor_combine_engine.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/type_traits/is_execution_policy.h ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file
18
+ * \brief A type trait that determines if a type is an \a ExecutionPolicy.
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <thrust/detail/config.h>
24
+
25
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
26
+ # pragma GCC system_header
27
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
28
+ # pragma clang system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
30
+ # pragma system_header
31
+ #endif // no system header
32
+
33
+ #include <thrust/detail/execution_policy.h>
34
+ #include <thrust/detail/type_traits.h>
35
+
36
+ THRUST_NAMESPACE_BEGIN
37
+
38
+ /*! \addtogroup utility
39
+ * \{
40
+ */
41
+
42
+ /*! \addtogroup type_traits Type Traits
43
+ * \{
44
+ */
45
+
46
+ /*! \brief <a href="https://en.cppreference.com/w/cpp/named_req/UnaryTypeTrait"><i>UnaryTypeTrait</i></a>
47
+ * that returns \c true_type if \c T is an \a ExecutionPolicy and \c false_type
48
+ * otherwise.
49
+ */
50
+ template <typename T>
51
+ using is_execution_policy = ::cuda::std::is_base_of<detail::execution_policy_marker, T>;
52
+
53
+ #if _CCCL_STD_VER >= 2014
54
+ /*! \brief <tt>constexpr bool</tt> that is \c true if \c T is an
55
+ * \a ExecutionPolicy and \c false otherwise.
56
+ */
57
+ template <typename T>
58
+ constexpr bool is_execution_policy_v = is_execution_policy<T>::value;
59
+ #endif
60
+
61
+ /*! \} // type traits
62
+ */
63
+
64
+ /*! \} // utility
65
+ */
66
+
67
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/type_traits/is_trivially_relocatable.h ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file
18
+ * \brief <a href="https://wg21.link/P1144">P1144</a>'s proposed
19
+ * \c std::is_trivially_relocatable, an extensible type trait indicating
20
+ * whether a type can be bitwise copied with a facility like
21
+ * <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>.
22
+ */
23
+
24
+ #pragma once
25
+
26
+ #include <thrust/detail/config.h>
27
+
28
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
29
+ # pragma GCC system_header
30
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
31
+ # pragma clang system_header
32
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
33
+ # pragma system_header
34
+ #endif // no system header
35
+ #include <thrust/detail/static_assert.h>
36
+ #include <thrust/detail/type_traits.h>
37
+ #include <thrust/type_traits/is_contiguous_iterator.h>
38
+
39
+ #include <cuda/std/__fwd/pair.h>
40
+ #include <cuda/std/__fwd/tuple.h>
41
+ #include <cuda/std/__type_traits/conjunction.h>
42
+
43
+ #include <type_traits>
44
+
45
+ THRUST_NAMESPACE_BEGIN
46
+
47
+ /*! \addtogroup utility
48
+ * \{
49
+ */
50
+
51
+ /*! \addtogroup type_traits Type Traits
52
+ * \{
53
+ */
54
+
55
+ /*! \cond
56
+ */
57
+
58
+ namespace detail
59
+ {
60
+
61
+ template <typename T>
62
+ struct is_trivially_relocatable_impl;
63
+
64
+ } // namespace detail
65
+
66
+ /*! \endcond
67
+ */
68
+
69
+ /*! \brief <a href="https://en.cppreference.com/w/cpp/named_req/UnaryTypeTrait"><i>UnaryTypeTrait</i></a>
70
+ * that returns \c true_type if \c T is
71
+ * <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
72
+ * aka can be bitwise copied with a facility like
73
+ * <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
74
+ * and \c false_type otherwise.
75
+ *
76
+ * \see is_trivially_relocatable_v
77
+ * \see is_trivially_relocatable_to
78
+ * \see is_indirectly_trivially_relocatable_to
79
+ * \see proclaim_trivially_relocatable
80
+ * \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
81
+ */
82
+ template <typename T>
83
+ using is_trivially_relocatable = detail::is_trivially_relocatable_impl<T>;
84
+
85
+ #if _CCCL_STD_VER >= 2014
86
+ /*! \brief <tt>constexpr bool</tt> that is \c true if \c T is
87
+ * <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
88
+ * aka can be bitwise copied with a facility like
89
+ * <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
90
+ * and \c false otherwise.
91
+ *
92
+ * \see is_trivially_relocatable
93
+ * \see is_trivially_relocatable_to
94
+ * \see is_indirectly_trivially_relocatable_to
95
+ * \see proclaim_trivially_relocatable
96
+ * \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
97
+ */
98
+ template <typename T>
99
+ constexpr bool is_trivially_relocatable_v = is_trivially_relocatable<T>::value;
100
+ #endif
101
+
102
+ /*! \brief <a href="https://en.cppreference.com/w/cpp/named_req/BinaryTypeTrait"><i>BinaryTypeTrait</i></a>
103
+ * that returns \c true_type if \c From is
104
+ * <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
105
+ * to \c To, aka can be bitwise copied with a facility like
106
+ * <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
107
+ * and \c false_type otherwise.
108
+ *
109
+ * \see is_trivially_relocatable_to_v
110
+ * \see is_trivially_relocatable
111
+ * \see is_indirectly_trivially_relocatable_to
112
+ * \see proclaim_trivially_relocatable
113
+ * \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
114
+ */
115
+ template <typename From, typename To>
116
+ using is_trivially_relocatable_to =
117
+ integral_constant<bool, ::cuda::std::is_same<From, To>::value && is_trivially_relocatable<To>::value>;
118
+
119
+ #if _CCCL_STD_VER >= 2014
120
+ /*! \brief <tt>constexpr bool</tt> that is \c true if \c From is
121
+ * <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
122
+ * to \c To, aka can be bitwise copied with a facility like
123
+ * <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
124
+ * and \c false otherwise.
125
+ *
126
+ * \see is_trivially_relocatable_to
127
+ * \see is_trivially_relocatable
128
+ * \see is_indirectly_trivially_relocatable_to
129
+ * \see proclaim_trivially_relocatable
130
+ * \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
131
+ */
132
+ template <typename From, typename To>
133
+ constexpr bool is_trivially_relocatable_to_v = is_trivially_relocatable_to<From, To>::value;
134
+ #endif
135
+
136
+ /*! \brief <a href="https://en.cppreference.com/w/cpp/named_req/BinaryTypeTrait"><i>BinaryTypeTrait</i></a>
137
+ * that returns \c true_type if the element type of \c FromIterator is
138
+ * <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
139
+ * to the element type of \c ToIterator, aka can be bitwise copied with a
140
+ * facility like
141
+ * <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
142
+ * and \c false_type otherwise.
143
+ *
144
+ * \see is_indirectly_trivially_relocatable_to_v
145
+ * \see is_trivially_relocatable
146
+ * \see is_trivially_relocatable_to
147
+ * \see proclaim_trivially_relocatable
148
+ * \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
149
+ */
150
+ template <typename FromIterator, typename ToIterator>
151
+ using is_indirectly_trivially_relocatable_to =
152
+ integral_constant<bool,
153
+ is_contiguous_iterator<FromIterator>::value && is_contiguous_iterator<ToIterator>::value
154
+ && is_trivially_relocatable_to<typename thrust::iterator_traits<FromIterator>::value_type,
155
+ typename thrust::iterator_traits<ToIterator>::value_type>::value>;
156
+
157
+ #if _CCCL_STD_VER >= 2014
158
+ /*! \brief <tt>constexpr bool</tt> that is \c true if the element type of
159
+ * \c FromIterator is
160
+ * <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
161
+ * to the element type of \c ToIterator, aka can be bitwise copied with a
162
+ * facility like
163
+ * <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
164
+ * and \c false otherwise.
165
+ *
166
+ * \see is_indirectly_trivially_relocatable_to
167
+ * \see is_trivially_relocatable
168
+ * \see is_trivially_relocatable_to
169
+ * \see proclaim_trivially_relocatable
170
+ * \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
171
+ */
172
+ template <typename FromIterator, typename ToIterator>
173
+ constexpr bool is_indirectly_trivially_relocate_to_v =
174
+ is_indirectly_trivially_relocatable_to<FromIterator, ToIterator>::value;
175
+ #endif
176
+
177
+ /*! \brief <a href="http://eel.is/c++draft/namespace.std#def:customization_point"><i>customization point</i></a>
178
+ * that can be specialized customized to indicate that a type \c T is
179
+ * <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
180
+ * aka it can be bitwise copied with a facility like
181
+ * <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>.
182
+ *
183
+ * \see is_indirectly_trivially_relocatable_to
184
+ * \see is_trivially_relocatable
185
+ * \see is_trivially_relocatable_to
186
+ * \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
187
+ */
188
+ template <typename T>
189
+ struct proclaim_trivially_relocatable : false_type
190
+ {};
191
+
192
+ /*! \brief Declares that the type \c T is
193
+ * <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
194
+ * aka it can be bitwise copied with a facility like
195
+ * <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
196
+ * by specializing \c proclaim_trivially_relocatable.
197
+ *
198
+ * \see is_indirectly_trivially_relocatable_to
199
+ * \see is_trivially_relocatable
200
+ * \see is_trivially_relocatable_to
201
+ * \see proclaim_trivially_relocatable
202
+ */
203
+ #define THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(T) \
204
+ THRUST_NAMESPACE_BEGIN \
205
+ template <> \
206
+ struct proclaim_trivially_relocatable<T> : THRUST_NS_QUALIFIER::true_type \
207
+ {}; \
208
+ THRUST_NAMESPACE_END \
209
+ /**/
210
+
211
+ ///////////////////////////////////////////////////////////////////////////////
212
+
213
+ /*! \cond
214
+ */
215
+
216
+ namespace detail
217
+ {
218
+
219
+ // https://wg21.link/P1144R0#wording-inheritance
220
+ template <typename T>
221
+ struct is_trivially_relocatable_impl
222
+ : integral_constant<bool, ::cuda::std::is_trivially_copyable<T>::value || proclaim_trivially_relocatable<T>::value>
223
+ {};
224
+
225
+ template <typename T, std::size_t N>
226
+ struct is_trivially_relocatable_impl<T[N]> : is_trivially_relocatable_impl<T>
227
+ {};
228
+
229
+ } // namespace detail
230
+
231
+ THRUST_NAMESPACE_END
232
+
233
+ #if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
234
+
235
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(char1)
236
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(char2)
237
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(char3)
238
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(char4)
239
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uchar1)
240
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uchar2)
241
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uchar3)
242
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uchar4)
243
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(short1)
244
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(short2)
245
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(short3)
246
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(short4)
247
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ushort1)
248
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ushort2)
249
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ushort3)
250
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ushort4)
251
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(int1)
252
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(int2)
253
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(int3)
254
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(int4)
255
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uint1)
256
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uint2)
257
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uint3)
258
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uint4)
259
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(long1)
260
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(long2)
261
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(long3)
262
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(long4)
263
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulong1)
264
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulong2)
265
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulong3)
266
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulong4)
267
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(longlong1)
268
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(longlong2)
269
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(longlong3)
270
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(longlong4)
271
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulonglong1)
272
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulonglong2)
273
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulonglong3)
274
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulonglong4)
275
+
276
+ struct __half;
277
+ struct __half2;
278
+
279
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(__half)
280
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(__half2)
281
+
282
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(float1)
283
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(float2)
284
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(float3)
285
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(float4)
286
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(double1)
287
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(double2)
288
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(double3)
289
+ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(double4)
290
+ #endif
291
+
292
+ THRUST_NAMESPACE_BEGIN
293
+ template <typename T, typename U>
294
+ struct proclaim_trivially_relocatable<::cuda::std::pair<T, U>>
295
+ : ::cuda::std::conjunction<is_trivially_relocatable<T>, is_trivially_relocatable<U>>
296
+ {};
297
+
298
+ template <typename... Ts>
299
+ struct proclaim_trivially_relocatable<::cuda::std::tuple<Ts...>>
300
+ : ::cuda::std::conjunction<is_trivially_relocatable<Ts>...>
301
+ {};
302
+ THRUST_NAMESPACE_END
303
+
304
+ /*! \endcond
305
+ */
306
+
307
+ ///////////////////////////////////////////////////////////////////////////////
308
+
309
+ /*! \} // type traits
310
+ */
311
+
312
+ /*! \} // utility
313
+ */
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/type_traits/void_t.h ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2018-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file
18
+ * \brief C++17's `void_t`.
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <thrust/detail/config.h>
24
+
25
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
26
+ # pragma GCC system_header
27
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
28
+ # pragma clang system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
30
+ # pragma system_header
31
+ #endif // no system header
32
+
33
+ THRUST_NAMESPACE_BEGIN
34
+
35
+ /*! \addtogroup utility
36
+ * \{
37
+ */
38
+
39
+ /*! \addtogroup type_traits Type Traits
40
+ * \{
41
+ */
42
+
43
+ template <typename...>
44
+ struct CCCL_DEPRECATED_BECAUSE("Use ::cuda::std::void_t") voider
45
+ {
46
+ using type = void;
47
+ };
48
+
49
+ template <typename... Ts>
50
+ using void_t CCCL_DEPRECATED_BECAUSE("Use ::cuda::std::void_t") = void;
51
+
52
+ /*! \} // type traits
53
+ */
54
+
55
+ /*! \} // utility
56
+ */
57
+
58
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_dlpack/LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2017 by Contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_dlpack/dlpack.h ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * Copyright (c) 2017 by Contributors
3
+ * \file dlpack.h
4
+ * \brief The common header of DLPack.
5
+ */
6
+ #ifndef DLPACK_DLPACK_H_
7
+ #define DLPACK_DLPACK_H_
8
+
9
+ /**
10
+ * \brief Compatibility with C++
11
+ */
12
+ #ifdef __cplusplus
13
+ #define DLPACK_EXTERN_C extern "C"
14
+ #else
15
+ #define DLPACK_EXTERN_C
16
+ #endif
17
+
18
+ /*! \brief The current major version of dlpack */
19
+ #define DLPACK_MAJOR_VERSION 1
20
+
21
+ /*! \brief The current minor version of dlpack */
22
+ #define DLPACK_MINOR_VERSION 0
23
+
24
+ /*! \brief DLPACK_DLL prefix for windows */
25
+ #ifdef _WIN32
26
+ #ifdef DLPACK_EXPORTS
27
+ #define DLPACK_DLL __declspec(dllexport)
28
+ #else
29
+ #define DLPACK_DLL __declspec(dllimport)
30
+ #endif
31
+ #else
32
+ #define DLPACK_DLL
33
+ #endif
34
+
35
+ #include <stdint.h>
36
+ #include <stddef.h>
37
+
38
+ #ifdef __cplusplus
39
+ extern "C" {
40
+ #endif
41
+
42
+ /*!
43
+ * \brief The DLPack version.
44
+ *
45
+ * A change in major version indicates that we have changed the
46
+ * data layout of the ABI - DLManagedTensorVersioned.
47
+ *
48
+ * A change in minor version indicates that we have added new
49
+ * code, such as a new device type, but the ABI is kept the same.
50
+ *
51
+ * If an obtained DLPack tensor has a major version that disagrees
52
+ * with the version number specified in this header file
53
+ * (i.e. major != DLPACK_MAJOR_VERSION), the consumer must call the deleter
54
+ * (and it is safe to do so). It is not safe to access any other fields
55
+ * as the memory layout will have changed.
56
+ *
57
+ * In the case of a minor version mismatch, the tensor can be safely used as
58
+ * long as the consumer knows how to interpret all fields. Minor version
59
+ * updates indicate the addition of enumeration values.
60
+ */
61
+ typedef struct {
62
+ /*! \brief DLPack major version. */
63
+ uint32_t major;
64
+ /*! \brief DLPack minor version. */
65
+ uint32_t minor;
66
+ } DLPackVersion;
67
+
68
+ /*!
69
+ * \brief The device type in DLDevice.
70
+ */
71
+ #ifdef __cplusplus
72
+ typedef enum : int32_t {
73
+ #else
74
+ typedef enum {
75
+ #endif
76
+ /*! \brief CPU device */
77
+ kDLCPU = 1,
78
+ /*! \brief CUDA GPU device */
79
+ kDLCUDA = 2,
80
+ /*!
81
+ * \brief Pinned CUDA CPU memory by cudaMallocHost
82
+ */
83
+ kDLCUDAHost = 3,
84
+ /*! \brief OpenCL devices. */
85
+ kDLOpenCL = 4,
86
+ /*! \brief Vulkan buffer for next generation graphics. */
87
+ kDLVulkan = 7,
88
+ /*! \brief Metal for Apple GPU. */
89
+ kDLMetal = 8,
90
+ /*! \brief Verilog simulator buffer */
91
+ kDLVPI = 9,
92
+ /*! \brief ROCm GPUs for AMD GPUs */
93
+ kDLROCM = 10,
94
+ /*!
95
+ * \brief Pinned ROCm CPU memory allocated by hipMallocHost
96
+ */
97
+ kDLROCMHost = 11,
98
+ /*!
99
+ * \brief Reserved extension device type,
100
+ * used for quickly test extension device
101
+ * The semantics can differ depending on the implementation.
102
+ */
103
+ kDLExtDev = 12,
104
+ /*!
105
+ * \brief CUDA managed/unified memory allocated by cudaMallocManaged
106
+ */
107
+ kDLCUDAManaged = 13,
108
+ /*!
109
+ * \brief Unified shared memory allocated on a oneAPI non-partititioned
110
+ * device. Call to oneAPI runtime is required to determine the device
111
+ * type, the USM allocation type and the sycl context it is bound to.
112
+ *
113
+ */
114
+ kDLOneAPI = 14,
115
+ /*! \brief GPU support for next generation WebGPU standard. */
116
+ kDLWebGPU = 15,
117
+ /*! \brief Qualcomm Hexagon DSP */
118
+ kDLHexagon = 16,
119
+ /*! \brief Microsoft MAIA devices */
120
+ kDLMAIA = 17,
121
+ } DLDeviceType;
122
+
123
+ /*!
124
+ * \brief A Device for Tensor and operator.
125
+ */
126
+ typedef struct {
127
+ /*! \brief The device type used in the device. */
128
+ DLDeviceType device_type;
129
+ /*!
130
+ * \brief The device index.
131
+ * For vanilla CPU memory, pinned memory, or managed memory, this is set to 0.
132
+ */
133
+ int32_t device_id;
134
+ } DLDevice;
135
+
136
+ /*!
137
+ * \brief The type code options DLDataType.
138
+ */
139
+ typedef enum {
140
+ /*! \brief signed integer */
141
+ kDLInt = 0U,
142
+ /*! \brief unsigned integer */
143
+ kDLUInt = 1U,
144
+ /*! \brief IEEE floating point */
145
+ kDLFloat = 2U,
146
+ /*!
147
+ * \brief Opaque handle type, reserved for testing purposes.
148
+ * Frameworks need to agree on the handle data type for the exchange to be well-defined.
149
+ */
150
+ kDLOpaqueHandle = 3U,
151
+ /*! \brief bfloat16 */
152
+ kDLBfloat = 4U,
153
+ /*!
154
+ * \brief complex number
155
+ * (C/C++/Python layout: compact struct per complex number)
156
+ */
157
+ kDLComplex = 5U,
158
+ /*! \brief boolean */
159
+ kDLBool = 6U,
160
+ } DLDataTypeCode;
161
+
162
+ /*!
163
+ * \brief The data type the tensor can hold. The data type is assumed to follow the
164
+ * native endian-ness. An explicit error message should be raised when attempting to
165
+ * export an array with non-native endianness
166
+ *
167
+ * Examples
168
+ * - float: type_code = 2, bits = 32, lanes = 1
169
+ * - float4(vectorized 4 float): type_code = 2, bits = 32, lanes = 4
170
+ * - int8: type_code = 0, bits = 8, lanes = 1
171
+ * - std::complex<float>: type_code = 5, bits = 64, lanes = 1
172
+ * - bool: type_code = 6, bits = 8, lanes = 1 (as per common array library convention, the underlying storage size of bool is 8 bits)
173
+ */
174
+ typedef struct {
175
+ /*!
176
+ * \brief Type code of base types.
177
+ * We keep it uint8_t instead of DLDataTypeCode for minimal memory
178
+ * footprint, but the value should be one of DLDataTypeCode enum values.
179
+ * */
180
+ uint8_t code;
181
+ /*!
182
+ * \brief Number of bits, common choices are 8, 16, 32.
183
+ */
184
+ uint8_t bits;
185
+ /*! \brief Number of lanes in the type, used for vector types. */
186
+ uint16_t lanes;
187
+ } DLDataType;
188
+
189
+ /*!
190
+ * \brief Plain C Tensor object, does not manage memory.
191
+ */
192
+ typedef struct {
193
+ /*!
194
+ * \brief The data pointer points to the allocated data. This will be CUDA
195
+ * device pointer or cl_mem handle in OpenCL. It may be opaque on some device
196
+ * types. This pointer is always aligned to 256 bytes as in CUDA. The
197
+ * `byte_offset` field should be used to point to the beginning of the data.
198
+ *
199
+ * Note that as of Nov 2021, multiply libraries (CuPy, PyTorch, TensorFlow,
200
+ * TVM, perhaps others) do not adhere to this 256 byte aligment requirement
201
+ * on CPU/CUDA/ROCm, and always use `byte_offset=0`. This must be fixed
202
+ * (after which this note will be updated); at the moment it is recommended
203
+ * to not rely on the data pointer being correctly aligned.
204
+ *
205
+ * For given DLTensor, the size of memory required to store the contents of
206
+ * data is calculated as follows:
207
+ *
208
+ * \code{.c}
209
+ * static inline size_t GetDataSize(const DLTensor* t) {
210
+ * size_t size = 1;
211
+ * for (tvm_index_t i = 0; i < t->ndim; ++i) {
212
+ * size *= t->shape[i];
213
+ * }
214
+ * size *= (t->dtype.bits * t->dtype.lanes + 7) / 8;
215
+ * return size;
216
+ * }
217
+ * \endcode
218
+ *
219
+ * Note that if the tensor is of size zero, then the data pointer should be
220
+ * set to `NULL`.
221
+ */
222
+ void* data;
223
+ /*! \brief The device of the tensor */
224
+ DLDevice device;
225
+ /*! \brief Number of dimensions */
226
+ int32_t ndim;
227
+ /*! \brief The data type of the pointer*/
228
+ DLDataType dtype;
229
+ /*! \brief The shape of the tensor */
230
+ int64_t* shape;
231
+ /*!
232
+ * \brief strides of the tensor (in number of elements, not bytes)
233
+ * can be NULL, indicating tensor is compact and row-majored.
234
+ */
235
+ int64_t* strides;
236
+ /*! \brief The offset in bytes to the beginning pointer to data */
237
+ uint64_t byte_offset;
238
+ } DLTensor;
239
+
240
+ /*!
241
+ * \brief C Tensor object, manage memory of DLTensor. This data structure is
242
+ * intended to facilitate the borrowing of DLTensor by another framework. It is
243
+ * not meant to transfer the tensor. When the borrowing framework doesn't need
244
+ * the tensor, it should call the deleter to notify the host that the resource
245
+ * is no longer needed.
246
+ *
247
+ * \note This data structure is used as Legacy DLManagedTensor
248
+ * in DLPack exchange and is deprecated after DLPack v0.8
249
+ * Use DLManagedTensorVersioned instead.
250
+ * This data structure may get renamed or deleted in future versions.
251
+ *
252
+ * \sa DLManagedTensorVersioned
253
+ */
254
+ typedef struct DLManagedTensor {
255
+ /*! \brief DLTensor which is being memory managed */
256
+ DLTensor dl_tensor;
257
+ /*! \brief the context of the original host framework of DLManagedTensor in
258
+ * which DLManagedTensor is used in the framework. It can also be NULL.
259
+ */
260
+ void * manager_ctx;
261
+ /*!
262
+ * \brief Destructor - this should be called
263
+ * to destruct the manager_ctx which backs the DLManagedTensor. It can be
264
+ * NULL if there is no way for the caller to provide a reasonable destructor.
265
+ * The destructor deletes the argument self as well.
266
+ */
267
+ void (*deleter)(struct DLManagedTensor * self);
268
+ } DLManagedTensor;
269
+
270
+ // bit masks used in in the DLManagedTensorVersioned
271
+
272
+ /*! \brief bit mask to indicate that the tensor is read only. */
273
+ #define DLPACK_FLAG_BITMASK_READ_ONLY (1UL << 0UL)
274
+
275
+ /*!
276
+ * \brief bit mask to indicate that the tensor is a copy made by the producer.
277
+ *
278
+ * If set, the tensor is considered solely owned throughout its lifetime by the
279
+ * consumer, until the producer-provided deleter is invoked.
280
+ */
281
+ #define DLPACK_FLAG_BITMASK_IS_COPIED (1UL << 1UL)
282
+
283
+ /*!
284
+ * \brief A versioned and managed C Tensor object, manage memory of DLTensor.
285
+ *
286
+ * This data structure is intended to facilitate the borrowing of DLTensor by
287
+ * another framework. It is not meant to transfer the tensor. When the borrowing
288
+ * framework doesn't need the tensor, it should call the deleter to notify the
289
+ * host that the resource is no longer needed.
290
+ *
291
+ * \note This is the current standard DLPack exchange data structure.
292
+ */
293
+ struct DLManagedTensorVersioned {
294
+ /*!
295
+ * \brief The API and ABI version of the current managed Tensor
296
+ */
297
+ DLPackVersion version;
298
+ /*!
299
+ * \brief the context of the original host framework.
300
+ *
301
+ * Stores DLManagedTensorVersioned is used in the
302
+ * framework. It can also be NULL.
303
+ */
304
+ void *manager_ctx;
305
+ /*!
306
+ * \brief Destructor.
307
+ *
308
+ * This should be called to destruct manager_ctx which holds the DLManagedTensorVersioned.
309
+ * It can be NULL if there is no way for the caller to provide a reasonable
310
+ * destructor. The destructor deletes the argument self as well.
311
+ */
312
+ void (*deleter)(struct DLManagedTensorVersioned *self);
313
+ /*!
314
+ * \brief Additional bitmask flags information about the tensor.
315
+ *
316
+ * By default the flags should be set to 0.
317
+ *
318
+ * \note Future ABI changes should keep everything until this field
319
+ * stable, to ensure that deleter can be correctly called.
320
+ *
321
+ * \sa DLPACK_FLAG_BITMASK_READ_ONLY
322
+ * \sa DLPACK_FLAG_BITMASK_IS_COPIED
323
+ */
324
+ uint64_t flags;
325
+ /*! \brief DLTensor which is being memory managed */
326
+ DLTensor dl_tensor;
327
+ };
328
+
329
+ #ifdef __cplusplus
330
+ } // DLPACK_EXTERN_C
331
+ #endif
332
+ #endif // DLPACK_DLPACK_H_
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/catrig.h ADDED
@@ -0,0 +1,732 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2012 Stephen Montgomery-Smith <stephen@FreeBSD.ORG>
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ *
31
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41
+ * SUCH DAMAGE.
42
+ */
43
+
44
+ /*
45
+ * Adapted from FreeBSD by Filipe Maia <filipe.c.maia@gmail.com>:
46
+ * freebsd/lib/msun/src/catrig.c
47
+ */
48
+
49
+ #pragma once
50
+
51
+ #include <cupy/complex/complex.h>
52
+ #include <cupy/complex/math_private.h>
53
+
54
+ #include <cupy/complex/namespace.h>
55
+
56
+ THRUST_NAMESPACE_BEGIN
57
+ namespace detail {
58
+ namespace complex {
59
+
60
+ using thrust::complex;
61
+
62
+ __host__ __device__ inline void raise_inexact() {
63
+ const volatile float tiny = 7.888609052210118054117286e-31; /* 0x1p-100; */
64
+ // needs the volatile to prevent compiler from ignoring it
65
+ volatile float junk = 1 + tiny;
66
+ (void)junk;
67
+ }
68
+
69
+ __host__ __device__ inline complex<double> clog_for_large_values(complex<double> z);
70
+
71
+ /*
72
+ * Testing indicates that all these functions are accurate up to 4 ULP.
73
+ * The functions casin(h) and cacos(h) are about 2.5 times slower than asinh.
74
+ * The functions catan(h) are a little under 2 times slower than atanh.
75
+ *
76
+ * The code for casinh, casin, cacos, and cacosh comes first. The code is
77
+ * rather complicated, and the four functions are highly interdependent.
78
+ *
79
+ * The code for catanh and catan comes at the end. It is much simpler than
80
+ * the other functions, and the code for these can be disconnected from the
81
+ * rest of the code.
82
+ */
83
+
84
+ /*
85
+ * ================================
86
+ * | casinh, casin, cacos, cacosh |
87
+ * ================================
88
+ */
89
+
90
+ /*
91
+ * The algorithm is very close to that in "Implementing the complex arcsine
92
+ * and arccosine functions using exception handling" by T. E. Hull, Thomas F.
93
+ * Fairgrieve, and Ping Tak Peter Tang, published in ACM Transactions on
94
+ * Mathematical Software, Volume 23 Issue 3, 1997, Pages 299-335,
95
+ * http://dl.acm.org/citation.cfm?id=275324.
96
+ *
97
+ * Throughout we use the convention z = x + I*y.
98
+ *
99
+ * casinh(z) = sign(x)*log(A+sqrt(A*A-1)) + I*asin(B)
100
+ * where
101
+ * A = (|z+I| + |z-I|) / 2
102
+ * B = (|z+I| - |z-I|) / 2 = y/A
103
+ *
104
+ * These formulas become numerically unstable:
105
+ * (a) for Re(casinh(z)) when z is close to the line segment [-I, I] (that
106
+ * is, Re(casinh(z)) is close to 0);
107
+ * (b) for Im(casinh(z)) when z is close to either of the intervals
108
+ * [I, I*infinity) or (-I*infinity, -I] (that is, |Im(casinh(z))| is
109
+ * close to PI/2).
110
+ *
111
+ * These numerical problems are overcome by defining
112
+ * f(a, b) = (hypot(a, b) - b) / 2 = a*a / (hypot(a, b) + b) / 2
113
+ * Then if A < A_crossover, we use
114
+ * log(A + sqrt(A*A-1)) = log1p((A-1) + sqrt((A-1)*(A+1)))
115
+ * A-1 = f(x, 1+y) + f(x, 1-y)
116
+ * and if B > B_crossover, we use
117
+ * asin(B) = atan2(y, sqrt(A*A - y*y)) = atan2(y, sqrt((A+y)*(A-y)))
118
+ * A-y = f(x, y+1) + f(x, y-1)
119
+ * where without loss of generality we have assumed that x and y are
120
+ * non-negative.
121
+ *
122
+ * Much of the difficulty comes because the intermediate computations may
123
+ * produce overflows or underflows. This is dealt with in the paper by Hull
124
+ * et al by using exception handling. We do this by detecting when
125
+ * computations risk underflow or overflow. The hardest part is handling the
126
+ * underflows when computing f(a, b).
127
+ *
128
+ * Note that the function f(a, b) does not appear explicitly in the paper by
129
+ * Hull et al, but the idea may be found on pages 308 and 309. Introducing the
130
+ * function f(a, b) allows us to concentrate many of the clever tricks in this
131
+ * paper into one function.
132
+ */
133
+
134
+ /*
135
+ * Function f(a, b, hypot_a_b) = (hypot(a, b) - b) / 2.
136
+ * Pass hypot(a, b) as the third argument.
137
+ */
138
+ __host__ __device__ inline double f(double a, double b, double hypot_a_b) {
139
+ if (b < 0) return ((hypot_a_b - b) / 2);
140
+ if (b == 0) return (a / 2);
141
+ return (a * a / (hypot_a_b + b) / 2);
142
+ }
143
+
144
+ /*
145
+ * All the hard work is contained in this function.
146
+ * x and y are assumed positive or zero, and less than RECIP_EPSILON.
147
+ * Upon return:
148
+ * rx = Re(casinh(z)) = -Im(cacos(y + I*x)).
149
+ * B_is_usable is set to 1 if the value of B is usable.
150
+ * If B_is_usable is set to 0, sqrt_A2my2 = sqrt(A*A - y*y), and new_y = y.
151
+ * If returning sqrt_A2my2 has potential to result in an underflow, it is
152
+ * rescaled, and new_y is similarly rescaled.
153
+ */
154
+ __host__ __device__ inline void do_hard_work(double x, double y, double* rx,
155
+ int* B_is_usable, double* B,
156
+ double* sqrt_A2my2, double* new_y) {
157
+ double R, S, A; /* A, B, R, and S are as in Hull et al. */
158
+ double Am1, Amy; /* A-1, A-y. */
159
+ const double A_crossover =
160
+ 10; /* Hull et al suggest 1.5, but 10 works better */
161
+ const double FOUR_SQRT_MIN =
162
+ 5.966672584960165394632772e-154; /* =0x1p-509; >= 4 * sqrt(DBL_MIN) */
163
+ const double B_crossover = 0.6417; /* suggested by Hull et al */
164
+
165
+ R = hypot(x, y + 1); /* |z+I| */
166
+ S = hypot(x, y - 1); /* |z-I| */
167
+
168
+ /* A = (|z+I| + |z-I|) / 2 */
169
+ A = (R + S) / 2;
170
+ /*
171
+ * Mathematically A >= 1. There is a small chance that this will not
172
+ * be so because of rounding errors. So we will make certain it is
173
+ * so.
174
+ */
175
+ if (A < 1) A = 1;
176
+
177
+ if (A < A_crossover) {
178
+ /*
179
+ * Am1 = fp + fm, where fp = f(x, 1+y), and fm = f(x, 1-y).
180
+ * rx = log1p(Am1 + sqrt(Am1*(A+1)))
181
+ */
182
+ if (y == 1 && x < DBL_EPSILON * DBL_EPSILON / 128) {
183
+ /*
184
+ * fp is of order x^2, and fm = x/2.
185
+ * A = 1 (inexactly).
186
+ */
187
+ *rx = sqrt(x);
188
+ } else if (x >= DBL_EPSILON * fabs(y - 1)) {
189
+ /*
190
+ * Underflow will not occur because
191
+ * x >= DBL_EPSILON^2/128 >= FOUR_SQRT_MIN
192
+ */
193
+ Am1 = f(x, 1 + y, R) + f(x, 1 - y, S);
194
+ *rx = log1p(Am1 + sqrt(Am1 * (A + 1)));
195
+ } else if (y < 1) {
196
+ /*
197
+ * fp = x*x/(1+y)/4, fm = x*x/(1-y)/4, and
198
+ * A = 1 (inexactly).
199
+ */
200
+ *rx = x / sqrt((1 - y) * (1 + y));
201
+ } else { /* if (y > 1) */
202
+ /*
203
+ * A-1 = y-1 (inexactly).
204
+ */
205
+ *rx = log1p((y - 1) + sqrt((y - 1) * (y + 1)));
206
+ }
207
+ } else {
208
+ *rx = log(A + sqrt(A * A - 1));
209
+ }
210
+
211
+ *new_y = y;
212
+
213
+ if (y < FOUR_SQRT_MIN) {
214
+ /*
215
+ * Avoid a possible underflow caused by y/A. For casinh this
216
+ * would be legitimate, but will be picked up by invoking atan2
217
+ * later on. For cacos this would not be legitimate.
218
+ */
219
+ *B_is_usable = 0;
220
+ *sqrt_A2my2 = A * (2 / DBL_EPSILON);
221
+ *new_y = y * (2 / DBL_EPSILON);
222
+ return;
223
+ }
224
+
225
+ /* B = (|z+I| - |z-I|) / 2 = y/A */
226
+ *B = y / A;
227
+ *B_is_usable = 1;
228
+
229
+ if (*B > B_crossover) {
230
+ *B_is_usable = 0;
231
+ /*
232
+ * Amy = fp + fm, where fp = f(x, y+1), and fm = f(x, y-1).
233
+ * sqrt_A2my2 = sqrt(Amy*(A+y))
234
+ */
235
+ if (y == 1 && x < DBL_EPSILON / 128) {
236
+ /*
237
+ * fp is of order x^2, and fm = x/2.
238
+ * A = 1 (inexactly).
239
+ */
240
+ *sqrt_A2my2 = sqrt(x) * sqrt((A + y) / 2);
241
+ } else if (x >= DBL_EPSILON * fabs(y - 1)) {
242
+ /*
243
+ * Underflow will not occur because
244
+ * x >= DBL_EPSILON/128 >= FOUR_SQRT_MIN
245
+ * and
246
+ * x >= DBL_EPSILON^2 >= FOUR_SQRT_MIN
247
+ */
248
+ Amy = f(x, y + 1, R) + f(x, y - 1, S);
249
+ *sqrt_A2my2 = sqrt(Amy * (A + y));
250
+ } else if (y > 1) {
251
+ /*
252
+ * fp = x*x/(y+1)/4, fm = x*x/(y-1)/4, and
253
+ * A = y (inexactly).
254
+ *
255
+ * y < RECIP_EPSILON. So the following
256
+ * scaling should avoid any underflow problems.
257
+ */
258
+ *sqrt_A2my2 =
259
+ x * (4 / DBL_EPSILON / DBL_EPSILON) * y / sqrt((y + 1) * (y - 1));
260
+ *new_y = y * (4 / DBL_EPSILON / DBL_EPSILON);
261
+ } else { /* if (y < 1) */
262
+ /*
263
+ * fm = 1-y >= DBL_EPSILON, fp is of order x^2, and
264
+ * A = 1 (inexactly).
265
+ */
266
+ *sqrt_A2my2 = sqrt((1 - y) * (1 + y));
267
+ }
268
+ }
269
+ }
270
+
271
+ /*
272
+ * casinh(z) = z + O(z^3) as z -> 0
273
+ *
274
+ * casinh(z) = sign(x)*clog(sign(x)*z) + O(1/z^2) as z -> infinity
275
+ * The above formula works for the imaginary part as well, because
276
+ * Im(casinh(z)) = sign(x)*atan2(sign(x)*y, fabs(x)) + O(y/z^3)
277
+ * as z -> infinity, uniformly in y
278
+ */
279
+ __host__ __device__ inline complex<double> casinh(complex<double> z) {
280
+ double x, y, ax, ay, rx, ry, B, sqrt_A2my2, new_y;
281
+ int B_is_usable;
282
+ complex<double> w;
283
+ const double RECIP_EPSILON = 1.0 / DBL_EPSILON;
284
+ const double m_ln2 = 6.9314718055994531e-1; /* 0x162e42fefa39ef.0p-53 */
285
+ x = z.real();
286
+ y = z.imag();
287
+ ax = fabs(x);
288
+ ay = fabs(y);
289
+
290
+ if (isnan(x) || isnan(y)) {
291
+ /* casinh(+-Inf + I*NaN) = +-Inf + I*NaN */
292
+ if (isinf(x)) return (complex<double>(x, y + y));
293
+ /* casinh(NaN + I*+-Inf) = opt(+-)Inf + I*NaN */
294
+ if (isinf(y)) return (complex<double>(y, x + x));
295
+ /* casinh(NaN + I*0) = NaN + I*0 */
296
+ if (y == 0) return (complex<double>(x + x, y));
297
+ /*
298
+ * All other cases involving NaN return NaN + I*NaN.
299
+ * C99 leaves it optional whether to raise invalid if one of
300
+ * the arguments is not NaN, so we opt not to raise it.
301
+ */
302
+ return (complex<double>(x + 0.0 + (y + 0.0), x + 0.0 + (y + 0.0)));
303
+ }
304
+
305
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
306
+ /* clog...() will raise inexact unless x or y is infinite. */
307
+ if (signbit(x) == 0)
308
+ w = clog_for_large_values(z) + m_ln2;
309
+ else
310
+ w = clog_for_large_values(-z) + m_ln2;
311
+ return (complex<double>(copysign(w.real(), x), copysign(w.imag(), y)));
312
+ }
313
+
314
+ /* Avoid spuriously raising inexact for z = 0. */
315
+ if (x == 0 && y == 0) return (z);
316
+
317
+ /* All remaining cases are inexact. */
318
+ raise_inexact();
319
+
320
+ const double SQRT_6_EPSILON =
321
+ 3.6500241499888571e-8; /* 0x13988e1409212e.0p-77 */
322
+ if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4) return (z);
323
+
324
+ do_hard_work(ax, ay, &rx, &B_is_usable, &B, &sqrt_A2my2, &new_y);
325
+ if (B_is_usable)
326
+ ry = asin(B);
327
+ else
328
+ ry = atan2(new_y, sqrt_A2my2);
329
+ return (complex<double>(copysign(rx, x), copysign(ry, y)));
330
+ }
331
+
332
+ /*
333
+ * casin(z) = reverse(casinh(reverse(z)))
334
+ * where reverse(x + I*y) = y + I*x = I*conj(z).
335
+ */
336
+ __host__ __device__ inline complex<double> casin(complex<double> z) {
337
+ complex<double> w = casinh(complex<double>(z.imag(), z.real()));
338
+
339
+ return (complex<double>(w.imag(), w.real()));
340
+ }
341
+
342
+ /*
343
+ * cacos(z) = PI/2 - casin(z)
344
+ * but do the computation carefully so cacos(z) is accurate when z is
345
+ * close to 1.
346
+ *
347
+ * cacos(z) = PI/2 - z + O(z^3) as z -> 0
348
+ *
349
+ * cacos(z) = -sign(y)*I*clog(z) + O(1/z^2) as z -> infinity
350
+ * The above formula works for the real part as well, because
351
+ * Re(cacos(z)) = atan2(fabs(y), x) + O(y/z^3)
352
+ * as z -> infinity, uniformly in y
353
+ */
354
+ __host__ __device__ inline complex<double> cacos(complex<double> z) {
355
+ double x, y, ax, ay, rx, ry, B, sqrt_A2mx2, new_x;
356
+ int sx, sy;
357
+ int B_is_usable;
358
+ complex<double> w;
359
+ const double pio2_hi = 1.5707963267948966e0; /* 0x1921fb54442d18.0p-52 */
360
+ const volatile double pio2_lo =
361
+ 6.1232339957367659e-17; /* 0x11a62633145c07.0p-106 */
362
+ const double m_ln2 = 6.9314718055994531e-1; /* 0x162e42fefa39ef.0p-53 */
363
+
364
+ x = z.real();
365
+ y = z.imag();
366
+ sx = signbit(x);
367
+ sy = signbit(y);
368
+ ax = fabs(x);
369
+ ay = fabs(y);
370
+
371
+ if (isnan(x) || isnan(y)) {
372
+ /* cacos(+-Inf + I*NaN) = NaN + I*opt(-)Inf */
373
+ if (isinf(x)) return (complex<double>(y + y, -infinity<double>()));
374
+ /* cacos(NaN + I*+-Inf) = NaN + I*-+Inf */
375
+ if (isinf(y)) return (complex<double>(x + x, -y));
376
+ /* cacos(0 + I*NaN) = PI/2 + I*NaN with inexact */
377
+ if (x == 0) return (complex<double>(pio2_hi + pio2_lo, y + y));
378
+ /*
379
+ * All other cases involving NaN return NaN + I*NaN.
380
+ * C99 leaves it optional whether to raise invalid if one of
381
+ * the arguments is not NaN, so we opt not to raise it.
382
+ */
383
+ return (complex<double>(x + 0.0 + (y + 0), x + 0.0 + (y + 0)));
384
+ }
385
+
386
+ const double RECIP_EPSILON = 1.0 / DBL_EPSILON;
387
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
388
+ /* clog...() will raise inexact unless x or y is infinite. */
389
+ w = clog_for_large_values(z);
390
+ rx = fabs(w.imag());
391
+ ry = w.real() + m_ln2;
392
+ if (sy == 0) ry = -ry;
393
+ return (complex<double>(rx, ry));
394
+ }
395
+
396
+ /* Avoid spuriously raising inexact for z = 1. */
397
+ if (x == 1.0 && y == 0.0) return (complex<double>(0, -y));
398
+
399
+ /* All remaining cases are inexact. */
400
+ raise_inexact();
401
+
402
+ const double SQRT_6_EPSILON =
403
+ 3.6500241499888571e-8; /* 0x13988e1409212e.0p-77 */
404
+ if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
405
+ return (complex<double>(pio2_hi - (x - pio2_lo), -y));
406
+
407
+ do_hard_work(ay, ax, &ry, &B_is_usable, &B, &sqrt_A2mx2, &new_x);
408
+ if (B_is_usable) {
409
+ if (sx == 0)
410
+ rx = acos(B);
411
+ else
412
+ rx = acos(-B);
413
+ } else {
414
+ if (sx == 0)
415
+ rx = atan2(sqrt_A2mx2, new_x);
416
+ else
417
+ rx = atan2(sqrt_A2mx2, -new_x);
418
+ }
419
+ if (sy == 0) ry = -ry;
420
+ return (complex<double>(rx, ry));
421
+ }
422
+
423
+ /*
424
+ * cacosh(z) = I*cacos(z) or -I*cacos(z)
425
+ * where the sign is chosen so Re(cacosh(z)) >= 0.
426
+ */
427
+ __host__ __device__ inline complex<double> cacosh(complex<double> z) {
428
+ complex<double> w;
429
+ double rx, ry;
430
+
431
+ w = cacos(z);
432
+ rx = w.real();
433
+ ry = w.imag();
434
+ /* cacosh(NaN + I*NaN) = NaN + I*NaN */
435
+ if (isnan(rx) && isnan(ry)) return (complex<double>(ry, rx));
436
+ /* cacosh(NaN + I*+-Inf) = +Inf + I*NaN */
437
+ /* cacosh(+-Inf + I*NaN) = +Inf + I*NaN */
438
+ if (isnan(rx)) return (complex<double>(fabs(ry), rx));
439
+ /* cacosh(0 + I*NaN) = NaN + I*NaN */
440
+ if (isnan(ry)) return (complex<double>(ry, ry));
441
+ return (complex<double>(fabs(ry), copysign(rx, z.imag())));
442
+ }
443
+
444
+ /*
445
+ * Optimized version of clog() for |z| finite and larger than ~RECIP_EPSILON.
446
+ */
447
+ __host__ __device__ inline complex<double> clog_for_large_values(complex<double> z) {
448
+ double x, y;
449
+ double ax, ay, t;
450
+ const double m_e = 2.7182818284590452e0; /* 0x15bf0a8b145769.0p-51 */
451
+
452
+ x = z.real();
453
+ y = z.imag();
454
+ ax = fabs(x);
455
+ ay = fabs(y);
456
+ if (ax < ay) {
457
+ t = ax;
458
+ ax = ay;
459
+ ay = t;
460
+ }
461
+
462
+ /*
463
+ * Avoid overflow in hypot() when x and y are both very large.
464
+ * Divide x and y by E, and then add 1 to the logarithm. This depends
465
+ * on E being larger than sqrt(2).
466
+ * Dividing by E causes an insignificant loss of accuracy; however
467
+ * this method is still poor since it is unnecessarily slow.
468
+ */
469
+ if (ax > DBL_MAX / 2)
470
+ return (complex<double>(log(hypot(x / m_e, y / m_e)) + 1, atan2(y, x)));
471
+
472
+ /*
473
+ * Avoid overflow when x or y is large. Avoid underflow when x or
474
+ * y is small.
475
+ */
476
+ const double QUARTER_SQRT_MAX =
477
+ 5.966672584960165394632772e-154; /* = 0x1p509; <= sqrt(DBL_MAX) / 4 */
478
+ const double SQRT_MIN =
479
+ 1.491668146240041348658193e-154; /* = 0x1p-511; >= sqrt(DBL_MIN) */
480
+ if (ax > QUARTER_SQRT_MAX || ay < SQRT_MIN)
481
+ return (complex<double>(log(hypot(x, y)), atan2(y, x)));
482
+
483
+ return (complex<double>(log(ax * ax + ay * ay) / 2, atan2(y, x)));
484
+ }
485
+
486
+ /*
487
+ * =================
488
+ * | catanh, catan |
489
+ * =================
490
+ */
491
+
492
+ /*
493
+ * sum_squares(x,y) = x*x + y*y (or just x*x if y*y would underflow).
494
+ * Assumes x*x and y*y will not overflow.
495
+ * Assumes x and y are finite.
496
+ * Assumes y is non-negative.
497
+ * Assumes fabs(x) >= DBL_EPSILON.
498
+ */
499
+ __host__ __device__ inline double sum_squares(double x, double y) {
500
+ const double SQRT_MIN =
501
+ 1.491668146240041348658193e-154; /* = 0x1p-511; >= sqrt(DBL_MIN) */
502
+ /* Avoid underflow when y is small. */
503
+ if (y < SQRT_MIN) return (x * x);
504
+
505
+ return (x * x + y * y);
506
+ }
507
+
508
+ /*
509
+ * real_part_reciprocal(x, y) = Re(1/(x+I*y)) = x/(x*x + y*y).
510
+ * Assumes x and y are not NaN, and one of x and y is larger than
511
+ * RECIP_EPSILON. We avoid unwarranted underflow. It is important to not use
512
+ * the code creal(1/z), because the imaginary part may produce an unwanted
513
+ * underflow.
514
+ * This is only called in a context where inexact is always raised before
515
+ * the call, so no effort is made to avoid or force inexact.
516
+ */
517
+ __host__ __device__ inline double real_part_reciprocal(double x, double y) {
518
+ double scale;
519
+ uint32_t hx, hy;
520
+ int32_t ix, iy;
521
+
522
+ /*
523
+ * This code is inspired by the C99 document n1124.pdf, Section G.5.1,
524
+ * example 2.
525
+ */
526
+ get_high_word(hx, x);
527
+ ix = hx & 0x7ff00000;
528
+ get_high_word(hy, y);
529
+ iy = hy & 0x7ff00000;
530
+ //#define BIAS (DBL_MAX_EXP - 1)
531
+ const int BIAS = DBL_MAX_EXP - 1;
532
+ /* XXX more guard digits are useful iff there is extra precision. */
533
+ //#define CUTOFF (DBL_MANT_DIG / 2 + 1) /* just half or 1 guard digit */
534
+ const int CUTOFF = (DBL_MANT_DIG / 2 + 1);
535
+ if (ix - iy >= CUTOFF << 20 || isinf(x))
536
+ return (1 / x); /* +-Inf -> +-0 is special */
537
+ if (iy - ix >= CUTOFF << 20)
538
+ return (x / y / y); /* should avoid double div, but hard */
539
+ if (ix <= (BIAS + DBL_MAX_EXP / 2 - CUTOFF) << 20)
540
+ return (x / (x * x + y * y));
541
+ scale = 1;
542
+ set_high_word(scale, 0x7ff00000 - ix); /* 2**(1-ilogb(x)) */
543
+ x *= scale;
544
+ y *= scale;
545
+ return (x / (x * x + y * y) * scale);
546
+ }
547
+
548
+ /*
549
+ * catanh(z) = log((1+z)/(1-z)) / 2
550
+ * = log1p(4*x / |z-1|^2) / 4
551
+ * + I * atan2(2*y, (1-x)*(1+x)-y*y) / 2
552
+ *
553
+ * catanh(z) = z + O(z^3) as z -> 0
554
+ *
555
+ * catanh(z) = 1/z + sign(y)*I*PI/2 + O(1/z^3) as z -> infinity
556
+ * The above formula works for the real part as well, because
557
+ * Re(catanh(z)) = x/|z|^2 + O(x/z^4)
558
+ * as z -> infinity, uniformly in x
559
+ */
560
+ #if __cplusplus >= 201103L || !defined _MSC_VER
561
+ __host__ __device__ inline complex<double> catanh(complex<double> z) {
562
+ double x, y, ax, ay, rx, ry;
563
+ const volatile double pio2_lo =
564
+ 6.1232339957367659e-17; /* 0x11a62633145c07.0p-106 */
565
+ const double pio2_hi = 1.5707963267948966e0; /* 0x1921fb54442d18.0p-52 */
566
+
567
+ x = z.real();
568
+ y = z.imag();
569
+ ax = fabs(x);
570
+ ay = fabs(y);
571
+
572
+ /* This helps handle many cases. */
573
+ if (y == 0 && ax <= 1) return (complex<double>(atanh(x), y));
574
+
575
+ /* To ensure the same accuracy as atan(), and to filter out z = 0. */
576
+ if (x == 0) return (complex<double>(x, atan(y)));
577
+
578
+ if (isnan(x) || isnan(y)) {
579
+ /* catanh(+-Inf + I*NaN) = +-0 + I*NaN */
580
+ if (isinf(x)) return (complex<double>(copysign(0.0, x), y + y));
581
+ /* catanh(NaN + I*+-Inf) = sign(NaN)0 + I*+-PI/2 */
582
+ if (isinf(y))
583
+ return (
584
+ complex<double>(copysign(0.0, x), copysign(pio2_hi + pio2_lo, y)));
585
+ /*
586
+ * All other cases involving NaN return NaN + I*NaN.
587
+ * C99 leaves it optional whether to raise invalid if one of
588
+ * the arguments is not NaN, so we opt not to raise it.
589
+ */
590
+ return (complex<double>(x + 0.0 + (y + 0), x + 0.0 + (y + 0)));
591
+ }
592
+
593
+ const double RECIP_EPSILON = 1.0 / DBL_EPSILON;
594
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON)
595
+ return (complex<double>(real_part_reciprocal(x, y),
596
+ copysign(pio2_hi + pio2_lo, y)));
597
+
598
+ const double SQRT_3_EPSILON =
599
+ 2.5809568279517849e-8; /* 0x1bb67ae8584caa.0p-78 */
600
+ if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) {
601
+ /*
602
+ * z = 0 was filtered out above. All other cases must raise
603
+ * inexact, but this is the only only that needs to do it
604
+ * explicitly.
605
+ */
606
+ raise_inexact();
607
+ return (z);
608
+ }
609
+
610
+ const double m_ln2 = 6.9314718055994531e-1; /* 0x162e42fefa39ef.0p-53 */
611
+ if (ax == 1 && ay < DBL_EPSILON)
612
+ rx = (m_ln2 - log(ay)) / 2;
613
+ else
614
+ rx = log1p(4 * ax / sum_squares(ax - 1, ay)) / 4;
615
+
616
+ if (ax == 1)
617
+ ry = atan2(2.0, -ay) / 2;
618
+ else if (ay < DBL_EPSILON)
619
+ ry = atan2(2 * ay, (1 - ax) * (1 + ax)) / 2;
620
+ else
621
+ ry = atan2(2 * ay, (1 - ax) * (1 + ax) - ay * ay) / 2;
622
+
623
+ return (complex<double>(copysign(rx, x), copysign(ry, y)));
624
+ }
625
+
626
+ /*
627
+ * catan(z) = reverse(catanh(reverse(z)))
628
+ * where reverse(x + I*y) = y + I*x = I*conj(z).
629
+ */
630
+ __host__ __device__ inline complex<double> catan(complex<double> z) {
631
+ complex<double> w = catanh(complex<double>(z.imag(), z.real()));
632
+ return (complex<double>(w.imag(), w.real()));
633
+ }
634
+
635
+ #endif
636
+
637
+ } // namespace complex
638
+
639
+ } // namespace detail
640
+
641
+ template <typename ValueType>
642
+ __host__ __device__ inline complex<ValueType> acos(const complex<ValueType>& z) {
643
+ const complex<ValueType> ret = thrust::asin(z);
644
+ const ValueType pi = ValueType(3.14159265358979323846);
645
+ return complex<ValueType>(pi / 2 - ret.real(), -ret.imag());
646
+ }
647
+
648
+ template <typename ValueType>
649
+ __host__ __device__ inline complex<ValueType> asin(const complex<ValueType>& z) {
650
+ const complex<ValueType> i(0, 1);
651
+ return -i * asinh(i * z);
652
+ }
653
+
654
+ template <typename ValueType>
655
+ __host__ __device__ inline complex<ValueType> atan(const complex<ValueType>& z) {
656
+ const complex<ValueType> i(0, 1);
657
+ return -i * thrust::atanh(i * z);
658
+ }
659
+
660
+ template <typename ValueType>
661
+ __host__ __device__ inline complex<ValueType> acosh(const complex<ValueType>& z) {
662
+ thrust::complex<ValueType> ret(
663
+ (z.real() - z.imag()) * (z.real() + z.imag()) - ValueType(1.0),
664
+ ValueType(2.0) * z.real() * z.imag());
665
+ ret = thrust::sqrt(ret);
666
+ if (z.real() < ValueType(0.0)) {
667
+ ret = -ret;
668
+ }
669
+ ret += z;
670
+ ret = thrust::log(ret);
671
+ if (ret.real() < ValueType(0.0)) {
672
+ ret = -ret;
673
+ }
674
+ return ret;
675
+ }
676
+
677
+ template <typename ValueType>
678
+ __host__ __device__ inline complex<ValueType> asinh(const complex<ValueType>& z) {
679
+ return thrust::log(thrust::sqrt(z * z + ValueType(1)) + z);
680
+ }
681
+
682
+ template <typename ValueType>
683
+ __host__ __device__ inline complex<ValueType> atanh(const complex<ValueType>& z) {
684
+ ValueType imag2 = z.imag() * z.imag();
685
+ ValueType n = ValueType(1.0) + z.real();
686
+ n = imag2 + n * n;
687
+
688
+ ValueType d = ValueType(1.0) - z.real();
689
+ d = imag2 + d * d;
690
+ complex<ValueType> ret(ValueType(0.25) * (::log(n) - ::log(d)), 0);
691
+
692
+ d = ValueType(1.0) - z.real() * z.real() - imag2;
693
+
694
+ ret.imag(ValueType(0.5) * ::atan2(ValueType(2.0) * z.imag(), d));
695
+ return ret;
696
+ }
697
+
698
+ template <>
699
+ __host__ __device__ inline complex<double> acos(const complex<double>& z) {
700
+ return detail::complex::cacos(z);
701
+ }
702
+
703
+ template <>
704
+ __host__ __device__ inline complex<double> asin(const complex<double>& z) {
705
+ return detail::complex::casin(z);
706
+ }
707
+
708
+ #if __cplusplus >= 201103L || !defined _MSC_VER
709
+ template <>
710
+ __host__ __device__ inline complex<double> atan(const complex<double>& z) {
711
+ return detail::complex::catan(z);
712
+ }
713
+ #endif
714
+
715
+ template <>
716
+ __host__ __device__ inline complex<double> acosh(const complex<double>& z) {
717
+ return detail::complex::cacosh(z);
718
+ }
719
+
720
+ template <>
721
+ __host__ __device__ inline complex<double> asinh(const complex<double>& z) {
722
+ return detail::complex::casinh(z);
723
+ }
724
+
725
+ #if __cplusplus >= 201103L || !defined _MSC_VER
726
+ template <>
727
+ __host__ __device__ inline complex<double> atanh(const complex<double>& z) {
728
+ return detail::complex::catanh(z);
729
+ }
730
+ #endif
731
+
732
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/catrigf.h ADDED
@@ -0,0 +1,446 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2012 Stephen Montgomery-Smith <stephen@FreeBSD.ORG>
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ *
31
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41
+ * SUCH DAMAGE.
42
+ */
43
+
44
+ /*
45
+ * Adapted from FreeBSD by Filipe Maia <filipe.c.maia@gmail.com>:
46
+ * freebsd/lib/msun/src/catrig.c
47
+ */
48
+
49
+
50
+ #pragma once
51
+
52
+ #include <cupy/complex/complex.h>
53
+ #include <cupy/complex/math_private.h>
54
+
55
+ #include <cupy/complex/namespace.h>
56
+
57
+ THRUST_NAMESPACE_BEGIN
58
+ namespace detail {
59
+ namespace complex {
60
+
61
+ using thrust::complex;
62
+
63
+ __host__ __device__ inline complex<float> clog_for_large_values(complex<float> z);
64
+
65
+ /*
66
+ * The algorithm is very close to that in "Implementing the complex arcsine
67
+ * and arccosine functions using exception handling" by T. E. Hull, Thomas F.
68
+ * Fairgrieve, and Ping Tak Peter Tang, published in ACM Transactions on
69
+ * Mathematical Software, Volume 23 Issue 3, 1997, Pages 299-335,
70
+ * http://dl.acm.org/citation.cfm?id=275324.
71
+ *
72
+ * See catrig.c for complete comments.
73
+ *
74
+ * XXX comments were removed automatically, and even short ones on the right
75
+ * of statements were removed (all of them), contrary to normal style. Only
76
+ * a few comments on the right of declarations remain.
77
+ */
78
+
79
+ __host__ __device__ inline float f(float a, float b, float hypot_a_b) {
80
+ if (b < 0.0f) return ((hypot_a_b - b) / 2.0f);
81
+ if (b == 0.0f) return (a / 2.0f);
82
+ return (a * a / (hypot_a_b + b) / 2.0f);
83
+ }
84
+
85
+ /*
86
+ * All the hard work is contained in this function.
87
+ * x and y are assumed positive or zero, and less than RECIP_EPSILON.
88
+ * Upon return:
89
+ * rx = Re(casinh(z)) = -Im(cacos(y + I*x)).
90
+ * B_is_usable is set to 1 if the value of B is usable.
91
+ * If B_is_usable is set to 0, sqrt_A2my2 = sqrt(A*A - y*y), and new_y = y.
92
+ * If returning sqrt_A2my2 has potential to result in an underflow, it is
93
+ * rescaled, and new_y is similarly rescaled.
94
+ */
95
+ __host__ __device__ inline void do_hard_work(float x, float y, float* rx,
96
+ int* B_is_usable, float* B,
97
+ float* sqrt_A2my2, float* new_y) {
98
+ float R, S, A; /* A, B, R, and S are as in Hull et al. */
99
+ float Am1, Amy; /* A-1, A-y. */
100
+ const float A_crossover =
101
+ 10; /* Hull et al suggest 1.5, but 10 works better */
102
+ const float FOUR_SQRT_MIN = 4.336808689942017736029811e-19f;
103
+ ; /* =0x1p-61; >= 4 * sqrt(FLT_MIN) */
104
+ const float B_crossover = 0.6417f; /* suggested by Hull et al */
105
+ R = hypotf(x, y + 1);
106
+ S = hypotf(x, y - 1);
107
+
108
+ A = (R + S) / 2;
109
+ if (A < 1) A = 1;
110
+
111
+ if (A < A_crossover) {
112
+ if (y == 1 && x < FLT_EPSILON * FLT_EPSILON / 128) {
113
+ *rx = sqrtf(x);
114
+ } else if (x >= FLT_EPSILON * fabsf(y - 1)) {
115
+ Am1 = f(x, 1 + y, R) + f(x, 1 - y, S);
116
+ *rx = log1pf(Am1 + sqrtf(Am1 * (A + 1)));
117
+ } else if (y < 1) {
118
+ *rx = x / sqrtf((1 - y) * (1 + y));
119
+ } else {
120
+ *rx = log1pf((y - 1) + sqrtf((y - 1) * (y + 1)));
121
+ }
122
+ } else {
123
+ *rx = logf(A + sqrtf(A * A - 1));
124
+ }
125
+
126
+ *new_y = y;
127
+
128
+ if (y < FOUR_SQRT_MIN) {
129
+ *B_is_usable = 0;
130
+ *sqrt_A2my2 = A * (2 / FLT_EPSILON);
131
+ *new_y = y * (2 / FLT_EPSILON);
132
+ return;
133
+ }
134
+
135
+ *B = y / A;
136
+ *B_is_usable = 1;
137
+
138
+ if (*B > B_crossover) {
139
+ *B_is_usable = 0;
140
+ if (y == 1 && x < FLT_EPSILON / 128) {
141
+ *sqrt_A2my2 = sqrtf(x) * sqrtf((A + y) / 2);
142
+ } else if (x >= FLT_EPSILON * fabsf(y - 1)) {
143
+ Amy = f(x, y + 1, R) + f(x, y - 1, S);
144
+ *sqrt_A2my2 = sqrtf(Amy * (A + y));
145
+ } else if (y > 1) {
146
+ *sqrt_A2my2 =
147
+ x * (4 / FLT_EPSILON / FLT_EPSILON) * y / sqrtf((y + 1) * (y - 1));
148
+ *new_y = y * (4 / FLT_EPSILON / FLT_EPSILON);
149
+ } else {
150
+ *sqrt_A2my2 = sqrtf((1 - y) * (1 + y));
151
+ }
152
+ }
153
+ }
154
+
155
+ __host__ __device__ inline complex<float> casinhf(complex<float> z) {
156
+ float x, y, ax, ay, rx, ry, B, sqrt_A2my2, new_y;
157
+ int B_is_usable;
158
+ complex<float> w;
159
+ const float RECIP_EPSILON = 1.0 / FLT_EPSILON;
160
+ const float m_ln2 = 6.9314718055994531e-1f; /* 0x162e42fefa39ef.0p-53 */
161
+ x = z.real();
162
+ y = z.imag();
163
+ ax = fabsf(x);
164
+ ay = fabsf(y);
165
+
166
+ if (isnan(x) || isnan(y)) {
167
+ if (isinf(x)) return (complex<float>(x, y + y));
168
+ if (isinf(y)) return (complex<float>(y, x + x));
169
+ if (y == 0) return (complex<float>(x + x, y));
170
+ return (complex<float>(x + 0.0f + (y + 0), x + 0.0f + (y + 0)));
171
+ }
172
+
173
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
174
+ if (signbit(x) == 0)
175
+ w = clog_for_large_values(z) + m_ln2;
176
+ else
177
+ w = clog_for_large_values(-z) + m_ln2;
178
+ return (complex<float>(copysignf(w.real(), x), copysignf(w.imag(), y)));
179
+ }
180
+
181
+ if (x == 0 && y == 0) return (z);
182
+
183
+ raise_inexact();
184
+
185
+ const float SQRT_6_EPSILON = 8.4572793338e-4f; /* 0xddb3d7.0p-34 */
186
+ if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4) return (z);
187
+
188
+ do_hard_work(ax, ay, &rx, &B_is_usable, &B, &sqrt_A2my2, &new_y);
189
+ if (B_is_usable)
190
+ ry = asinf(B);
191
+ else
192
+ ry = atan2f(new_y, sqrt_A2my2);
193
+ return (complex<float>(copysignf(rx, x), copysignf(ry, y)));
194
+ }
195
+
196
+ __host__ __device__ inline complex<float> casinf(complex<float> z) {
197
+ complex<float> w = casinhf(complex<float>(z.imag(), z.real()));
198
+
199
+ return (complex<float>(w.imag(), w.real()));
200
+ }
201
+
202
+ __host__ __device__ inline complex<float> cacosf(complex<float> z) {
203
+ float x, y, ax, ay, rx, ry, B, sqrt_A2mx2, new_x;
204
+ int sx, sy;
205
+ int B_is_usable;
206
+ complex<float> w;
207
+ const float pio2_hi = 1.5707963267948966e0f; /* 0x1921fb54442d18.0p-52 */
208
+ const volatile float pio2_lo =
209
+ 6.1232339957367659e-17f; /* 0x11a62633145c07.0p-106 */
210
+ const float m_ln2 = 6.9314718055994531e-1f; /* 0x162e42fefa39ef.0p-53 */
211
+
212
+ x = z.real();
213
+ y = z.imag();
214
+ sx = signbit(x);
215
+ sy = signbit(y);
216
+ ax = fabsf(x);
217
+ ay = fabsf(y);
218
+
219
+ if (isnan(x) || isnan(y)) {
220
+ if (isinf(x)) return (complex<float>(y + y, -infinity<float>()));
221
+ if (isinf(y)) return (complex<float>(x + x, -y));
222
+ if (x == 0) return (complex<float>(pio2_hi + pio2_lo, y + y));
223
+ return (complex<float>(x + 0.0f + (y + 0), x + 0.0f + (y + 0)));
224
+ }
225
+
226
+ const float RECIP_EPSILON = 1.0 / FLT_EPSILON;
227
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
228
+ w = clog_for_large_values(z);
229
+ rx = fabsf(w.imag());
230
+ ry = w.real() + m_ln2;
231
+ if (sy == 0) ry = -ry;
232
+ return (complex<float>(rx, ry));
233
+ }
234
+
235
+ if (x == 1 && y == 0) return (complex<float>(0, -y));
236
+
237
+ raise_inexact();
238
+
239
+ const float SQRT_6_EPSILON = 8.4572793338e-4f; /* 0xddb3d7.0p-34 */
240
+ if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
241
+ return (complex<float>(pio2_hi - (x - pio2_lo), -y));
242
+
243
+ do_hard_work(ay, ax, &ry, &B_is_usable, &B, &sqrt_A2mx2, &new_x);
244
+ if (B_is_usable) {
245
+ if (sx == 0)
246
+ rx = acosf(B);
247
+ else
248
+ rx = acosf(-B);
249
+ } else {
250
+ if (sx == 0)
251
+ rx = atan2f(sqrt_A2mx2, new_x);
252
+ else
253
+ rx = atan2f(sqrt_A2mx2, -new_x);
254
+ }
255
+ if (sy == 0) ry = -ry;
256
+ return (complex<float>(rx, ry));
257
+ }
258
+
259
+ __host__ __device__ inline complex<float> cacoshf(complex<float> z) {
260
+ complex<float> w;
261
+ float rx, ry;
262
+
263
+ w = cacosf(z);
264
+ rx = w.real();
265
+ ry = w.imag();
266
+ /* cacosh(NaN + I*NaN) = NaN + I*NaN */
267
+ if (isnan(rx) && isnan(ry)) return (complex<float>(ry, rx));
268
+ /* cacosh(NaN + I*+-Inf) = +Inf + I*NaN */
269
+ /* cacosh(+-Inf + I*NaN) = +Inf + I*NaN */
270
+ if (isnan(rx)) return (complex<float>(fabsf(ry), rx));
271
+ /* cacosh(0 + I*NaN) = NaN + I*NaN */
272
+ if (isnan(ry)) return (complex<float>(ry, ry));
273
+ return (complex<float>(fabsf(ry), copysignf(rx, z.imag())));
274
+ }
275
+
276
+ /*
277
+ * Optimized version of clog() for |z| finite and larger than ~RECIP_EPSILON.
278
+ */
279
+ __host__ __device__ inline complex<float> clog_for_large_values(complex<float> z) {
280
+ float x, y;
281
+ float ax, ay, t;
282
+ const float m_e = 2.7182818284590452e0f; /* 0x15bf0a8b145769.0p-51 */
283
+
284
+ x = z.real();
285
+ y = z.imag();
286
+ ax = fabsf(x);
287
+ ay = fabsf(y);
288
+ if (ax < ay) {
289
+ t = ax;
290
+ ax = ay;
291
+ ay = t;
292
+ }
293
+
294
+ if (ax > FLT_MAX / 2)
295
+ return (complex<float>(logf(hypotf(x / m_e, y / m_e)) + 1, atan2f(y, x)));
296
+
297
+ const float QUARTER_SQRT_MAX =
298
+ 2.3058430092136939520000000e+18f; /* = 0x1p61; <= sqrt(FLT_MAX) / 4 */
299
+ const float SQRT_MIN =
300
+ 1.084202172485504434007453e-19f; /* 0x1p-63; >= sqrt(FLT_MIN) */
301
+ if (ax > QUARTER_SQRT_MAX || ay < SQRT_MIN)
302
+ return (complex<float>(logf(hypotf(x, y)), atan2f(y, x)));
303
+
304
+ return (complex<float>(logf(ax * ax + ay * ay) / 2, atan2f(y, x)));
305
+ }
306
+
307
+ /*
308
+ * =================
309
+ * | catanh, catan |
310
+ * =================
311
+ */
312
+
313
+ /*
314
+ * sum_squares(x,y) = x*x + y*y (or just x*x if y*y would underflow).
315
+ * Assumes x*x and y*y will not overflow.
316
+ * Assumes x and y are finite.
317
+ * Assumes y is non-negative.
318
+ * Assumes fabsf(x) >= FLT_EPSILON.
319
+ */
320
+ __host__ __device__ inline float sum_squares(float x, float y) {
321
+ const float SQRT_MIN =
322
+ 1.084202172485504434007453e-19f; /* 0x1p-63; >= sqrt(FLT_MIN) */
323
+ /* Avoid underflow when y is small. */
324
+ if (y < SQRT_MIN) return (x * x);
325
+
326
+ return (x * x + y * y);
327
+ }
328
+
329
+ __host__ __device__ inline float real_part_reciprocal(float x, float y) {
330
+ float scale;
331
+ uint32_t hx, hy;
332
+ int32_t ix, iy;
333
+
334
+ get_float_word(hx, x);
335
+ ix = hx & 0x7f800000;
336
+ get_float_word(hy, y);
337
+ iy = hy & 0x7f800000;
338
+ //#define BIAS (FLT_MAX_EXP - 1)
339
+ const int BIAS = FLT_MAX_EXP - 1;
340
+ //#define CUTOFF (FLT_MANT_DIG / 2 + 1)
341
+ const int CUTOFF = (FLT_MANT_DIG / 2 + 1);
342
+ if (ix - iy >= CUTOFF << 23 || isinf(x)) return (1 / x);
343
+ if (iy - ix >= CUTOFF << 23) return (x / y / y);
344
+ if (ix <= (BIAS + FLT_MAX_EXP / 2 - CUTOFF) << 23)
345
+ return (x / (x * x + y * y));
346
+ set_float_word(scale, 0x7f800000 - ix);
347
+ x *= scale;
348
+ y *= scale;
349
+ return (x / (x * x + y * y) * scale);
350
+ }
351
+
352
+ #if __cplusplus >= 201103L || !defined _MSC_VER
353
+ __host__ __device__ inline complex<float> catanhf(complex<float> z) {
354
+ float x, y, ax, ay, rx, ry;
355
+ const volatile float pio2_lo =
356
+ 6.1232339957367659e-17; /* 0x11a62633145c07.0p-106 */
357
+ const float pio2_hi = 1.5707963267948966e0; /* 0x1921fb54442d18.0p-52 */
358
+
359
+ x = z.real();
360
+ y = z.imag();
361
+ ax = fabsf(x);
362
+ ay = fabsf(y);
363
+
364
+ if (y == 0 && ax <= 1) return (complex<float>(atanhf(x), y));
365
+
366
+ if (x == 0) return (complex<float>(x, atanf(y)));
367
+
368
+ if (isnan(x) || isnan(y)) {
369
+ if (isinf(x)) return (complex<float>(copysignf(0, x), y + y));
370
+ if (isinf(y))
371
+ return (complex<float>(copysignf(0, x), copysignf(pio2_hi + pio2_lo, y)));
372
+ return (complex<float>(x + 0.0f + (y + 0.0f), x + 0.0f + (y + 0.0f)));
373
+ }
374
+
375
+ const float RECIP_EPSILON = 1.0f / FLT_EPSILON;
376
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON)
377
+ return (complex<float>(real_part_reciprocal(x, y),
378
+ copysignf(pio2_hi + pio2_lo, y)));
379
+
380
+ const float SQRT_3_EPSILON = 5.9801995673e-4; /* 0x9cc471.0p-34 */
381
+ if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) {
382
+ raise_inexact();
383
+ return (z);
384
+ }
385
+
386
+ const float m_ln2 = 6.9314718056e-1f; /* 0xb17218.0p-24 */
387
+ if (ax == 1 && ay < FLT_EPSILON)
388
+ rx = (m_ln2 - logf(ay)) / 2;
389
+ else
390
+ rx = log1pf(4 * ax / sum_squares(ax - 1, ay)) / 4;
391
+
392
+ if (ax == 1)
393
+ ry = atan2f(2, -ay) / 2;
394
+ else if (ay < FLT_EPSILON)
395
+ ry = atan2f(2 * ay, (1 - ax) * (1 + ax)) / 2;
396
+ else
397
+ ry = atan2f(2 * ay, (1 - ax) * (1 + ax) - ay * ay) / 2;
398
+
399
+ return (complex<float>(copysignf(rx, x), copysignf(ry, y)));
400
+ }
401
+
402
+ __host__ __device__ inline complex<float> catanf(complex<float> z) {
403
+ complex<float> w = catanhf(complex<float>(z.imag(), z.real()));
404
+ return (complex<float>(w.imag(), w.real()));
405
+ }
406
+ #endif
407
+
408
+ } // namespace complex
409
+
410
+ } // namespace detail
411
+
412
+ template <>
413
+ __host__ __device__ inline complex<float> acos(const complex<float>& z) {
414
+ return detail::complex::cacosf(z);
415
+ }
416
+
417
+ template <>
418
+ __host__ __device__ inline complex<float> asin(const complex<float>& z) {
419
+ return detail::complex::casinf(z);
420
+ }
421
+
422
+ #if __cplusplus >= 201103L || !defined _MSC_VER
423
+ template <>
424
+ __host__ __device__ inline complex<float> atan(const complex<float>& z) {
425
+ return detail::complex::catanf(z);
426
+ }
427
+ #endif
428
+
429
+ template <>
430
+ __host__ __device__ inline complex<float> acosh(const complex<float>& z) {
431
+ return detail::complex::cacoshf(z);
432
+ }
433
+
434
+ template <>
435
+ __host__ __device__ inline complex<float> asinh(const complex<float>& z) {
436
+ return detail::complex::casinhf(z);
437
+ }
438
+
439
+ #if __cplusplus >= 201103L || !defined _MSC_VER
440
+ template <>
441
+ __host__ __device__ inline complex<float> atanh(const complex<float>& z) {
442
+ return detail::complex::catanhf(z);
443
+ }
444
+ #endif
445
+
446
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/cexp.h ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ *
31
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41
+ * SUCH DAMAGE.
42
+ */
43
+
44
+ /* adapted from FreeBSD:
45
+ * lib/msun/src/s_cexp.c
46
+ * lib/msun/src/k_exp.c
47
+ *
48
+ */
49
+
50
+ #pragma once
51
+
52
+ #include <cupy/complex/complex.h>
53
+ #include <cupy/complex/math_private.h>
54
+
55
+ #include <cupy/complex/namespace.h>
56
+
57
+ THRUST_NAMESPACE_BEGIN
58
+ namespace detail {
59
+ namespace complex {
60
+
61
+ /*
62
+ * Compute exp(x), scaled to avoid spurious overflow. An exponent is
63
+ * returned separately in 'expt'.
64
+ *
65
+ * Input: ln(DBL_MAX) <= x < ln(2 * DBL_MAX / DBL_MIN_DENORM) ~= 1454.91
66
+ * Output: 2**1023 <= y < 2**1024
67
+ */
68
+ __host__ __device__ inline double frexp_exp(double x, int* expt) {
69
+ const uint32_t k = 1799; /* constant for reduction */
70
+ const double kln2 = 1246.97177782734161156; /* k * ln2 */
71
+
72
+ double exp_x;
73
+ uint32_t hx;
74
+
75
+ /*
76
+ * We use exp(x) = exp(x - kln2) * 2**k, carefully chosen to
77
+ * minimize |exp(kln2) - 2**k|. We also scale the exponent of
78
+ * exp_x to MAX_EXP so that the result can be multiplied by
79
+ * a tiny number without losing accuracy due to denormalization.
80
+ */
81
+ exp_x = exp(x - kln2);
82
+ get_high_word(hx, exp_x);
83
+ *expt = (hx >> 20) - (0x3ff + 1023) + k;
84
+ set_high_word(exp_x, (hx & 0xfffff) | ((0x3ff + 1023) << 20));
85
+ return (exp_x);
86
+ }
87
+
88
+ __host__ __device__ inline complex<double> ldexp_cexp(complex<double> z, int expt) {
89
+ double x, y, exp_x, scale1, scale2;
90
+ int ex_expt, half_expt;
91
+
92
+ x = z.real();
93
+ y = z.imag();
94
+ exp_x = frexp_exp(x, &ex_expt);
95
+ expt += ex_expt;
96
+
97
+ /*
98
+ * Arrange so that scale1 * scale2 == 2**expt. We use this to
99
+ * compensate for scalbn being horrendously slow.
100
+ */
101
+ half_expt = expt / 2;
102
+ insert_words(scale1, (0x3ff + half_expt) << 20, 0);
103
+ half_expt = expt - half_expt;
104
+ insert_words(scale2, (0x3ff + half_expt) << 20, 0);
105
+
106
+ return (complex<double>(::cos(y) * exp_x * scale1 * scale2,
107
+ ::sin(y) * exp_x * scale1 * scale2));
108
+ }
109
+
110
+ __host__ __device__ inline complex<double> cexp(const complex<double>& z) {
111
+ double x, y, exp_x;
112
+ uint32_t hx, hy, lx, ly;
113
+
114
+ const uint32_t exp_ovfl = 0x40862e42, /* high bits of MAX_EXP * ln2 ~= 710 */
115
+ cexp_ovfl = 0x4096b8e4; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */
116
+
117
+ x = z.real();
118
+ y = z.imag();
119
+
120
+ extract_words(hy, ly, y);
121
+ hy &= 0x7fffffff;
122
+
123
+ /* cexp(x + I 0) = exp(x) + I 0 */
124
+ if ((hy | ly) == 0) return (complex<double>(exp(x), y));
125
+ extract_words(hx, lx, x);
126
+ /* cexp(0 + I y) = cos(y) + I sin(y) */
127
+ if (((hx & 0x7fffffff) | lx) == 0) return (complex<double>(cos(y), sin(y)));
128
+
129
+ if (hy >= 0x7ff00000) {
130
+ if (lx != 0 || (hx & 0x7fffffff) != 0x7ff00000) {
131
+ /* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */
132
+ return (complex<double>(y - y, y - y));
133
+ } else if (hx & 0x80000000) {
134
+ /* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */
135
+ return (complex<double>(0.0, 0.0));
136
+ } else {
137
+ /* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */
138
+ return (complex<double>(x, y - y));
139
+ }
140
+ }
141
+
142
+ if (hx >= exp_ovfl && hx <= cexp_ovfl) {
143
+ /*
144
+ * x is between 709.7 and 1454.3, so we must scale to avoid
145
+ * overflow in exp(x).
146
+ */
147
+ return (ldexp_cexp(z, 0));
148
+ } else {
149
+ /*
150
+ * Cases covered here:
151
+ * - x < exp_ovfl and exp(x) won't overflow (common case)
152
+ * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0
153
+ * - x = +-Inf (generated by exp())
154
+ * - x = NaN (spurious inexact exception from y)
155
+ */
156
+ exp_x = ::exp(x);
157
+ return (complex<double>(exp_x * cos(y), exp_x * sin(y)));
158
+ }
159
+ }
160
+
161
+ } // namespace complex
162
+
163
+ } // namespace detail
164
+
165
+ template <typename ValueType>
166
+ __host__ __device__ inline complex<ValueType> exp(const complex<ValueType>& z) {
167
+ return polar(::exp(z.real()), z.imag());
168
+ }
169
+
170
+ template <>
171
+ __host__ __device__ inline complex<double> exp(const complex<double>& z) {
172
+ return detail::complex::cexp(z);
173
+ }
174
+
175
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/cexpf.h ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ *
31
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41
+ * SUCH DAMAGE.
42
+ */
43
+
44
+ /* adapted from FreeBSD:
45
+ * lib/msun/src/s_cexpf.c
46
+ * lib/msun/src/k_exp.c
47
+ *
48
+ */
49
+
50
+ #pragma once
51
+
52
+ #include <cupy/complex/complex.h>
53
+ #include <cupy/complex/math_private.h>
54
+
55
+ #include <cupy/complex/namespace.h>
56
+
57
+ THRUST_NAMESPACE_BEGIN
58
+ namespace detail {
59
+ namespace complex {
60
+
61
+ __host__ __device__ inline float frexp_expf(float x, int* expt) {
62
+ const uint32_t k = 235; /* constant for reduction */
63
+ const float kln2 = 162.88958740F; /* k * ln2 */
64
+
65
+ // should this be a double instead?
66
+ float exp_x;
67
+ uint32_t hx;
68
+
69
+ exp_x = expf(x - kln2);
70
+ get_float_word(hx, exp_x);
71
+ *expt = (hx >> 23) - (0x7f + 127) + k;
72
+ set_float_word(exp_x, (hx & 0x7fffff) | ((0x7f + 127) << 23));
73
+ return (exp_x);
74
+ }
75
+
76
+ __host__ __device__ inline complex<float> ldexp_cexpf(complex<float> z, int expt) {
77
+ float x, y, exp_x, scale1, scale2;
78
+ int ex_expt, half_expt;
79
+
80
+ x = z.real();
81
+ y = z.imag();
82
+ exp_x = frexp_expf(x, &ex_expt);
83
+ expt += ex_expt;
84
+
85
+ half_expt = expt / 2;
86
+ set_float_word(scale1, (0x7f + half_expt) << 23);
87
+ half_expt = expt - half_expt;
88
+ set_float_word(scale2, (0x7f + half_expt) << 23);
89
+
90
+ return (complex<float>(cos(y) * exp_x * scale1 * scale2,
91
+ sin(y) * exp_x * scale1 * scale2));
92
+ }
93
+
94
+ __host__ __device__ inline complex<float> cexpf(const complex<float>& z) {
95
+ float x, y, exp_x;
96
+ uint32_t hx, hy;
97
+
98
+ const uint32_t exp_ovfl = 0x42b17218, /* MAX_EXP * ln2 ~= 88.722839355 */
99
+ cexp_ovfl = 0x43400074; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */
100
+
101
+ x = z.real();
102
+ y = z.imag();
103
+
104
+ get_float_word(hy, y);
105
+ hy &= 0x7fffffff;
106
+
107
+ /* cexp(x + I 0) = exp(x) + I 0 */
108
+ if (hy == 0) return (complex<float>(exp(x), y));
109
+ get_float_word(hx, x);
110
+ /* cexp(0 + I y) = cos(y) + I sin(y) */
111
+ if ((hx & 0x7fffffff) == 0) {
112
+ return (complex<float>(cos(y), sin(y)));
113
+ }
114
+ if (hy >= 0x7f800000) {
115
+ if ((hx & 0x7fffffff) != 0x7f800000) {
116
+ /* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */
117
+ return (complex<float>(y - y, y - y));
118
+ } else if (hx & 0x80000000) {
119
+ /* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */
120
+ return (complex<float>(0.0, 0.0));
121
+ } else {
122
+ /* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */
123
+ return (complex<float>(x, y - y));
124
+ }
125
+ }
126
+
127
+ if (hx >= exp_ovfl && hx <= cexp_ovfl) {
128
+ /*
129
+ * x is between 88.7 and 192, so we must scale to avoid
130
+ * overflow in expf(x).
131
+ */
132
+ return (ldexp_cexpf(z, 0));
133
+ } else {
134
+ /*
135
+ * Cases covered here:
136
+ * - x < exp_ovfl and exp(x) won't overflow (common case)
137
+ * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0
138
+ * - x = +-Inf (generated by exp())
139
+ * - x = NaN (spurious inexact exception from y)
140
+ */
141
+ exp_x = ::exp(x);
142
+ return (complex<float>(exp_x * ::cos(y), exp_x * ::sin(y)));
143
+ }
144
+ }
145
+
146
+ } // namespace complex
147
+
148
+ } // namespace detail
149
+
150
+ template <>
151
+ __host__ __device__ inline complex<float> exp(const complex<float>& z) {
152
+ return detail::complex::cexpf(z);
153
+ }
154
+
155
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/clog.h ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2012 Stephen Montgomery-Smith <stephen@FreeBSD.ORG>
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ *
31
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41
+ * SUCH DAMAGE.
42
+ */
43
+
44
+ /* adapted from FreeBSDs msun:*/
45
+
46
+ #pragma once
47
+
48
+ #include <cupy/complex/complex.h>
49
+ #include <cupy/complex/math_private.h>
50
+
51
+ #include <cupy/complex/namespace.h>
52
+
53
+ THRUST_NAMESPACE_BEGIN
54
+ namespace detail {
55
+ namespace complex {
56
+
57
+ using thrust::complex;
58
+
59
+ /* round down to 18 = 54/3 bits */
60
+ __host__ __device__ inline double trim(double x) {
61
+ uint32_t hi;
62
+ get_high_word(hi, x);
63
+ insert_words(x, hi & 0xfffffff8, 0);
64
+ return x;
65
+ }
66
+
67
+ __host__ __device__ inline complex<double> clog(const complex<double>& z) {
68
+ // Adapted from FreeBSDs msun
69
+ double x, y;
70
+ double ax, ay;
71
+ double x0, y0, x1, y1, x2, y2, t, hm1;
72
+ double val[12];
73
+ int i, sorted;
74
+ const double e = 2.7182818284590452354;
75
+
76
+ x = z.real();
77
+ y = z.imag();
78
+
79
+ /* Handle NaNs using the general formula to mix them right. */
80
+ if (x != x || y != y) {
81
+ return (complex<double>(::log(norm(z)), ::atan2(y, x)));
82
+ }
83
+
84
+ ax = ::abs(x);
85
+ ay = ::abs(y);
86
+ if (ax < ay) {
87
+ t = ax;
88
+ ax = ay;
89
+ ay = t;
90
+ }
91
+
92
+ /*
93
+ * To avoid unnecessary overflow, if x and y are very large, divide x
94
+ * and y by M_E, and then add 1 to the logarithm. This depends on
95
+ * M_E being larger than sqrt(2).
96
+ * There is a potential loss of accuracy caused by dividing by M_E,
97
+ * but this case should happen extremely rarely.
98
+ */
99
+ // if (ay > 5e307){
100
+ // For high values of ay -> hypotf(DBL_MAX,ay) = inf
101
+ // We expect that for values at or below ay = 5e307 this should not happen
102
+ if (ay > 5e307) {
103
+ return (complex<double>(::log(hypot(x / e, y / e)) + 1.0, ::atan2(y, x)));
104
+ }
105
+ if (ax == 1.) {
106
+ if (ay < 1e-150) {
107
+ return (complex<double>((ay * 0.5) * ay, ::atan2(y, x)));
108
+ }
109
+ return (complex<double>(log1p(ay * ay) * 0.5, ::atan2(y, x)));
110
+ }
111
+
112
+ /*
113
+ * Because atan2 and hypot conform to C99, this also covers all the
114
+ * edge cases when x or y are 0 or infinite.
115
+ */
116
+ if (ax < 1e-50 || ay < 1e-50 || ax > 1e50 || ay > 1e50) {
117
+ return (complex<double>(::log(hypot(x, y)), ::atan2(y, x)));
118
+ }
119
+
120
+ /*
121
+ * From this point on, we don't need to worry about underflow or
122
+ * overflow in calculating ax*ax or ay*ay.
123
+ */
124
+
125
+ /* Some easy cases. */
126
+
127
+ if (ax >= 1.0) {
128
+ return (complex<double>(log1p((ax - 1) * (ax + 1) + ay * ay) * 0.5,
129
+ atan2(y, x)));
130
+ }
131
+
132
+ if (ax * ax + ay * ay <= 0.7) {
133
+ return (complex<double>(::log(ax * ax + ay * ay) * 0.5, ::atan2(y, x)));
134
+ }
135
+
136
+ /*
137
+ * Take extra care so that ULP of real part is small if hypot(x,y) is
138
+ * moderately close to 1.
139
+ */
140
+
141
+ x0 = trim(ax);
142
+ ax = ax - x0;
143
+ x1 = trim(ax);
144
+ x2 = ax - x1;
145
+ y0 = trim(ay);
146
+ ay = ay - y0;
147
+ y1 = trim(ay);
148
+ y2 = ay - y1;
149
+
150
+ val[0] = x0 * x0;
151
+ val[1] = y0 * y0;
152
+ val[2] = 2 * x0 * x1;
153
+ val[3] = 2 * y0 * y1;
154
+ val[4] = x1 * x1;
155
+ val[5] = y1 * y1;
156
+ val[6] = 2 * x0 * x2;
157
+ val[7] = 2 * y0 * y2;
158
+ val[8] = 2 * x1 * x2;
159
+ val[9] = 2 * y1 * y2;
160
+ val[10] = x2 * x2;
161
+ val[11] = y2 * y2;
162
+
163
+ /* Bubble sort. */
164
+
165
+ do {
166
+ sorted = 1;
167
+ for (i = 0; i < 11; i++) {
168
+ if (val[i] < val[i + 1]) {
169
+ sorted = 0;
170
+ t = val[i];
171
+ val[i] = val[i + 1];
172
+ val[i + 1] = t;
173
+ }
174
+ }
175
+ } while (!sorted);
176
+
177
+ hm1 = -1;
178
+ for (i = 0; i < 12; i++) {
179
+ hm1 += val[i];
180
+ }
181
+ return (complex<double>(0.5 * log1p(hm1), atan2(y, x)));
182
+ }
183
+
184
+ } // namespace complex
185
+
186
+ } // namespace detail
187
+
188
+ template <typename ValueType>
189
+ __host__ __device__ inline complex<ValueType> log(const complex<ValueType>& z) {
190
+ return complex<ValueType>(::log(thrust::abs(z)), thrust::arg(z));
191
+ }
192
+
193
+ template <>
194
+ __host__ __device__ inline complex<double> log(const complex<double>& z) {
195
+ return detail::complex::clog(z);
196
+ }
197
+
198
+ template <typename ValueType>
199
+ __host__ __device__ inline complex<ValueType> log10(const complex<ValueType>& z) {
200
+ // Using the explicit literal prevents compile time warnings in
201
+ // devices that don't support doubles
202
+ return thrust::log(z) / ValueType(2.30258509299404568402);
203
+ }
204
+
205
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/clogf.h ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2012 Stephen Montgomery-Smith <stephen@FreeBSD.ORG>
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ *
31
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41
+ * SUCH DAMAGE.
42
+ */
43
+
44
+ /* adapted from FreeBSDs msun:*/
45
+
46
+ #pragma once
47
+
48
+ #include <cupy/complex/complex.h>
49
+ #include <cupy/complex/math_private.h>
50
+
51
+ #include <cupy/complex/namespace.h>
52
+
53
+ THRUST_NAMESPACE_BEGIN
54
+ namespace detail {
55
+ namespace complex {
56
+
57
+ using thrust::complex;
58
+
59
+ /* round down to 8 = 24/3 bits */
60
+ __host__ __device__ inline float trim(float x) {
61
+ uint32_t hx;
62
+ get_float_word(hx, x);
63
+ hx &= 0xffff0000;
64
+ float ret;
65
+ set_float_word(ret, hx);
66
+ return ret;
67
+ }
68
+
69
+ __host__ __device__ inline complex<float> clogf(const complex<float>& z) {
70
+ // Adapted from FreeBSDs msun
71
+ float x, y;
72
+ float ax, ay;
73
+ float x0, y0, x1, y1, x2, y2, t, hm1;
74
+ float val[12];
75
+ int i, sorted;
76
+ const float e = 2.7182818284590452354f;
77
+
78
+ x = z.real();
79
+ y = z.imag();
80
+
81
+ /* Handle NaNs using the general formula to mix them right. */
82
+ if (x != x || y != y) {
83
+ return (complex<float>(::log(norm(z)), ::atan2(y, x)));
84
+ }
85
+
86
+ ax = ::abs(x);
87
+ ay = ::abs(y);
88
+ if (ax < ay) {
89
+ t = ax;
90
+ ax = ay;
91
+ ay = t;
92
+ }
93
+
94
+ /*
95
+ * To avoid unnecessary overflow, if x and y are very large, divide x
96
+ * and y by M_E, and then add 1 to the logarithm. This depends on
97
+ * M_E being larger than sqrt(2).
98
+ * There is a potential loss of accuracy caused by dividing by M_E,
99
+ * but this case should happen extremely rarely.
100
+ */
101
+ // For high values of ay -> hypotf(FLT_MAX,ay) = inf
102
+ // We expect that for values at or below ay = 1e34f this should not happen
103
+ if (ay > 1e34f) {
104
+ return (complex<float>(::log(hypotf(x / e, y / e)) + 1.0f, ::atan2(y, x)));
105
+ }
106
+ if (ax == 1.f) {
107
+ if (ay < 1e-19f) {
108
+ return (complex<float>((ay * 0.5f) * ay, ::atan2(y, x)));
109
+ }
110
+ return (complex<float>(log1pf(ay * ay) * 0.5f, ::atan2(y, x)));
111
+ }
112
+
113
+ /*
114
+ * Because atan2 and hypot conform to C99, this also covers all the
115
+ * edge cases when x or y are 0 or infinite.
116
+ */
117
+ if (ax < 1e-6f || ay < 1e-6f || ax > 1e6f || ay > 1e6f) {
118
+ return (complex<float>(::log(hypotf(x, y)), ::atan2(y, x)));
119
+ }
120
+
121
+ /*
122
+ * From this point on, we don't need to worry about underflow or
123
+ * overflow in calculating ax*ax or ay*ay.
124
+ */
125
+
126
+ /* Some easy cases. */
127
+
128
+ if (ax >= 1.0f) {
129
+ return (complex<float>(log1pf((ax - 1.f) * (ax + 1.f) + ay * ay) * 0.5f,
130
+ atan2(y, x)));
131
+ }
132
+
133
+ if (ax * ax + ay * ay <= 0.7f) {
134
+ return (complex<float>(::log(ax * ax + ay * ay) * 0.5f, ::atan2(y, x)));
135
+ }
136
+
137
+ /*
138
+ * Take extra care so that ULP of real part is small if hypot(x,y) is
139
+ * moderately close to 1.
140
+ */
141
+
142
+ x0 = trim(ax);
143
+ ax = ax - x0;
144
+ x1 = trim(ax);
145
+ x2 = ax - x1;
146
+ y0 = trim(ay);
147
+ ay = ay - y0;
148
+ y1 = trim(ay);
149
+ y2 = ay - y1;
150
+
151
+ val[0] = x0 * x0;
152
+ val[1] = y0 * y0;
153
+ val[2] = 2 * x0 * x1;
154
+ val[3] = 2 * y0 * y1;
155
+ val[4] = x1 * x1;
156
+ val[5] = y1 * y1;
157
+ val[6] = 2 * x0 * x2;
158
+ val[7] = 2 * y0 * y2;
159
+ val[8] = 2 * x1 * x2;
160
+ val[9] = 2 * y1 * y2;
161
+ val[10] = x2 * x2;
162
+ val[11] = y2 * y2;
163
+
164
+ /* Bubble sort. */
165
+
166
+ do {
167
+ sorted = 1;
168
+ for (i = 0; i < 11; i++) {
169
+ if (val[i] < val[i + 1]) {
170
+ sorted = 0;
171
+ t = val[i];
172
+ val[i] = val[i + 1];
173
+ val[i + 1] = t;
174
+ }
175
+ }
176
+ } while (!sorted);
177
+
178
+ hm1 = -1;
179
+ for (i = 0; i < 12; i++) {
180
+ hm1 += val[i];
181
+ }
182
+ return (complex<float>(0.5f * log1pf(hm1), atan2(y, x)));
183
+ }
184
+
185
+ } // namespace complex
186
+
187
+ } // namespace detail
188
+
189
+ template <>
190
+ __host__ __device__ inline complex<float> log(const complex<float>& z) {
191
+ return detail::complex::clogf(z);
192
+ }
193
+
194
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/complex.h ADDED
@@ -0,0 +1,676 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Copyright 2008-2013 NVIDIA Corporation
2
+ * Copyright 2013 Filipe RNC Maia
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file complex.h
18
+ * \brief Complex numbers
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <cupy/complex/namespace.h>
24
+
25
+ THRUST_NAMESPACE_BEGIN
26
+
27
+ template <typename T, typename U, bool x>
28
+ struct _select_greater_type_impl {
29
+ typedef T type;
30
+ };
31
+
32
+ template <typename T, typename U>
33
+ struct _select_greater_type_impl<T, U, false> {
34
+ typedef U type;
35
+ };
36
+
37
+ template <typename T, typename U>
38
+ struct _select_greater_type
39
+ : _select_greater_type_impl<T, U, (sizeof(T) > sizeof(U))> {};
40
+
41
+ /*
42
+ * Calls to the standard math library from inside the thrust namespace
43
+ * with real arguments require explicit scope otherwise they will fail
44
+ * to resolve as it will find the equivalent complex function but then
45
+ * fail to match the template, and give up looking for other scopes.
46
+ */
47
+
48
+ /*! \addtogroup numerics
49
+ * \{
50
+ */
51
+
52
+ /*! \addtogroup complex_numbers Complex Numbers
53
+ * \{
54
+ */
55
+
56
+ /*! \p complex is the Thrust equivalent to <tt>std::complex</tt>. It is
57
+ * functionally
58
+ * equivalent to it, but can also be used in device code which
59
+ * <tt>std::complex</tt> currently cannot.
60
+ *
61
+ * \tparam T The type used to hold the real and imaginary parts. Should be
62
+ * <tt>float</tt>
63
+ * or <tt>double</tt>. Others types are not supported.
64
+ *
65
+ */
66
+ template <typename T>
67
+ #if defined(__CUDACC__)
68
+ struct __align__(sizeof(T)*2) complex {
69
+ #else
70
+ // ROCm (hipcc) does not support `__align__`
71
+ struct complex {
72
+ #endif
73
+ public:
74
+ /*! \p value_type is the type of \p complex's real and imaginary parts.
75
+ */
76
+ typedef T value_type;
77
+
78
+ /* --- Constructors --- */
79
+
80
+ /*! Construct a complex number with an imaginary part of 0.
81
+ *
82
+ * \param re The real part of the number.
83
+ */
84
+ inline __host__ __device__ complex(const T& re);
85
+
86
+ /*! Construct a complex number from its real and imaginary parts.
87
+ *
88
+ * \param re The real part of the number.
89
+ * \param im The imaginary part of the number.
90
+ */
91
+ inline __host__ __device__ complex(const T& re, const T& im);
92
+
93
+ #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)
94
+ /*! Default construct a complex number.
95
+ */
96
+ inline complex() = default;
97
+
98
+ /*! This copy constructor copies from a \p complex with a type that is
99
+ * convertible to this \p complex's \c value_type.
100
+ *
101
+ * \param z The \p complex to copy from.
102
+ */
103
+ inline complex(const complex<T>& z) = default;
104
+ #else
105
+ /*! Default construct a complex number.
106
+ */
107
+ inline __host__ __device__ complex();
108
+
109
+ /*! This copy constructor copies from a \p complex with a type that is
110
+ * convertible to this \p complex's \c value_type.
111
+ *
112
+ * \param z The \p complex to copy from.
113
+ */
114
+ inline __host__ __device__ complex(const complex<T>& z);
115
+ #endif // c++11
116
+
117
+ /*! This copy constructor copies from a \p complex with a type that
118
+ * is convertible to this \p complex \c value_type.
119
+ *
120
+ * \param z The \p complex to copy from.
121
+ *
122
+ * \tparam X is convertible to \c value_type.
123
+ */
124
+ template <typename X>
125
+ inline __host__ __device__ complex(const complex<X>& z);
126
+
127
+ /* --- Assignment Operators --- */
128
+
129
+ /*! Assign `re` to the real part of this \p complex and set the imaginary part
130
+ * to 0.
131
+ *
132
+ * \param re The real part of the number.
133
+ */
134
+ inline __host__ __device__ complex& operator=(const T& re);
135
+
136
+ /*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this
137
+ * \p complex respectively.
138
+ *
139
+ * \param z The \p complex to copy from.
140
+ */
141
+ inline __host__ __device__ complex& operator=(const complex<T>& z);
142
+
143
+ /*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this
144
+ * \p complex respectively.
145
+ *
146
+ * \param z The \p complex to copy from.
147
+ *
148
+ * \tparam U is convertible to \c value_type.
149
+ */
150
+ template <typename U>
151
+ inline __host__ __device__ complex& operator=(const complex<U>& z);
152
+
153
+ /* --- Compound Assignment Operators --- */
154
+
155
+ /*! Adds a \p complex to this \p complex and
156
+ * assigns the result to this \p complex.
157
+ *
158
+ * \param z The \p complex to be Added.
159
+ */
160
+ __host__ __device__ inline complex<T>& operator+=(const complex<T> z);
161
+
162
+ /*! Subtracts a \p complex from this \p complex and
163
+ * assigns the result to this \p complex.
164
+ *
165
+ * \param z The \p complex to be subtracted.
166
+ */
167
+ __host__ __device__ inline complex<T>& operator-=(const complex<T> z);
168
+
169
+ /*! Multiplies this \p complex by another \p complex and
170
+ * assigns the result to this \p complex.
171
+ *
172
+ * \param z The \p complex to be multiplied.
173
+ */
174
+ __host__ __device__ inline complex<T>& operator*=(const complex<T> z);
175
+
176
+ /*! Divides this \p complex by another \p complex and
177
+ * assigns the result to this \p complex.
178
+ *
179
+ * \param z The \p complex to be divided.
180
+ */
181
+ __host__ __device__ inline complex<T>& operator/=(const complex<T> z);
182
+
183
+ /* --- Getter functions ---
184
+ * The volatile ones are there to help for example
185
+ * with certain reductions optimizations
186
+ */
187
+
188
+ /*! Returns the real part of this \p complex.
189
+ */
190
+ __host__ __device__ inline T real() const volatile { return m_data[0]; }
191
+
192
+ /*! Returns the imaginary part of this \p complex.
193
+ */
194
+ __host__ __device__ inline T imag() const volatile { return m_data[1]; }
195
+
196
+ /*! Returns the real part of this \p complex.
197
+ */
198
+ __host__ __device__ inline T real() const { return m_data[0]; }
199
+
200
+ /*! Returns the imaginary part of this \p complex.
201
+ */
202
+ __host__ __device__ inline T imag() const { return m_data[1]; }
203
+
204
+ /* --- Setter functions ---
205
+ * The volatile ones are there to help for example
206
+ * with certain reductions optimizations
207
+ */
208
+
209
+ /*! Sets the real part of this \p complex.
210
+ *
211
+ * \param re The new real part of this \p complex.
212
+ */
213
+ __host__ __device__ inline void real(T re) volatile { m_data[0] = re; }
214
+
215
+ /*! Sets the imaginary part of this \p complex.
216
+ *
217
+ * \param im The new imaginary part of this \p complex.e
218
+ */
219
+ __host__ __device__ inline void imag(T im) volatile { m_data[1] = im; }
220
+
221
+ /*! Sets the real part of this \p complex.
222
+ *
223
+ * \param re The new real part of this \p complex.
224
+ */
225
+ __host__ __device__ inline void real(T re) { m_data[0] = re; }
226
+
227
+ /*! Sets the imaginary part of this \p complex.
228
+ *
229
+ * \param im The new imaginary part of this \p complex.
230
+ */
231
+ __host__ __device__ inline void imag(T im) { m_data[1] = im; }
232
+
233
+ private:
234
+ T m_data[2];
235
+ };
236
+
237
+ /* --- General Functions --- */
238
+
239
+ /*! Returns the magnitude (also known as absolute value) of a \p complex.
240
+ *
241
+ * \param z The \p complex from which to calculate the absolute value.
242
+ */
243
+ template <typename T>
244
+ __host__ __device__ inline T abs(const complex<T>& z);
245
+
246
+ /*! Returns the phase angle (also known as argument) in radians of a \p complex.
247
+ *
248
+ * \param z The \p complex from which to calculate the phase angle.
249
+ */
250
+ template <typename T>
251
+ __host__ __device__ inline T arg(const complex<T>& z);
252
+
253
+ /*! Returns the square of the magnitude of a \p complex.
254
+ *
255
+ * \param z The \p complex from which to calculate the norm.
256
+ */
257
+ template <typename T>
258
+ __host__ __device__ inline T norm(const complex<T>& z);
259
+
260
+ /*! Returns the complex conjugate of a \p complex.
261
+ *
262
+ * \param z The \p complex from which to calculate the complex conjugate.
263
+ */
264
+ template <typename T>
265
+ __host__ __device__ inline complex<T> conj(const complex<T>& z);
266
+
267
+ /*! Returns the real part of a \p complex.
268
+ *
269
+ * \param z The \p complex from which to return the real part
270
+ */
271
+ template <typename T>
272
+ __host__ __device__ inline T real(const complex<T>& z);
273
+
274
+ /*! Returns the imaginary part of a \p complex.
275
+ *
276
+ * \param z The \p complex from which to return the imaginary part
277
+ */
278
+ template <typename T>
279
+ __host__ __device__ inline T imag(const complex<T>& z);
280
+
281
+ /*! Returns a \p complex with the specified magnitude and phase.
282
+ *
283
+ * \param m The magnitude of the returned \p complex.
284
+ * \param theta The phase of the returned \p complex in radians.
285
+ */
286
+ template <typename T>
287
+ __host__ __device__ inline complex<T> polar(const T& m, const T& theta = 0);
288
+
289
+ /*! Returns the projection of a \p complex on the Riemann sphere.
290
+ * For all finite \p complex it returns the argument. For \p complexs
291
+ * with a non finite part returns (INFINITY,+/-0) where the sign of
292
+ * the zero matches the sign of the imaginary part of the argument.
293
+ *
294
+ * \param z The \p complex argument.
295
+ */
296
+ template <typename T>
297
+ __host__ __device__ inline complex<T> proj(const T& z);
298
+
299
+ /* --- Binary Arithmetic operators --- */
300
+
301
+ /*! Multiplies two \p complex numbers.
302
+ *
303
+ * \param lhs The first \p complex.
304
+ * \param rhs The second \p complex.
305
+ */
306
+ template <typename T>
307
+ __host__ __device__ inline complex<T> operator*(const complex<T>& lhs,
308
+ const complex<T>& rhs);
309
+
310
+ /*! Multiplies a \p complex number by a scalar.
311
+ *
312
+ * \param lhs The \p complex.
313
+ * \param rhs The scalar.
314
+ */
315
+ template <typename T>
316
+ __host__ __device__ inline complex<T> operator*(const complex<T>& lhs, const T& rhs);
317
+
318
+ /*! Multiplies a scalar by a \p complex number.
319
+ *
320
+ * \param lhs The scalar.
321
+ * \param rhs The \p complex.
322
+ */
323
+ template <typename T>
324
+ __host__ __device__ inline complex<T> operator*(const T& lhs, const complex<T>& rhs);
325
+
326
+ /*! Divides two \p complex numbers.
327
+ *
328
+ * \param lhs The numerator (dividend).
329
+ * \param rhs The denomimator (divisor).
330
+ */
331
+ template <typename T>
332
+ __host__ __device__ inline complex<T> operator/(const complex<T>& lhs,
333
+ const complex<T>& rhs);
334
+
335
+ /*! Divides a \p complex number by a scalar.
336
+ *
337
+ * \param lhs The complex numerator (dividend).
338
+ * \param rhs The scalar denomimator (divisor).
339
+ */
340
+ template <typename T>
341
+ __host__ __device__ inline complex<T> operator/(const complex<T>& lhs, const T& rhs);
342
+
343
+ /*! Divides a scalar by a \p complex number.
344
+ *
345
+ * \param lhs The scalar numerator (dividend).
346
+ * \param rhs The complex denomimator (divisor).
347
+ */
348
+ template <typename T>
349
+ __host__ __device__ inline complex<T> operator/(const T& lhs, const complex<T>& rhs);
350
+
351
+ /*! Adds two \p complex numbers.
352
+ *
353
+ * \param lhs The first \p complex.
354
+ * \param rhs The second \p complex.
355
+ */
356
+ template <typename T>
357
+ __host__ __device__ inline complex<T> operator+(const complex<T>& lhs,
358
+ const complex<T>& rhs);
359
+
360
+ /*! Adds a scalar to a \p complex number.
361
+ *
362
+ * \param lhs The \p complex.
363
+ * \param rhs The scalar.
364
+ */
365
+ template <typename T>
366
+ __host__ __device__ inline complex<T> operator+(const complex<T>& lhs, const T& rhs);
367
+
368
+ /*! Adds a \p complex number to a scalar.
369
+ *
370
+ * \param lhs The scalar.
371
+ * \param rhs The \p complex.
372
+ */
373
+ template <typename T>
374
+ __host__ __device__ inline complex<T> operator+(const T& lhs, const complex<T>& rhs);
375
+
376
+ /*! Subtracts two \p complex numbers.
377
+ *
378
+ * \param lhs The first \p complex (minuend).
379
+ * \param rhs The second \p complex (subtrahend).
380
+ */
381
+ template <typename T>
382
+ __host__ __device__ inline complex<T> operator-(const complex<T>& lhs,
383
+ const complex<T>& rhs);
384
+
385
+ /*! Subtracts a scalar from a \p complex number.
386
+ *
387
+ * \param lhs The \p complex (minuend).
388
+ * \param rhs The scalar (subtrahend).
389
+ */
390
+ template <typename T>
391
+ __host__ __device__ inline complex<T> operator-(const complex<T>& lhs, const T& rhs);
392
+
393
+ /*! Subtracts a \p complex number from a scalar.
394
+ *
395
+ * \param lhs The scalar (minuend).
396
+ * \param rhs The \p complex (subtrahend).
397
+ */
398
+ template <typename T>
399
+ __host__ __device__ inline complex<T> operator-(const T& lhs, const complex<T>& rhs);
400
+
401
+ /* --- Unary Arithmetic operators --- */
402
+
403
+ /*! Unary plus, returns its \p complex argument.
404
+ *
405
+ * \param rhs The \p complex argument.
406
+ */
407
+ template <typename T>
408
+ __host__ __device__ inline complex<T> operator+(const complex<T>& rhs);
409
+
410
+ /*! Unary minus, returns the additive inverse (negation) of its \p complex
411
+ * argument.
412
+ *
413
+ * \param rhs The \p complex argument.
414
+ */
415
+ template <typename T>
416
+ __host__ __device__ inline complex<T> operator-(const complex<T>& rhs);
417
+
418
+ /* --- Exponential Functions --- */
419
+
420
+ /*! Returns the complex exponential of a \p complex number.
421
+ *
422
+ * \param z The \p complex argument.
423
+ */
424
+ template <typename T>
425
+ __host__ __device__ complex<T> exp(const complex<T>& z);
426
+
427
+ /*! Returns the complex natural logarithm of a \p complex number.
428
+ *
429
+ * \param z The \p complex argument.
430
+ */
431
+ template <typename T>
432
+ __host__ __device__ complex<T> log(const complex<T>& z);
433
+
434
+ /*! Returns the complex base 10 logarithm of a \p complex number.
435
+ *
436
+ * \param z The \p complex argument.
437
+ */
438
+ template <typename T>
439
+ __host__ __device__ inline complex<T> log10(const complex<T>& z);
440
+
441
+ /* --- Power Functions --- */
442
+
443
+ /*! Returns a \p complex number raised to another.
444
+ *
445
+ * \param x The base.
446
+ * \param y The exponent.
447
+ */
448
+ template <typename T>
449
+ __host__ __device__ complex<T> pow(const complex<T>& x, const complex<T>& y);
450
+
451
+ /*! Returns a \p complex number raised to a scalar.
452
+ *
453
+ * \param x The \p complex base.
454
+ * \param y The scalar exponent.
455
+ */
456
+ template <typename T>
457
+ __host__ __device__ complex<T> pow(const complex<T>& x, const T& y);
458
+
459
+ /*! Returns a scalar raised to a \p complex number.
460
+ *
461
+ * \param x The scalar base.
462
+ * \param y The \p complex exponent.
463
+ */
464
+ template <typename T>
465
+ __host__ __device__ complex<T> pow(const T& x, const complex<T>& y);
466
+
467
+ /*! Returns a \p complex number raised to another. The types of the two \p
468
+ * complex should be compatible
469
+ * and the type of the returned \p complex is the promoted type of the two
470
+ * arguments.
471
+ *
472
+ * \param x The base.
473
+ * \param y The exponent.
474
+ */
475
+ template <typename T, typename U>
476
+ __host__ __device__ complex<typename _select_greater_type<T, U>::type> pow(
477
+ const complex<T>& x, const complex<U>& y);
478
+
479
+ /*! Returns a \p complex number raised to a scalar. The type of the \p complex
480
+ * should be compatible with the scalar
481
+ * and the type of the returned \p complex is the promoted type of the two
482
+ * arguments.
483
+ *
484
+ * \param x The base.
485
+ * \param y The exponent.
486
+ */
487
+ template <typename T, typename U>
488
+ __host__ __device__ complex<typename _select_greater_type<T, U>::type> pow(
489
+ const complex<T>& x, const U& y);
490
+
491
+ /*! Returns a scalar raised to a \p complex number. The type of the \p complex
492
+ * should be compatible with the scalar
493
+ * and the type of the returned \p complex is the promoted type of the two
494
+ * arguments.
495
+ *
496
+ * \param x The base.
497
+ * \param y The exponent.
498
+ */
499
+ template <typename T, typename U>
500
+ __host__ __device__ complex<typename _select_greater_type<T, U>::type> pow(
501
+ const T& x, const complex<U>& y);
502
+
503
+ /*! Returns the complex square root of a \p complex number.
504
+ *
505
+ * \param z The \p complex argument.
506
+ */
507
+ template <typename T>
508
+ __host__ __device__ complex<T> sqrt(const complex<T>& z);
509
+
510
+ /* --- Trigonometric Functions --- */
511
+
512
+ /*! Returns the complex cosine of a \p complex number.
513
+ *
514
+ * \param z The \p complex argument.
515
+ */
516
+ template <typename T>
517
+ __host__ __device__ complex<T> cos(const complex<T>& z);
518
+
519
+ /*! Returns the complex sine of a \p complex number.
520
+ *
521
+ * \param z The \p complex argument.
522
+ */
523
+ template <typename T>
524
+ __host__ __device__ complex<T> sin(const complex<T>& z);
525
+
526
+ /*! Returns the complex tangent of a \p complex number.
527
+ *
528
+ * \param z The \p complex argument.
529
+ */
530
+ template <typename T>
531
+ __host__ __device__ complex<T> tan(const complex<T>& z);
532
+
533
+ /* --- Hyperbolic Functions --- */
534
+
535
+ /*! Returns the complex hyperbolic cosine of a \p complex number.
536
+ *
537
+ * \param z The \p complex argument.
538
+ */
539
+ template <typename T>
540
+ __host__ __device__ complex<T> cosh(const complex<T>& z);
541
+
542
+ /*! Returns the complex hyperbolic sine of a \p complex number.
543
+ *
544
+ * \param z The \p complex argument.
545
+ */
546
+ template <typename T>
547
+ __host__ __device__ complex<T> sinh(const complex<T>& z);
548
+
549
+ /*! Returns the complex hyperbolic tangent of a \p complex number.
550
+ *
551
+ * \param z The \p complex argument.
552
+ */
553
+ template <typename T>
554
+ __host__ __device__ complex<T> tanh(const complex<T>& z);
555
+
556
+ /* --- Inverse Trigonometric Functions --- */
557
+
558
+ /*! Returns the complex arc cosine of a \p complex number.
559
+ *
560
+ * The range of the real part of the result is [0, Pi] and
561
+ * the range of the imaginary part is [-inf, +inf]
562
+ *
563
+ * \param z The \p complex argument.
564
+ */
565
+ template <typename T>
566
+ __host__ __device__ complex<T> acos(const complex<T>& z);
567
+
568
+ /*! Returns the complex arc sine of a \p complex number.
569
+ *
570
+ * The range of the real part of the result is [-Pi/2, Pi/2] and
571
+ * the range of the imaginary part is [-inf, +inf]
572
+ *
573
+ * \param z The \p complex argument.
574
+ */
575
+ template <typename T>
576
+ __host__ __device__ complex<T> asin(const complex<T>& z);
577
+
578
+ /*! Returns the complex arc tangent of a \p complex number.
579
+ *
580
+ * The range of the real part of the result is [-Pi/2, Pi/2] and
581
+ * the range of the imaginary part is [-inf, +inf]
582
+ *
583
+ * \param z The \p complex argument.
584
+ */
585
+ template <typename T>
586
+ __host__ __device__ complex<T> atan(const complex<T>& z);
587
+
588
+ /* --- Inverse Hyperbolic Functions --- */
589
+
590
+ /*! Returns the complex inverse hyperbolic cosine of a \p complex number.
591
+ *
592
+ * The range of the real part of the result is [0, +inf] and
593
+ * the range of the imaginary part is [-Pi, Pi]
594
+ *
595
+ * \param z The \p complex argument.
596
+ */
597
+ template <typename T>
598
+ __host__ __device__ complex<T> acosh(const complex<T>& z);
599
+
600
+ /*! Returns the complex inverse hyperbolic sine of a \p complex number.
601
+ *
602
+ * The range of the real part of the result is [-inf, +inf] and
603
+ * the range of the imaginary part is [-Pi/2, Pi/2]
604
+ *
605
+ * \param z The \p complex argument.
606
+ */
607
+ template <typename T>
608
+ __host__ __device__ complex<T> asinh(const complex<T>& z);
609
+
610
+ /*! Returns the complex inverse hyperbolic tangent of a \p complex number.
611
+ *
612
+ * The range of the real part of the result is [-inf, +inf] and
613
+ * the range of the imaginary part is [-Pi/2, Pi/2]
614
+ *
615
+ * \param z The \p complex argument.
616
+ */
617
+ template <typename T>
618
+ __host__ __device__ complex<T> atanh(const complex<T>& z);
619
+
620
+ /* --- Equality Operators --- */
621
+
622
+ /*! Returns true if two \p complex numbers are equal and false otherwise.
623
+ *
624
+ * \param lhs The first \p complex.
625
+ * \param rhs The second \p complex.
626
+ */
627
+ template <typename T>
628
+ __host__ __device__ inline bool operator==(const complex<T>& lhs, const complex<T>& rhs);
629
+
630
+ /*! Returns true if the imaginary part of the \p complex number is zero and the
631
+ * real part is equal to the scalar. Returns false otherwise.
632
+ *
633
+ * \param lhs The scalar.
634
+ * \param rhs The \p complex.
635
+ */
636
+ template <typename T>
637
+ __host__ __device__ inline bool operator==(const T& lhs, const complex<T>& rhs);
638
+
639
+ /*! Returns true if the imaginary part of the \p complex number is zero and the
640
+ * real part is equal to the scalar. Returns false otherwise.
641
+ *
642
+ * \param lhs The \p complex.
643
+ * \param rhs The scalar.
644
+ */
645
+ template <typename T>
646
+ __host__ __device__ inline bool operator==(const complex<T>& lhs, const T& rhs);
647
+
648
+ /*! Returns true if two \p complex numbers are different and false otherwise.
649
+ *
650
+ * \param lhs The first \p complex.
651
+ * \param rhs The second \p complex.
652
+ */
653
+ template <typename T>
654
+ __host__ __device__ inline bool operator!=(const complex<T>& lhs, const complex<T>& rhs);
655
+
656
+ /*! Returns true if the imaginary part of the \p complex number is not zero or
657
+ * the real part is different from the scalar. Returns false otherwise.
658
+ *
659
+ * \param lhs The scalar.
660
+ * \param rhs The \p complex.
661
+ */
662
+ template <typename T>
663
+ __host__ __device__ inline bool operator!=(const T& lhs, const complex<T>& rhs);
664
+
665
+ /*! Returns true if the imaginary part of the \p complex number is not zero or
666
+ * the real part is different from the scalar. Returns false otherwise.
667
+ *
668
+ * \param lhs The \p complex.
669
+ * \param rhs The scalar.
670
+ */
671
+ template <typename T>
672
+ __host__ __device__ inline bool operator!=(const complex<T>& lhs, const T& rhs);
673
+
674
+ THRUST_NAMESPACE_END
675
+
676
+ #include <cupy/complex/complex_inl.h>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/complex_inl.h ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <cupy/complex/complex.h>
21
+
22
+ #include <cupy/complex/namespace.h>
23
+
24
+ THRUST_NAMESPACE_BEGIN
25
+
26
+ /* --- Constructors --- */
27
+ template <typename T>
28
+ inline __host__ __device__ complex<T>::complex(const T& re) {
29
+ real(re);
30
+ imag(T());
31
+ }
32
+
33
+ template <typename T>
34
+ inline __host__ __device__ complex<T>::complex(const T& re, const T& im) {
35
+ real(re);
36
+ imag(im);
37
+ }
38
+
39
+ #if ((!defined(_MSC_VER) && __cplusplus < 201103L) || \
40
+ (defined(_MSC_VER) && _MSC_VER < 1900))
41
+ template <typename T>
42
+ inline __host__ __device__ complex<T>::complex() {
43
+ real(T());
44
+ imag(T());
45
+ }
46
+
47
+ template <typename T>
48
+ inline __host__ __device__ complex<T>::complex(const complex<T>& z) {
49
+ real(z.real());
50
+ imag(z.imag());
51
+ }
52
+ #endif
53
+
54
+ template <typename T>
55
+ template <typename X>
56
+ inline __host__ __device__ complex<T>::complex(const complex<X>& z) {
57
+ // The explicit T() is there no prevent Visual Studio from complaining
58
+ // about potential loss of precision
59
+ real(T(z.real()));
60
+ imag(T(z.imag()));
61
+ }
62
+
63
+ /* --- Assignment Operators --- */
64
+
65
+ template <typename T>
66
+ inline __host__ __device__ complex<T>& complex<T>::operator=(const T& re) {
67
+ real(re);
68
+ imag(T());
69
+ return *this;
70
+ }
71
+
72
+ template <typename T>
73
+ inline __host__ __device__ complex<T>& complex<T>::operator=(const complex<T>& z) {
74
+ real(z.real());
75
+ imag(z.imag());
76
+ return *this;
77
+ }
78
+
79
+ template <typename T>
80
+ template <typename U>
81
+ inline __host__ __device__ complex<T>& complex<T>::operator=(const complex<U>& z) {
82
+ real(T(z.real()));
83
+ imag(T(z.imag()));
84
+ return *this;
85
+ }
86
+
87
+ /* --- Compound Assignment Operators --- */
88
+ // TODO(leofang): support operators with argument of type T, see upstream
89
+
90
+ template <typename T>
91
+ __host__ __device__ inline complex<T>& complex<T>::operator+=(const complex<T> z) {
92
+ *this = *this + z;
93
+ return *this;
94
+ }
95
+
96
+ template <typename T>
97
+ __host__ __device__ inline complex<T>& complex<T>::operator-=(const complex<T> z) {
98
+ *this = *this - z;
99
+ return *this;
100
+ }
101
+
102
+ template <typename T>
103
+ __host__ __device__ inline complex<T>& complex<T>::operator*=(const complex<T> z) {
104
+ *this = *this * z;
105
+ return *this;
106
+ }
107
+
108
+ template <typename T>
109
+ __host__ __device__ inline complex<T>& complex<T>::operator/=(const complex<T> z) {
110
+ *this = *this / z;
111
+ return *this;
112
+ }
113
+
114
+ /* --- Equality Operators --- */
115
+
116
+ template <typename T>
117
+ __host__ __device__ inline bool operator==(const complex<T>& lhs,
118
+ const complex<T>& rhs) {
119
+ return lhs.real() == rhs.real() && lhs.imag() == rhs.imag();
120
+ }
121
+
122
+ template <typename T>
123
+ __host__ __device__ inline bool operator==(const T& lhs, const complex<T>& rhs) {
124
+ return lhs == rhs.real() && rhs.imag() == 0;
125
+ }
126
+
127
+ template <typename T>
128
+ __host__ __device__ inline bool operator==(const complex<T>& lhs, const T& rhs) {
129
+ return lhs.real() == rhs && lhs.imag() == 0;
130
+ }
131
+
132
+ template <typename T>
133
+ __host__ __device__ inline bool operator!=(const complex<T>& lhs,
134
+ const complex<T>& rhs) {
135
+ return !(lhs == rhs);
136
+ }
137
+
138
+ template <typename T>
139
+ __host__ __device__ inline bool operator!=(const T& lhs, const complex<T>& rhs) {
140
+ return !(lhs == rhs);
141
+ }
142
+
143
+ template <typename T>
144
+ __host__ __device__ inline bool operator!=(const complex<T>& lhs, const T& rhs) {
145
+ return !(lhs == rhs);
146
+ }
147
+
148
+ THRUST_NAMESPACE_END
149
+
150
+
151
+ #include <cupy/complex/arithmetic.h>
152
+ #include <cupy/complex/cproj.h>
153
+ #include <cupy/complex/cexp.h>
154
+ #include <cupy/complex/cexpf.h>
155
+ #include <cupy/complex/clog.h>
156
+ #include <cupy/complex/clogf.h>
157
+ #include <cupy/complex/cpow.h>
158
+ #include <cupy/complex/ccosh.h>
159
+ #include <cupy/complex/ccoshf.h>
160
+ #include <cupy/complex/csinh.h>
161
+ #include <cupy/complex/csinhf.h>
162
+ #include <cupy/complex/ctanh.h>
163
+ #include <cupy/complex/ctanhf.h>
164
+ #include <cupy/complex/csqrt.h>
165
+ #include <cupy/complex/csqrtf.h>
166
+ #include <cupy/complex/catrig.h>
167
+ #include <cupy/complex/catrigf.h>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/csinh.h ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice unmodified, this list of conditions, and the following
27
+ * disclaimer.
28
+ * 2. Redistributions in binary form must reproduce the above copyright
29
+ * notice, this list of conditions and the following disclaimer in the
30
+ * documentation and/or other materials provided with the distribution.
31
+ *
32
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+ */
43
+
44
+ /* adapted from FreeBSD:
45
+ * lib/msun/src/s_csinh.c
46
+ */
47
+
48
+ #pragma once
49
+
50
+ #include <cupy/complex/complex.h>
51
+ #include <cupy/complex/math_private.h>
52
+
53
+ #include <cupy/complex/namespace.h>
54
+
55
+ THRUST_NAMESPACE_BEGIN
56
+ namespace detail {
57
+ namespace complex {
58
+
59
+ using thrust::complex;
60
+
61
+ __host__ __device__ inline complex<double> csinh(const complex<double>& z) {
62
+ double x, y, h;
63
+ uint32_t hx, hy, ix, iy, lx, ly;
64
+ const double huge = 8.98846567431157953864652595395e+307; // 0x1p1023;
65
+
66
+ x = z.real();
67
+ y = z.imag();
68
+
69
+ extract_words(hx, lx, x);
70
+ extract_words(hy, ly, y);
71
+
72
+ ix = 0x7fffffff & hx;
73
+ iy = 0x7fffffff & hy;
74
+
75
+ /* Handle the nearly-non-exceptional cases where x and y are finite. */
76
+ if (ix < 0x7ff00000 && iy < 0x7ff00000) {
77
+ if ((iy | ly) == 0) return (complex<double>(sinh(x), y));
78
+ if (ix < 0x40360000) /* small x: normal case */
79
+ return (complex<double>(sinh(x) * cos(y), cosh(x) * sin(y)));
80
+
81
+ /* |x| >= 22, so cosh(x) ~= exp(|x|) */
82
+ if (ix < 0x40862e42) {
83
+ /* x < 710: exp(|x|) won't overflow */
84
+ h = exp(fabs(x)) * 0.5;
85
+ return (complex<double>(copysign(h, x) * cos(y), h * sin(y)));
86
+ } else if (ix < 0x4096bbaa) {
87
+ /* x < 1455: scale to avoid overflow */
88
+ complex<double> z_ = ldexp_cexp(complex<double>(fabs(x), y), -1);
89
+ return (complex<double>(z_.real() * copysign(1.0, x), z_.imag()));
90
+ } else {
91
+ /* x >= 1455: the result always overflows */
92
+ h = huge * x;
93
+ return (complex<double>(h * cos(y), h * h * sin(y)));
94
+ }
95
+ }
96
+
97
+ /*
98
+ * sinh(+-0 +- I Inf) = sign(d(+-0, dNaN))0 + I dNaN.
99
+ * The sign of 0 in the result is unspecified. Choice = normally
100
+ * the same as dNaN. Raise the invalid floating-point exception.
101
+ *
102
+ * sinh(+-0 +- I NaN) = sign(d(+-0, NaN))0 + I d(NaN).
103
+ * The sign of 0 in the result is unspecified. Choice = normally
104
+ * the same as d(NaN).
105
+ */
106
+ if ((ix | lx) == 0 && iy >= 0x7ff00000)
107
+ return (complex<double>(copysign(0.0, x * (y - y)), y - y));
108
+
109
+ /*
110
+ * sinh(+-Inf +- I 0) = +-Inf + I +-0.
111
+ *
112
+ * sinh(NaN +- I 0) = d(NaN) + I +-0.
113
+ */
114
+ if ((iy | ly) == 0 && ix >= 0x7ff00000) {
115
+ if (((hx & 0xfffff) | lx) == 0) return (complex<double>(x, y));
116
+ return (complex<double>(x, copysign(0.0, y)));
117
+ }
118
+
119
+ /*
120
+ * sinh(x +- I Inf) = dNaN + I dNaN.
121
+ * Raise the invalid floating-point exception for finite nonzero x.
122
+ *
123
+ * sinh(x + I NaN) = d(NaN) + I d(NaN).
124
+ * Optionally raises the invalid floating-point exception for finite
125
+ * nonzero x. Choice = don't raise (except for signaling NaNs).
126
+ */
127
+ if (ix < 0x7ff00000 && iy >= 0x7ff00000)
128
+ return (complex<double>(y - y, x * (y - y)));
129
+
130
+ /*
131
+ * sinh(+-Inf + I NaN) = +-Inf + I d(NaN).
132
+ * The sign of Inf in the result is unspecified. Choice = normally
133
+ * the same as d(NaN).
134
+ *
135
+ * sinh(+-Inf +- I Inf) = +Inf + I dNaN.
136
+ * The sign of Inf in the result is unspecified. Choice = always +.
137
+ * Raise the invalid floating-point exception.
138
+ *
139
+ * sinh(+-Inf + I y) = +-Inf cos(y) + I Inf sin(y)
140
+ */
141
+ if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) {
142
+ if (iy >= 0x7ff00000) return (complex<double>(x * x, x * (y - y)));
143
+ return (complex<double>(x * cos(y), infinity<double>() * sin(y)));
144
+ }
145
+
146
+ /*
147
+ * sinh(NaN + I NaN) = d(NaN) + I d(NaN).
148
+ *
149
+ * sinh(NaN +- I Inf) = d(NaN) + I d(NaN).
150
+ * Optionally raises the invalid floating-point exception.
151
+ * Choice = raise.
152
+ *
153
+ * sinh(NaN + I y) = d(NaN) + I d(NaN).
154
+ * Optionally raises the invalid floating-point exception for finite
155
+ * nonzero y. Choice = don't raise (except for signaling NaNs).
156
+ */
157
+ return (complex<double>((x * x) * (y - y), (x + x) * (y - y)));
158
+ }
159
+
160
+ __host__ __device__ inline complex<double> csin(complex<double> z) {
161
+ /* csin(z) = -I * csinh(I * z) */
162
+ z = csinh(complex<double>(-z.imag(), z.real()));
163
+ return (complex<double>(z.imag(), -z.real()));
164
+ }
165
+
166
+ } // namespace complex
167
+
168
+ } // namespace detail
169
+
170
+ template <typename ValueType>
171
+ __host__ __device__ inline complex<ValueType> sin(const complex<ValueType>& z) {
172
+ const ValueType re = z.real();
173
+ const ValueType im = z.imag();
174
+ return complex<ValueType>(::sin(re) * ::cosh(im), ::cos(re) * ::sinh(im));
175
+ }
176
+
177
+ template <typename ValueType>
178
+ __host__ __device__ inline complex<ValueType> sinh(const complex<ValueType>& z) {
179
+ const ValueType re = z.real();
180
+ const ValueType im = z.imag();
181
+ return complex<ValueType>(::sinh(re) * ::cos(im), ::cosh(re) * ::sin(im));
182
+ }
183
+
184
+ template <>
185
+ __host__ __device__ inline complex<double> sin(const complex<double>& z) {
186
+ return detail::complex::csin(z);
187
+ }
188
+
189
+ template <>
190
+ __host__ __device__ inline complex<double> sinh(const complex<double>& z) {
191
+ return detail::complex::csinh(z);
192
+ }
193
+
194
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/csinhf.h ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice unmodified, this list of conditions, and the following
27
+ * disclaimer.
28
+ * 2. Redistributions in binary form must reproduce the above copyright
29
+ * notice, this list of conditions and the following disclaimer in the
30
+ * documentation and/or other materials provided with the distribution.
31
+ *
32
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+ */
43
+
44
+ /* adapted from FreeBSD:
45
+ * lib/msun/src/s_csinhf.c
46
+ */
47
+
48
+ #pragma once
49
+
50
+ #include <cupy/complex/complex.h>
51
+ #include <cupy/complex/math_private.h>
52
+
53
+ #include <cupy/complex/namespace.h>
54
+
55
+ THRUST_NAMESPACE_BEGIN
56
+ namespace detail {
57
+ namespace complex {
58
+
59
+ using thrust::complex;
60
+
61
+ __host__ __device__ inline complex<float> csinhf(const complex<float>& z) {
62
+ float x, y, h;
63
+ uint32_t hx, hy, ix, iy;
64
+
65
+ const float huge = 1.70141183460469231731687303716e+38; // 0x1p127;
66
+
67
+ x = z.real();
68
+ y = z.imag();
69
+
70
+ get_float_word(hx, x);
71
+ get_float_word(hy, y);
72
+
73
+ ix = 0x7fffffff & hx;
74
+ iy = 0x7fffffff & hy;
75
+
76
+ if (ix < 0x7f800000 && iy < 0x7f800000) {
77
+ if (iy == 0) return (complex<float>(sinhf(x), y));
78
+ if (ix < 0x41100000) /* small x: normal case */
79
+ return (complex<float>(sinhf(x) * cosf(y), coshf(x) * sinf(y)));
80
+
81
+ /* |x| >= 9, so cosh(x) ~= exp(|x|) */
82
+ if (ix < 0x42b17218) {
83
+ /* x < 88.7: expf(|x|) won't overflow */
84
+ h = expf(fabsf(x)) * 0.5f;
85
+ return (complex<float>(copysignf(h, x) * cosf(y), h * sinf(y)));
86
+ } else if (ix < 0x4340b1e7) {
87
+ /* x < 192.7: scale to avoid overflow */
88
+ complex<float> z_ = ldexp_cexpf(complex<float>(fabsf(x), y), -1);
89
+ return (complex<float>(z_.real() * copysignf(1.0f, x), z_.imag()));
90
+ } else {
91
+ /* x >= 192.7: the result always overflows */
92
+ h = huge * x;
93
+ return (complex<float>(h * cosf(y), h * h * sinf(y)));
94
+ }
95
+ }
96
+
97
+ if (ix == 0 && iy >= 0x7f800000)
98
+ return (complex<float>(copysignf(0, x * (y - y)), y - y));
99
+
100
+ if (iy == 0 && ix >= 0x7f800000) {
101
+ if ((hx & 0x7fffff) == 0) return (complex<float>(x, y));
102
+ return (complex<float>(x, copysignf(0.0f, y)));
103
+ }
104
+
105
+ if (ix < 0x7f800000 && iy >= 0x7f800000)
106
+ return (complex<float>(y - y, x * (y - y)));
107
+
108
+ if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) {
109
+ if (iy >= 0x7f800000) return (complex<float>(x * x, x * (y - y)));
110
+ return (complex<float>(x * cosf(y), infinity<float>() * sinf(y)));
111
+ }
112
+
113
+ return (complex<float>((x * x) * (y - y), (x + x) * (y - y)));
114
+ }
115
+
116
+ __host__ __device__ inline complex<float> csinf(complex<float> z) {
117
+ z = csinhf(complex<float>(-z.imag(), z.real()));
118
+ return (complex<float>(z.imag(), -z.real()));
119
+ }
120
+
121
+ } // namespace complex
122
+
123
+ } // namespace detail
124
+
125
+ template <>
126
+ __host__ __device__ inline complex<float> sin(const complex<float>& z) {
127
+ return detail::complex::csinf(z);
128
+ }
129
+
130
+ template <>
131
+ __host__ __device__ inline complex<float> sinh(const complex<float>& z) {
132
+ return detail::complex::csinhf(z);
133
+ }
134
+
135
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/ctanh.h ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2011 David Schultz
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice unmodified, this list of conditions, and the following
27
+ * disclaimer.
28
+ * 2. Redistributions in binary form must reproduce the above copyright
29
+ * notice, this list of conditions and the following disclaimer in the
30
+ * documentation and/or other materials provided with the distribution.
31
+ *
32
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+ */
43
+
44
+ /*
45
+ * Adapted from FreeBSD by Filipe Maia <filipe.c.maia@gmail.com>:
46
+ * freebsd/lib/msun/src/s_ctanh.c
47
+ */
48
+
49
+ /*
50
+ * Hyperbolic tangent of a complex argument z = x + i y.
51
+ *
52
+ * The algorithm is from:
53
+ *
54
+ * W. Kahan. Branch Cuts for Complex Elementary Functions or Much
55
+ * Ado About Nothing's Sign Bit. In The State of the Art in
56
+ * Numerical Analysis, pp. 165 ff. Iserles and Powell, eds., 1987.
57
+ *
58
+ * Method:
59
+ *
60
+ * Let t = tan(x)
61
+ * beta = 1/cos^2(y)
62
+ * s = sinh(x)
63
+ * rho = cosh(x)
64
+ *
65
+ * We have:
66
+ *
67
+ * tanh(z) = sinh(z) / cosh(z)
68
+ *
69
+ * sinh(x) cos(y) + i cosh(x) sin(y)
70
+ * = ---------------------------------
71
+ * cosh(x) cos(y) + i sinh(x) sin(y)
72
+ *
73
+ * cosh(x) sinh(x) / cos^2(y) + i tan(y)
74
+ * = -------------------------------------
75
+ * 1 + sinh^2(x) / cos^2(y)
76
+ *
77
+ * beta rho s + i t
78
+ * = ----------------
79
+ * 1 + beta s^2
80
+ *
81
+ * Modifications:
82
+ *
83
+ * I omitted the original algorithm's handling of overflow in tan(x) after
84
+ * verifying with nearpi.c that this can't happen in IEEE single or double
85
+ * precision. I also handle large x differently.
86
+ */
87
+
88
+ #pragma once
89
+
90
+ #include <cupy/complex/complex.h>
91
+ #include <cupy/complex/math_private.h>
92
+
93
+ #include <cupy/complex/namespace.h>
94
+
95
+ THRUST_NAMESPACE_BEGIN
96
+ namespace detail {
97
+ namespace complex {
98
+
99
+ using thrust::complex;
100
+
101
+ __host__ __device__ inline complex<double> ctanh(const complex<double>& z) {
102
+ double x, y;
103
+ double t, beta, s, rho, denom;
104
+ uint32_t hx, ix, lx;
105
+
106
+ x = z.real();
107
+ y = z.imag();
108
+
109
+ extract_words(hx, lx, x);
110
+ ix = hx & 0x7fffffff;
111
+
112
+ /*
113
+ * ctanh(NaN + i 0) = NaN + i 0
114
+ *
115
+ * ctanh(NaN + i y) = NaN + i NaN for y != 0
116
+ *
117
+ * The imaginary part has the sign of x*sin(2*y), but there's no
118
+ * special effort to get this right.
119
+ *
120
+ * ctanh(+-Inf +- i Inf) = +-1 +- 0
121
+ *
122
+ * ctanh(+-Inf + i y) = +-1 + 0 sin(2y) for y finite
123
+ *
124
+ * The imaginary part of the sign is unspecified. This special
125
+ * case is only needed to avoid a spurious invalid exception when
126
+ * y is infinite.
127
+ */
128
+ if (ix >= 0x7ff00000) {
129
+ if ((ix & 0xfffff) | lx) /* x is NaN */
130
+ return (complex<double>(x, (y == 0 ? y : x * y)));
131
+ set_high_word(x, hx - 0x40000000); /* x = copysign(1, x) */
132
+ return (complex<double>(x, copysign(0.0, isinf(y) ? y : sin(y) * cos(y))));
133
+ }
134
+
135
+ /*
136
+ * ctanh(x + i NAN) = NaN + i NaN
137
+ * ctanh(x +- i Inf) = NaN + i NaN
138
+ */
139
+ if (!isfinite(y)) return (complex<double>(y - y, y - y));
140
+
141
+ /*
142
+ * ctanh(+-huge + i +-y) ~= +-1 +- i 2sin(2y)/exp(2x), using the
143
+ * approximation sinh^2(huge) ~= exp(2*huge) / 4.
144
+ * We use a modified formula to avoid spurious overflow.
145
+ */
146
+ if (ix >= 0x40360000) { /* x >= 22 */
147
+ double exp_mx = exp(-fabs(x));
148
+ return (complex<double>(copysign(1.0, x),
149
+ 4.0 * sin(y) * cos(y) * exp_mx * exp_mx));
150
+ }
151
+
152
+ /* Kahan's algorithm */
153
+ t = tan(y);
154
+ beta = 1.0 + t * t; /* = 1 / cos^2(y) */
155
+ s = sinh(x);
156
+ rho = sqrt(1.0 + s * s); /* = cosh(x) */
157
+ denom = 1.0 + beta * s * s;
158
+ return (complex<double>((beta * rho * s) / denom, t / denom));
159
+ }
160
+
161
+ __host__ __device__ inline complex<double> ctan(complex<double> z) {
162
+ /* ctan(z) = -I * ctanh(I * z) */
163
+ z = ctanh(complex<double>(-z.imag(), z.real()));
164
+ return (complex<double>(z.imag(), -z.real()));
165
+ }
166
+
167
+ } // namespace complex
168
+
169
+ } // namespace detail
170
+
171
+ template <typename ValueType>
172
+ __host__ __device__ inline complex<ValueType> tan(const complex<ValueType>& z) {
173
+ return sin(z) / cos(z);
174
+ }
175
+
176
+ template <typename ValueType>
177
+ __host__ __device__ inline complex<ValueType> tanh(const complex<ValueType>& z) {
178
+ // This implementation seems better than the simple sin/cos
179
+ return (thrust::exp(ValueType(2) * z) - ValueType(1)) /
180
+ (thrust::exp(ValueType(2) * z) + ValueType(1));
181
+ }
182
+
183
+ template <>
184
+ __host__ __device__ inline complex<double> tan(const complex<double>& z) {
185
+ return detail::complex::ctan(z);
186
+ }
187
+
188
+ template <>
189
+ __host__ __device__ inline complex<double> tanh(const complex<double>& z) {
190
+ return detail::complex::ctanh(z);
191
+ }
192
+
193
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/complex/ctanhf.h ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2011 David Schultz
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice unmodified, this list of conditions, and the following
27
+ * disclaimer.
28
+ * 2. Redistributions in binary form must reproduce the above copyright
29
+ * notice, this list of conditions and the following disclaimer in the
30
+ * documentation and/or other materials provided with the distribution.
31
+ *
32
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+ */
43
+
44
+ /*
45
+ * Adapted from FreeBSD by Filipe Maia, filipe.c.maia@gmail.com:
46
+ * freebsd/lib/msun/src/s_ctanhf.c
47
+ */
48
+
49
+ /*
50
+ * Hyperbolic tangent of a complex argument z. See ctanh.c for details.
51
+ */
52
+
53
+ #pragma once
54
+
55
+ #include <cupy/complex/complex.h>
56
+ #include <cupy/complex/math_private.h>
57
+
58
+ #include <cupy/complex/namespace.h>
59
+
60
+ THRUST_NAMESPACE_BEGIN
61
+ namespace detail {
62
+ namespace complex {
63
+
64
+ using thrust::complex;
65
+
66
+ __host__ __device__ inline complex<float> ctanhf(const complex<float>& z) {
67
+ float x, y;
68
+ float t, beta, s, rho, denom;
69
+ uint32_t hx, ix;
70
+
71
+ x = z.real();
72
+ y = z.imag();
73
+
74
+ get_float_word(hx, x);
75
+ ix = hx & 0x7fffffff;
76
+
77
+ if (ix >= 0x7f800000) {
78
+ if (ix & 0x7fffff) return (complex<float>(x, (y == 0.0f ? y : x * y)));
79
+ set_float_word(x, hx - 0x40000000);
80
+ return (complex<float>(x, copysignf(0, isinf(y) ? y : sinf(y) * cosf(y))));
81
+ }
82
+
83
+ if (!isfinite(y)) return (complex<float>(y - y, y - y));
84
+
85
+ if (ix >= 0x41300000) { /* x >= 11 */
86
+ float exp_mx = expf(-fabsf(x));
87
+ return (complex<float>(copysignf(1.0f, x),
88
+ 4.0f * sinf(y) * cosf(y) * exp_mx * exp_mx));
89
+ }
90
+
91
+ t = tanf(y);
92
+ beta = 1.0f + t * t;
93
+ s = sinhf(x);
94
+ rho = sqrtf(1.0f + s * s);
95
+ denom = 1.0f + beta * s * s;
96
+ return (complex<float>((beta * rho * s) / denom, t / denom));
97
+ }
98
+
99
+ __host__ __device__ inline complex<float> ctanf(complex<float> z) {
100
+ z = ctanhf(complex<float>(-z.imag(), z.real()));
101
+ return (complex<float>(z.imag(), -z.real()));
102
+ }
103
+
104
+ } // namespace complex
105
+
106
+ } // namespace detail
107
+
108
+ template <>
109
+ __host__ __device__ inline complex<float> tan(const complex<float>& z) {
110
+ return detail::complex::ctanf(z);
111
+ }
112
+
113
+ template <>
114
+ __host__ __device__ inline complex<float> tanh(const complex<float>& z) {
115
+ return detail::complex::ctanhf(z);
116
+ }
117
+
118
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_indexing/__init__.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Functions from the following NumPy document
2
+ # https://numpy.org/doc/stable/reference/routines.indexing.html
vllm/lib/python3.10/site-packages/cupy/_indexing/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (164 Bytes). View file
 
vllm/lib/python3.10/site-packages/cupy/_indexing/__pycache__/generate.cpython-310.pyc ADDED
Binary file (16.1 kB). View file
 
vllm/lib/python3.10/site-packages/cupy/_indexing/__pycache__/indexing.cpython-310.pyc ADDED
Binary file (6.89 kB). View file
 
vllm/lib/python3.10/site-packages/cupy/_indexing/__pycache__/insert.cpython-310.pyc ADDED
Binary file (7.58 kB). View file
 
vllm/lib/python3.10/site-packages/cupy/_indexing/__pycache__/iterate.cpython-310.pyc ADDED
Binary file (3.66 kB). View file
 
vllm/lib/python3.10/site-packages/cupy/_indexing/generate.py ADDED
@@ -0,0 +1,588 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # class s_(object):
2
+
3
+ import functools
4
+ import numbers
5
+ import operator
6
+
7
+ import numpy
8
+
9
+ import cupy
10
+ from cupy._creation import from_data
11
+ from cupy._manipulation import join
12
+
13
+
14
+ class AxisConcatenator(object):
15
+ """Translates slice objects to concatenation along an axis.
16
+
17
+ For detailed documentation on usage, see :func:`cupy.r_`.
18
+ This implementation is partially borrowed from NumPy's one.
19
+
20
+ """
21
+
22
+ def _output_obj(self, obj, ndim, ndmin, trans1d):
23
+ k2 = ndmin - ndim
24
+ if trans1d < 0:
25
+ trans1d += k2 + 1
26
+ defaxes = list(range(ndmin))
27
+ k1 = trans1d
28
+ axes = defaxes[:k1] + defaxes[k2:] + \
29
+ defaxes[k1:k2]
30
+ return obj.transpose(axes)
31
+
32
+ def __init__(self, axis=0, matrix=False, ndmin=1, trans1d=-1):
33
+ self.axis = axis
34
+ self.trans1d = trans1d
35
+ self.matrix = matrix
36
+ self.ndmin = ndmin
37
+
38
+ def __getitem__(self, key):
39
+ trans1d = self.trans1d
40
+ ndmin = self.ndmin
41
+ objs = []
42
+ arrays = []
43
+ scalars = []
44
+ if isinstance(key, str):
45
+ raise NotImplementedError
46
+ if not isinstance(key, tuple):
47
+ key = (key,)
48
+
49
+ for i, k in enumerate(key):
50
+ if isinstance(k, slice):
51
+ raise NotImplementedError
52
+ elif isinstance(k, str):
53
+ if i != 0:
54
+ raise ValueError(
55
+ 'special directives must be the first entry.')
56
+ raise NotImplementedError
57
+ elif type(k) in numpy.ScalarType:
58
+ newobj = from_data.array(k, ndmin=ndmin)
59
+ scalars.append(i)
60
+ else:
61
+ newobj = from_data.array(k, copy=False, ndmin=ndmin)
62
+ if ndmin > 1:
63
+ ndim = from_data.array(k, copy=False).ndim
64
+ if trans1d != -1 and ndim < ndmin:
65
+ newobj = self._output_obj(newobj, ndim, ndmin, trans1d)
66
+ arrays.append(newobj)
67
+
68
+ objs.append(newobj)
69
+
70
+ final_dtype = numpy.result_type(*arrays, *[key[k] for k in scalars])
71
+ if final_dtype is not None:
72
+ for k in scalars:
73
+ objs[k] = objs[k].astype(final_dtype)
74
+
75
+ return join.concatenate(tuple(objs), axis=self.axis)
76
+
77
+ def __len__(self):
78
+ return 0
79
+
80
+
81
+ class CClass(AxisConcatenator):
82
+
83
+ def __init__(self):
84
+ super(CClass, self).__init__(-1, ndmin=2, trans1d=0)
85
+
86
+
87
+ c_ = CClass()
88
+ """Translates slice objects to concatenation along the second axis.
89
+
90
+ This is a CuPy object that corresponds to :obj:`cupy.r_`, which is
91
+ useful because of its common occurrence. In particular, arrays will be
92
+ stacked along their last axis after being upgraded to at least 2-D with
93
+ 1's post-pended to the shape (column vectors made out of 1-D arrays).
94
+
95
+ For detailed documentation, see :obj:`r_`.
96
+
97
+ This implementation is partially borrowed from NumPy's one.
98
+
99
+ Returns:
100
+ cupy.ndarray: Joined array.
101
+
102
+ .. seealso:: :obj:`numpy.c_`
103
+
104
+ Examples
105
+ --------
106
+ >>> a = cupy.array([[1, 2, 3]], dtype=np.int32)
107
+ >>> b = cupy.array([[4, 5, 6]], dtype=np.int32)
108
+ >>> cupy.c_[a, 0, 0, b]
109
+ array([[1, 2, 3, 0, 0, 4, 5, 6]], dtype=int32)
110
+
111
+ """
112
+
113
+
114
+ class RClass(AxisConcatenator):
115
+
116
+ def __init__(self):
117
+ super(RClass, self).__init__()
118
+
119
+
120
+ r_ = RClass()
121
+ """Translates slice objects to concatenation along the first axis.
122
+
123
+ This is a simple way to build up arrays quickly.
124
+ If the index expression contains comma separated arrays, then stack
125
+ them along their first axis.
126
+
127
+ This object can build up from normal CuPy arrays.
128
+ Therefore, the other objects (e.g. writing strings like '2,3,4',
129
+ or using imaginary numbers like [1,2,3j],
130
+ or using string integers like '-1') are not implemented yet
131
+ compared with NumPy.
132
+
133
+ This implementation is partially borrowed from NumPy's one.
134
+
135
+ Returns:
136
+ cupy.ndarray: Joined array.
137
+
138
+ .. seealso:: :obj:`numpy.r_`
139
+
140
+ Examples
141
+ --------
142
+ >>> a = cupy.array([1, 2, 3], dtype=np.int32)
143
+ >>> b = cupy.array([4, 5, 6], dtype=np.int32)
144
+ >>> cupy.r_[a, 0, 0, b]
145
+ array([1, 2, 3, 0, 0, 4, 5, 6], dtype=int32)
146
+
147
+ """
148
+
149
+
150
+ def indices(dimensions, dtype=int):
151
+ """Returns an array representing the indices of a grid.
152
+
153
+ Computes an array where the subarrays contain index values 0,1,...
154
+ varying only along the corresponding axis.
155
+
156
+ Args:
157
+ dimensions: The shape of the grid.
158
+ dtype: Data type specifier. It is int by default.
159
+
160
+ Returns:
161
+ ndarray:
162
+ The array of grid indices,
163
+ ``grid.shape = (len(dimensions),) + tuple(dimensions)``.
164
+
165
+ Examples
166
+ --------
167
+ >>> grid = cupy.indices((2, 3))
168
+ >>> grid.shape
169
+ (2, 2, 3)
170
+ >>> grid[0] # row indices
171
+ array([[0, 0, 0],
172
+ [1, 1, 1]])
173
+ >>> grid[1] # column indices
174
+ array([[0, 1, 2],
175
+ [0, 1, 2]])
176
+
177
+ .. seealso:: :func:`numpy.indices`
178
+
179
+ """
180
+ dimensions = tuple(dimensions)
181
+ N = len(dimensions)
182
+ shape = (1,) * N
183
+ res = cupy.empty((N,) + dimensions, dtype=dtype)
184
+ for i, dim in enumerate(dimensions):
185
+ res[i] = cupy.arange(dim, dtype=dtype).reshape(
186
+ shape[:i] + (dim,) + shape[i + 1:]
187
+ )
188
+ return res
189
+
190
+
191
+ def ix_(*args):
192
+ """Construct an open mesh from multiple sequences.
193
+
194
+ This function takes N 1-D sequences and returns N outputs with N
195
+ dimensions each, such that the shape is 1 in all but one dimension
196
+ and the dimension with the non-unit shape value cycles through all
197
+ N dimensions.
198
+
199
+ Using `ix_` one can quickly construct index arrays that will index
200
+ the cross product. ``a[cupy.ix_([1,3],[2,5])]`` returns the array
201
+ ``[[a[1,2] a[1,5]], [a[3,2] a[3,5]]]``.
202
+
203
+ Args:
204
+ *args: 1-D sequences
205
+
206
+ Returns:
207
+ tuple of ndarrays:
208
+ N arrays with N dimensions each, with N the number of input sequences.
209
+ Together these arrays form an open mesh.
210
+
211
+ Examples
212
+ --------
213
+ >>> a = cupy.arange(10).reshape(2, 5)
214
+ >>> a
215
+ array([[0, 1, 2, 3, 4],
216
+ [5, 6, 7, 8, 9]])
217
+ >>> ixgrid = cupy.ix_([0,1], [2,4])
218
+ >>> ixgrid
219
+ (array([[0],
220
+ [1]]), array([[2, 4]]))
221
+
222
+ .. warning::
223
+
224
+ This function may synchronize the device.
225
+
226
+ .. seealso:: :func:`numpy.ix_`
227
+
228
+ """
229
+ # TODO(niboshi): Avoid nonzero which may synchronize the device.
230
+ out = []
231
+ nd = len(args)
232
+ for k, new in enumerate(args):
233
+ new = from_data.asarray(new)
234
+ if new.ndim != 1:
235
+ raise ValueError('Cross index must be 1 dimensional')
236
+ if new.size == 0:
237
+ # Explicitly type empty arrays to avoid float default
238
+ new = new.astype(numpy.intp)
239
+ if cupy.issubdtype(new.dtype, cupy.bool_):
240
+ new, = new.nonzero() # may synchronize
241
+ new = new.reshape((1,) * k + (new.size,) + (1,) * (nd - k - 1))
242
+ out.append(new)
243
+ return tuple(out)
244
+
245
+
246
+ def ravel_multi_index(multi_index, dims, mode='wrap', order='C'):
247
+ """
248
+ Converts a tuple of index arrays into an array of flat indices, applying
249
+ boundary modes to the multi-index.
250
+
251
+ Args:
252
+ multi_index (tuple of cupy.ndarray) : A tuple of integer arrays, one
253
+ array for each dimension.
254
+ dims (tuple of ints): The shape of array into which the indices from
255
+ ``multi_index`` apply.
256
+ mode ('raise', 'wrap' or 'clip'), optional: Specifies how out-of-bounds
257
+ indices are handled. Can specify either one mode or a tuple of
258
+ modes, one mode per index:
259
+
260
+ - *'raise'* -- raise an error
261
+ - *'wrap'* -- wrap around (default)
262
+ - *'clip'* -- clip to the range
263
+
264
+ In 'clip' mode, a negative index which would normally wrap will
265
+ clip to 0 instead.
266
+ order ('C' or 'F'), optional: Determines whether the multi-index should
267
+ be viewed as indexing in row-major (C-style) or column-major
268
+ (Fortran-style) order.
269
+
270
+ Returns:
271
+ raveled_indices (cupy.ndarray): An array of indices into the flattened
272
+ version of an array of dimensions ``dims``.
273
+
274
+ .. warning::
275
+
276
+ This function may synchronize the device when ``mode == 'raise'``.
277
+
278
+ Notes
279
+ -----
280
+ Note that the default `mode` (``'wrap'``) is different than in NumPy. This
281
+ is done to avoid potential device synchronization.
282
+
283
+ Examples
284
+ --------
285
+ >>> cupy.ravel_multi_index(cupy.asarray([[3,6,6],[4,5,1]]), (7,6))
286
+ array([22, 41, 37])
287
+ >>> cupy.ravel_multi_index(cupy.asarray([[3,6,6],[4,5,1]]), (7,6),
288
+ ... order='F')
289
+ array([31, 41, 13])
290
+ >>> cupy.ravel_multi_index(cupy.asarray([[3,6,6],[4,5,1]]), (4,6),
291
+ ... mode='clip')
292
+ array([22, 23, 19])
293
+ >>> cupy.ravel_multi_index(cupy.asarray([[3,6,6],[4,5,1]]), (4,4),
294
+ ... mode=('clip', 'wrap'))
295
+ array([12, 13, 13])
296
+ >>> cupy.ravel_multi_index(cupy.asarray((3,1,4,1)), (6,7,8,9))
297
+ array(1621)
298
+
299
+ .. seealso:: :func:`numpy.ravel_multi_index`, :func:`unravel_index`
300
+ """
301
+
302
+ ndim = len(dims)
303
+ if len(multi_index) != ndim:
304
+ raise ValueError(
305
+ "parameter multi_index must be a sequence of "
306
+ "length {}".format(ndim))
307
+
308
+ for d in dims:
309
+ if not isinstance(d, numbers.Integral):
310
+ raise TypeError(
311
+ "{} object cannot be interpreted as an integer".format(
312
+ type(d)))
313
+
314
+ if isinstance(mode, str):
315
+ mode = (mode, ) * ndim
316
+
317
+ if functools.reduce(operator.mul, dims) > cupy.iinfo(cupy.int64).max:
318
+ raise ValueError("invalid dims: array size defined by dims is larger "
319
+ "than the maximum possible size")
320
+
321
+ s = 1
322
+ ravel_strides = [1] * ndim
323
+
324
+ order = 'C' if order is None else order.upper()
325
+ if order == 'C':
326
+ for i in range(ndim - 2, -1, -1):
327
+ s = s * dims[i + 1]
328
+ ravel_strides[i] = s
329
+ elif order == 'F':
330
+ for i in range(1, ndim):
331
+ s = s * dims[i - 1]
332
+ ravel_strides[i] = s
333
+ else:
334
+ raise ValueError('order not understood')
335
+
336
+ multi_index = cupy.broadcast_arrays(*multi_index)
337
+ raveled_indices = cupy.zeros(multi_index[0].shape, dtype=cupy.int64)
338
+ for d, stride, idx, _mode in zip(dims, ravel_strides, multi_index, mode):
339
+
340
+ if not isinstance(idx, cupy.ndarray):
341
+ raise TypeError("elements of multi_index must be cupy arrays")
342
+ if not cupy.can_cast(idx, cupy.int64, 'same_kind'):
343
+ raise TypeError(
344
+ 'multi_index entries could not be cast from dtype(\'{}\') to '
345
+ 'dtype(\'{}\') according to the rule \'same_kind\''.format(
346
+ idx.dtype, cupy.int64().dtype))
347
+ idx = idx.astype(cupy.int64, copy=False)
348
+
349
+ if _mode == "raise":
350
+ if cupy.any(cupy.logical_or(idx >= d, idx < 0)):
351
+ raise ValueError("invalid entry in coordinates array")
352
+ elif _mode == "clip":
353
+ idx = cupy.clip(idx, 0, d - 1)
354
+ elif _mode == 'wrap':
355
+ idx = idx % d
356
+ else:
357
+ raise ValueError('Unrecognized mode: {}'.format(_mode))
358
+ raveled_indices += stride * idx
359
+ return raveled_indices
360
+
361
+
362
+ def unravel_index(indices, dims, order='C'):
363
+ """Converts array of flat indices into a tuple of coordinate arrays.
364
+
365
+ Args:
366
+ indices (cupy.ndarray): An integer array whose elements are indices
367
+ into the flattened version of an array of dimensions :obj:`dims`.
368
+ dims (tuple of ints): The shape of the array to use for unraveling
369
+ indices.
370
+ order ('C' or 'F'): Determines whether the indices should be viewed as
371
+ indexing in row-major (C-style) or column-major (Fortran-style)
372
+ order.
373
+
374
+ Returns:
375
+ tuple of ndarrays:
376
+ Each array in the tuple has the same shape as the indices array.
377
+
378
+ Examples
379
+ --------
380
+ >>> cupy.unravel_index(cupy.array([22, 41, 37]), (7, 6))
381
+ (array([3, 6, 6]), array([4, 5, 1]))
382
+ >>> cupy.unravel_index(cupy.array([31, 41, 13]), (7, 6), order='F')
383
+ (array([3, 6, 6]), array([4, 5, 1]))
384
+
385
+ .. warning::
386
+
387
+ This function may synchronize the device.
388
+
389
+ .. seealso:: :func:`numpy.unravel_index`, :func:`ravel_multi_index`
390
+
391
+ """
392
+ order = 'C' if order is None else order.upper()
393
+ if order == 'C':
394
+ dims = reversed(dims)
395
+ elif order == 'F':
396
+ pass
397
+ else:
398
+ raise ValueError('order not understood')
399
+
400
+ if not cupy.can_cast(indices, cupy.int64, 'same_kind'):
401
+ raise TypeError(
402
+ 'Iterator operand 0 dtype could not be cast '
403
+ 'from dtype(\'{}\') to dtype(\'{}\') '
404
+ 'according to the rule \'same_kind\''.format(
405
+ indices.dtype, cupy.int64().dtype))
406
+
407
+ if (indices < 0).any(): # synchronize!
408
+ raise ValueError('invalid entry in index array')
409
+
410
+ unraveled_coords = []
411
+ for dim in dims:
412
+ unraveled_coords.append(indices % dim)
413
+ indices = indices // dim
414
+
415
+ if (indices > 0).any(): # synchronize!
416
+ raise ValueError('invalid entry in index array')
417
+
418
+ if order == 'C':
419
+ unraveled_coords = reversed(unraveled_coords)
420
+ return tuple(unraveled_coords)
421
+
422
+
423
+ def mask_indices(n, mask_func, k=0):
424
+ """
425
+ Return the indices to access (n, n) arrays, given a masking function.
426
+
427
+ Assume `mask_func` is a function that, for a square array a of
428
+ size ``(n, n)`` with a possible offset argument `k`, when called
429
+ as ``mask_func(a, k)`` returns a new array with zeros in certain
430
+ locations (functions like :func:`~cupy.triu` or :func:`~cupy.tril` do
431
+ precisely this). Then this function returns the indices where the non-zero
432
+ values would be located.
433
+
434
+ Args:
435
+ n (int): The returned indices will be valid to access arrays
436
+ of shape (n, n).
437
+ mask_func (callable): A function whose call signature is
438
+ similar to that of :func:`~cupy.triu`, :func:`~tril`. That is,
439
+ ``mask_func(x, k)`` returns a boolean array, shaped like
440
+ `x`. `k` is an optional argument to the function.
441
+ k (scalar): An optional argument which is passed through to
442
+ `mask_func`. Functions like :func:`~cupy.triu`, :func:`~cupy.tril`
443
+ take a second argument that is interpreted as an offset.
444
+
445
+ Returns:
446
+ tuple of arrays: The `n` arrays of indices corresponding to
447
+ the locations where ``mask_func(np.ones((n, n)), k)`` is
448
+ True.
449
+
450
+ .. warning::
451
+
452
+ This function may synchronize the device.
453
+
454
+ .. seealso:: :func:`numpy.mask_indices`
455
+ """
456
+ a = cupy.ones((n, n), dtype=cupy.int8)
457
+ return mask_func(a, k).nonzero()
458
+
459
+
460
+ # TODO(okuta): Implement diag_indices
461
+
462
+
463
+ # TODO(okuta): Implement diag_indices_from
464
+
465
+
466
+ def tril_indices(n, k=0, m=None):
467
+ """Returns the indices of the lower triangular matrix.
468
+ Here, the first group of elements contains row coordinates
469
+ of all indices and the second group of elements
470
+ contains column coordinates.
471
+
472
+ Parameters
473
+ ----------
474
+ n : int
475
+ The row dimension of the arrays for which the returned
476
+ indices will be valid.
477
+ k : int, optional
478
+ Diagonal above which to zero elements. `k = 0`
479
+ (the default) is the main diagonal, `k < 0` is
480
+ below it and `k > 0` is above.
481
+ m : int, optional
482
+ The column dimension of the arrays for which the
483
+ returned arrays will be valid. By default, `m = n`.
484
+
485
+ Returns
486
+ -------
487
+ y : tuple of ndarrays
488
+ The indices for the triangle. The returned tuple
489
+ contains two arrays, each with the indices along
490
+ one dimension of the array.
491
+
492
+ See Also
493
+ --------
494
+ numpy.tril_indices
495
+
496
+ """
497
+
498
+ tri_ = cupy.tri(n, m, k=k, dtype=bool)
499
+
500
+ return tuple(cupy.broadcast_to(inds, tri_.shape)[tri_]
501
+ for inds in cupy.indices(tri_.shape, dtype=int))
502
+
503
+
504
+ def tril_indices_from(arr, k=0):
505
+ """Returns the indices for the lower-triangle of arr.
506
+
507
+ Parameters
508
+ ----------
509
+ arr : cupy.ndarray
510
+ The indices are valid for square arrays
511
+ whose dimensions are the same as arr.
512
+ k : int, optional
513
+ Diagonal offset.
514
+
515
+ See Also
516
+ --------
517
+ numpy.tril_indices_from
518
+
519
+ """
520
+
521
+ if arr.ndim != 2:
522
+ raise ValueError("input array must be 2-d")
523
+ return tril_indices(arr.shape[-2], k=k, m=arr.shape[-1])
524
+
525
+
526
+ def triu_indices(n, k=0, m=None):
527
+ """Returns the indices of the upper triangular matrix.
528
+ Here, the first group of elements contains row coordinates
529
+ of all indices and the second group of elements
530
+ contains column coordinates.
531
+
532
+ Parameters
533
+ ----------
534
+ n : int
535
+ The size of the arrays for which the returned indices will
536
+ be valid.
537
+ k : int, optional
538
+ Refers to the diagonal offset. By default, `k = 0` i.e.
539
+ the main dialogal. The positive value of `k`
540
+ denotes the diagonals above the main diagonal, while the negative
541
+ value includes the diagonals below the main diagonal.
542
+ m : int, optional
543
+ The column dimension of the arrays for which the
544
+ returned arrays will be valid. By default, `m = n`.
545
+
546
+ Returns
547
+ -------
548
+ y : tuple of ndarrays
549
+ The indices for the triangle. The returned tuple
550
+ contains two arrays, each with the indices along
551
+ one dimension of the array.
552
+
553
+ See Also
554
+ --------
555
+ numpy.triu_indices
556
+
557
+ """
558
+
559
+ tri_ = ~cupy.tri(n, m, k=k - 1, dtype=bool)
560
+
561
+ return tuple(cupy.broadcast_to(inds, tri_.shape)[tri_]
562
+ for inds in cupy.indices(tri_.shape, dtype=int))
563
+
564
+
565
+ def triu_indices_from(arr, k=0):
566
+ """Returns indices for the upper-triangle of arr.
567
+
568
+ Parameters
569
+ ----------
570
+ arr : cupy.ndarray
571
+ The indices are valid for square arrays.
572
+ k : int, optional
573
+ Diagonal offset (see 'triu_indices` for details).
574
+
575
+ Returns
576
+ -------
577
+ triu_indices_from : tuple of ndarrays
578
+ Indices for the upper-triangle of `arr`.
579
+
580
+ See Also
581
+ --------
582
+ numpy.triu_indices_from
583
+
584
+ """
585
+
586
+ if arr.ndim != 2:
587
+ raise ValueError("input array must be 2-d")
588
+ return triu_indices(arr.shape[-2], k=k, m=arr.shape[-1])
vllm/lib/python3.10/site-packages/cupy/_indexing/indexing.py ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cupy
2
+ from cupy._core import internal
3
+
4
+
5
+ def take(a, indices, axis=None, out=None):
6
+ """Takes elements of an array at specified indices along an axis.
7
+
8
+ This is an implementation of "fancy indexing" at single axis.
9
+
10
+ This function does not support ``mode`` option.
11
+
12
+ Args:
13
+ a (cupy.ndarray): Array to extract elements.
14
+ indices (int or array-like): Indices of elements that this function
15
+ takes.
16
+ axis (int): The axis along which to select indices. The flattened input
17
+ is used by default.
18
+ out (cupy.ndarray): Output array. If provided, it should be of
19
+ appropriate shape and dtype.
20
+
21
+ Returns:
22
+ cupy.ndarray: The result of fancy indexing.
23
+
24
+ .. seealso:: :func:`numpy.take`
25
+
26
+ """
27
+ # TODO(okuta): check type
28
+ return a.take(indices, axis, out)
29
+
30
+
31
+ def take_along_axis(a, indices, axis):
32
+ """Take values from the input array by matching 1d index and data slices.
33
+
34
+ Args:
35
+ a (cupy.ndarray): Array to extract elements.
36
+ indices (cupy.ndarray): Indices to take along each 1d slice of ``a``.
37
+ axis (int): The axis to take 1d slices along.
38
+
39
+ Returns:
40
+ cupy.ndarray: The indexed result.
41
+
42
+ .. seealso:: :func:`numpy.take_along_axis`
43
+ """
44
+
45
+ if indices.dtype.kind not in ('i', 'u'):
46
+ raise IndexError('`indices` must be an integer array')
47
+
48
+ if axis is None:
49
+ a = a.ravel()
50
+ axis = 0
51
+
52
+ ndim = a.ndim
53
+
54
+ axis = internal._normalize_axis_index(axis, ndim)
55
+
56
+ if ndim != indices.ndim:
57
+ raise ValueError(
58
+ '`indices` and `a` must have the same number of dimensions')
59
+
60
+ fancy_index = []
61
+ for i, n in enumerate(a.shape):
62
+ if i == axis:
63
+ fancy_index.append(indices)
64
+ else:
65
+ ind_shape = (1,) * i + (-1,) + (1,) * (ndim - i - 1)
66
+ fancy_index.append(cupy.arange(n).reshape(ind_shape))
67
+
68
+ return a[tuple(fancy_index)]
69
+
70
+
71
+ def choose(a, choices, out=None, mode='raise'):
72
+ return a.choose(choices, out, mode)
73
+
74
+
75
+ def compress(condition, a, axis=None, out=None):
76
+ """Returns selected slices of an array along given axis.
77
+
78
+ Args:
79
+ condition (1-D array of bools): Array that selects which entries to
80
+ return. If len(condition) is less than the size of a along the
81
+ given axis, then output is truncated to the length of the condition
82
+ array.
83
+ a (cupy.ndarray): Array from which to extract a part.
84
+ axis (int): Axis along which to take slices. If None (default), work
85
+ on the flattened array.
86
+ out (cupy.ndarray): Output array. If provided, it should be of
87
+ appropriate shape and dtype.
88
+
89
+ Returns:
90
+ cupy.ndarray: A copy of a without the slices along axis for which
91
+ condition is false.
92
+
93
+ .. warning::
94
+
95
+ This function may synchronize the device.
96
+
97
+
98
+ .. seealso:: :func:`numpy.compress`
99
+
100
+ """
101
+ return a.compress(condition, axis, out)
102
+
103
+
104
+ def diagonal(a, offset=0, axis1=0, axis2=1):
105
+ """Returns specified diagonals.
106
+
107
+ This function extracts the diagonals along two specified axes. The other
108
+ axes are not changed. This function returns a writable view of this array
109
+ as NumPy 1.10 will do.
110
+
111
+ Args:
112
+ a (cupy.ndarray): Array from which the diagonals are taken.
113
+ offset (int): Index of the diagonals. Zero indicates the main
114
+ diagonals, a positive value upper diagonals, and a negative value
115
+ lower diagonals.
116
+ axis1 (int): The first axis to take diagonals from.
117
+ axis2 (int): The second axis to take diagonals from.
118
+
119
+ Returns:
120
+ cupy.ndarray: A view of the diagonals of ``a``.
121
+
122
+ .. seealso:: :func:`numpy.diagonal`
123
+
124
+ """
125
+ # TODO(okuta): check type
126
+ return a.diagonal(offset, axis1, axis2)
127
+
128
+
129
+ def extract(condition, a):
130
+ """Return the elements of an array that satisfy some condition.
131
+
132
+ This is equivalent to ``np.compress(ravel(condition), ravel(arr))``.
133
+ If ``condition`` is boolean, ``np.extract`` is equivalent to
134
+ ``arr[condition]``.
135
+
136
+ Args:
137
+ condition (int or array_like): An array whose nonzero or True entries
138
+ indicate the elements of array to extract.
139
+ a (cupy.ndarray): Input array of the same size as condition.
140
+
141
+ Returns:
142
+ cupy.ndarray: Rank 1 array of values from arr where condition is True.
143
+
144
+ .. warning::
145
+
146
+ This function may synchronize the device.
147
+
148
+ .. seealso:: :func:`numpy.extract`
149
+ """
150
+
151
+ if not isinstance(a, cupy.ndarray):
152
+ raise TypeError('extract requires input array to be cupy.ndarray')
153
+
154
+ if not isinstance(condition, cupy.ndarray):
155
+ condition = cupy.array(condition)
156
+
157
+ a = a.ravel()
158
+ condition = condition.ravel()
159
+
160
+ return a.take(condition.nonzero()[0])
161
+
162
+
163
+ def select(condlist, choicelist, default=0):
164
+ """Return an array drawn from elements in choicelist, depending on conditions.
165
+
166
+ Args:
167
+ condlist (list of bool arrays): The list of conditions which determine
168
+ from which array in `choicelist` the output elements are taken.
169
+ When multiple conditions are satisfied, the first one encountered
170
+ in `condlist` is used.
171
+ choicelist (list of cupy.ndarray): The list of arrays from which the
172
+ output elements are taken. It has to be of the same length
173
+ as `condlist`.
174
+ default (scalar) : If provided, will fill element inserted in `output`
175
+ when all conditions evaluate to False. default value is 0.
176
+
177
+ Returns:
178
+ cupy.ndarray: The output at position m is the m-th element of the
179
+ array in `choicelist` where the m-th element of the corresponding
180
+ array in `condlist` is True.
181
+
182
+ .. seealso:: :func:`numpy.select`
183
+ """ # NOQA
184
+
185
+ if len(condlist) != len(choicelist):
186
+ raise ValueError(
187
+ 'list of cases must be same length as list of conditions')
188
+
189
+ if len(condlist) == 0:
190
+ raise ValueError("select with an empty condition list is not possible")
191
+
192
+ if not cupy.isscalar(default):
193
+ raise TypeError("default only accepts scalar values")
194
+
195
+ for i in range(len(choicelist)):
196
+ if not isinstance(choicelist[i], cupy.ndarray):
197
+ raise TypeError("choicelist only accepts lists of cupy ndarrays")
198
+ cond = condlist[i]
199
+ if cond.dtype.type is not cupy.bool_:
200
+ raise ValueError(
201
+ 'invalid entry {} in condlist: should be boolean ndarray'
202
+ .format(i))
203
+
204
+ dtype = cupy.result_type(*choicelist)
205
+
206
+ condlist = cupy.broadcast_arrays(*condlist)
207
+ choicelist = cupy.broadcast_arrays(*choicelist, default)
208
+
209
+ if choicelist[0].ndim == 0:
210
+ result_shape = condlist[0].shape
211
+ else:
212
+ result_shape = cupy.broadcast_arrays(condlist[0],
213
+ choicelist[0])[0].shape
214
+
215
+ result = cupy.empty(result_shape, dtype)
216
+ cupy.copyto(result, default)
217
+
218
+ choicelist = choicelist[-2::-1]
219
+ condlist = condlist[::-1]
220
+ for choice, cond in zip(choicelist, condlist):
221
+ cupy.copyto(result, choice, where=cond)
222
+
223
+ return result
vllm/lib/python3.10/site-packages/cupy/_indexing/insert.py ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy
2
+
3
+ import cupy
4
+ from cupy import _core
5
+
6
+
7
+ def place(arr, mask, vals):
8
+ """Change elements of an array based on conditional and input values.
9
+
10
+ This function uses the first N elements of `vals`, where N is the number
11
+ of true values in `mask`.
12
+
13
+ Args:
14
+ arr (cupy.ndarray): Array to put data into.
15
+ mask (array-like): Boolean mask array. Must have the same size as `a`.
16
+ vals (array-like): Values to put into `a`. Only the first
17
+ N elements are used, where N is the number of True values in
18
+ `mask`. If `vals` is smaller than N, it will be repeated, and if
19
+ elements of `a` are to be masked, this sequence must be non-empty.
20
+
21
+ Examples
22
+ --------
23
+ >>> arr = np.arange(6).reshape(2, 3)
24
+ >>> np.place(arr, arr>2, [44, 55])
25
+ >>> arr
26
+ array([[ 0, 1, 2],
27
+ [44, 55, 44]])
28
+
29
+ .. warning::
30
+
31
+ This function may synchronize the device.
32
+
33
+ .. seealso:: :func:`numpy.place`
34
+ """
35
+ # TODO(niboshi): Avoid nonzero which may synchronize the device.
36
+ mask = cupy.asarray(mask)
37
+ if arr.size != mask.size:
38
+ raise ValueError('Mask and data must be the same size.')
39
+ vals = cupy.asarray(vals)
40
+
41
+ mask_indices = mask.ravel().nonzero()[0] # may synchronize
42
+ if mask_indices.size == 0:
43
+ return
44
+ if vals.size == 0:
45
+ raise ValueError('Cannot insert from an empty array.')
46
+ arr.put(mask_indices, vals, mode='wrap')
47
+
48
+
49
+ def put(a, ind, v, mode='wrap'):
50
+ """Replaces specified elements of an array with given values.
51
+
52
+ Args:
53
+ a (cupy.ndarray): Target array.
54
+ ind (array-like): Target indices, interpreted as integers.
55
+ v (array-like): Values to place in `a` at target indices.
56
+ If `v` is shorter than `ind` it will be repeated as necessary.
57
+ mode (str): How out-of-bounds indices will behave. Its value must be
58
+ either `'raise'`, `'wrap'` or `'clip'`. Otherwise,
59
+ :class:`TypeError` is raised.
60
+
61
+ .. note::
62
+ Default `mode` is set to `'wrap'` to avoid unintended performance drop.
63
+ If you need NumPy's behavior, please pass `mode='raise'` manually.
64
+
65
+ .. seealso:: :func:`numpy.put`
66
+ """
67
+ a.put(ind, v, mode=mode)
68
+
69
+
70
+ _putmask_kernel = _core.ElementwiseKernel(
71
+ 'Q mask, raw S values, uint64 len_vals', 'T out',
72
+ '''
73
+ if (mask) out = (T) values[i % len_vals];
74
+ ''',
75
+ 'cupy_putmask_kernel'
76
+ )
77
+
78
+
79
+ def putmask(a, mask, values):
80
+ """
81
+ Changes elements of an array inplace, based on a conditional mask and
82
+ input values.
83
+
84
+ Sets ``a.flat[n] = values[n]`` for each n where ``mask.flat[n]==True``.
85
+ If `values` is not the same size as `a` and `mask` then it will repeat.
86
+
87
+ Args:
88
+ a (cupy.ndarray): Target array.
89
+ mask (cupy.ndarray): Boolean mask array. It has to be
90
+ the same shape as `a`.
91
+ values (cupy.ndarray or scalar): Values to put into `a` where `mask`
92
+ is True. If `values` is smaller than `a`, then it will be
93
+ repeated.
94
+
95
+ Examples
96
+ --------
97
+ >>> x = cupy.arange(6).reshape(2, 3)
98
+ >>> cupy.putmask(x, x>2, x**2)
99
+ >>> x
100
+ array([[ 0, 1, 2],
101
+ [ 9, 16, 25]])
102
+
103
+ If `values` is smaller than `a` it is repeated:
104
+
105
+ >>> x = cupy.arange(6)
106
+ >>> cupy.putmask(x, x>2, cupy.array([-33, -44]))
107
+ >>> x
108
+ array([ 0, 1, 2, -44, -33, -44])
109
+
110
+ .. seealso:: :func:`numpy.putmask`
111
+
112
+ """
113
+
114
+ if not isinstance(a, cupy.ndarray):
115
+ raise TypeError('`a` should be of type cupy.ndarray')
116
+ if not isinstance(mask, cupy.ndarray):
117
+ raise TypeError('`mask` should be of type cupy.ndarray')
118
+ if not (cupy.isscalar(values) or isinstance(values, cupy.ndarray)):
119
+ raise TypeError('`values` should be of type cupy.ndarray')
120
+
121
+ if not a.shape == mask.shape:
122
+ raise ValueError('mask and data must be the same size')
123
+
124
+ mask = mask.astype(numpy.bool_)
125
+
126
+ if cupy.isscalar(values):
127
+ a[mask] = values
128
+
129
+ elif not numpy.can_cast(values.dtype, a.dtype):
130
+ raise TypeError('Cannot cast array data from'
131
+ ' {} to {} according to the rule \'safe\''
132
+ .format(values.dtype, a.dtype))
133
+
134
+ elif a.shape == values.shape:
135
+ a[mask] = values[mask]
136
+
137
+ else:
138
+ values = values.ravel()
139
+ _putmask_kernel(mask, values, len(values), a)
140
+
141
+
142
+ def fill_diagonal(a, val, wrap=False):
143
+ """Fills the main diagonal of the given array of any dimensionality.
144
+
145
+ For an array `a` with ``a.ndim > 2``, the diagonal is the list of
146
+ locations with indices ``a[i, i, ..., i]`` all identical. This function
147
+ modifies the input array in-place, it does not return a value.
148
+
149
+ Args:
150
+ a (cupy.ndarray): The array, at least 2-D.
151
+ val (scalar): The value to be written on the diagonal.
152
+ Its type must be compatible with that of the array a.
153
+ wrap (bool): If specified, the diagonal is "wrapped" after N columns.
154
+ This affects only tall matrices.
155
+
156
+ Examples
157
+ --------
158
+ >>> a = cupy.zeros((3, 3), int)
159
+ >>> cupy.fill_diagonal(a, 5)
160
+ >>> a
161
+ array([[5, 0, 0],
162
+ [0, 5, 0],
163
+ [0, 0, 5]])
164
+
165
+ .. seealso:: :func:`numpy.fill_diagonal`
166
+ """
167
+ # The following are imported from the original numpy
168
+ if a.ndim < 2:
169
+ raise ValueError('array must be at least 2-d')
170
+ end = None
171
+ if a.ndim == 2:
172
+ step = a.shape[1] + 1
173
+ if not wrap:
174
+ end = a.shape[1] * a.shape[1]
175
+ else:
176
+ if not numpy.all(numpy.diff(a.shape) == 0):
177
+ raise ValueError('All dimensions of input must be of equal length')
178
+ step = 1 + numpy.cumprod(a.shape[:-1]).sum()
179
+
180
+ a.flat[:end:step] = val
181
+
182
+
183
+ def diag_indices(n, ndim=2):
184
+ """Return the indices to access the main diagonal of an array.
185
+
186
+ Returns a tuple of indices that can be used to access the main
187
+ diagonal of an array with ``ndim >= 2`` dimensions and shape
188
+ (n, n, ..., n).
189
+
190
+ Args:
191
+ n (int): The size, along each dimension of the arrays for which
192
+ the indices are to be returned.
193
+ ndim (int): The number of dimensions. default `2`.
194
+
195
+ Examples
196
+ --------
197
+ Create a set of indices to access the diagonal of a (4, 4) array:
198
+
199
+ >>> di = cupy.diag_indices(4)
200
+ >>> di
201
+ (array([0, 1, 2, 3]), array([0, 1, 2, 3]))
202
+ >>> a = cupy.arange(16).reshape(4, 4)
203
+ >>> a
204
+ array([[ 0, 1, 2, 3],
205
+ [ 4, 5, 6, 7],
206
+ [ 8, 9, 10, 11],
207
+ [12, 13, 14, 15]])
208
+ >>> a[di] = 100
209
+ >>> a
210
+ array([[100, 1, 2, 3],
211
+ [ 4, 100, 6, 7],
212
+ [ 8, 9, 100, 11],
213
+ [ 12, 13, 14, 100]])
214
+
215
+ Create indices to manipulate a 3-D array:
216
+
217
+ >>> d3 = cupy.diag_indices(2, 3)
218
+ >>> d3
219
+ (array([0, 1]), array([0, 1]), array([0, 1]))
220
+
221
+ And use it to set the diagonal of an array of zeros to 1:
222
+
223
+ >>> a = cupy.zeros((2, 2, 2), dtype=int)
224
+ >>> a[d3] = 1
225
+ >>> a
226
+ array([[[1, 0],
227
+ [0, 0]],
228
+ <BLANKLINE>
229
+ [[0, 0],
230
+ [0, 1]]])
231
+
232
+ .. seealso:: :func:`numpy.diag_indices`
233
+
234
+ """
235
+ idx = cupy.arange(n)
236
+ return (idx,) * ndim
237
+
238
+
239
+ def diag_indices_from(arr):
240
+ """
241
+ Return the indices to access the main diagonal of an n-dimensional array.
242
+ See `diag_indices` for full details.
243
+
244
+ Args:
245
+ arr (cupy.ndarray): At least 2-D.
246
+
247
+ .. seealso:: :func:`numpy.diag_indices_from`
248
+
249
+ """
250
+ if not isinstance(arr, cupy.ndarray):
251
+ raise TypeError("Argument must be cupy.ndarray")
252
+
253
+ if not arr.ndim >= 2:
254
+ raise ValueError("input array must be at least 2-d")
255
+ # For more than d=2, the strided formula is only valid for arrays with
256
+ # all dimensions equal, so we check first.
257
+ if not cupy.all(cupy.diff(arr.shape) == 0):
258
+ raise ValueError("All dimensions of input must be of equal length")
259
+
260
+ return diag_indices(arr.shape[0], arr.ndim)
vllm/lib/python3.10/site-packages/cupy/_indexing/iterate.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy
2
+
3
+ import cupy
4
+ from cupy import _core
5
+ from cupy._core import internal
6
+
7
+
8
+ class flatiter:
9
+ """Flat iterator object to iterate over arrays.
10
+
11
+ A flatiter iterator is returned by ``x.flat`` for any array ``x``. It
12
+ allows iterating over the array as if it were a 1-D array, either in a
13
+ for-loop or by calling its ``next`` method.
14
+
15
+ Iteration is done in row-major, C-style order (the last index varying the
16
+ fastest).
17
+
18
+ Attributes:
19
+ base (cupy.ndarray): A reference to the array that is iterated over.
20
+
21
+ .. note::
22
+ Restricted support of basic slicing is currently supplied. Advanced
23
+ indexing is not supported yet.
24
+
25
+ .. seealso:: :func:`numpy.flatiter`
26
+
27
+ """
28
+
29
+ def __init__(self, a):
30
+ self._base = a
31
+ self._index = 0
32
+
33
+ def __setitem__(self, ind, value):
34
+ if ind is Ellipsis:
35
+ self[:] = value
36
+ return
37
+
38
+ if isinstance(ind, tuple):
39
+ raise IndexError('unsupported iterator index')
40
+
41
+ if isinstance(ind, bool):
42
+ raise IndexError('unsupported iterator index')
43
+
44
+ if numpy.isscalar(ind):
45
+ ind = int(ind)
46
+ base = self._base
47
+ size = base.size
48
+ indices = []
49
+ for s in base.shape:
50
+ size = size // s
51
+ indices.append(ind // size)
52
+ ind %= size
53
+ base[tuple(indices)] = value
54
+ return
55
+
56
+ if isinstance(ind, slice):
57
+ base = self._base
58
+ s = internal.complete_slice(ind, base.size)
59
+ s_start = s.start
60
+ s_step = s.step
61
+ size = s.stop - s.start
62
+ if s_step > 0:
63
+ size = (size - 1) // s_step + 1
64
+ else:
65
+ size = (size + 1) // s_step + 1
66
+ value = cupy.asarray(value, dtype=base.dtype)
67
+ _flatiter_setitem_slice(value, s_start, s_step, base, size=size)
68
+ return
69
+
70
+ raise IndexError('unsupported iterator index')
71
+
72
+ def __getitem__(self, ind):
73
+ if ind is Ellipsis:
74
+ return self[:]
75
+
76
+ if isinstance(ind, tuple):
77
+ raise IndexError('unsupported iterator index')
78
+
79
+ if isinstance(ind, bool):
80
+ raise IndexError('unsupported iterator index')
81
+
82
+ if numpy.isscalar(ind):
83
+ ind = int(ind)
84
+ base = self._base
85
+ size = base.size
86
+ indices = []
87
+ for s in base.shape:
88
+ size = size // s
89
+ indices.append(ind // size)
90
+ ind %= size
91
+ return base[tuple(indices)].copy()
92
+
93
+ if isinstance(ind, slice):
94
+ base = self._base
95
+ s = internal.complete_slice(ind, base.size)
96
+ s_start = s.start
97
+ s_step = s.step
98
+ size = s.stop - s.start
99
+ if s_step > 0:
100
+ size = (size - 1) // s_step + 1
101
+ else:
102
+ size = (size + 1) // s_step + 1
103
+ return _flatiter_getitem_slice(base, s_start, s_step, size=size)
104
+
105
+ raise IndexError('unsupported iterator index')
106
+
107
+ def __iter__(self):
108
+ return self
109
+
110
+ def __next__(self):
111
+ index = self._index
112
+ if index == len(self):
113
+ raise StopIteration()
114
+ self._index += 1
115
+ return self[index]
116
+
117
+ def copy(self):
118
+ """Get a copy of the iterator as a 1-D array."""
119
+ return self.base.flatten()
120
+
121
+ @property
122
+ def base(self):
123
+ """A reference to the array that is iterated over."""
124
+ return self._base
125
+
126
+ # TODO(Takagi): Implement coords
127
+
128
+ # TODO(Takagi): Implement index
129
+
130
+ # TODO(Takagi): Implement __lt__
131
+
132
+ # TODO(Takagi): Implement __le__
133
+
134
+ # TODO(Takagi): Implement __eq__
135
+
136
+ # TODO(Takagi): Implement __ne__
137
+
138
+ # TODO(Takagi): Implement __ge__
139
+
140
+ # TODO(Takagi): Implement __gt__
141
+
142
+ def __len__(self):
143
+ return self.base.size
144
+
145
+
146
+ _flatiter_setitem_slice = _core.ElementwiseKernel(
147
+ 'raw T val, int64 start, int64 step', 'raw T a',
148
+ 'a[start + i * step] = val[i % val.size()]',
149
+ 'cupy_flatiter_setitem_slice')
150
+
151
+
152
+ _flatiter_getitem_slice = _core.ElementwiseKernel(
153
+ 'raw T a, int64 start, int64 step', 'T o',
154
+ 'o = a[start + i * step]',
155
+ 'cupy_flatiter_getitem_slice')
vllm/lib/python3.10/site-packages/cupy/array_api/__init__.py ADDED
@@ -0,0 +1,388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ A NumPy sub-namespace that conforms to the Python array API standard.
3
+
4
+ This submodule accompanies NEP 47, which proposes its inclusion in NumPy. It
5
+ is still considered experimental, and will issue a warning when imported.
6
+
7
+ This is a proof-of-concept namespace that wraps the corresponding NumPy
8
+ functions to give a conforming implementation of the Python array API standard
9
+ (https://data-apis.github.io/array-api/latest/). The standard is currently in
10
+ an RFC phase and comments on it are both welcome and encouraged. Comments
11
+ should be made either at https://github.com/data-apis/array-api or at
12
+ https://github.com/data-apis/consortium-feedback/discussions.
13
+
14
+ NumPy already follows the proposed spec for the most part, so this module
15
+ serves mostly as a thin wrapper around it. However, NumPy also implements a
16
+ lot of behavior that is not included in the spec, so this serves as a
17
+ restricted subset of the API. Only those functions that are part of the spec
18
+ are included in this namespace, and all functions are given with the exact
19
+ signature given in the spec, including the use of position-only arguments, and
20
+ omitting any extra keyword arguments implemented by NumPy but not part of the
21
+ spec. The behavior of some functions is also modified from the NumPy behavior
22
+ to conform to the standard. Note that the underlying array object itself is
23
+ wrapped in a wrapper Array() class, but is otherwise unchanged. This submodule
24
+ is implemented in pure Python with no C extensions.
25
+
26
+ The array API spec is designed as a "minimal API subset" and explicitly allows
27
+ libraries to include behaviors not specified by it. But users of this module
28
+ that intend to write portable code should be aware that only those behaviors
29
+ that are listed in the spec are guaranteed to be implemented across libraries.
30
+ Consequently, the NumPy implementation was chosen to be both conforming and
31
+ minimal, so that users can use this implementation of the array API namespace
32
+ and be sure that behaviors that it defines will be available in conforming
33
+ namespaces from other libraries.
34
+
35
+ A few notes about the current state of this submodule:
36
+
37
+ - There is a test suite that tests modules against the array API standard at
38
+ https://github.com/data-apis/array-api-tests. The test suite is still a work
39
+ in progress, but the existing tests pass on this module, with a few
40
+ exceptions:
41
+
42
+ - DLPack support (see https://github.com/data-apis/array-api/pull/106) is
43
+ not included here, as it requires a full implementation in NumPy proper
44
+ first.
45
+
46
+ The test suite is not yet complete, and even the tests that exist are not
47
+ guaranteed to give a comprehensive coverage of the spec. Therefore, when
48
+ reviewing and using this submodule, you should refer to the standard
49
+ documents themselves. There are some tests in numpy.array_api.tests, but
50
+ they primarily focus on things that are not tested by the official array API
51
+ test suite.
52
+
53
+ - There is a custom array object, numpy.array_api.Array, which is returned by
54
+ all functions in this module. All functions in the array API namespace
55
+ implicitly assume that they will only receive this object as input. The only
56
+ way to create instances of this object is to use one of the array creation
57
+ functions. It does not have a public constructor on the object itself. The
58
+ object is a small wrapper class around numpy.ndarray. The main purpose of it
59
+ is to restrict the namespace of the array object to only those dtypes and
60
+ only those methods that are required by the spec, as well as to limit/change
61
+ certain behavior that differs in the spec. In particular:
62
+
63
+ - The array API namespace does not have scalar objects, only 0-D arrays.
64
+ Operations on Array that would create a scalar in NumPy create a 0-D
65
+ array.
66
+
67
+ - Indexing: Only a subset of indices supported by NumPy are required by the
68
+ spec. The Array object restricts indexing to only allow those types of
69
+ indices that are required by the spec. See the docstring of the
70
+ numpy.array_api.Array._validate_indices helper function for more
71
+ information.
72
+
73
+ - Type promotion: Some type promotion rules are different in the spec. In
74
+ particular, the spec does not have any value-based casting. The spec also
75
+ does not require cross-kind casting, like integer -> floating-point. Only
76
+ those promotions that are explicitly required by the array API
77
+ specification are allowed in this module. See NEP 47 for more info.
78
+
79
+ - Functions do not automatically call asarray() on their input, and will not
80
+ work if the input type is not Array. The exception is array creation
81
+ functions, and Python operators on the Array object, which accept Python
82
+ scalars of the same type as the array dtype.
83
+
84
+ - All functions include type annotations, corresponding to those given in the
85
+ spec (see _typing.py for definitions of some custom types). These do not
86
+ currently fully pass mypy due to some limitations in mypy.
87
+
88
+ - Dtype objects are just the NumPy dtype objects, e.g., float64 =
89
+ np.dtype('float64'). The spec does not require any behavior on these dtype
90
+ objects other than that they be accessible by name and be comparable by
91
+ equality, but it was considered too much extra complexity to create custom
92
+ objects to represent dtypes.
93
+
94
+ - All places where the implementations in this submodule are known to deviate
95
+ from their corresponding functions in NumPy are marked with "# Note:"
96
+ comments.
97
+
98
+ Still TODO in this module are:
99
+
100
+ - DLPack support for numpy.ndarray is still in progress. See
101
+ https://github.com/numpy/numpy/pull/19083.
102
+
103
+ - The copy=False keyword argument to asarray() is not yet implemented. This
104
+ requires support in numpy.asarray() first.
105
+
106
+ - Some functions are not yet fully tested in the array API test suite, and may
107
+ require updates that are not yet known until the tests are written.
108
+
109
+ - The spec is still in an RFC phase and may still have minor updates, which
110
+ will need to be reflected here.
111
+
112
+ - Complex number support in array API spec is planned but not yet finalized,
113
+ as are the fft extension and certain linear algebra functions such as eig
114
+ that require complex dtypes.
115
+
116
+ """
117
+
118
+ # CuPy-specific: still need to support Python 3.7.
119
+ import sys
120
+
121
+ if sys.version_info < (3, 8):
122
+ raise RuntimeError('cupy.array_api requires Python 3.8+')
123
+
124
+
125
+ import warnings
126
+
127
+ warnings.warn(
128
+ "The cupy.array_api submodule is still experimental. See NEP 47.", stacklevel=2
129
+ )
130
+
131
+ __array_api_version__ = "2021.12"
132
+
133
+ __all__ = ["__array_api_version__"]
134
+
135
+ from ._constants import e, inf, nan, pi
136
+
137
+ __all__ += ["e", "inf", "nan", "pi"]
138
+
139
+ from ._creation_functions import (
140
+ asarray,
141
+ arange,
142
+ empty,
143
+ empty_like,
144
+ eye,
145
+ from_dlpack,
146
+ full,
147
+ full_like,
148
+ linspace,
149
+ meshgrid,
150
+ ones,
151
+ ones_like,
152
+ tril,
153
+ triu,
154
+ zeros,
155
+ zeros_like,
156
+ )
157
+
158
+ __all__ += [
159
+ "asarray",
160
+ "arange",
161
+ "empty",
162
+ "empty_like",
163
+ "eye",
164
+ "from_dlpack",
165
+ "full",
166
+ "full_like",
167
+ "linspace",
168
+ "meshgrid",
169
+ "ones",
170
+ "ones_like",
171
+ "tril",
172
+ "triu",
173
+ "zeros",
174
+ "zeros_like",
175
+ ]
176
+
177
+ from ._data_type_functions import (
178
+ astype,
179
+ broadcast_arrays,
180
+ broadcast_to,
181
+ can_cast,
182
+ finfo,
183
+ iinfo,
184
+ result_type,
185
+ )
186
+
187
+ __all__ += [
188
+ "astype",
189
+ "broadcast_arrays",
190
+ "broadcast_to",
191
+ "can_cast",
192
+ "finfo",
193
+ "iinfo",
194
+ "result_type",
195
+ ]
196
+
197
+ from ._dtypes import (
198
+ int8,
199
+ int16,
200
+ int32,
201
+ int64,
202
+ uint8,
203
+ uint16,
204
+ uint32,
205
+ uint64,
206
+ float32,
207
+ float64,
208
+ bool,
209
+ )
210
+
211
+ __all__ += [
212
+ "int8",
213
+ "int16",
214
+ "int32",
215
+ "int64",
216
+ "uint8",
217
+ "uint16",
218
+ "uint32",
219
+ "uint64",
220
+ "float32",
221
+ "float64",
222
+ "bool",
223
+ ]
224
+
225
+ from ._elementwise_functions import (
226
+ abs,
227
+ acos,
228
+ acosh,
229
+ add,
230
+ asin,
231
+ asinh,
232
+ atan,
233
+ atan2,
234
+ atanh,
235
+ bitwise_and,
236
+ bitwise_left_shift,
237
+ bitwise_invert,
238
+ bitwise_or,
239
+ bitwise_right_shift,
240
+ bitwise_xor,
241
+ ceil,
242
+ cos,
243
+ cosh,
244
+ divide,
245
+ equal,
246
+ exp,
247
+ expm1,
248
+ floor,
249
+ floor_divide,
250
+ greater,
251
+ greater_equal,
252
+ isfinite,
253
+ isinf,
254
+ isnan,
255
+ less,
256
+ less_equal,
257
+ log,
258
+ log1p,
259
+ log2,
260
+ log10,
261
+ logaddexp,
262
+ logical_and,
263
+ logical_not,
264
+ logical_or,
265
+ logical_xor,
266
+ multiply,
267
+ negative,
268
+ not_equal,
269
+ positive,
270
+ pow,
271
+ remainder,
272
+ round,
273
+ sign,
274
+ sin,
275
+ sinh,
276
+ square,
277
+ sqrt,
278
+ subtract,
279
+ tan,
280
+ tanh,
281
+ trunc,
282
+ )
283
+
284
+ __all__ += [
285
+ "abs",
286
+ "acos",
287
+ "acosh",
288
+ "add",
289
+ "asin",
290
+ "asinh",
291
+ "atan",
292
+ "atan2",
293
+ "atanh",
294
+ "bitwise_and",
295
+ "bitwise_left_shift",
296
+ "bitwise_invert",
297
+ "bitwise_or",
298
+ "bitwise_right_shift",
299
+ "bitwise_xor",
300
+ "ceil",
301
+ "cos",
302
+ "cosh",
303
+ "divide",
304
+ "equal",
305
+ "exp",
306
+ "expm1",
307
+ "floor",
308
+ "floor_divide",
309
+ "greater",
310
+ "greater_equal",
311
+ "isfinite",
312
+ "isinf",
313
+ "isnan",
314
+ "less",
315
+ "less_equal",
316
+ "log",
317
+ "log1p",
318
+ "log2",
319
+ "log10",
320
+ "logaddexp",
321
+ "logical_and",
322
+ "logical_not",
323
+ "logical_or",
324
+ "logical_xor",
325
+ "multiply",
326
+ "negative",
327
+ "not_equal",
328
+ "positive",
329
+ "pow",
330
+ "remainder",
331
+ "round",
332
+ "sign",
333
+ "sin",
334
+ "sinh",
335
+ "square",
336
+ "sqrt",
337
+ "subtract",
338
+ "tan",
339
+ "tanh",
340
+ "trunc",
341
+ ]
342
+
343
+ from ._indexing_functions import take
344
+
345
+ __all__ += ["take"]
346
+
347
+ # linalg is an extension in the array API spec, which is a sub-namespace. Only
348
+ # a subset of functions in it are imported into the top-level namespace.
349
+ from . import linalg
350
+
351
+ __all__ += ["linalg"]
352
+
353
+ from .linalg import matmul, tensordot, matrix_transpose, vecdot
354
+
355
+ __all__ += ["matmul", "tensordot", "matrix_transpose", "vecdot"]
356
+
357
+ from ._manipulation_functions import (
358
+ concat,
359
+ expand_dims,
360
+ flip,
361
+ permute_dims,
362
+ reshape,
363
+ roll,
364
+ squeeze,
365
+ stack,
366
+ )
367
+
368
+ __all__ += ["concat", "expand_dims", "flip", "permute_dims", "reshape", "roll", "squeeze", "stack"]
369
+
370
+ from ._searching_functions import argmax, argmin, nonzero, where
371
+
372
+ __all__ += ["argmax", "argmin", "nonzero", "where"]
373
+
374
+ from ._set_functions import unique_all, unique_counts, unique_inverse, unique_values
375
+
376
+ __all__ += ["unique_all", "unique_counts", "unique_inverse", "unique_values"]
377
+
378
+ from ._sorting_functions import argsort, sort
379
+
380
+ __all__ += ["argsort", "sort"]
381
+
382
+ from ._statistical_functions import max, mean, min, prod, std, sum, var
383
+
384
+ __all__ += ["max", "mean", "min", "prod", "std", "sum", "var"]
385
+
386
+ from ._utility_functions import all, any
387
+
388
+ __all__ += ["all", "any"]