DVecSVecEqualExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECSVECEQUALEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECSVECEQUALEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
47 #include <blaze/math/shims/Equal.h>
49 #include <blaze/util/Types.h>
50 
51 
52 namespace blaze {
53 
54 //=================================================================================================
55 //
56 // GLOBAL BINARY RELATIONAL OPERATORS
57 //
58 //=================================================================================================
59 
60 //*************************************************************************************************
74 template< bool RF // Relaxation flag
75  , typename VT1 // Type of the left-hand side dense vector
76  , bool TF1 // Transpose flag of the left-hand side dense vector
77  , typename VT2 // Type of the right-hand side sparse vector
78  , bool TF2 > // Transpose flag of the right-hand side sparse vector
79 inline bool equal( const DenseVector<VT1,TF1>& lhs, const SparseVector<VT2,TF2>& rhs )
80 {
81  using CT1 = CompositeType_t<VT1>;
82  using CT2 = CompositeType_t<VT2>;
83 
84  // Early exit in case the vector sizes don't match
85  if( (~lhs).size() != (~rhs).size() ) return false;
86 
87  // Evaluation of the dense vector and sparse vector operand
88  CT1 a( ~lhs );
89  CT2 b( ~rhs );
90 
91  // In order to compare the two vectors, the data values of the lower-order data
92  // type are converted to the higher-order data type within the equal function.
93  size_t i( 0UL );
94 
95  for( auto element=b.begin(); element!=b.end(); ++element, ++i ) {
96  for( ; i<element->index(); ++i ) {
97  if( !isDefault<RF>( a[i] ) ) return false;
98  }
99  if( !equal<RF>( element->value(), a[i] ) ) return false;
100  }
101  for( ; i<a.size(); ++i ) {
102  if( !isDefault<RF>( a[i] ) ) return false;
103  }
104 
105  return true;
106 }
108 //*************************************************************************************************
109 
110 
111 //*************************************************************************************************
125 template< bool RF // Relaxation flag
126  , typename VT1 // Type of the left-hand side sparse vector
127  , bool TF1 // Transpose flag of the left-hand side sparse vector
128  , typename VT2 // Type of the right-hand side dense vector
129  , bool TF2 > // Transpose flag of the right-hand side dense vector
130 inline bool equal( const SparseVector<VT1,TF1>& lhs, const DenseVector<VT2,TF2>& rhs )
131 {
132  return equal<RF>( rhs, lhs );
133 }
135 //*************************************************************************************************
136 
137 
138 //*************************************************************************************************
146 template< typename VT1 // Type of the left-hand side dense vector
147  , bool TF1 // Transpose flag of the left-hand side dense vector
148  , typename VT2 // Type of the right-hand side sparse vector
149  , bool TF2 > // Transpose flag of the right-hand side sparse vector
150 inline bool operator==( const DenseVector<VT1,TF1>& lhs, const SparseVector<VT2,TF2>& rhs )
151 {
152  return equal<relaxed>( lhs, rhs );
153 }
154 //*************************************************************************************************
155 
156 
157 //*************************************************************************************************
165 template< typename VT1 // Type of the left-hand side sparse vector
166  , bool TF1 // Transpose flag of the left-hand side sparse vector
167  , typename VT2 // Type of the right-hand side dense vector
168  , bool TF2 > // Transpose flag of the right-hand side dense vector
169 inline bool operator==( const SparseVector<VT1,TF1>& lhs, const DenseVector<VT2,TF2>& rhs )
170 {
171  return equal<relaxed>( rhs, lhs );
172 }
173 //*************************************************************************************************
174 
175 
176 //*************************************************************************************************
184 template< typename VT1 // Type of the left-hand side dense vector
185  , bool TF1 // Transpose flag of the left-hand side dense vector
186  , typename VT2 // Type of the right-hand side sparse vector
187  , bool TF2 > // Transpose flag of the right-hand side sparse vector
188 inline bool operator!=( const DenseVector<VT1,TF1>& lhs, const SparseVector<VT2,TF2>& rhs )
189 {
190  return !equal<relaxed>( lhs, rhs );
191 }
192 //*************************************************************************************************
193 
194 
195 //*************************************************************************************************
203 template< typename VT1 // Type of the left-hand side sparse vector
204  , bool TF1 // Transpose flag of the left-hand side sparse vector
205  , typename VT2 // Type of the right-hand side dense vector
206  , bool TF2 > // Transpose flag of the right-hand side dense vector
207 inline bool operator!=( const SparseVector<VT1,TF1>& lhs, const DenseVector<VT2,TF2>& rhs )
208 {
209  return !equal<relaxed>( rhs, lhs );
210 }
211 //*************************************************************************************************
212 
213 } // namespace blaze
214 
215 #endif
Header file for auxiliary alias declarations.
Header file for basic type definitions.
Header file for the SparseVector base class.
Header file for the DenseVector base class.
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
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 relaxation flag types.
Header file for the isDefault shim.
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:138
bool equal(const SharedValue< T1 > &lhs, const SharedValue< T2 > &rhs)
Equality check for a two shared values.
Definition: SharedValue.h:342