13 #ifndef ML_FLOATING_POINT_VECTOR_H
14 #define ML_FLOATING_POINT_VECTOR_H
40 template <
class DT,
size_t size>
61 template <
class T,
size_t size,
class DataContainer = FloatingPo
intVectorDataContainerBase<T, size> >
153 return (*
this - buffer).length();
159 return (*
this - buffer).lengthSquared();
223 r[0] = this->_buffer[1]*b.
_buffer[2] - this->_buffer[2]*b.
_buffer[1];
224 r[1] = this->_buffer[2]*b.
_buffer[0] - this->_buffer[0]*b.
_buffer[2];
225 r[2] = this->_buffer[0]*b.
_buffer[1] - this->_buffer[1]*b.
_buffer[0];
251 template <
class T,
size_t size,
class DataContainer>
254 for (
size_t i=0; i<size; ++i){ op1[i] += buffer[i]; }
262 template <
class T,
size_t size,
class DataContainer>
265 for (
size_t i=0; i<size; ++i){ op1[i] -= buffer[i]; }
273 template <
class T,
size_t size,
class DataContainer>
276 for (
size_t i=0; i<size; ++i){ op1[i] *=
static_cast<T
>(value); }
284 template <
class T,
size_t size,
class DataContainer>
287 for (
size_t i=0; i<size; ++i){ op1[i] *= op2[i]; }
296 template <
class T,
size_t size,
class DataContainer>
302 for (
size_t i=0; i<size; ++i){ op1[i] /=
static_cast<T
>(value); }
311 template <
class T,
size_t size,
class DataContainer>
317 for (
size_t i=0; i<size; ++i){ op1[i] /= op2[i]; }
325 template <
class T,
size_t size,
class DataContainer>
329 for (
size_t c=1; c<size; c++){ v &= !a[c]; }
337 template <
class T,
size_t size,
class DataContainer>
348 template <
class T,
size_t size,
class DataContainer>
359 template <
class T,
size_t size,
class DataContainer>
370 template <
class T,
size_t size,
class DataContainer>
374 for (
size_t i=0; i<size; ++i){ buf[i] *= -1; }
382 template <
class T,
size_t size,
class DataContainer>
392 template <
class T,
size_t size,
class DataContainer>
395 return lhs *=
static_cast<T
>(rhs);
402 template <
class T,
size_t size,
class DataContainer>
405 return rhs *=
static_cast<T
>(lhs);
412 template <
class T,
size_t size,
class DataContainer>
415 return lhs /=
static_cast<T
>(rhs);
422 template <
class T,
size_t size,
class DataContainer>
434 template <
class T,
size_t size,
class DataContainer>
446 template <
class T,
size_t size,
class DataContainer>
457 template <
class T,
size_t size,
class DataContainer>
469 template <
class T,
size_t size,
class DataContainer>
481 template <
class T,
size_t size,
class DataContainer>
494 template <
class T,
size_t size,
class DataContainer>
507 template <
class T,
size_t size,
class DataContainer>
522 template <
class T,
size_t size,
class DataContainer>
536 template <
class T,
size_t size,
class DataContainer>
553 template <
class T,
size_t size,
class DataContainer>
554 inline ostream&
operator<<(ostream& os,
const ML_LA_NAMESPACE::FloatingPointVector<T, size, DataContainer>& v)
556 return v.writeOut(os);
562 template <
class T,
size_t size,
class DataContainer>
563 inline istream&
operator>>(istream&
is, ML_LA_NAMESPACE::FloatingPointVector<T, size, DataContainer>& v)
570 ML_LA_START_NAMESPACE
585 template <
class T,
size_t size,
class DataContainer>
588 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = value; }
594 template <
class T,
size_t size,
class DataContainer>
597 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = value; }
608 template <
class T,
size_t size,
class DataContainer>
611 for (
size_t i=0; i<size; ++i){
623 template <
class T,
size_t size,
class DataContainer>
626 for (
size_t i=0; i<size; ++i){
644 template <
class T,
size_t size,
class DataContainer>
647 for (
size_t i=0; i<size; ++i) {
665 template <
class T,
size_t size,
class DataContainer>
668 return this->_buffer[i];
676 template <
class T,
size_t size,
class DataContainer>
679 return this->_buffer[i];
695 template <
class T,
size_t size,
class DataContainer>
705 template <
class T,
size_t size,
class DataContainer>
709 for (
size_t i=0; i<size; ++i){ norm += this->_buffer[i]*this->_buffer[i]; }
711 return static_cast<T
>(sqrt(norm));
713 return static_cast<T
>(::sqrt(norm));
721 template <
class T,
size_t size,
class DataContainer>
725 for (
size_t i=0; i<size; ++i){
726 norm += this->_buffer[i]*this->_buffer[i] * weight.
_buffer[i]*weight.
_buffer[i];
740 template <
class T,
size_t size,
class DataContainer>
744 for (
size_t i=0; i<size; ++i){ sum += this->_buffer[i]*buffer.
_buffer[i]; }
752 template <
class T,
size_t size,
class DataContainer>
758 T inv_norm =
static_cast<T
>(1.0/norm);
759 for (
size_t i=0; i<size; ++i){ this->_buffer[i] *= inv_norm; }
768 template <
class T,
size_t size,
class DataContainer>
777 template <
class T,
size_t size,
class DataContainer>
786 template <
class T,
size_t size,
class DataContainer>
789 T retVal=this->_buffer[0];
790 for (
size_t i=1; i<size; ++i){ retVal += this->_buffer[i]; }
797 template <
class T,
size_t size,
class DataContainer>
800 T retVal=this->_buffer[0];
801 for (
size_t i=1; i<size; ++i){ retVal *= this->_buffer[i]; }
808 template <
class T,
size_t size,
class DataContainer>
812 T m =
static_cast<T
>(
MLAbs(this->_buffer[i++]));
814 for (; i<size; ++i){ m = (n =
static_cast<T
>(
MLAbs(this->_buffer[i])) ) > m ? n : m; }
821 template <
class T,
size_t size,
class DataContainer>
824 for (
size_t i=0; i<size; ++i){
825 this->_buffer[i] = this->_buffer[i] < buffer.
_buffer[i] ? this->_buffer[i] : buffer.
_buffer[i];
832 template <
class T,
size_t size,
class DataContainer>
835 for (
size_t i=0; i<size; ++i){
836 this->_buffer[i] = this->_buffer[i] < buffer.
_buffer[i] ? buffer.
_buffer[i] :this->_buffer[i];
843 template <
class T,
size_t size,
class DataContainer>
846 for (
size_t i=0; i<size; ++i){ this->_buffer[i] =
static_cast<T
>(
MLAbs(this->_buffer[i])); }
853 template <
class T,
size_t size,
class DataContainer>
856 for (
size_t i=0; i<size; ++i){ this->_buffer[i] /= d.
_buffer[i]; }
862 template <
class T,
size_t size,
class DataContainer>
865 for (
size_t i=0; i<size; ++i){ this->_buffer[i] *= this->_buffer[i]; }
872 template <
class T,
size_t size,
class DataContainer>
875 for (
size_t i=0; i<size; ++i){
877 this->_buffer[i] =
static_cast<T
>( sqrt(this->_buffer[i]));
879 this->_buffer[i] =
static_cast<T
>(::sqrt(this->_buffer[i]));
888 template <
class T,
size_t size,
class DataContainer>
898 template <
class T,
size_t size,
class DataContainer>
911 template <
class T,
size_t size,
class DataContainer>
925 template <
class T,
size_t size,
class DataContainer>
928 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = std::floor(this->_buffer[i] +
static_cast<T
>(0.5)); }
934 template <
class T,
size_t size,
class DataContainer>
937 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = std::floor(this->_buffer[i]); }
943 template <
class T,
size_t size,
class DataContainer>
946 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = std::ceil(this->_buffer[i]); }
952 template <
class T,
size_t size,
class DataContainer>
955 for (
size_t i=0; i<size; ++i){ this->_buffer[i] = f(this->_buffer[i]); }
962 template <
class T,
size_t size,
class DataContainer>
965 for (
size_t i=0; i<size; ++i){ os << this->_buffer[i] <<
" "; }
972 template <
class T,
size_t size,
class DataContainer>
975 for (
size_t i=0; i<size; ++i){
is >> this->_buffer[i]; }
Base class of the FloatingPointVector class that holds the data buffer.
Template class for vector arithmetic with floating point datatypes.
FloatingPointVector(T value=T(0))
Default and value constructor.
FloatingPointVector< T, 3, DataContainer > cross(const FloatingPointVector< T, 3, DataContainer > &b) const
Returns the cross product for elements, i.e., the returned vector is orthogonal to *this and b.
FloatingPointVector< T, size, DataContainer > operator/(FloatingPointVector< T, size, DataContainer > lhs, MLdouble rhs)
Component-wise division of lhs by specialized rhs of type MLdouble.
FloatingPointVector< T, size, DataContainer > & operator/=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &op2)
Arithmetic assignment: Component-wise division of *this by the values of a vector of the same size.
FloatingPointVector< T, size, DataContainer > operator*(FloatingPointVector< T, size, DataContainer > lhs, MLdouble rhs)
Component-wise multiplication of lhs with rhs.
std::ostream & writeOut(std::ostream &os) const
Writes all components to ostream os starting from index 0 to size-1.
FloatingPointVector< T, size, DataContainer > compMax(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component-wise maximum of buffer1 and buffer2.
void clampMax(const FloatingPointVector< T, size, DataContainer > &upper)
Calculates and sets all components clamped to upper, i.e., if any component is greater than the corre...
void compMin(FloatingPointVector< T, size, DataContainer > buffer)
Sets the component-wise minimum of *this and buffer in *this.
T & operator[](const size_t i)
Indexing operators.
FloatingPointVector< T, size, DataContainer > & operator*=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &op2)
Arithmetic assignment: Component-wise multiplication *this with a vector of the same size.
T length() const
Returns the length of the vector, i.e., norm2().
void clamp(const FloatingPointVector< T, size, DataContainer > &lower, const FloatingPointVector< T, size, DataContainer > &upper)
Calculates and sets all components of *this so that they are between minimum lower and maximum upper.
FloatingPointVector< T, size, DataContainer > & operator/=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component-wise division of *this by scalar value.
FloatingPointVector< T, size, DataContainer > operator+(const FloatingPointVector< T, size, DataContainer > &buffer)
Unary plus, for completeness and for those who really want to use that.
bool operator==(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns whether *this and buffer are component-wise equal.
FloatingPointVector< T, size, DataContainer > & operator-=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component-wise subtraction of buffer from *this.
void compMax(FloatingPointVector< T, size, DataContainer > buffer)
Sets the component-wise maximum of *this and buffer in *this.
FloatingPointVector< T, size, DataContainer > clamp(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &lower, const FloatingPointVector< T, size, DataContainer > &upper)
Returns a new vector with all components from vec clamped to range [lower, upper].
T normalize()
Normalizes the buffer and returns the Euclidean length of vector before normalization,...
void compAbs()
Kills negative signs from all components.
const T & operator[](const size_t i) const
Constant indexing operators.
T distance(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns the distance of this vector to a given one.
T compMaxAbs() const
Returns the maximum of absolute component values.
void compFloor()
Rounds all components of this vector using floor(component).
void compDiv(const FloatingPointVector< T, size, DataContainer > &d)
Divides each vector component by the corresponding one of d.
T compMul() const
Returns the product of all vector components.
bool operator!(const FloatingPointVector< T, size, DataContainer > &a)
Returns whether all components are 0.
FloatingPointVector< T, size, DataContainer > & operator=(T value)
Assignment of scalar value to all components.
T compMul(const FloatingPointVector< T, size, DataContainer > &vec)
Returns the product of all components.
FloatingPointVector< T, size, DataContainer > clampMax(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &m)
Returns a new vector with all components from vec clamped to maximum m.
FloatingPointVector< T, size, DataContainer > compSqrt(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec square-rooted.
FloatingPointVector< T, size, DataContainer > compSqr(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec squared.
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).
void compRound()
Rounds all components of this vector using floor(component + 0.5).
T norm2(const FloatingPointVector< T, size, DataContainer > &weight) const
Returns the weighted Euclidean norm, i.e., square root of sum of squares of all components multiplied...
T dot(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns the dot product, i.e., sum of all components multiplied with corresponding components of buff...
void compSqr()
Calculates and sets the square of all components.
bool operator!=(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns whether any components of *this and buffer are not equal.
T norm2() const
Returns the Euclidean norm (the vector length), i.e., square root of sum of squares of all components...
T compSum() const
Returns the sum of all components.
FloatingPointVector< T, size, DataContainer > operator+(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component-wise addition of lhs and rhs.
std::istream & readIn(std::istream &is)
Reads all components from istream is starting starting from index 0 to size-1.
FloatingPointVector< T, size, DataContainer > compMin(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component-wise minimum of buffer1 and buffer2.
void compCeil()
Rounds all components of this vector to integer using ceil(component).
size_t getSize() const
Returns the number of elements of value buffer.
void clampMin(const FloatingPointVector< T, size, DataContainer > &lower)
Calculates and sets all components clamped to lower, i.e., if any component is smaller than the corre...
void compSqrt()
Calculates and sets square root of all components.
FloatingPointVector< T, size, DataContainer > & operator+=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component-wise addition.
FloatingPointVector< T, size, DataContainer > operator-(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component-wise subtraction of rhs from lhs.
FloatingPointVector< T, size, DataContainer > operator*(MLdouble lhs, FloatingPointVector< T, size, DataContainer > rhs)
Component-wise multiplication of rhs with lhs.
FloatingPointVector< T, size, DataContainer > compAbs(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec without negative sign.
T distanceSquared(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns the squared distance of this vector to a given one.
void apply(ML_LA_FROM_DOUBLE_TO_DOUBLE f)
Applies the function f to each component starting from index 0 to index size-1.
FloatingPointVector< T, size, DataContainer > & operator*=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component-wise multiplication *this with specialized MLdouble scalar value.
FloatingPointVector< T, size, DataContainer > operator-(const FloatingPointVector< T, size, DataContainer > &buffer)
Unary minus, all components of the vector are multiplied with -1.
T ComponentType
A typedef to 'export' the type of components.
FloatingPointVector< T, size, DataContainer > clampMin(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &m)
Returns a new vector with all components from vec clamped to minimum m.
T lengthSquared() const
Returns the squared length of the vector.
FloatingPointVector< T, size, DataContainer > compDiv(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &d)
Component-wise division of vec / d.
bool MLValueIs0WOM(MLint8 a)
Returns true if value is 0; otherwise, it returns false.
DT MLAbs(const DT val)
Defines a templated MLAbs version to circumvent fabs ambiguities on different platforms.
bool MLValuesDifferWOM(MLint8 a, MLint8 b)
Returns true if values differ; otherwise, it returns false.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.
double(* ML_LA_FROM_DOUBLE_TO_DOUBLE)(double)
Template base class for floating point vectors.
istream & operator>>(istream &is, ml::FloatingPointVector< T, size, DataContainer > &v)
Reads a vector from std::istream.
FloatingPointVector< T, size, DataContainer > compMax(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component-wise maximum of buffer1 and buffer2.
FloatingPointVector< T, size, DataContainer > clamp(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &lower, const FloatingPointVector< T, size, DataContainer > &upper)
Returns a new vector with all components from vec clamped to range [lower, upper].
bool operator==(const Tmat2< DT > &a, const Tmat2< DT > &b)
a == b ? Returns true if yes.
T compMul(const FloatingPointVector< T, size, DataContainer > &vec)
Returns the product of all components.
FloatingPointVector< T, size, DataContainer > clampMax(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &m)
Returns a new vector with all components from vec clamped to maximum m.
FloatingPointVector< T, size, DataContainer > compSqrt(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec square-rooted.
FloatingPointVector< T, size, DataContainer > compSqr(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec squared.
bool operator!=(const Tmat2< DT > &a, const Tmat2< DT > &b)
a != b ? Returns true if yes.
FloatingPointVector< T, size, DataContainer > compMin(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component-wise minimum of buffer1 and buffer2.
constexpr Is< T > is(T d)
FloatingPointVector< T, size, DataContainer > compAbs(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec without negative sign.
FloatingPointVector< T, size, DataContainer > clampMin(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &m)
Returns a new vector with all components from vec clamped to minimum m.
FloatingPointVector< T, size, DataContainer > compDiv(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &d)
Component-wise division of vec / d.