1 //================================================================================================= 2 /*! 3 // \file blaze/math/functors/Max.h 4 // \brief Header file for the Max 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_MAX_H_ 36 #define _BLAZE_MATH_FUNCTORS_MAX_H_ 37 38 39 //************************************************************************************************* 40 // Includes 41 //************************************************************************************************* 42 43 #include <utility> 44 #include <blaze/math/constraints/SIMDPack.h> 45 #include <blaze/math/simd/Max.h> 46 #include <blaze/math/typetraits/HasSIMDMax.h> 47 #include <blaze/math/typetraits/IsLower.h> 48 #include <blaze/math/typetraits/IsStrictlyLower.h> 49 #include <blaze/math/typetraits/IsStrictlyUpper.h> 50 #include <blaze/math/typetraits/IsSymmetric.h> 51 #include <blaze/math/typetraits/IsUniform.h> 52 #include <blaze/math/typetraits/IsUniLower.h> 53 #include <blaze/math/typetraits/IsUniUpper.h> 54 #include <blaze/math/typetraits/IsUpper.h> 55 #include <blaze/math/typetraits/YieldsLower.h> 56 #include <blaze/math/typetraits/YieldsStrictlyLower.h> 57 #include <blaze/math/typetraits/YieldsStrictlyUpper.h> 58 #include <blaze/math/typetraits/YieldsSymmetric.h> 59 #include <blaze/math/typetraits/YieldsUniform.h> 60 #include <blaze/math/typetraits/YieldsUniLower.h> 61 #include <blaze/math/typetraits/YieldsUniUpper.h> 62 #include <blaze/math/typetraits/YieldsUpper.h> 63 #include <blaze/util/algorithms/Max.h> 64 #include <blaze/system/HostDevice.h> 65 #include <blaze/system/Inline.h> 66 #include <blaze/util/IntegralConstant.h> 67 68 69 namespace blaze { 70 71 //================================================================================================= 72 // 73 // CLASS DEFINITION 74 // 75 //================================================================================================= 76 77 //************************************************************************************************* 78 /*!\brief Generic wrapper for the max() function. 79 // \ingroup functors 80 */ 81 struct Max 82 { 83 //********************************************************************************************** 84 /*!\brief Returns the result of the max() function for the given objects/values. 85 // 86 // \param a The left-hand side object/value. 87 // \param b The right-hand side object/value. 88 // \return The result of the max() function for the given objects/values. 89 */ 90 template< typename T1, typename T2 > decltypeMax91 BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( T1&& a, T2&& b ) const 92 { 93 return max( std::forward<T1>( a ), std::forward<T2>( b ) ); 94 } 95 //********************************************************************************************** 96 97 //********************************************************************************************** 98 /*!\brief Returns whether SIMD is enabled for the specified data types \a T1 and \a T2. 99 // 100 // \return \a true in case SIMD is enabled for the data types \a T1 and \a T2, \a false if not. 101 */ 102 template< typename T1, typename T2 > simdEnabledMax103 static constexpr bool simdEnabled() { return HasSIMDMax_v<T1,T2>; } 104 //********************************************************************************************** 105 106 //********************************************************************************************** 107 /*!\brief Returns whether the operation supports padding, i.e. whether it can deal with zeros. 108 // 109 // \return \a true in case padding is supported, \a false if not. 110 */ paddingEnabledMax111 static constexpr bool paddingEnabled() { return true; } 112 //********************************************************************************************** 113 114 //********************************************************************************************** 115 /*!\brief Returns the result of the max() function for the given SIMD vector. 116 // 117 // \param a The left-hand side SIMD vector. 118 // \param b The right-hand side SIMD vector. 119 // \return The result of the max() function for the given SIMD vectors. 120 */ 121 template< typename T1, typename T2 > decltypeMax122 BLAZE_ALWAYS_INLINE decltype(auto) load( const T1& a, const T2& b ) const 123 { 124 BLAZE_CONSTRAINT_MUST_BE_SIMD_PACK( T1 ); 125 BLAZE_CONSTRAINT_MUST_BE_SIMD_PACK( T2 ); 126 return max( a, b ); 127 } 128 //********************************************************************************************** 129 }; 130 //************************************************************************************************* 131 132 133 134 135 //================================================================================================= 136 // 137 // YIELDSUNIFORM SPECIALIZATIONS 138 // 139 //================================================================================================= 140 141 //************************************************************************************************* 142 /*! \cond BLAZE_INTERNAL */ 143 template< typename T1, typename T2 > 144 struct YieldsUniform<Max,T1,T2> 145 : public BoolConstant< IsUniform_v<T1> && IsUniform_v<T2> > 146 {}; 147 /*! \endcond */ 148 //************************************************************************************************* 149 150 151 152 153 //================================================================================================= 154 // 155 // YIELDSSYMMETRIC SPECIALIZATIONS 156 // 157 //================================================================================================= 158 159 //************************************************************************************************* 160 /*! \cond BLAZE_INTERNAL */ 161 template< typename MT1, typename MT2 > 162 struct YieldsSymmetric<Max,MT1,MT2> 163 : public BoolConstant< IsSymmetric_v<MT1> && IsSymmetric_v<MT2> > 164 {}; 165 /*! \endcond */ 166 //************************************************************************************************* 167 168 169 170 171 //================================================================================================= 172 // 173 // YIELDSLOWER SPECIALIZATIONS 174 // 175 //================================================================================================= 176 177 //************************************************************************************************* 178 /*! \cond BLAZE_INTERNAL */ 179 template< typename MT1, typename MT2 > 180 struct YieldsLower<Max,MT1,MT2> 181 : public BoolConstant< IsLower_v<MT1> && IsLower_v<MT2> > 182 {}; 183 /*! \endcond */ 184 //************************************************************************************************* 185 186 187 188 189 //================================================================================================= 190 // 191 // YIELDSUNILOWER SPECIALIZATIONS 192 // 193 //================================================================================================= 194 195 //************************************************************************************************* 196 /*! \cond BLAZE_INTERNAL */ 197 template< typename MT1, typename MT2 > 198 struct YieldsUniLower<Max,MT1,MT2> 199 : public BoolConstant< ( IsUniLower_v<MT1> && ( IsUniLower_v<MT2> || IsStrictlyLower_v<MT2> ) ) || 200 ( IsUniLower_v<MT2> && ( IsUniLower_v<MT1> || IsStrictlyLower_v<MT1> ) ) > 201 {}; 202 /*! \endcond */ 203 //************************************************************************************************* 204 205 206 207 208 //================================================================================================= 209 // 210 // YIELDSSTRICTLYLOWER SPECIALIZATIONS 211 // 212 //================================================================================================= 213 214 //************************************************************************************************* 215 /*! \cond BLAZE_INTERNAL */ 216 template< typename MT1, typename MT2 > 217 struct YieldsStrictlyLower<Max,MT1,MT2> 218 : public BoolConstant< IsStrictlyLower_v<MT1> && IsStrictlyLower_v<MT2> > 219 {}; 220 /*! \endcond */ 221 //************************************************************************************************* 222 223 224 225 226 //================================================================================================= 227 // 228 // YIELDSUPPER SPECIALIZATIONS 229 // 230 //================================================================================================= 231 232 //************************************************************************************************* 233 /*! \cond BLAZE_INTERNAL */ 234 template< typename MT1, typename MT2 > 235 struct YieldsUpper<Max,MT1,MT2> 236 : public BoolConstant< IsUpper_v<MT1> && IsUpper_v<MT2> > 237 {}; 238 /*! \endcond */ 239 //************************************************************************************************* 240 241 242 243 244 //================================================================================================= 245 // 246 // YIELDSUNIUPPER SPECIALIZATIONS 247 // 248 //================================================================================================= 249 250 //************************************************************************************************* 251 /*! \cond BLAZE_INTERNAL */ 252 template< typename MT1, typename MT2 > 253 struct YieldsUniUpper<Max,MT1,MT2> 254 : public BoolConstant< ( IsUniUpper_v<MT1> && ( IsUniUpper_v<MT2> || IsStrictlyUpper_v<MT2> ) ) || 255 ( IsUniUpper_v<MT2> && ( IsUniUpper_v<MT1> || IsStrictlyUpper_v<MT1> ) ) > 256 {}; 257 /*! \endcond */ 258 //************************************************************************************************* 259 260 261 262 263 //================================================================================================= 264 // 265 // YIELDSSTRICTLYUPPER SPECIALIZATIONS 266 // 267 //================================================================================================= 268 269 //************************************************************************************************* 270 /*! \cond BLAZE_INTERNAL */ 271 template< typename MT1, typename MT2 > 272 struct YieldsStrictlyUpper<Max,MT1,MT2> 273 : public BoolConstant< IsStrictlyUpper_v<MT1> && IsStrictlyUpper_v<MT2> > 274 {}; 275 /*! \endcond */ 276 //************************************************************************************************* 277 278 } // namespace blaze 279 280 #endif 281