added tensor2 norm and fixed equivalent
parent
c0581cd100
commit
4169e08215
|
|
@ -73,7 +73,8 @@ namespace tensors {
|
||||||
|
|
||||||
template<class B>
|
template<class B>
|
||||||
bool equivalent(const Tensor1Expression<B, I> & q, double tol = 1e-9) const {
|
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 */
|
/** Check if two expressions are equal */
|
||||||
|
|
|
||||||
|
|
@ -133,12 +133,19 @@ namespace tensors {
|
||||||
return true;
|
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>
|
template<class B>
|
||||||
bool equivalent(const Tensor2Expression<B, I, J> & q, double tol) const {
|
bool equivalent(const Tensor2Expression<B, I, J> & q, double tol) const {
|
||||||
for (int j = 0; j < J::dim; j++)
|
return ((*this) * (1.0 / norm())).equals(q * (1.0 / q.norm()), tol)
|
||||||
if (!(*this)(j).equivalent(q(j), tol)) return false;
|
|| ((*this) * (-1.0 / norm())).equals(q * (1.0 / q.norm()), tol);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** element access */
|
/** element access */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue