10#ifndef SFM_BA_DENSE_VECTOR_HEADER
11#define SFM_BA_DENSE_VECTOR_HEADER
27 DenseVector (std::size_t size, T
const& value = T(0));
28 void resize (std::size_t size, T
const& value = T(0));
30 void fill (T
const& value);
31 std::size_t size (
void)
const;
34 T
const* data (
void)
const;
36 T
const* begin (
void)
const;
38 T
const* end (
void)
const;
42 T& operator[] (std::size_t index);
43 T
const& operator[] (std::size_t index)
const;
44 T& at (std::size_t index);
45 T
const& at (std::size_t index)
const;
48 T squared_norm (
void)
const;
53 void multiply_self (T
const& factor);
54 void negate_self (
void);
57 std::vector<T> values;
66 this->resize(size, value);
74 this->values.resize(size, value);
88 std::fill(this->values.begin(), this->values.end(), value);
95 return this->values.
size();
102 return this->values.
data();
109 return this->values.
data();
116 return this->values.
data();
123 return this->values.
data();
130 return this->values.
data() + this->values.size();
137 return this->values.
data() + this->values.size();
145 for (std::size_t i = 0; i < this->size(); ++i)
146 ret[i] = -this->at(i);
154 if (this->size() != rhs.
size())
156 for (std::size_t i = 0; i < this->size(); ++i)
157 if (this->at(i) != rhs.
at(i))
166 return this->values[index];
173 return this->values[index];
180 return this->values[index];
187 return this->values[index];
194 return std::sqrt(this->squared_norm());
201 return this->dot(*
this);
208 if (this->size() != rhs.
size())
209 throw std::invalid_argument(
"Incompatible vector dimensions");
212 for (std::size_t i = 0; i < this->size(); ++i)
213 ret += this->values[i] * rhs.values[i];
221 if (this->size() != rhs.
size())
222 throw std::invalid_argument(
"Incompatible vector dimensions");
225 for (std::size_t i = 0; i < this->size(); ++i)
226 ret.values[i] = this->values[i] - rhs.values[i];
234 if (this->size() != rhs.
size())
235 throw std::invalid_argument(
"Incompatible vector dimensions");
238 for (std::size_t i = 0; i < this->size(); ++i)
239 ret.values[i] = this->values[i] + rhs.values[i];
248 for (std::size_t i = 0; i < this->size(); ++i)
249 ret[i] = this->at(i) * factor;
257 for (std::size_t i = 0; i < this->size(); ++i)
258 this->at(i) *= factor;
265 for (std::size_t i = 0; i < this->size(); ++i)
266 this->at(i) = -this->at(i);
DenseVector(void)=default
T & at(std::size_t index)
std::size_t size(void) const
#define SFM_BA_NAMESPACE_BEGIN
#define SFM_NAMESPACE_END
#define SFM_NAMESPACE_BEGIN
#define SFM_BA_NAMESPACE_END