1 #ifndef SELDON_FILE_TINY_VECTOR_INLINE_CXX
3 #include "TinyVectorExpressionInline.cxx"
14 template <
class T,
int m>
22 template <
class T,
int m>
30 template <
class T,
int m>
40 template <
class T,
int m>
51 template <
class T,
int m>
63 template <
class T,
int m>
76 template <
class T,
int m>
79 #ifdef SELDON_CHECK_BOUNDS
82 string(
"size should be greater than 1,")+
83 "but is equal to" +
to_str(m) +
".");
91 template <
class T,
int m>
94 #ifdef SELDON_CHECK_BOUNDS
97 string(
"size should be greater than 2,")+
98 "but is equal to" +
to_str(m) +
".");
107 template <
class T,
int m>
110 #ifdef SELDON_CHECK_BOUNDS
113 string(
"size should be greater than 3,")+
114 "but is equal to" +
to_str(m) +
".");
124 template <
class T,
int m>
127 #ifdef SELDON_CHECK_BOUNDS
130 string(
"size should be greater than 4,")
131 +
"but is equal to" +
to_str(m) +
".");
142 template <
class T,
int m>
144 const T& c,
const T& d,
const T& e)
146 #ifdef SELDON_CHECK_BOUNDS
149 string(
"size should be greater than 5,")+
150 "but is equal to" +
to_str(m) +
".");
162 template<
class T,
int m_>
170 template<
class T,
int m_>
178 template<
class T,
int m_>
186 template<
class T,
int m_>
194 template<
class T,
int m_>
202 template<
class T,
int m_>
210 template <
class T,
int m_>
213 #ifdef SELDON_CHECK_BOUNDS
214 CheckBounds(i, m_,
"TinVector");
217 return this->data_[i];
222 template <
class T,
int m_>
225 #ifdef SELDON_CHECK_BOUNDS
226 CheckBounds(i, m_,
"TinVector");
229 return this->data_[i];
234 template <
class T,
int m>
242 template <
class T,
int m>
250 template <
class T,
int m>
258 template <
class T,
int m>
266 template<
class T,
int m>
template<
class T0>
274 template <
class T,
int m>
282 template <
class T,
int m>
290 template <
class T,
int m>
298 template <
class T,
int m>
301 return sqrt(DistanceSquare(p));
311 template <
class T,
int m_>
318 template <
class T,
int m_>
325 template <
class T,
int m_>
332 template <
class T,
int m_>
339 template <
class T,
int m_>
347 template <
class T,
int m_>
355 template<
class T,
int m_>
template<
class E>
363 template<
class T,
int m_>
template<
class T1,
class E>
373 template<
class T,
int m_>
template<
class T1,
class E>
383 template<
class T,
int m_>
template<
class T1,
class E>
393 template<
class T,
int m_>
402 template <
class T,
int m>
template<
class T1>
411 template <
class T,
int m>
template<
class T1>
414 T one; SetComplexOne(one);
524 template<
class T,
int m,
class E1,
class E2>
533 template<
class T,
int m,
class E1,
class E2>
542 template<
class T,
int m,
class E1,
class E2>
550 template<
class T,
int m,
class E1,
class E2>
559 template<
class T,
int m,
class E1,
class E2>
568 template<
class T,
int m,
class E1,
class E2>
577 template <
class T,
int m>
586 template <
class T,
int m>
599 template<
int n>
template<
int m,
class T0>
608 template <
int n>
template<
int m,
class T0>
617 template <
int n>
template<
int m,
class T0>
625 template <
int n>
template<
int m,
class T0,
class T1>
634 template <
int n>
template<
int m,
class T0>
643 template <
int n>
template<
int m,
class T0>
652 template<
int n>
template<
int m,
class T0,
class E0>
663 template<
int n>
template<
int m,
class T1,
class E,
class T0>
672 template<
int n>
template<
int m,
class T1,
class E,
class T0>
681 template<
int n>
template<
int m,
class T1,
class E,
class T0>
690 template<
int n>
template<
int m,
class T0,
class T1>
694 u(n-1) = uvec(n-1)(j);
700 template<
int n>
template<
int m,
class T0,
class T1>
704 uvec(n-1)(j) = u(n-1);
710 template<
int n>
template<
int m,
class T0,
class T1>
714 tmp(n-1) = Vh(m*j + n-1);
720 template<
int n>
template<
int m,
class T>
724 vr(n-1) = realpart(Vh(m*j + n-1));
725 vi(n-1) = imagpart(Vh(m*j + n-1));
731 template<
int n>
template<
int m,
class T0,
class T1>
735 Vh(m*j + n-1) = tmp(n-1);
741 template<
int n>
template<
int m,
class T0,
class T1>
745 tmp(n-1) += Vh(offset + n-1);
751 template<
int n>
template<
int m,
class T0,
class T1>
755 Vh(offset + n-1) += tmp(n-1);
761 template<
int n>
template<
int m,
class T0,
class T1>
765 tmp(n-1) = Vh(offset + n-1);
771 template<
int n>
template<
int m,
class T0,
class T1>
775 Vh(offset + n-1) = tmp(n-1);
781 template<
int n>
template<
int m,
class T0,
class T1>
786 v(n-1) = u(offset+n-1)(j);
792 template<
int n>
template<
int m,
class T0,
class T1>
797 u(offset+n-1)(j) = v(n-1);
803 template<
int n>
template<
int p,
int m,
class T0,
class T1>
808 v(n-1) = u(offset+n-1)(j)(k);
814 template<
int n>
template<
int m,
class T0,
class T1>
819 tmp(n-1) = Vh(row_num(nb + n-1));
825 template<
int n>
template<
int m,
class T0,
class T1>
830 Vh(row_num(nb + n-1)) = tmp(n-1);
836 template<
int n>
template<
class T0,
class T1>
841 x_dest(offset_dest + n-1) = x_src(offset_source + n-1);
847 template<
int n>
template<
int m,
class T0,
class T1>
852 Vh(row_num(nb + n-1)) += alpha*tmp(n-1);
858 template<
int n>
template<
int m,
class T0,
class T1>
863 tmp(n-1) = conjugate(Vh(row_num(nb + n-1)));
869 template<
int n>
template<
int m,
class T0,
class T1>
874 Vh(row_num(nb + n-1)) = conjugate(tmp(n-1));
880 template<
int n>
template<
int m,
class T0,
class T1>
885 Vh(row_num(nb + n-1)) += alpha*conjugate(tmp(n-1));
891 template<
int n>
template<
int m,
class T0,
class T1>
895 uvec(n-1)(j) *= alpha;
901 template <
int n>
template<
int m,
class T0,
class T1,
class E0,
class E1>
914 template <
int n>
template<
int m,
class T0,
class T1,
class E0,
class E1>
928 template <
int n>
template<
int m,
class T0,
class T1,
class E0,
class E1>
942 template <
int n>
template<
int m,
class T0,
class T1>
946 if (x.data_[m-n] != y.data_[m-n])
954 template <
int n>
template<
int m,
class T0,
class T1>
958 if (x.data_[m-n] < y.data_[m-n] )
960 else if ( x.data_[m-n] > y.data_[m-n])
968 template <
int n>
template<
int m,
class T0,
class T1>
971 if (x.data_[m-n] < y.data_[m-n])
973 else if (x.data_[m-n] > y.data_[m-n])
981 template <
int n>
template<
int m,
class T0,
class T1>
990 template <
int n>
template<
int m,
class T0,
class T1,
class T2,
class E0,
class E1>
1001 template <
int n>
template<
int m,
class T0,
class T1,
class T2,
class E0,
class E1>
1006 scal += conjugate(u(n))*v(n);
1012 template <
int n>
template<
int m,
class T0,
class T1,
class E0>
1021 template <
int n>
template<
int m,
class T0,
class T1,
class E0>
1024 scal = max(scal, abs(u(n)));
1030 template <
int n>
template<
int m,
class T0,
class T1,
class E0>
1039 template<
int n>
template<
int m,
class T>
1052 template<
int n>
template<
int m,
class T>
1065 template<
int n>
template<
int m,
class T>
1074 template<
int n>
template<
class T,
int m>
1077 v.data_[n-1] = min(v.data_[n-1], u.data_[n-1]);
1083 template<
int n>
template<
class T,
int m>
1086 v.data_[n-1] = max(v.data_[n-1], u.data_[n-1]);
1097 template<
class T,
int m,
class E1,
class E2>
1109 template<
class T,
int m,
class E1,
class E2>
1113 complex<T> scal = u(0)*v(0);
1121 template<
class T,
int m,
class E1,
class E2>
1125 complex<T> scal = u(0)*v(0);
1133 template<
class T,
int m,
class E1,
class E2>
1137 complex<T> scal = conjugate(u(0))*v(0);
1145 template<
class T,
int m,
class E>
1148 typename ClassComplexType<T>::Treal scal =
absSquare(u(0));
1156 template<
class T,
int m,
class E>
1159 typename ClassComplexType<T>::Treal scal = abs(u(0));
1167 template<
class T,
int m,
class E>
1170 typename ClassComplexType<T>::Treal scal = abs(u(0));
1178 template <
class T,
int m>
1181 return u.Distance(v);
1186 template<
class T,
int m,
class E>
1194 template<
class T0,
class T1,
class T2,
int m>
1202 template<
class T0,
class T1,
class T2,
int m>
1210 template<
class T0,
class T,
int m>
1223 template<
int p,
int m,
class T0,
class T1>
1232 template<
int m,
class T0,
class T1>
1241 template<
int m,
class T0,
class T1>
1250 template<
int m,
class T0,
class T1>
1259 template<
int m,
class T0,
class T1>
1268 template<
int m,
class T0,
class T1>
1277 template<
int m,
class T0,
class T1>
1286 template<
int m,
class T0,
class T1>
1295 template<
int m,
class T0,
class T1>
1304 template<
int m,
class T0,
class T1>
1313 template<
int m,
class T0,
class T1>
1322 template<
int m,
class T0,
class T1>
1330 template<
int m,
class T0,
class T1>
1338 template<
int m,
class T>
1347 template<
int m,
class T0,
class T1>
1355 template<
int m,
class T0,
class T1>
1363 template<
int m,
class T0,
class T1>
1371 template<
int m,
class T0,
class T1>
1385 template<
class T0,
int m>
1389 T0 scal = 2*(-d - DotProd(u, normale));
1391 Add(scal, normale, v);
1396 template<
class T,
int m>
1404 template<
class T,
int m>
1412 template<
int m,
class T0,
class T1>
1419 template<
class T,
int p>
1420 inline void Mlt(
const T& alpha, Vector<TinyVector<T, p> >& X)
1423 Xvec.SetData(X.GetM()*p,
reinterpret_cast<T*
>(X.GetData()));
1429 template<
class T,
class Prop,
class Storage,
int p>
1430 inline void Mlt(
const SeldonTranspose& trans,
const Matrix<T, Prop, Storage>& A,
1431 const Vector<TinyVector<T, p> >& x, Vector<TinyVector<T, p> >& y)
1433 if (trans.NoTrans())
1434 MltVector(SeldonNoTrans, A, x, y);
1436 MltVector(SeldonTrans, A, x, y);
1440 template<
class T,
class Prop,
class Storage,
int p>
1441 inline void Mlt(
const Matrix<T, Prop, Storage>& A,
1442 const Vector<TinyVector<T, p> >& x, Vector<TinyVector<T, p> >& y)
1454 template<
class T1,
class T2,
class T3>
1458 res(0) = u(1)*v(2) - u(2)*v(1);
1459 res(1) = u(2)*v(0) - u(0)*v(2);
1460 res(2) = u(0)*v(1) - u(1)*v(0);
1465 template<
class T1,
class T2>
1468 return u(0)*v(1) - u(1)*v(0);
1476 if (abs(normale(0)) > abs(normale(1)))
1477 v0.Init(-normale(1)*v0(1)/normale(0), v0(1));
1479 v0.Init(v0(0), -normale(0)*v0(0)/normale(1));
1487 if (abs(normale(0)) > max(abs(normale(1)), abs(normale(2))))
1488 v0.Init(-(normale(2)*v0(2)+normale(1)*v0(1))/normale(0), v0(1), v0(2));
1489 else if (abs(normale(1)) > max(abs(normale(0)), abs(normale(2))))
1490 v0.Init(v0(0), -(normale(0)*v0(0)+normale(2)*v0(2))/normale(1), v0(2));
1492 v0.Init(v0(0), v0(1), -(normale(0)*v0(0)+normale(1)*v0(1))/normale(2));
1523 template<
class T0,
class T1,
class T2,
class T3>
1527 v(0) = -u(1); v(1) = u(0); v(2) = u(2);
1528 w(0) = -v(1); w(1) = v(0); w(2) = v(2);
1529 t(0) = -w(1); t(1) = w(0); t(2) = w(2);
1538 T res = u(0)*(v(1)*w(2)-v(2)*w(1)) - u(1)*(v(0)*w(2)-v(2)*w(0)) + u(2)*(v(0)*w(1)-v(1)*w(0));
1548 inline void FillZero(
double& X)
1554 inline void FillZero(complex<double>& X)
1560 inline void FillZero(
int& X)
1566 inline void FillZero(
float& X)
1572 inline void FillZero(complex<float>& X)
1578 inline void FillZero(
bool& X)
1584 template<
class T,
class Storage,
class Allocator>
1587 for (
int i = 0; i < X.GetM(); i++)
1592 template<
class T,
class Prop,
class Storage,
class Allocator>
1595 for (
int i = 0; i < X.GetM(); i++)
1596 for (
int j = 0; j < X.GetN(); j++)
1601 template<
class T,
class Prop,
class Allocator>
1607 template<
class T,
class Prop,
class Allocator>
1613 template<
class T,
int m>
1621 inline void FillZero(T& x)
1628 inline void FillZero(complex<T>& x)
1630 x = complex<T>(0, 0);
1633 template<
class T,
int p>
1634 inline void SetComplexZero(TinyVector<T, p>& x)
1636 T zero; SetComplexZero(zero);
1641 inline bool IsComplexZero(
const T& x)
1650 inline bool IsComplexZero(
const complex<T>& x)
1652 if (x == complex<T>(0, 0))
1660 #define SELDON_FILE_TINY_VECTOR_INLINE_CXX
void GenerateSymPts(const TinyVector< T0, 3 > &u, TinyVector< T1, 3 > &v, TinyVector< T2, 3 > &w, TinyVector< T3, 3 > &t)
generates four points respecting the symmetry of the reference pyramid with one point
bool operator==(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns true if *this == u
void TimesProd(const TinyVector< T1, 3 > &u, const TinyVector< T2, 3 > &v, TinyVector< T3, 3 > &res)
cross product res = u^v where u,v and res are vectors
static void ExtractVectorConj(const Vector< T0 > &Vh, const IVect &row_num, int j, TinyVector< T1, m > &tmp)
tmp = conj(Vh(row_num(nb+:)))
static void ExtractVector(const Vector< T0 > &Vh, int j, TinyVector< T1, m > &tmp)
tmp(:) = Vh(offset + :)
static void DiffCopy(const TinyVectorExpression< T1, m, E > &x, TinyVector< T0, m > &y)
y -= x
static void FillRand(TinyVector< T0, m > &x)
sets randomly the components with function rand()
Class storing a tiny vector whose size is known at compilation time.
ClassComplexType< T >::Treal Norm2(const VectorExpression< T, E > &X)
returns 2-norm of an expression with vectors
Expression between vectors.
std::string to_str(const T &input)
Converts most types to string.
ClassComplexType< T >::Treal Norm1(const VectorExpression< T, E > &X)
returns 1-norm of an expression with vectors
TinyVector()
Sets all components to 0.
static void Zero(TinyVector< T0, m > &x)
Sets all components to 0.
static ostream & WriteText(const TinyVector< T, m > &V, ostream &out)
displays V
static void Copy(const TinyVectorExpression< T1, m, E > &x, TinyVector< T0, m > &y)
y = x
static void AddCopy(const TinyVectorExpression< T1, m, E > &x, TinyVector< T0, m > &y)
y += x
void FillRand()
sets randomly the components with function rand()
static void UpdateMaximum(const TinyVector< T, m > &u, TinyVector< T, m > &v)
sets v = max(v, u)
class used for unrolling loops for operators/functions of TinyVector
static void CopyVector(const TinyVector< Vector< T0 >, m > &uvec, int j, TinyVector< T1, m > &u)
u(:) = uvec(:)(j)
ClassComplexType< T >::Treal DistanceSquare(const TinyVector< T, m_ > &p) const
returns |u-v|^2 (usual euclidian norm)
vector with real/complex components
static void Mlt(const T1 &alpha, TinyVector< T0, m > &x)
Multiplies x by alpha.
Row-major sparse-matrix class.
static void Abs(const TinyVectorExpression< T0, m, E0 > &u, T1 &scal)
computes scal = \sum |u_i|^2
void AddVectorConj(const T0 &alpha, const TinyVector< T1, m > &tmp, const IVect &row_num, int nb, Vector< T0 > &Vh)
Vh(row_num(nb+:)) += alpha * conj(tmp)
static bool IsZero(const TinyVectorExpression< T0, m, E0 > &x)
returns true if all components are 0
ClassComplexType< T >::Treal Distance(const TinyVector< T, m_ > &p) const
returns |u-v| (usual euclidian norm)
bool operator<=(const TinyVector< int, m > &u, const TinyVector< int, m > &v)
returns true if u <= v, false otherwise
void Init(const T &a)
sets first component to a
void ExtractVector(const Vector< Vector< TinyVector< T0, p > > > &u, int j, int k, int offset, TinyVector< T1, m > &v)
v(:) = u(offset+:)(j)(k)
int GetSize() const
Returns the number of stored elements.
static bool Less(const TinyVectorExpression< T0, m, E0 > &x, const TinyVectorExpression< T1, m, E1 > &y)
returns x < y
void ForceZeroVdotN(const TinyVector< T, 2 > &normale, TinyVector< T, 2 > &v0)
modifies v0 such that v0 \cdot normale = 0
TinyVector_Base()
all components are set to 0
void UpdateMinimum(const TinyVector< T, m > &u, TinyVector< T, m > &v)
sets v = min(v, u) elementwise
void UpdateMaximum(const TinyVector< T, m > &u, TinyVector< T, m > &v)
sets v = max(v, u) elementwise
static void NormInf(const TinyVectorExpression< T0, m, E0 > &u, T1 &scal)
computes scal = max |u_i|^2
void CopyVector(const Vector< T1, Storage1, Allocator1 > &X, Vector< T2, Storage2, Allocator2 > &Y)
Y = X.
bool PointInsideBoundingBox(const TinyVector< T, 2 > &, const TinyVector< TinyVector< T, 2 >, 2 > &)
returns true if x is inside the bounding box s
istream & operator>>(istream &out, TinyVector< T, m > &V)
reads V
static void Print(const TinyVector< T, m > &V, ostream &out)
displays V without brackets
void Print() const
displays the vector without brackets
int GetLength() const
Returns the number of stored elements.
static bool LessInt(const TinyVector< T0, m > &x, const TinyVector< T1, m > &y)
returns x < y
bool IsZero() const
returns true if all components are 0
Row-major sparse-matrix class.
void Zero()
Sets all components to 0.
static bool LessOrEqualInt(const TinyVector< T0, m > &x, const TinyVector< T1, m > &y)
returns x <= y
void Fill()
Sets the vector to [0, 1, 2, 3, ..., n-1].
TinyVector< T, m_ > & operator+=(const TinyVectorExpression< T1, m_, E > &u)
Operator *this += expression with vectors.
bool operator>=(const TinyVector< int, m > &u, const TinyVector< int, m > &v)
returns true if u >= v, false otherwise
static void Fill(TinyVector< T0, m > &x, const T1 &a)
Sets all components to a given value.
ClassComplexType< T >::Treal NormInf(const Matrix< T, Prop, Storage, Allocator > &A)
Returns the infinity-norm of a matrix.
T absSquare(const T &x)
returns the square modulus of z
TinyVector< T, m_ > & operator=(const TinyVectorExpression< T1, m_, E > &u)
Operator *this = expression with vectors.
TinyVector< T, m_ > & GetLeafClass()
returns leaf class
static void DotProd(const TinyVectorExpression< T0, m, E0 > &u, const TinyVectorExpression< T1, m, E1 > &v, T2 &scal)
scal = u.v
bool operator!=(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns true if *this != u
static void FillGreater(TinyVector< T0, m > &x, const T0 &a)
Fills with a in ascendant order (instead of descendant order for Fill)
static void AddVectorConj(const T0 &alpha, const TinyVector< T1, m > &tmp, const IVect &row_num, int j, Vector< T0 > &Vh)
Vh(row_num(nb+:)) += alpha * conj(tmp)
static void AddVector(const Vector< T0 > &Vh, int j, TinyVector< T1, m > &tmp)
tmp(:) += Vh(offset + :)
static void UpdateMinimum(const TinyVector< T, m > &u, TinyVector< T, m > &v)
sets v = min(v, u)
TinyVector< T, m_ > & operator-=(const TinyVectorExpression< T1, m_, E > &u)
Operator *this -= expression with vectors.
ClassComplexType< T >::Treal AbsSquare(const TinyVectorExpression< T, m, E > &u)
returns || u ||^2
T Distance(const TinyVector< T, m > &u, const TinyVector< T, m > &v)
returns || u-v ||
void SymmetrizePointPlane(const TinyVector< T0, m > &u, const TinyVector< T0, m > &normale, const T0 &d, TinyVector< T0, m > &v)
Applies the symmetry with respect to the hyperplane a x + b y + c z + .. + d = 0 v = S(u) where S is ...
static void InitValue(TinyVector< T0, m > &x, const T0 &a)
initializes a single value
void ExtractVectorConj(const Vector< T0 > &Vh, const IVect &row_num, int nb, TinyVector< T1, m > &tmp)
tmp = conj(Vh(row_num(nb+:)))
size_t GetMemorySize() const
returns the size used by the object in bytes
T Determinant(const TinyVector< T, 3 > &u, const TinyVector< T, 3 > &v, const TinyVector< T, 3 > &w)
res = (u^v) . w = det(u,v,w) where u,v and w are vectors
ostream & operator<<(ostream &out, const Array< T, N, Allocator > &A)
operator<< overloaded for a 3D array.
static void AbsSquare(const TinyVectorExpression< T0, m, E0 > &u, T1 &scal)
computes scal = \sum |u_i|^2
const T & operator()(int i) const
returns x(i)
static void MltVector(const T1 &alpha, int j, TinyVector< Vector< T0 >, m > &uvec)
u(:)(j) *= alpha
static istream & ReadText(TinyVector< T, m > &V, istream &in)
reads V
static void DotProdConj(const TinyVectorExpression< T0, m, E0 > &u, const TinyVectorExpression< T1, m, E1 > &v, T2 &scal)
returns (conj(u), v)
bool operator>(const TinyVector< int, m > &u, const TinyVector< int, m > &v)
returns true if u > v, false otherwise
bool operator<(const TinyVector< int, m > &u, const TinyVector< int, m > &v)
returns *this < u
void SetComplexReal(int n, std::complex< T > &number)
Sets a complex number to (n, 0).
int GetM() const
Returns the number of stored elements.
void AddVector(const T0 &alpha, const Vector< T1, Storage1, Allocator1 > &X, Vector< T2, Storage2, Allocator2 > &Y)
Adds two vectors Y = Y + alpha X.
static bool LessOrEqual(const TinyVectorExpression< T0, m, E0 > &x, const TinyVectorExpression< T1, m, E1 > &y)
returns x <= y
static bool Equal(const TinyVectorExpression< T0, m, E0 > &x, const TinyVectorExpression< T1, m, E1 > &y)
returns x == y
static bool EqualInt(const TinyVector< T0, m > &x, const TinyVector< T1, m > &y)
returns x == y