Blaze  3.6
DMatSMatEqualExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATSMATEQUALEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DMATSMATEQUALEXPR_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 MT1 // Type of the left-hand side dense matrix
76  , bool SO // Storage order of the left-hand side dense matrix
77  , typename MT2 > // Type of the right-hand side sparse matrix
78 inline bool equal( const DenseMatrix<MT1,SO>& lhs, const SparseMatrix<MT2,false>& rhs )
79 {
80  using CT1 = CompositeType_t<MT1>;
81  using CT2 = CompositeType_t<MT2>;
82 
83  // Early exit in case the matrix sizes don't match
84  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
85  return false;
86 
87  // Evaluation of the dense matrix and sparse matrix operand
88  CT1 A( ~lhs );
89  CT2 B( ~rhs );
90 
91  // In order to compare the two matrices, 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 j( 0UL );
94 
95  for( size_t i=0UL; i<B.rows(); ++i ) {
96  j = 0UL;
97  for( auto element=B.begin(i); element!=B.end(i); ++element, ++j ) {
98  for( ; j<element->index(); ++j ) {
99  if( !isDefault<RF>( A(i,j) ) ) return false;
100  }
101  if( !equal<RF>( element->value(), A(i,j) ) ) return false;
102  }
103  for( ; j<A.columns(); ++j ) {
104  if( !isDefault<RF>( A(i,j) ) ) return false;
105  }
106  }
107 
108  return true;
109 }
111 //*************************************************************************************************
112 
113 
114 //*************************************************************************************************
128 template< bool RF // Relaxation flag
129  , typename MT1 // Type of the left-hand side dense matrix
130  , bool SO // Storage order of the left-hand side dense matrix
131  , typename MT2 > // Type of the right-hand side sparse matrix
132 inline bool equal( const DenseMatrix<MT1,SO>& lhs, const SparseMatrix<MT2,true>& rhs )
133 {
134  using CT1 = CompositeType_t<MT1>;
135  using CT2 = CompositeType_t<MT2>;
136 
137  // Early exit in case the matrix sizes don't match
138  if( (~lhs).rows() != (~rhs).rows() || (~lhs).columns() != (~rhs).columns() )
139  return false;
140 
141  // Evaluation of the dense matrix and sparse matrix operand
142  CT1 A( ~lhs );
143  CT2 B( ~rhs );
144 
145  // In order to compare the two matrices, the data values of the lower-order data
146  // type are converted to the higher-order data type within the equal function.
147  size_t i( 0UL );
148 
149  for( size_t j=0UL; j<B.columns(); ++j ) {
150  i = 0UL;
151  for( auto element=B.begin(j); element!=B.end(j); ++element, ++i ) {
152  for( ; i<element->index(); ++i ) {
153  if( !isDefault<RF>( A(i,j) ) ) return false;
154  }
155  if( !equal<RF>( element->value(), A(i,j) ) ) return false;
156  }
157  for( ; i<A.rows(); ++i ) {
158  if( !isDefault<RF>( A(i,j) ) ) return false;
159  }
160  }
161 
162  return true;
163 }
165 //*************************************************************************************************
166 
167 
168 //*************************************************************************************************
182 template< bool RF // Relaxation flag
183  , typename MT1 // Type of the left-hand side sparse matrix
184  , bool SO1 // Storage order of the left-hand side sparse matrix
185  , typename MT2 // Type of the right-hand side dense matrix
186  , bool SO2 > // Storage order of the right-hand side dense matrix
187 inline bool equal( const SparseMatrix<MT1,SO1>& lhs, const DenseMatrix<MT2,SO2>& rhs )
188 {
189  return equal<RF>( rhs, lhs );
190 }
192 //*************************************************************************************************
193 
194 
195 //*************************************************************************************************
203 template< typename MT1 // Type of the left-hand side dense matrix
204  , bool SO1 // Storage order of the left-hand side dense matrix
205  , typename MT2 // Type of the right-hand side sparse matrix
206  , bool SO2 > // Storage order of the right-hand side dense matrix
207 inline bool operator==( const DenseMatrix<MT1,SO1>& lhs, const SparseMatrix<MT2,SO2>& rhs )
208 {
209  return equal<relaxed>( lhs, rhs );
210 }
211 //*************************************************************************************************
212 
213 
214 //*************************************************************************************************
222 template< typename MT1 // Type of the left-hand side sparse matrix
223  , bool SO1 // Storage order of the left-hand side sparse matrix
224  , typename MT2 // Type of the right-hand side dense matrix
225  , bool SO2 > // Storage order of the right-hand side dense matrix
226 inline bool operator==( const SparseMatrix<MT1,SO1>& lhs, const DenseMatrix<MT2,SO2>& rhs )
227 {
228  return equal<relaxed>( rhs, lhs );
229 }
230 //*************************************************************************************************
231 
232 
233 //*************************************************************************************************
241 template< typename MT1 // Type of the left-hand side dense matrix
242  , bool SO1 // Storage order of the left-hand side dense matrix
243  , typename MT2 // Type of the right-hand side sparse matrix
244  , bool SO2 > // Storage order of the right-hand side sparse matrix
245 inline bool operator!=( const DenseMatrix<MT1,SO1>& lhs, const SparseMatrix<MT2,SO2>& rhs )
246 {
247  return !equal( lhs, rhs );
248 }
249 //*************************************************************************************************
250 
251 
252 //*************************************************************************************************
260 template< typename MT1 // Type of the left-hand side sparse matrix
261  , bool SO1 // Storage order of the left-hand side sparse matrix
262  , typename MT2 // Type of the right-hand side dense matrix
263  , bool SO2 > // Storage order right-hand side dense matrix
264 inline bool operator!=( const SparseMatrix<MT1,SO1>& lhs, const DenseMatrix<MT2,SO2>& rhs )
265 {
266  return !equal( rhs, lhs );
267 }
268 //*************************************************************************************************
269 
270 } // namespace blaze
271 
272 #endif
Header file for auxiliary alias declarations.
Header file for basic type definitions.
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes....
Definition: DenseMatrix.h:81
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes....
Definition: Forward.h:145
Header file for the SparseMatrix base class.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the DenseMatrix base class.
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 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 rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
bool equal(const SharedValue< T1 > &lhs, const SharedValue< T2 > &rhs)
Equality check for a two shared values.
Definition: SharedValue.h:342