Blaze 3.9
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>
49#include <blaze/util/Types.h>
50
51
52namespace blaze {
53
54//=================================================================================================
55//
56// GLOBAL BINARY RELATIONAL OPERATORS
57//
58//=================================================================================================
59
60//*************************************************************************************************
74template< RelaxationFlag 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
78inline 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//*************************************************************************************************
128template< RelaxationFlag 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
132inline 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//*************************************************************************************************
182template< RelaxationFlag 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
187inline bool equal( const SparseMatrix<MT1,SO1>& lhs, const DenseMatrix<MT2,SO2>& rhs )
188{
189 return equal<RF>( rhs, lhs );
190}
192//*************************************************************************************************
193
194
195//*************************************************************************************************
203template< 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
207inline bool operator==( const DenseMatrix<MT1,SO1>& lhs, const SparseMatrix<MT2,SO2>& rhs )
208{
209 return equal<relaxed>( lhs, rhs );
210}
211//*************************************************************************************************
212
213
214//*************************************************************************************************
222template< 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
226inline bool operator==( const SparseMatrix<MT1,SO1>& lhs, const DenseMatrix<MT2,SO2>& rhs )
227{
228 return equal<relaxed>( rhs, lhs );
229}
230//*************************************************************************************************
231
232
233//*************************************************************************************************
241template< 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
245inline bool operator!=( const DenseMatrix<MT1,SO1>& lhs, const SparseMatrix<MT2,SO2>& rhs )
246{
247 return !equal( lhs, rhs );
248}
249//*************************************************************************************************
250
251
252//*************************************************************************************************
260template< 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
264inline 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 the isDefault shim.
Header file for the relaxation flag enumeration.
Base class for dense matrices.
Definition: DenseMatrix.h:82
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Header file for the DenseMatrix base class.
Header file for the SparseMatrix base class.
bool operator!=(const SparseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Inequality operator for the comparison of a sparse matrix and a dense matrix.
Definition: DMatSMatEqualExpr.h:264
bool operator==(const SparseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Equality operator for the comparison of a sparse matrix and a dense matrix.
Definition: DMatSMatEqualExpr.h:226
RelaxationFlag
Relaxation flag for strict or relaxed semantics.
Definition: RelaxationFlag.h:66
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.