DVecDVecEqualExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECDVECEQUALEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECDVECEQUALEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
46 #include <blaze/math/shims/Equal.h>
47 #include <blaze/math/SIMD.h>
51 #include <blaze/util/DisableIf.h>
52 #include <blaze/util/EnableIf.h>
53 #include <blaze/util/Types.h>
55 
56 
57 namespace blaze {
58 
59 //=================================================================================================
60 //
61 // CLASS DEFINITION
62 //
63 //=================================================================================================
64 
65 //*************************************************************************************************
70 template< typename VT1 // Type of the left-hand side dense vector
71  , typename VT2 > // Type of the right-hand side dense vector
72 struct DVecDVecEqualExprHelper
73 {
74  //**Type definitions****************************************************************************
76  using CT1 = RemoveReference_t< CompositeType_t<VT1> >;
77 
79  using CT2 = RemoveReference_t< CompositeType_t<VT2> >;
80  //**********************************************************************************************
81 
82  //**********************************************************************************************
83  static constexpr bool value =
84  ( useOptimizedKernels &&
85  CT1::simdEnabled &&
86  CT2::simdEnabled &&
87  HasSIMDEqual_v< ElementType_t<CT1>, ElementType_t<CT2> > );
88  //**********************************************************************************************
89 };
91 //*************************************************************************************************
92 
93 
94 
95 
96 //=================================================================================================
97 //
98 // GLOBAL BINARY RELATIONAL OPERATORS
99 //
100 //=================================================================================================
101 
102 //*************************************************************************************************
115 template< bool RF // Relaxation flag
116  , typename VT1 // Type of the left-hand side dense vector
117  , bool TF1 // Transpose flag of the left-hand side dense vector
118  , typename VT2 // Type of the right-hand side dense vector
119  , bool TF2 > // Transpose flag of the right-hand side dense vector
120 inline auto equal( const DenseVector<VT1,TF1>& lhs, const DenseVector<VT2,TF2>& rhs )
121  -> DisableIf_t< DVecDVecEqualExprHelper<VT1,VT2>::value, bool >
122 {
123  using CT1 = CompositeType_t<VT1>;
124  using CT2 = CompositeType_t<VT2>;
125 
126  // Early exit in case the vector sizes don't match
127  if( (~lhs).size() != (~rhs).size() ) return false;
128 
129  // Evaluation of the two dense vector operands
130  CT1 a( ~lhs );
131  CT2 b( ~rhs );
132 
133  // In order to compare the two vectors, the data values of the lower-order data
134  // type are converted to the higher-order data type within the equal function.
135  for( size_t i=0UL; i<a.size(); ++i )
136  if( !equal<RF>( a[i], b[i] ) ) return false;
137  return true;
138 }
140 //*************************************************************************************************
141 
142 
143 //*************************************************************************************************
156 template< bool RF // Relaxation flag
157  , typename VT1 // Type of the left-hand side dense vector
158  , bool TF1 // Transpose flag of the left-hand side dense vector
159  , typename VT2 // Type of the right-hand side dense vector
160  , bool TF2 > // Transpose flag of the right-hand side dense vector
161 inline auto equal( const DenseVector<VT1,TF1>& lhs, const DenseVector<VT2,TF2>& rhs )
162  -> EnableIf_t< DVecDVecEqualExprHelper<VT1,VT2>::value, bool >
163 {
164  using CT1 = CompositeType_t<VT1>;
165  using CT2 = CompositeType_t<VT2>;
166  using XT1 = RemoveReference_t<CT1>;
167  using XT2 = RemoveReference_t<CT2>;
168 
169  // Early exit in case the vector sizes don't match
170  if( (~lhs).size() != (~rhs).size() ) return false;
171 
172  // Evaluation of the two dense vector operands
173  CT1 a( ~lhs );
174  CT2 b( ~rhs );
175 
176  constexpr size_t SIMDSIZE = SIMDTrait< ElementType_t<VT1> >::size;
177  constexpr bool remainder( !usePadding || !IsPadded_v<XT1> || !IsPadded_v<XT2> );
178 
179  const size_t N( a.size() );
180 
181  const size_t ipos( ( remainder )?( N & size_t(-SIMDSIZE) ):( N ) );
182  BLAZE_INTERNAL_ASSERT( !remainder || ( N - ( N % SIMDSIZE ) ) == ipos, "Invalid end calculation" );
183 
184  size_t i( 0UL );
185 
186  for( ; (i+SIMDSIZE*3UL) < ipos; i+=SIMDSIZE*4UL ) {
187  if( !equal<RF>( a.load(i ), b.load(i ) ) ) return false;
188  if( !equal<RF>( a.load(i+SIMDSIZE ), b.load(i+SIMDSIZE ) ) ) return false;
189  if( !equal<RF>( a.load(i+SIMDSIZE*2UL), b.load(i+SIMDSIZE*2UL) ) ) return false;
190  if( !equal<RF>( a.load(i+SIMDSIZE*3UL), b.load(i+SIMDSIZE*3UL) ) ) return false;
191  }
192  for( ; (i+SIMDSIZE) < ipos; i+=SIMDSIZE*2UL ) {
193  if( !equal<RF>( a.load(i ), b.load(i ) ) ) return false;
194  if( !equal<RF>( a.load(i+SIMDSIZE), b.load(i+SIMDSIZE) ) ) return false;
195  }
196  for( ; i<ipos; i+=SIMDSIZE ) {
197  if( !equal<RF>( a.load(i), b.load(i) ) ) return false;
198  }
199  for( ; remainder && i<N; ++i ) {
200  if( !equal<RF>( a[i], b[i] ) ) return false;
201  }
202 
203  return true;
204 }
206 //*************************************************************************************************
207 
208 
209 //*************************************************************************************************
217 template< typename VT1 // Type of the left-hand side dense vector
218  , bool TF1 // Transpose flag of the left-hand side dense vector
219  , typename VT2 // Type of the right-hand side dense vector
220  , bool TF2 > // Transpose flag of the right-hand side dense vector
221 inline bool operator==( const DenseVector<VT1,TF1>& lhs, const DenseVector<VT2,TF2>& rhs )
222 {
223  return equal<relaxed>( lhs, rhs );
224 }
225 //*************************************************************************************************
226 
227 
228 //*************************************************************************************************
236 template< typename VT1 // Type of the left-hand side dense vector
237  , bool TF1 // Transpose flag of the left-hand side dense vector
238  , typename VT2 // Type of the right-hand side dense vector
239  , bool TF2 > // Transpose flag of the right-hand side dense vector
240 inline bool operator!=( const DenseVector<VT1,TF1>& lhs, const DenseVector<VT2,TF2>& rhs )
241 {
242  return !equal<relaxed>( lhs, rhs );
243 }
244 //*************************************************************************************************
245 
246 } // namespace blaze
247 
248 #endif
Header file for auxiliary alias declarations.
Header file for basic type definitions.
Header file for the DenseVector base class.
System settings for performance optimizations.
Header file for the DisableIf class template.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:253
Header file for all SIMD functionality.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
Header file for the equal shim.
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
Header file for the EnableIf class template.
Header file for the IsPadded type trait.
Header file for the relaxation flag types.
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
Header file for the RemoveReference type trait.
Header file for the HasSIMDEqual type trait.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
bool equal(const SharedValue< T1 > &lhs, const SharedValue< T2 > &rhs)
Equality check for a two shared values.
Definition: SharedValue.h:342