Blaze  3.6
SVecSVecEqualExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSVECEQUALEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECSVECEQUALEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
46 #include <blaze/math/shims/Equal.h>
48 
49 
50 namespace blaze {
51 
52 //=================================================================================================
53 //
54 // GLOBAL BINARY RELATIONAL OPERATORS
55 //
56 //=================================================================================================
57 
58 //*************************************************************************************************
71 template< bool RF // Relaxation flag
72  , typename VT1 // Type of the left-hand side sparse vector
73  , bool TF1 // Transpose flag of the left-hand side sparse vector
74  , typename VT2 // Type of the right-hand side sparse vector
75  , bool TF2 > // Transpose flag of the right-hand side sparse vector
76 inline bool equal( const SparseVector<VT1,TF1>& lhs, const SparseVector<VT2,TF2>& rhs )
77 {
78  using CT1 = CompositeType_t<VT1>;
79  using CT2 = CompositeType_t<VT2>;
80 
81  // Early exit in case the vector sizes don't match
82  if( (~lhs).size() != (~rhs).size() ) return false;
83 
84  // Evaluation of the two sparse vector operands
85  CT1 a( ~lhs );
86  CT2 b( ~rhs );
87 
88  // In order to compare the two vectors, the data values of the lower-order data
89  // type are converted to the higher-order data type within the equal function.
90  const auto lend( a.end() );
91  const auto rend( b.end() );
92 
93  auto lelem( a.begin() );
94  auto relem( b.begin() );
95 
96  while( lelem != lend && relem != rend )
97  {
98  if( isDefault<RF>( lelem->value() ) ) { ++lelem; continue; }
99  if( isDefault<RF>( relem->value() ) ) { ++relem; continue; }
100 
101  if( lelem->index() != relem->index() || !equal<RF>( lelem->value(), relem->value() ) ) {
102  return false;
103  }
104  else {
105  ++lelem;
106  ++relem;
107  }
108  }
109 
110  while( lelem != lend ) {
111  if( !isDefault<RF>( lelem->value() ) )
112  return false;
113  ++lelem;
114  }
115 
116  while( relem != rend ) {
117  if( !isDefault<RF>( relem->value() ) )
118  return false;
119  ++relem;
120  }
121 
122  return true;
123 }
125 //*************************************************************************************************
126 
127 
128 //*************************************************************************************************
136 template< typename VT1 // Type of the left-hand side sparse vector
137  , bool TF1 // Transpose flag of the left-hand side sparse vector
138  , typename VT2 // Type of the right-hand side sparse vector
139  , bool TF2 > // Transpose flag of the right-hand side sparse vector
140 inline bool operator==( const SparseVector<VT1,TF1>& lhs, const SparseVector<VT2,TF2>& rhs )
141 {
142  return equal<relaxed>( lhs, rhs );
143 }
144 //*************************************************************************************************
145 
146 
147 //*************************************************************************************************
155 template< typename VT1 // Type of the left-hand side sparse vector
156  , bool TF1 // Transpose flag of the left-hand side sparse vector
157  , typename VT2 // Type of the right-hand side sparse vector
158  , bool TF2 > // Transpose flag of the right-hand side sparse vector
159 inline bool operator!=( const SparseVector<VT1,TF1>& lhs, const SparseVector<VT2,TF2>& rhs )
160 {
161  return !equal<relaxed>( lhs, rhs );
162 }
163 //*************************************************************************************************
164 
165 } // namespace blaze
166 
167 #endif
Header file for auxiliary alias declarations.
Header file for the SparseVector 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 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:146
bool equal(const SharedValue< T1 > &lhs, const SharedValue< T2 > &rhs)
Equality check for a two shared values.
Definition: SharedValue.h:342