1 //=================================================================================================
2 /*!
3 //  \file blaze/math/functors/Sqrt.h
4 //  \brief Header file for the Sqrt functor
5 //
6 //  Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved
7 //
8 //  This file is part of the Blaze library. You can redistribute it and/or modify it under
9 //  the terms of the New (Revised) BSD License. Redistribution and use in source and binary
10 //  forms, with or without modification, are permitted provided that the following conditions
11 //  are met:
12 //
13 //  1. Redistributions of source code must retain the above copyright notice, this list of
14 //     conditions and the following disclaimer.
15 //  2. Redistributions in binary form must reproduce the above copyright notice, this list
16 //     of conditions and the following disclaimer in the documentation and/or other materials
17 //     provided with the distribution.
18 //  3. Neither the names of the Blaze development group nor the names of its contributors
19 //     may be used to endorse or promote products derived from this software without specific
20 //     prior written permission.
21 //
22 //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23 //  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 //  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 //  SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 //  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 //  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 //  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 //  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 //  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 //  DAMAGE.
32 */
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_FUNCTORS_SQRT_H_
36 #define _BLAZE_MATH_FUNCTORS_SQRT_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <utility>
44 #include <blaze/math/constraints/SIMDPack.h>
45 #include <blaze/math/shims/Sqrt.h>
46 #include <blaze/math/simd/Sqrt.h>
47 #include <blaze/math/typetraits/HasSIMDSqrt.h>
48 #include <blaze/math/typetraits/IsHermitian.h>
49 #include <blaze/math/typetraits/IsLower.h>
50 #include <blaze/math/typetraits/IsStrictlyLower.h>
51 #include <blaze/math/typetraits/IsStrictlyUpper.h>
52 #include <blaze/math/typetraits/IsSymmetric.h>
53 #include <blaze/math/typetraits/IsUniform.h>
54 #include <blaze/math/typetraits/IsUniLower.h>
55 #include <blaze/math/typetraits/IsUniUpper.h>
56 #include <blaze/math/typetraits/IsUpper.h>
57 #include <blaze/math/typetraits/IsZero.h>
58 #include <blaze/math/typetraits/YieldsHermitian.h>
59 #include <blaze/math/typetraits/YieldsLower.h>
60 #include <blaze/math/typetraits/YieldsStrictlyLower.h>
61 #include <blaze/math/typetraits/YieldsStrictlyUpper.h>
62 #include <blaze/math/typetraits/YieldsSymmetric.h>
63 #include <blaze/math/typetraits/YieldsUniform.h>
64 #include <blaze/math/typetraits/YieldsUniLower.h>
65 #include <blaze/math/typetraits/YieldsUniUpper.h>
66 #include <blaze/math/typetraits/YieldsUpper.h>
67 #include <blaze/math/typetraits/YieldsZero.h>
68 #include <blaze/system/HostDevice.h>
69 #include <blaze/system/Inline.h>
70 
71 
72 namespace blaze {
73 
74 //=================================================================================================
75 //
76 //  CLASS DEFINITION
77 //
78 //=================================================================================================
79 
80 //*************************************************************************************************
81 /*!\brief Generic wrapper for the sqrt() function.
82 // \ingroup functors
83 */
84 struct Sqrt
85 {
86    //**********************************************************************************************
87    /*!\brief Returns the result of the sqrt() function for the given object/value.
88    //
89    // \param a The given object/value.
90    // \return The result of the sqrt() function for the given object/value.
91    */
92    template< typename T >
decltypeSqrt93    BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( T&& a ) const
94    {
95       return sqrt( std::forward<T>( a ) );
96    }
97    //**********************************************************************************************
98 
99    //**********************************************************************************************
100    /*!\brief Returns whether SIMD is enabled for the specified data type \a T.
101    //
102    // \return \a true in case SIMD is enabled for the data type \a T, \a false if not.
103    */
104    template< typename T >
simdEnabledSqrt105    static constexpr bool simdEnabled() { return HasSIMDSqrt_v<T>; }
106    //**********************************************************************************************
107 
108    //**********************************************************************************************
109    /*!\brief Returns whether the operation supports padding, i.e. whether it can deal with zeros.
110    //
111    // \return \a true in case padding is supported, \a false if not.
112    */
paddingEnabledSqrt113    static constexpr bool paddingEnabled() { return true; }
114    //**********************************************************************************************
115 
116    //**********************************************************************************************
117    /*!\brief Returns the result of the sqrt() function for the given SIMD vector.
118    //
119    // \param a The given SIMD vector.
120    // \return The result of the sqrt() function for the given SIMD vector.
121    */
122    template< typename T >
decltypeSqrt123    BLAZE_ALWAYS_INLINE decltype(auto) load( const T& a ) const
124    {
125       BLAZE_CONSTRAINT_MUST_BE_SIMD_PACK( T );
126       return sqrt( a );
127    }
128    //**********************************************************************************************
129 };
130 //*************************************************************************************************
131 
132 
133 
134 
135 //=================================================================================================
136 //
137 //  YIELDSUNIFORM SPECIALIZATIONS
138 //
139 //=================================================================================================
140 
141 //*************************************************************************************************
142 /*! \cond BLAZE_INTERNAL */
143 template< typename T >
144 struct YieldsUniform<Sqrt,T>
145    : public IsUniform<T>
146 {};
147 /*! \endcond */
148 //*************************************************************************************************
149 
150 
151 
152 
153 //=================================================================================================
154 //
155 //  YIELDSSYMMETRIC SPECIALIZATIONS
156 //
157 //=================================================================================================
158 
159 //*************************************************************************************************
160 /*! \cond BLAZE_INTERNAL */
161 template< typename MT >
162 struct YieldsSymmetric<Sqrt,MT>
163    : public IsSymmetric<MT>
164 {};
165 /*! \endcond */
166 //*************************************************************************************************
167 
168 
169 
170 
171 //=================================================================================================
172 //
173 //  YIELDSHERMITIAN SPECIALIZATIONS
174 //
175 //=================================================================================================
176 
177 //*************************************************************************************************
178 /*! \cond BLAZE_INTERNAL */
179 template< typename MT >
180 struct YieldsHermitian<Sqrt,MT>
181    : public IsHermitian<MT>
182 {};
183 /*! \endcond */
184 //*************************************************************************************************
185 
186 
187 
188 
189 //=================================================================================================
190 //
191 //  YIELDSLOWER SPECIALIZATIONS
192 //
193 //=================================================================================================
194 
195 //*************************************************************************************************
196 /*! \cond BLAZE_INTERNAL */
197 template< typename MT >
198 struct YieldsLower<Sqrt,MT>
199    : public IsLower<MT>
200 {};
201 /*! \endcond */
202 //*************************************************************************************************
203 
204 
205 
206 
207 //=================================================================================================
208 //
209 //  YIELDSUNILOWER SPECIALIZATIONS
210 //
211 //=================================================================================================
212 
213 //*************************************************************************************************
214 /*! \cond BLAZE_INTERNAL */
215 template< typename MT >
216 struct YieldsUniLower<Sqrt,MT>
217    : public IsUniLower<MT>
218 {};
219 /*! \endcond */
220 //*************************************************************************************************
221 
222 
223 
224 
225 //=================================================================================================
226 //
227 //  YIELDSSTRICTLYLOWER SPECIALIZATIONS
228 //
229 //=================================================================================================
230 
231 //*************************************************************************************************
232 /*! \cond BLAZE_INTERNAL */
233 template< typename MT >
234 struct YieldsStrictlyLower<Sqrt,MT>
235    : public IsStrictlyLower<MT>
236 {};
237 /*! \endcond */
238 //*************************************************************************************************
239 
240 
241 
242 
243 //=================================================================================================
244 //
245 //  YIELDSUPPER SPECIALIZATIONS
246 //
247 //=================================================================================================
248 
249 //*************************************************************************************************
250 /*! \cond BLAZE_INTERNAL */
251 template< typename MT >
252 struct YieldsUpper<Sqrt,MT>
253    : public IsUpper<MT>
254 {};
255 /*! \endcond */
256 //*************************************************************************************************
257 
258 
259 
260 
261 //=================================================================================================
262 //
263 //  YIELDSUNIUPPER SPECIALIZATIONS
264 //
265 //=================================================================================================
266 
267 //*************************************************************************************************
268 /*! \cond BLAZE_INTERNAL */
269 template< typename MT >
270 struct YieldsUniUpper<Sqrt,MT>
271    : public IsUniUpper<MT>
272 {};
273 /*! \endcond */
274 //*************************************************************************************************
275 
276 
277 
278 
279 //=================================================================================================
280 //
281 //  YIELDSSTRICTLYUPPER SPECIALIZATIONS
282 //
283 //=================================================================================================
284 
285 //*************************************************************************************************
286 /*! \cond BLAZE_INTERNAL */
287 template< typename MT >
288 struct YieldsStrictlyUpper<Sqrt,MT>
289    : public IsStrictlyUpper<MT>
290 {};
291 /*! \endcond */
292 //*************************************************************************************************
293 
294 
295 
296 
297 //=================================================================================================
298 //
299 //  YIELDSZERO SPECIALIZATIONS
300 //
301 //=================================================================================================
302 
303 //*************************************************************************************************
304 /*! \cond BLAZE_INTERNAL */
305 template< typename T >
306 struct YieldsZero<Sqrt,T>
307    : public IsZero<T>
308 {};
309 /*! \endcond */
310 //*************************************************************************************************
311 
312 } // namespace blaze
313 
314 #endif
315