Blaze  3.6
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>
46 #include <blaze/math/shims/Equal.h>
48 #include <blaze/util/Types.h>
49 
50 
51 namespace blaze {
52 
53 //=================================================================================================
54 //
55 // GLOBAL BINARY RELATIONAL OPERATORS
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
72 template< bool 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
75 inline 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 //*************************************************************************************************
151 template< bool 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
154 inline 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 //*************************************************************************************************
230 template< bool 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
234 inline 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 //*************************************************************************************************
251 template< 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
255 inline bool operator==( const SparseMatrix<MT1,SO1>& lhs, const SparseMatrix<MT2,SO2>& rhs )
256 {
257  return equal<relaxed>( lhs, rhs );
258 }
259 //*************************************************************************************************
260 
261 
262 //*************************************************************************************************
270 template< 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
274 inline 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 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 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
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