Go to the documentation of this file.
7 #ifndef INCLUDE_JET_VECTOR_N_H_
8 #define INCLUDE_JET_VECTOR_N_H_
13 #include <initializer_list>
32 static_assert(std::is_floating_point<T>::value,
33 "VectorN only can be instantiated with floating point types");
47 VectorN(
const std::initializer_list<U>& lst);
62 void resize(
size_t n,
const T& val = 0);
72 void set(
const std::initializer_list<U>& lst);
99 const T*
const data()
const;
102 typename ContainerType::iterator
begin();
105 typename ContainerType::const_iterator
begin()
const;
108 typename ContainerType::iterator
end();
111 typename ContainerType::const_iterator
end()
const;
120 T
at(
size_t i)
const;
159 template <
typename E>
163 template <
typename E>
167 template <
typename U>
171 template <
typename E>
175 template <
typename E>
177 T epsilon = std::numeric_limits<T>::epsilon())
const;
182 template <
typename E>
189 template <
typename E>
196 template <
typename E>
203 template <
typename E>
210 template <
typename E>
219 template <
typename E>
226 template <
typename E>
235 template <
typename E>
242 template <
typename E>
249 template <
typename E>
256 template <
typename E>
276 template <
typename Callback>
294 template <
typename Callback>
317 template <
typename Callback>
337 template <
typename Callback>
347 template <
typename U>
351 template <
typename E>
364 template <
typename E>
371 template <
typename E>
378 template <
typename E>
385 template <
typename E>
389 template <
typename E>
393 template <
typename E>
408 #include "detail/vector_n-inl.h"
410 #endif // INCLUDE_JET_VECTOR_N_H_
VectorScalarDiv< T, VectorN > normalized() const
Returns normalized vector.
T min() const
Returns the minimum element.
size_t dominantAxis() const
Returns the index of the dominant axis.
General purpose dynamically-sizedN-D vector class.
Definition: vector_n.h:30
void parallelForEach(Callback func)
Iterates the vector and invoke given func for each element in parallel using multi-threading.
Base class for vector expression.
Definition: vector_expression.h:25
size_t size() const
Returns the size of the vector.
bool operator==(const E &v) const
Returns true if other is the same as this vector.
VectorN(const VectorExpression< T, E > &other)
Constructs vector with expression template.
1-D read-only array accessor class.
Definition: array_accessor1.h:184
void idiv(const T &s)
Computes this /= (s, s, ... , s).
size_t subminantAxis() const
Returns the index of the subminant axis.
VectorN & operator*=(const E &v)
Computes this *= v.
VectorAdd< T, VectorN, E > add(const E &v) const
Computes this + v.
void iadd(const T &s)
Computes this += (s, s, ... , s).
void iadd(const E &v)
Computes this += v.
void imul(const T &s)
Computes this *= (s, s, ... , s).
ArrayAccessor1< T > accessor()
Returns the array accessor.
T lengthSquared() const
Returns the squared length of the vector.
VectorN & operator=(const VectorExpression< T, E > &other)
Sets vector with expression template.
void forEach(Callback func) const
Iterates the vector and invoke given func for each element.
Vector expression for unary operation.
Definition: vector_expression.h:47
void resize(size_t n, const T &val=0)
Resizes to n dimensional vector with initial value val.
VectorScalarMul< T, VectorN > mul(const T &s) const
Computes this * (s, s, ... , s).
void isub(const E &v)
Computes this -= v.
T operator[](size_t i) const
Returns the i -th element.
Vector expression for matrix-scalar binary operation.
Definition: vector_expression.h:114
const T *const data() const
Returns the const raw pointer to the vector data.
bool isEqual(const E &other) const
Returns true if other is the same as this vector.
void idiv(const E &v)
Computes this /= v.
VectorN & operator-=(const E &v)
Computes this -= v.
void parallelForEachIndex(Callback func) const
Iterates the vector and invoke given func for each index in parallel using multi-threading.
T at(size_t i) const
Returns const reference to the i -th element of the vector.
void set(const VectorExpression< T, E > &other)
Sets vector with expression template.
VectorN & operator*=(const T &s)
Computes this *= (s, s, ... , s)
VectorN< float > VectorNF
Float-type N-D vector.
Definition: vector_n.h:401
VectorScalarSub< T, VectorN > sub(const T &s) const
Computes this - (s, s, ... , s).
void swap(VectorN &other)
Swaps the content of the vector with other vector.
Vector expression for binary operation.
Definition: vector_expression.h:84
T distanceTo(const E &other) const
Returns the distance to the other vector.
Definition: advection_solver2.h:18
VectorN(const std::initializer_list< U > &lst)
Constructs vector with given initializer list.
VectorN & operator-=(const T &s)
Computes this -= (s, s, ... , s)
T absmin() const
Returns the absolute minimum element.
void set(const std::initializer_list< U > &lst)
Sets all elements with given initializer list.
void set(const T &s)
Sets all elements to s.
VectorN(size_t n, const T &val=0)
Constructs default vector (val, val, ... , val).
VectorN & operator=(VectorN &&other)
Move assignment.
VectorSub< T, VectorN, E > rsub(const E &v) const
Computes v - this.
VectorN & operator=(const std::initializer_list< U > &lst)
Sets vector with given initializer list.
VectorScalarAdd< T, VectorN > add(const T &s) const
Computes this + (s, s, ... , s).
T * data()
Returns the raw pointer to the vector data.
bool operator!=(const E &v) const
Returns true if other is the not same as this vector.
T dot(const E &v) const
Computes dot product.
void isub(const T &s)
Computes this -= (s, s, ... , s).
ContainerType::iterator end()
Returns the end iterator of the vector.
T & at(size_t i)
Returns reference to the i -th element of the vector.
VectorN & operator/=(const E &v)
Computes this /= v.
ConstArrayAccessor1< T > constAccessor() const
Returns the const array accessor.
T absmax() const
Returns the absolute maximum element.
VectorN(const VectorN &other)
Copy constructor.
VectorN & operator=(const VectorN &other)
Copy assignment.
T max() const
Returns the maximum element.
T sum() const
Returns the sum of all the elements.
VectorSub< T, VectorN, E > sub(const E &v) const
Computes this - v.
void normalize()
Normalizes this vector.
void clear()
Clears the vector and make it zero-dimensional.
VectorN()
Constructs empty vector.
T & operator[](size_t i)
Returns the reference to the i -th element.
VectorScalarRDiv< T, VectorN > rdiv(const T &s) const
Computes (s, s, ... , s) / this.
ContainerType::iterator begin()
Returns the begin iterator of the vector.
T avg() const
Returns the average of all the elements.
VectorScalarDiv< T, VectorN > div(const T &s) const
Computes this / (s, s, ... , s).
VectorDiv< T, VectorN, E > rdiv(const E &v) const
Computes v / this.
T distanceSquaredTo(const E &other) const
Returns the squared distance to the other vector.
ContainerType::const_iterator begin() const
Returns the begin const iterator of the vector.
VectorN & operator+=(const T &s)
Computes this += (s, s, ... , s)
ContainerType::const_iterator end() const
Returns the end const iterator of the vector.
VectorN & operator+=(const E &v)
Computes this += v.
VectorScalarRSub< T, VectorN > rsub(const T &s) const
Computes (s, s, ... , s) - this.
bool isSimilar(const E &other, T epsilon=std::numeric_limits< T >::epsilon()) const
Returns true if other is similar to this vector.
VectorN(VectorN &&other)
Move constructor.
VectorDiv< T, VectorN, E > div(const E &v) const
Computes this / v.
VectorN< double > VectorND
Double-type N-D vector.
Definition: vector_n.h:404
std::vector< T > ContainerType
Definition: vector_n.h:33
VectorMul< T, VectorN, E > mul(const E &v) const
Computes this * v.
void setZero()
Sets all elements to zero.
void forEachIndex(Callback func) const
Iterates the vector and invoke given func for each index.
VectorN & operator/=(const T &s)
Computes this /= (s, s, ... , s)
void append(const T &val)
Adds an element.
1-D array accessor class.
Definition: array_accessor1.h:27
void imul(const E &v)
Computes this *= v.
T length() const
Returns the length of the vector.
VectorTypeCast< U, VectorN< T >, T > castTo() const
Returns a vector with different value type.