added tensor2 norm and fixed equivalent

release/4.3a0
Frank Dellaert 2010-10-05 13:57:00 +00:00
parent c0581cd100
commit 4169e08215
2 changed files with 13 additions and 5 deletions

View File

@ -73,7 +73,8 @@ namespace tensors {
template<class B>
bool equivalent(const Tensor1Expression<B, I> & q, double tol = 1e-9) const {
return ((*this) * (1.0 / norm())).equals(q * (1.0 / q.norm()), tol);
return ((*this) * (1.0 / norm())).equals(q * (1.0 / q.norm()), tol)
|| ((*this) * (-1.0 / norm())).equals(q * (1.0 / q.norm()), tol);
}
/** Check if two expressions are equal */

View File

@ -133,12 +133,19 @@ namespace tensors {
return true;
}
// TODO: broken !!!! Should not treat Tensor1's separately: one scale only!
/** norm */
double norm() const {
double sumsqr = 0.0;
for (int i = 0; i < I::dim; i++)
for (int j = 0; j < J::dim; j++)
sumsqr += iter(i,j) * iter(i,j);
return sqrt(sumsqr);
}
template<class B>
bool equivalent(const Tensor2Expression<B, I, J> & q, double tol) const {
for (int j = 0; j < J::dim; j++)
if (!(*this)(j).equivalent(q(j), tol)) return false;
return true;
return ((*this) * (1.0 / norm())).equals(q * (1.0 / q.norm()), tol)
|| ((*this) * (-1.0 / norm())).equals(q * (1.0 / q.norm()), tol);
}
/** element access */