Blaze 3.9
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>
48#include <blaze/math/SIMD.h>
53#include <blaze/util/EnableIf.h>
54#include <blaze/util/Types.h>
56
57
58namespace blaze {
59
60//=================================================================================================
61//
62// CLASS DEFINITION
63//
64//=================================================================================================
65
66//*************************************************************************************************
71template< typename VT1 // Type of the left-hand side dense vector
72 , typename VT2 > // Type of the right-hand side dense vector
73struct DVecDVecEqualExprHelper
74{
75 //**Type definitions****************************************************************************
77 using CT1 = RemoveReference_t< CompositeType_t<VT1> >;
78
80 using CT2 = RemoveReference_t< CompositeType_t<VT2> >;
81 //**********************************************************************************************
82
83 //**********************************************************************************************
84 static constexpr bool value =
85 ( useOptimizedKernels &&
86 CT1::simdEnabled &&
87 CT2::simdEnabled &&
88 HasSIMDEqual_v< ElementType_t<CT1>, ElementType_t<CT2> > );
89 //**********************************************************************************************
90};
92//*************************************************************************************************
93
94
95
96
97//=================================================================================================
98//
99// GLOBAL BINARY RELATIONAL OPERATORS
100//
101//=================================================================================================
102
103//*************************************************************************************************
116template< RelaxationFlag RF // Relaxation flag
117 , typename VT1 // Type of the left-hand side dense vector
118 , bool TF1 // Transpose flag of the left-hand side dense vector
119 , typename VT2 // Type of the right-hand side dense vector
120 , bool TF2 > // Transpose flag of the right-hand side dense vector
121inline auto equal( const DenseVector<VT1,TF1>& lhs, const DenseVector<VT2,TF2>& rhs )
122 -> DisableIf_t< DVecDVecEqualExprHelper<VT1,VT2>::value, bool >
123{
124 using CT1 = CompositeType_t<VT1>;
125 using CT2 = CompositeType_t<VT2>;
126
127 // Early exit in case the vector sizes don't match
128 if( (*lhs).size() != (*rhs).size() ) return false;
129
130 // Evaluation of the two dense vector operands
131 CT1 a( *lhs );
132 CT2 b( *rhs );
133
134 // In order to compare the two vectors, the data values of the lower-order data
135 // type are converted to the higher-order data type within the equal function.
136 for( size_t i=0UL; i<a.size(); ++i )
137 if( !equal<RF>( a[i], b[i] ) ) return false;
138 return true;
139}
141//*************************************************************************************************
142
143
144//*************************************************************************************************
157template< RelaxationFlag RF // Relaxation flag
158 , typename VT1 // Type of the left-hand side dense vector
159 , bool TF1 // Transpose flag of the left-hand side dense vector
160 , typename VT2 // Type of the right-hand side dense vector
161 , bool TF2 > // Transpose flag of the right-hand side dense vector
162inline auto equal( const DenseVector<VT1,TF1>& lhs, const DenseVector<VT2,TF2>& rhs )
163 -> EnableIf_t< DVecDVecEqualExprHelper<VT1,VT2>::value, bool >
164{
165 using CT1 = CompositeType_t<VT1>;
166 using CT2 = CompositeType_t<VT2>;
167 using XT1 = RemoveReference_t<CT1>;
168 using XT2 = RemoveReference_t<CT2>;
169
170 // Early exit in case the vector sizes don't match
171 if( (*lhs).size() != (*rhs).size() ) return false;
172
173 // Evaluation of the two dense vector operands
174 CT1 a( *lhs );
175 CT2 b( *rhs );
176
177 constexpr size_t SIMDSIZE = SIMDTrait< ElementType_t<VT1> >::size;
178 constexpr bool remainder( !IsPadded_v<XT1> || !IsPadded_v<XT2> );
179
180 const size_t N( a.size() );
181
182 const size_t ipos( remainder ? prevMultiple( N, SIMDSIZE ) : N );
183 BLAZE_INTERNAL_ASSERT( ipos <= N, "Invalid end calculation" );
184
185 size_t i( 0UL );
186
187 for( ; (i+SIMDSIZE*3UL) < ipos; i+=SIMDSIZE*4UL ) {
188 if( !equal<RF>( a.load(i ), b.load(i ) ) ) return false;
189 if( !equal<RF>( a.load(i+SIMDSIZE ), b.load(i+SIMDSIZE ) ) ) return false;
190 if( !equal<RF>( a.load(i+SIMDSIZE*2UL), b.load(i+SIMDSIZE*2UL) ) ) return false;
191 if( !equal<RF>( a.load(i+SIMDSIZE*3UL), b.load(i+SIMDSIZE*3UL) ) ) return false;
192 }
193 for( ; (i+SIMDSIZE) < ipos; i+=SIMDSIZE*2UL ) {
194 if( !equal<RF>( a.load(i ), b.load(i ) ) ) return false;
195 if( !equal<RF>( a.load(i+SIMDSIZE), b.load(i+SIMDSIZE) ) ) return false;
196 }
197 for( ; i<ipos; i+=SIMDSIZE ) {
198 if( !equal<RF>( a.load(i), b.load(i) ) ) return false;
199 }
200 for( ; remainder && i<N; ++i ) {
201 if( !equal<RF>( a[i], b[i] ) ) return false;
202 }
203
204 return true;
205}
207//*************************************************************************************************
208
209
210//*************************************************************************************************
218template< typename VT1 // Type of the left-hand side dense vector
219 , bool TF1 // Transpose flag of the left-hand side dense vector
220 , typename VT2 // Type of the right-hand side dense vector
221 , bool TF2 > // Transpose flag of the right-hand side dense vector
222inline bool operator==( const DenseVector<VT1,TF1>& lhs, const DenseVector<VT2,TF2>& rhs )
223{
224 return equal<relaxed>( lhs, rhs );
225}
226//*************************************************************************************************
227
228
229//*************************************************************************************************
237template< typename VT1 // Type of the left-hand side dense vector
238 , bool TF1 // Transpose flag of the left-hand side dense vector
239 , typename VT2 // Type of the right-hand side dense vector
240 , bool TF2 > // Transpose flag of the right-hand side dense vector
241inline bool operator!=( const DenseVector<VT1,TF1>& lhs, const DenseVector<VT2,TF2>& rhs )
242{
243 return !equal<relaxed>( lhs, rhs );
244}
245//*************************************************************************************************
246
247} // namespace blaze
248
249#endif
Header file for auxiliary alias declarations.
Header file for the EnableIf class template.
Header file for the HasSIMDEqual type trait.
Header file for the IsPadded type trait.
Deactivation of problematic macros.
Header file for the prevMultiple shim.
Header file for the relaxation flag enumeration.
Header file for the RemoveReference type trait.
Header file for all SIMD functionality.
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Header file for the DenseVector base class.
bool operator!=(const DenseVector< VT1, TF1 > &lhs, const DenseVector< VT2, TF2 > &rhs)
Inequality operator for the comparison of two dense vectors.
Definition: DVecDVecEqualExpr.h:241
bool operator==(const DenseVector< VT1, TF1 > &lhs, const DenseVector< VT2, TF2 > &rhs)
Equality operator for the comparison of two dense vectors.
Definition: DVecDVecEqualExpr.h:222
RelaxationFlag
Relaxation flag for strict or relaxed semantics.
Definition: RelaxationFlag.h:66
BLAZE_ALWAYS_INLINE constexpr auto prevMultiple(T1 value, T2 factor) noexcept
Rounds down an integral value to the previous multiple of a given factor.
Definition: PrevMultiple.h:68
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:676
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
bool equal(const SharedValue< T1 > &lhs, const SharedValue< T2 > &rhs)
Equality check for a two shared values.
Definition: SharedValue.h:343
Header file for the equal shim.
System settings for performance optimizations.
Header file for basic type definitions.