1 //=================================================================================================
2 /*!
3 //  \file blaze/math/functors/Abs.h
4 //  \brief Header file for the Abs 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_ABS_H_
36 #define _BLAZE_MATH_FUNCTORS_ABS_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <utility>
44 #include <blaze/math/constraints/SIMDPack.h>
45 #include <blaze/math/shims/Abs.h>
46 #include <blaze/math/simd/Abs.h>
47 #include <blaze/math/typetraits/HasSIMDAbs.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/YieldsLower.h>
59 #include <blaze/math/typetraits/YieldsStrictlyLower.h>
60 #include <blaze/math/typetraits/YieldsStrictlyUpper.h>
61 #include <blaze/math/typetraits/YieldsSymmetric.h>
62 #include <blaze/math/typetraits/YieldsUniform.h>
63 #include <blaze/math/typetraits/YieldsUniLower.h>
64 #include <blaze/math/typetraits/YieldsUniUpper.h>
65 #include <blaze/math/typetraits/YieldsUpper.h>
66 #include <blaze/math/typetraits/YieldsZero.h>
67 #include <blaze/system/HostDevice.h>
68 #include <blaze/system/Inline.h>
69 #include <blaze/util/IntegralConstant.h>
70 
71 
72 namespace blaze {
73 
74 //=================================================================================================
75 //
76 //  CLASS DEFINITION
77 //
78 //=================================================================================================
79 
80 //*************************************************************************************************
81 /*!\brief Generic wrapper for the abs() function.
82 // \ingroup functors
83 */
84 struct Abs
85 {
86    //**********************************************************************************************
87    /*!\brief Returns the result of the abs() function for the given object/value.
88    //
89    // \param a The given object/value.
90    // \return The result of the abs() function for the given object/value.
91    */
92    template< typename T >
decltypeAbs93    BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( T&& a ) const
94    {
95       return abs( 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 >
simdEnabledAbs105    static constexpr bool simdEnabled() { return HasSIMDAbs_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    */
paddingEnabledAbs113    static constexpr bool paddingEnabled() { return true; }
114    //**********************************************************************************************
115 
116    //**********************************************************************************************
117    /*!\brief Returns the result of the abs() function for the given SIMD vector.
118    //
119    // \param a The given SIMD vector.
120    // \return The result of the abs() function for the given SIMD vector.
121    */
122    template< typename T >
decltypeAbs123    BLAZE_ALWAYS_INLINE decltype(auto) load( const T& a ) const
124    {
125       BLAZE_CONSTRAINT_MUST_BE_SIMD_PACK( T );
126       return abs( 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<Abs,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<Abs,MT>
163    : public BoolConstant< IsSymmetric_v<MT> || IsHermitian_v<MT> >
164 {};
165 /*! \endcond */
166 //*************************************************************************************************
167 
168 
169 
170 
171 //=================================================================================================
172 //
173 //  YIELDSLOWER SPECIALIZATIONS
174 //
175 //=================================================================================================
176 
177 //*************************************************************************************************
178 /*! \cond BLAZE_INTERNAL */
179 template< typename MT >
180 struct YieldsLower<Abs,MT>
181    : public IsLower<MT>
182 {};
183 /*! \endcond */
184 //*************************************************************************************************
185 
186 
187 
188 
189 //=================================================================================================
190 //
191 //  YIELDSUNILOWER SPECIALIZATIONS
192 //
193 //=================================================================================================
194 
195 //*************************************************************************************************
196 /*! \cond BLAZE_INTERNAL */
197 template< typename MT >
198 struct YieldsUniLower<Abs,MT>
199    : public IsUniLower<MT>
200 {};
201 /*! \endcond */
202 //*************************************************************************************************
203 
204 
205 
206 
207 //=================================================================================================
208 //
209 //  YIELDSSTRICTLYLOWER SPECIALIZATIONS
210 //
211 //=================================================================================================
212 
213 //*************************************************************************************************
214 /*! \cond BLAZE_INTERNAL */
215 template< typename MT >
216 struct YieldsStrictlyLower<Abs,MT>
217    : public IsStrictlyLower<MT>
218 {};
219 /*! \endcond */
220 //*************************************************************************************************
221 
222 
223 
224 
225 //=================================================================================================
226 //
227 //  YIELDSUPPER SPECIALIZATIONS
228 //
229 //=================================================================================================
230 
231 //*************************************************************************************************
232 /*! \cond BLAZE_INTERNAL */
233 template< typename MT >
234 struct YieldsUpper<Abs,MT>
235    : public IsUpper<MT>
236 {};
237 /*! \endcond */
238 //*************************************************************************************************
239 
240 
241 
242 
243 //=================================================================================================
244 //
245 //  YIELDSUNIUPPER SPECIALIZATIONS
246 //
247 //=================================================================================================
248 
249 //*************************************************************************************************
250 /*! \cond BLAZE_INTERNAL */
251 template< typename MT >
252 struct YieldsUniUpper<Abs,MT>
253    : public IsUniUpper<MT>
254 {};
255 /*! \endcond */
256 //*************************************************************************************************
257 
258 
259 
260 
261 //=================================================================================================
262 //
263 //  YIELDSSTRICTLYUPPER SPECIALIZATIONS
264 //
265 //=================================================================================================
266 
267 //*************************************************************************************************
268 /*! \cond BLAZE_INTERNAL */
269 template< typename MT >
270 struct YieldsStrictlyUpper<Abs,MT>
271    : public IsStrictlyUpper<MT>
272 {};
273 /*! \endcond */
274 //*************************************************************************************************
275 
276 
277 
278 
279 //=================================================================================================
280 //
281 //  YIELDSZERO SPECIALIZATIONS
282 //
283 //=================================================================================================
284 
285 //*************************************************************************************************
286 /*! \cond BLAZE_INTERNAL */
287 template< typename T >
288 struct YieldsZero<Abs,T>
289    : public IsZero<T>
290 {};
291 /*! \endcond */
292 //*************************************************************************************************
293 
294 } // namespace blaze
295 
296 #endif
297