Go to the documentation of this file.
7 #ifndef INCLUDE_JET_VECTOR_H_
8 #define INCLUDE_JET_VECTOR_H_
16 #include <type_traits>
30 template <
typename T,
size_t N>
34 "Size of static-sized vector should be greater than zero.");
35 static_assert(std::is_floating_point<T>::value,
36 "Vector only can be instantiated with floating point types");
44 template <
typename... Params>
52 Vector(
const std::initializer_list<U>& lst);
65 void set(
const std::initializer_list<U>& lst);
83 constexpr
size_t size()
const;
89 const T*
const data()
const;
92 typename ContainerType::iterator
begin();
95 typename ContainerType::const_iterator
begin()
const;
98 typename ContainerType::iterator
end();
101 typename ContainerType::const_iterator
end()
const;
110 T
at(
size_t i)
const;
149 template <
typename E>
153 template <
typename E>
157 template <
typename U>
161 template <
typename E>
165 template <
typename E>
167 T epsilon = std::numeric_limits<T>::epsilon())
const;
172 template <
typename E>
179 template <
typename E>
186 template <
typename E>
193 template <
typename E>
200 template <
typename E>
209 template <
typename E>
216 template <
typename E>
225 template <
typename E>
232 template <
typename E>
239 template <
typename E>
246 template <
typename E>
266 template <
typename Callback>
284 template <
typename Callback>
294 template <
typename U>
298 template <
typename E>
305 template <
typename E>
312 template <
typename E>
319 template <
typename E>
326 template <
typename E>
330 template <
typename E>
334 template <
typename E>
340 template <
typename... Params>
341 void setAt(
size_t i, T v, Params... params);
342 void setAt(
size_t i, T v);
346 template <
typename T,
size_t N>
353 #include "detail/vector-inl.h"
355 #endif // INCLUDE_JET_VECTOR_H_
T sum() const
Returns the sum of all the elements.
T absmin() const
Returns the absolute minimum element.
Vector(Params... params)
Constructs vector instance with parameters.
Vector & operator/=(const T &s)
Computes this /= (s, s, ... , s)
bool isSimilar(const E &other, T epsilon=std::numeric_limits< T >::epsilon()) const
Returns true if other is similar to this vector.
void imul(const T &s)
Computes this *= (s, s, ... , s).
VectorDiv< T, Vector, E > rdiv(const E &v) const
Computes v / this.
std::array< T, N > ContainerType
Definition: vector.h:34
Base class for vector expression.
Definition: vector_expression.h:25
T distanceTo(const E &other) const
Returns the distance to the other vector.
void set(const VectorExpression< T, E > &other)
Sets vector with expression template.
ArrayAccessor1< T > accessor()
Returns the array accessor.
T distanceSquaredTo(const E &other) const
Returns the squared distance to the other vector.
ConstArrayAccessor1< T > constAccessor() const
Returns the const array accessor.
1-D read-only array accessor class.
Definition: array_accessor1.h:184
T dot(const E &v) const
Computes dot product.
void normalize()
Normalizes this vector.
T length() const
Returns the length of the vector.
Vector()
Constructs a vector with zeros.
void idiv(const E &v)
Computes this /= v.
T & operator[](size_t)
Returns the reference to the i -th element.
Vector & operator+=(const T &s)
Computes this += (s, s, ... , s)
bool operator==(const E &v) const
Returns true if other is the same as this vector.
Vector expression for unary operation.
Definition: vector_expression.h:47
ContainerType::const_iterator end() const
Returns the end const iterator of the vector.
bool isEqual(const E &other) const
Returns true if other is the same as this vector.
Vector(const VectorExpression< T, E > &other)
Constructs vector with expression template.
Vector & operator*=(const T &s)
Computes this *= (s, s, ... , s)
T at(size_t i) const
Returns const reference to the i -th element of the vector.
Vector & operator=(const std::initializer_list< U > &lst)
Set vector instance with initializer list.
Vector expression for matrix-scalar binary operation.
Definition: vector_expression.h:114
void isub(const T &s)
Computes this -= (s, s, ... , s).
Vector(const Vector &other)
Copy constructor.
ContainerType::iterator begin()
Returns the begin iterator of the vector.
const T & operator[](size_t i) const
Returns the const reference to the i -th element.
VectorDiv< T, Vector, E > div(const E &v) const
Computes this / v.
VectorScalarSub< T, Vector > sub(const T &s) const
Computes this - (s, s, ... , s).
void setZero()
Sets all elements to zero.
Generic statically-sized N-D vector class.
Definition: vector.h:31
void iadd(const T &s)
Computes this += (s, s, ... , s).
size_t dominantAxis() const
Returns the index of the dominant axis.
ContainerType::const_iterator begin() const
Returns the begin const iterator of the vector.
VectorScalarMul< T, Vector > mul(const T &s) const
Computes this * (s, s, ... , s).
Vector & operator-=(const E &v)
Computes this -= v.
Vector expression for binary operation.
Definition: vector_expression.h:84
constexpr size_t size() const
Returns the size of the vector.
Definition: advection_solver2.h:18
T lengthSquared() const
Returns the squared length of the vector.
VectorSub< T, Vector, E > rsub(const E &v) const
Computes v - this.
const T *const data() const
Returns the const raw pointer to the vector data.
VectorMul< T, Vector, E > mul(const E &v) const
Computes this * v.
T avg() const
Returns the average of all the elements.
T & at(size_t i)
Returns reference to the i -th element of the vector.
VectorScalarAdd< T, Vector > add(const T &s) const
Computes this + (s, s, ... , s).
Vector & operator-=(const T &s)
Computes this -= (s, s, ... , s)
void iadd(const E &v)
Computes this += v.
void idiv(const T &s)
Computes this /= (s, s, ... , s).
T absmax() const
Returns the absolute maximum element.
VectorScalarDiv< T, Vector > normalized() const
Returns normalized vector.
void set(const std::initializer_list< U > &lst)
Set vector instance with initializer list.
VectorScalarRSub< T, Vector > rsub(const T &s) const
Computes (s, s, ... , s) - this.
VectorTypeCast< U, Vector< T, N >, T > castTo() const
Returns a vector with different value type.
T min() const
Returns the minimum element.
void set(const T &s)
Sets all elements to s.
void imul(const E &v)
Computes this *= v.
Vector & operator*=(const E &v)
Computes this *= v.
size_t subminantAxis() const
Returns the index of the subminant axis.
Vector & operator/=(const E &v)
Computes this /= v.
VectorAdd< T, Vector, E > add(const E &v) const
Computes this + v.
Vector(const std::initializer_list< U > &lst)
Constructs vector instance with initializer list.
Vector & operator=(const VectorExpression< T, E > &other)
Sets vector with expression template.
T value
Definition: vector.h:348
void isub(const E &v)
Computes this -= v.
bool operator!=(const E &v) const
Returns true if other is the not same as this vector.
VectorScalarDiv< T, Vector > div(const T &s) const
Computes this / (s, s, ... , s).
ContainerType::iterator end()
Returns the end iterator of the vector.
void forEachIndex(Callback func) const
Iterates the vector and invoke given func for each index.
VectorSub< T, Vector, E > sub(const E &v) const
Computes this - v.
void swap(Vector &other)
Swaps the content of the vector with other vector.
void forEach(Callback func) const
Iterates the vector and invoke given func for each element.
1-D array accessor class.
Definition: array_accessor1.h:27
T * data()
Returns the raw pointer to the vector data.
VectorScalarRDiv< T, Vector > rdiv(const T &s) const
Computes (s, s, ... , s) / this.
Vector & operator+=(const E &v)
Computes this += v.
Returns the type of the value itself.
Definition: type_helpers.h:14
T max() const
Returns the maximum element.