C++,
pasted
on Jun 25:
|
#include <iostream>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace boost::numeric::ublas;
template<typename T>
bool operator==(const matrix<T>& m, const matrix<T>& n)
{
bool returnValue =
(m.size1() == n.size1()) &&
(m.size2() == n.size2());
if (returnValue)
{
for (unsigned int i = 0; returnValue && i < m.size1(); ++i)
{
for (unsigned int j = 0; returnValue && j < m.size2(); ++j)
{
returnValue &= m(i,j) == n(i,j);
}
}
}
return returnValue;
}
int main ()
{
matrix<double> m (3, 3);
for (unsigned int i = 0; i < m.size1(); ++ i)
{
for (unsigned int j = 0; j < m.size2(); ++ j)
{
m (i, j) = 3 * i + j;
}
}
std::cout << m << std::endl;
matrix<double> n (3, 3);
std::cout << (m == n) << std::endl;
std::cout << (m == m) << std::endl;
}
|
Output:
|
[3,3]((0,1,2),(3,4,5),(6,7,8))
false
true
|
|