Blaze 3.9
SMatSMatEqualExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_SMATSMATEQUALEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SMATSMATEQUALEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
48#include <blaze/util/Types.h>
49
50
51namespace blaze {
52
53//=================================================================================================
54//
55// GLOBAL BINARY RELATIONAL OPERATORS
56//
57//=================================================================================================
58
59//*************************************************************************************************
72template< RelaxationFlag RF // Relaxation flag
73 , typename MT1 // Type of the left-hand side sparse matrix
74 , typename MT2 > // Type of the right-hand side sparse matrix
75inline bool equal( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,false>& rhs )
76{
77 using CT1 = CompositeType_t<MT1>;
78 using CT2 = CompositeType_t<MT2>;
79
80 // Early exit in case the matrix sizes don't match
81 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() )
82 return false;
83
84 // Evaluation of the two sparse matrix operands
85 CT1 A( *lhs );
86 CT2 B( *rhs );
87
88 // In order to compare the two matrices, the data values of the lower-order data
89 // type are converted to the higher-order data type within the equal function.
90 for( size_t i=0UL; i<A.rows(); ++i )
91 {
92 const auto lend( A.end(i) );
93 const auto rend( B.end(i) );
94
95 auto lelem( A.begin(i) );
96 auto relem( B.begin(i) );
97
98 while( lelem != lend && relem != rend )
99 {
100 if( lelem->index() < relem->index() ) {
101 if( !isDefault<RF>( lelem->value() ) )
102 return false;
103 ++lelem;
104 }
105 else if( lelem->index() > relem->index() ) {
106 if( !isDefault<RF>( relem->value() ) )
107 return false;
108 ++relem;
109 }
110 else if( !equal<RF>( lelem->value(), relem->value() ) ) {
111 return false;
112 }
113 else {
114 ++lelem;
115 ++relem;
116 }
117 }
118
119 while( lelem != lend ) {
120 if( !isDefault<RF>( lelem->value() ) )
121 return false;
122 ++lelem;
123 }
124
125 while( relem != rend ) {
126 if( !isDefault<RF>( relem->value() ) )
127 return false;
128 ++relem;
129 }
130 }
131
132 return true;
133}
135//*************************************************************************************************
136
137
138//*************************************************************************************************
151template< RelaxationFlag RF // Relaxation flag
152 , typename MT1 // Type of the left-hand side sparse matrix
153 , typename MT2 > // Type of the right-hand side sparse matrix
154inline bool equal( const SparseMatrix<MT1,true>& lhs, const SparseMatrix<MT2,true>& rhs )
155{
156 using CT1 = CompositeType_t<MT1>;
157 using CT2 = CompositeType_t<MT2>;
158
159 // Early exit in case the matrix sizes don't match
160 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() )
161 return false;
162
163 // Evaluation of the two sparse matrix operands
164 CT1 A( *lhs );
165 CT2 B( *rhs );
166
167 // In order to compare the two matrices, the data values of the lower-order data
168 // type are converted to the higher-order data type within the equal function.
169 for( size_t j=0UL; j<A.columns(); ++j )
170 {
171 const auto lend( A.end(j) );
172 const auto rend( B.end(j) );
173
174 auto lelem( A.begin(j) );
175 auto relem( B.begin(j) );
176
177 while( lelem != lend && relem != rend )
178 {
179 if( lelem->index() < relem->index() ) {
180 if( !isDefault<RF>( lelem->value() ) )
181 return false;
182 ++lelem;
183 }
184 else if( lelem->index() > relem->index() ) {
185 if( !isDefault<RF>( relem->value() ) )
186 return false;
187 ++relem;
188 }
189 else if( !equal<RF>( lelem->value(), relem->value() ) ) {
190 return false;
191 }
192 else {
193 ++lelem;
194 ++relem;
195 }
196 }
197
198 while( lelem != lend ) {
199 if( !isDefault<RF>( lelem->value() ) )
200 return false;
201 ++lelem;
202 }
203
204 while( relem != rend ) {
205 if( !isDefault<RF>( relem->value() ) )
206 return false;
207 ++relem;
208 }
209 }
210
211 return true;
212}
214//*************************************************************************************************
215
216
217//*************************************************************************************************
230template< RelaxationFlag RF // Relaxation flag
231 , typename MT1 // Type of the left-hand side sparse matrix
232 , typename MT2 // Type of the right-hand side sparse matrix
233 , bool SO > // Storage order
234inline bool equal( const SparseMatrix<MT1,SO>& lhs, const SparseMatrix<MT2,!SO>& rhs )
235{
236 const OppositeType_t<MT2> tmp( *rhs );
237 return equal<RF>( *lhs, tmp );
238}
240//*************************************************************************************************
241
242
243//*************************************************************************************************
251template< typename MT1 // Type of the left-hand side sparse matrix
252 , bool SO1 // Storage order of the left-hand side sparse matrix
253 , typename MT2 // Type of the right-hand side sparse matrix
254 , bool SO2 > // Storage order of the right-hand side sparse matrix
255inline bool operator==( const SparseMatrix<MT1,SO1>& lhs, const SparseMatrix<MT2,SO2>& rhs )
256{
257 return equal<relaxed>( lhs, rhs );
258}
259//*************************************************************************************************
260
261
262//*************************************************************************************************
270template< typename MT1 // Type of the left-hand side sparse matrix
271 , bool SO1 // Storage order of the left-hand side sparse matrix
272 , typename MT2 // Type of the right-hand side sparse matrix
273 , bool SO2 > // Storage order of the right-hand side sparse matrix
274inline bool operator!=( const SparseMatrix<MT1,SO1>& lhs, const SparseMatrix<MT2,SO2>& rhs )
275{
276 return !equal<relaxed>( lhs, rhs );
277}
278//*************************************************************************************************
279
280} // namespace blaze
281
282#endif
Header file for auxiliary alias declarations.
Header file for the isDefault shim.
Header file for the relaxation flag enumeration.
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Header file for the SparseMatrix base class.
RelaxationFlag
Relaxation flag for strict or relaxed semantics.
Definition: RelaxationFlag.h:66
bool operator!=(const SparseMatrix< MT1, SO1 > &lhs, const SparseMatrix< MT2, SO2 > &rhs)
Inequality operator for the comparison of two sparse matrices.
Definition: SMatSMatEqualExpr.h:274
bool operator==(const SparseMatrix< MT1, SO1 > &lhs, const SparseMatrix< MT2, SO2 > &rhs)
Equality operator for the comparison of two sparse matrices.
Definition: SMatSMatEqualExpr.h:255
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.
Header file for basic type definitions.