8 #include "../Math/Direction.hpp"
11 const NOMAD::Direction& NOMAD::Direction::operator=(
const NOMAD::Direction& dir)
13 NOMAD::ArrayOfDouble::operator=(dir);
20 const NOMAD::Double NOMAD::Direction::squaredNorm()
const
23 NOMAD::Double squaredNorm = 0;
25 for (
size_t i = 0; i < size(); i++)
27 squaredNorm += _array[i] * _array[i];
36 const NOMAD::Double NOMAD::Direction::infiniteNorm()
const
39 NOMAD::Double infiniteNorm = 0;
41 for (
size_t i = 0; i < size(); i++)
43 infiniteNorm =
NOMAD::max(infiniteNorm, _array[i].abs());
54 const NOMAD::Double NOMAD::Direction::norm()
const
57 NOMAD::Double dnorm = this->squaredNorm();
59 dnorm = sqrt(dnorm.todouble());
65 const NOMAD::Double NOMAD::Direction::dotProduct(
const NOMAD::Direction& dir1,
66 const NOMAD::Direction& dir2)
68 NOMAD::Double dot = 0.0;
70 size_t size = dir1.size();
71 if (size != dir2.size())
73 std::string err =
"Dot product: vectors are not of the same size: \n";
74 err += dir1.display() +
"\n";
75 err += dir2.display();
76 throw NOMAD::Exception(__FILE__, __LINE__, err);
79 for (
size_t i = 0; i < size; i++)
81 dot += dir1[i] * dir2[i];
88 const NOMAD::Double NOMAD::Direction::cos(
const NOMAD::Direction& dir1,
89 const NOMAD::Direction& dir2)
91 NOMAD::Double cos = 0.0;
93 NOMAD::Double norm1 = dir1.norm();
94 NOMAD::Double norm2 = dir2.norm();
95 if (0.0 == norm1 || 0.0 == norm2)
97 std::string err =
"Cosine: a vector is of size 0";
98 throw NOMAD::Exception(__FILE__, __LINE__, err);
101 cos = dotProduct(dir1, dir2) / (norm1 * norm2);
108 out << dir.display();
std::ostream & operator<<(std::ostream &os, const Algorithm &algo)
Operator to write parameters used for hot restart.
Double max(const Double d1, const Double d2)
Largest of two values >=.