SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MatrixComparison.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2012 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 /// @todo Documentation Core/Datatypes/MatrixComparison.h
29 
30 #ifndef CORE_DATATYPES_MATRIX_COMPARISON_H
31 #define CORE_DATATYPES_MATRIX_COMPARISON_H
32 
33 #include <Core/Datatypes/Matrix.h>
38 
39 namespace SCIRun {
40 namespace Core {
41 namespace Datatypes {
42 
43  template <typename T>
45  {
46  bool returnValue =
47  (lhs.rows() == rhs.rows()) &&
48  (lhs.cols() == rhs.cols());
49 
50  if (returnValue)
51  {
52  for (int i = 0; returnValue && i < lhs.rows(); ++i)
53  {
54  for (int j = 0; returnValue && j < lhs.cols(); ++j)
55  {
56  returnValue &= std::fabs(lhs(i,j) - rhs(i,j)) < 1e-15;
57  }
58  }
59  }
60  return returnValue;
61  }
62 
63  template <typename T>
65  {
66  return !(lhs == rhs);
67  }
68 
69  template <typename T>
71  {
72  bool returnValue = (lhs.rows() == rhs.rows());
73 
74  if (returnValue)
75  {
76  for (int i = 0; returnValue && i < lhs.rows(); ++i)
77  {
78  returnValue &= std::fabs(lhs(i) - rhs(i)) < 1e-15;
79  }
80  }
81  return returnValue;
82  }
83 
84  template <typename T>
86  {
87  return !(lhs == rhs);
88  }
89 
90  template <typename T>
92  {
93  if (lhs.rows() != rhs.rows())
94  return false;
95  if (lhs.cols() != rhs.cols())
96  return false;
97 
98  for (int k = 0; k < lhs.outerSize(); ++k)
99  {
100  typename SparseRowMatrixGeneric<T>::InnerIterator it1(lhs,k);
101  typename SparseRowMatrixGeneric<T>::InnerIterator it2(rhs,k);
102  for (; it1 && it2; ++it1, ++it2)
103  {
104  if (it1.index() != it2.index())
105  return false;
106  if (it1.value() != it2.value())
107  return false;
108  }
109  }
110  return true;
111  }
112 
113  template <typename T>
115  {
116  return !(lhs == rhs);
117  }
118 
119 }}}
120 
121 
122 #endif
Definition: DenseColumnMatrix.h:43
bool operator!=(const DenseMatrixGeneric< T > &lhs, const DenseMatrixGeneric< T > &rhs)
Definition: MatrixComparison.h:64
bool operator==(const DenseMatrixGeneric< T > &lhs, const DenseMatrixGeneric< T > &rhs)
Definition: MatrixComparison.h:44