Blaze 3.9
Vector.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_VECTOR_H_
36#define _BLAZE_MATH_VECTOR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <iomanip>
44#include <iosfwd>
45#include <blaze/math/Aliases.h>
54
55
56namespace blaze {
57
58//=================================================================================================
59//
60// GLOBAL FUNCTIONS
61//
62//=================================================================================================
63
64//*************************************************************************************************
67template< typename VT, bool TF >
68bool isUniform( const Vector<VT,TF>& v );
69
70template< typename VT, bool TF >
71decltype(auto) pow2( const Vector<VT,TF>& v );
72
73template< typename VT, bool TF >
74decltype(auto) pow3( const Vector<VT,TF>& v );
75
76template< typename VT, bool TF >
77decltype(auto) pow4( const Vector<VT,TF>& v );
78
79template< typename VT1, bool TF1, typename VT2, bool TF2 >
80decltype(auto) inner( const Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs );
81
82template< typename VT1, bool TF1, typename VT2, bool TF2 >
83decltype(auto) dot( const Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs );
84
85template< typename VT1, bool TF1, typename VT2, bool TF2 >
86decltype(auto) operator,( const Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs );
87
88template< typename VT1, bool TF1, typename VT2, bool TF2 >
89decltype(auto) outer( const Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs );
90
91template< typename VT1, typename VT2, bool TF >
92decltype(auto) cross( const Vector<VT1,TF>& lhs, const Vector<VT2,TF>& rhs );
93
94template< typename VT >
95decltype(auto) reverse( VT&& v );
97//*************************************************************************************************
98
99
100//*************************************************************************************************
133template< typename VT // Type of the vector
134 , bool TF > // Transpose flag
135inline bool isUniform( const Vector<VT,TF>& v )
136{
137 return isUniform<relaxed>( *v );
138}
139//*************************************************************************************************
140
141
142//*************************************************************************************************
159template< typename VT // Type of the vector
160 , bool TF > // Transpose flag
161inline decltype(auto) pow2( const Vector<VT,TF>& v )
162{
163 return (*v) * (*v);
164}
165//*************************************************************************************************
166
167
168//*************************************************************************************************
185template< typename VT // Type of the vector
186 , bool TF > // Transpose flag
187inline decltype(auto) pow3( const Vector<VT,TF>& v )
188{
189 return (*v) * (*v) * (*v);
190}
191//*************************************************************************************************
192
193
194//*************************************************************************************************
211template< typename VT // Type of the vector
212 , bool TF > // Transpose flag
213inline decltype(auto) pow4( const Vector<VT,TF>& v )
214{
215 return pow2( pow2( *v ) );
216}
217//*************************************************************************************************
218
219
220//*************************************************************************************************
244template< typename VT1 // Type of the left-hand side vector
245 , bool TF1 // Transpose flag of the left-hand side vector
246 , typename VT2 // Type of the right-hand side vector
247 , bool TF2 > // Transpose flag of the right-hand side vector
248inline decltype(auto) inner( const Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs )
249{
250 return transTo<rowVector>( *lhs ) * transTo<columnVector>( *rhs );
251}
252//*************************************************************************************************
253
254
255//*************************************************************************************************
279template< typename VT1 // Type of the left-hand side vector
280 , bool TF1 // Transpose flag of the left-hand side vector
281 , typename VT2 // Type of the right-hand side vector
282 , bool TF2 > // Transpose flag of the right-hand side vector
283inline decltype(auto) dot( const Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs )
284{
285 return inner( *lhs, *rhs );
286}
287//*************************************************************************************************
288
289
290//*************************************************************************************************
314template< typename VT1 // Type of the left-hand side vector
315 , bool TF1 // Transpose flag of the left-hand side vector
316 , typename VT2 // Type of the right-hand side vector
317 , bool TF2 > // Transpose flag of the right-hand side vector
318inline decltype(auto) operator,( const Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs )
319{
320 return inner( *lhs, *rhs );
321}
322//*************************************************************************************************
323
324
325//*************************************************************************************************
348template< typename VT1 // Type of the left-hand side vector
349 , bool TF1 // Transpose flag of the left-hand side vector
350 , typename VT2 // Type of the right-hand side vector
351 , bool TF2 > // Transpose flag of the right-hand side vector
352inline decltype(auto) outer( const Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs )
353{
354 return transTo<columnVector>( *lhs ) * transTo<rowVector>( *rhs );
355}
356//*************************************************************************************************
357
358
359//*************************************************************************************************
384template< typename VT1 // Type of the left-hand side vector
385 , typename VT2 // Type of the right-hand side vector
386 , bool TF > // Transpose flag
387inline decltype(auto) cross( const Vector<VT1,TF>& lhs, const Vector<VT2,TF>& rhs )
388{
389 return (*lhs) % (*rhs);
390}
391//*************************************************************************************************
392
393
394//*************************************************************************************************
411template< typename VT > // Type of the vector
412inline decltype(auto) reverse( VT&& v )
413{
414 return elements( *v, [max=(*v).size()-1UL]( size_t i ){ return max - i; }, (*v).size() );
415}
416//*************************************************************************************************
417
418
419
420
421//=================================================================================================
422//
423// GLOBAL OPERATORS
424//
425//=================================================================================================
426
427//*************************************************************************************************
430template< typename VT, bool TF >
431std::ostream& operator<<( std::ostream& os, const Vector<VT,TF>& v );
433//*************************************************************************************************
434
435
436//*************************************************************************************************
444template< typename VT // Type of the vector
445 , bool TF > // Transpose flag
446inline std::ostream& operator<<( std::ostream& os, const Vector<VT,TF>& v )
447{
448 CompositeType_t<VT> tmp( *v );
449
450 if( tmp.size() == 0UL ) {
451 os << "( )\n";
452 }
453 else if( TF == rowVector ) {
454 os << "(";
455 for( size_t i=0UL; i<tmp.size(); ++i )
456 os << " " << tmp[i];
457 os << " )\n";
458 }
459 else {
460 for( size_t i=0UL; i<tmp.size(); ++i )
461 os << "( " << std::setw( 11UL ) << tmp[i] << " )\n";
462 }
463
464 return os;
465}
466//*************************************************************************************************
467
468} // namespace blaze
469
470#endif
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
Base class for N-dimensional vectors.
Definition: Vector.h:82
Header file for the Vector CRTP base class.
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1375
decltype(auto) elements(Vector< VT, TF > &vector, REAs... args)
Creating a view on a selection of elements of the given vector.
Definition: Elements.h:143
decltype(auto) pow2(const Vector< VT, TF > &v)
Computes the square for each single element of the vector v.
Definition: Vector.h:161
decltype(auto) pow4(const Vector< VT, TF > &v)
Computes the quadruple for each single element of the vector v.
Definition: Vector.h:213
bool isUniform(const Vector< VT, TF > &v)
Checks if the given vector is a uniform vector.
Definition: Vector.h:135
decltype(auto) inner(const Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Scalar product (dot/inner product) of two vectors ( ).
Definition: Vector.h:248
std::ostream & operator<<(std::ostream &os, const Vector< VT, TF > &v)
Global output operator for dense and sparse vectors.
Definition: Vector.h:446
decltype(auto) pow3(const Vector< VT, TF > &v)
Computes the cube for each single element of the vector v.
Definition: Vector.h:187
decltype(auto) outer(const Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Outer product of two vectors ( ).
Definition: Vector.h:352
decltype(auto) dot(const Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Scalar product (dot/inner product) of two vectors ( ).
Definition: Vector.h:283
decltype(auto) cross(const Vector< VT1, TF > &lhs, const Vector< VT2, TF > &rhs)
Cross product of two vectors ( ).
Definition: Vector.h:387
decltype(auto) reverse(VT &&v)
Reverse the elements of a vector.
Definition: Vector.h:412
Header file for the vector transpose flag types.
constexpr bool rowVector
Transpose flag for row vectors.
Definition: TransposeFlag.h:73
Header file for all forward declarations for expression class templates.
Header file for the add shim.
Header file for the div shim.
Header file for the mult shim.
Header file for the sub shim.
Header file for the implementation of the Elements view.