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>
50 
51 
52 namespace blaze {
53 
54 //=================================================================================================
55 //
56 // GLOBAL FUNCTIONS
57 //
58 //=================================================================================================
59 
60 //*************************************************************************************************
63 template< typename VT, bool TF >
64 bool isUniform( const Vector<VT,TF>& v );
65 
66 template< typename T1, typename T2 >
67 decltype(auto) inner( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs );
68 
69 template< typename T1, typename T2 >
70 decltype(auto) inner( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs );
71 
72 template< typename T1, typename T2 >
73 decltype(auto) inner( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs );
74 
75 template< typename T1, typename T2 >
76 decltype(auto) inner( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs );
77 
78 template< typename T1, bool TF1, typename T2, bool TF2 >
79 decltype(auto) dot( const Vector<T1,TF1>& lhs, const Vector<T2,TF2>& rhs );
80 
81 template< typename T1, bool TF1, typename T2, bool TF2 >
82 decltype(auto) operator,( const Vector<T1,TF1>& lhs, const Vector<T2,TF2>& rhs );
83 
84 template< typename T1, typename T2 >
85 decltype(auto) outer( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs );
86 
87 template< typename T1, typename T2 >
88 decltype(auto) outer( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs );
89 
90 template< typename T1, typename T2 >
91 decltype(auto) outer( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs );
92 
93 template< typename T1, typename T2 >
94 decltype(auto) outer( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs );
95 
96 template< typename VT, bool TF >
97 decltype(auto) reverse( const Vector<VT,TF>& v );
99 //*************************************************************************************************
100 
101 
102 //*************************************************************************************************
135 template< typename VT // Type of the vector
136  , bool TF > // Transpose flag
137 inline bool isUniform( const Vector<VT,TF>& v )
138 {
139  return isUniform<relaxed>( ~v );
140 }
141 //*************************************************************************************************
142 
143 
144 //*************************************************************************************************
153 template< typename T1 // Type of the left-hand side vector
154  , typename T2 > // Type of the right-hand side vector
155 inline decltype(auto) inner( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs )
156 {
157  return trans(~lhs) * (~rhs);
158 }
159 //*************************************************************************************************
160 
161 
162 //*************************************************************************************************
171 template< typename T1 // Type of the left-hand side vector
172  , typename T2 > // Type of the right-hand side vector
173 inline decltype(auto) inner( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs )
174 {
175  return trans(~lhs) * trans(~rhs);
176 }
177 //*************************************************************************************************
178 
179 
180 //*************************************************************************************************
189 template< typename T1 // Type of the left-hand side vector
190  , typename T2 > // Type of the right-hand side vector
191 inline decltype(auto) inner( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs )
192 {
193  return (~lhs) * (~rhs);
194 }
195 //*************************************************************************************************
196 
197 
198 //*************************************************************************************************
207 template< typename T1 // Type of the left-hand side vector
208  , typename T2 > // Type of the right-hand side vector
209 inline decltype(auto) inner( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs )
210 {
211  return (~lhs) * trans(~rhs);
212 }
213 //*************************************************************************************************
214 
215 
216 //*************************************************************************************************
225 template< typename T1 // Type of the left-hand side vector
226  , bool TF1 // Transpose flag of the left-hand side vector
227  , typename T2 // Type of the right-hand side vector
228  , bool TF2 > // Transpose flag of the right-hand side vector
229 inline decltype(auto) dot( const Vector<T1,TF1>& lhs, const Vector<T2,TF2>& rhs )
230 {
231  return inner( ~lhs, ~rhs );
232 }
233 //*************************************************************************************************
234 
235 
236 //*************************************************************************************************
245 template< typename T1 // Type of the left-hand side vector
246  , bool TF1 // Transpose flag of the left-hand side vector
247  , typename T2 // Type of the right-hand side vector
248  , bool TF2 > // Transpose flag of the right-hand side vector
249 inline decltype(auto) operator,( const Vector<T1,TF1>& lhs, const Vector<T2,TF2>& rhs )
250 {
251  return inner( ~lhs, ~rhs );
252 }
253 //*************************************************************************************************
254 
255 
256 //*************************************************************************************************
265 template< typename T1 // Type of the left-hand side vector
266  , typename T2 > // Type of the right-hand side vector
267 inline decltype(auto) outer( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs )
268 {
269  return (~lhs) * trans(~rhs);
270 }
271 //*************************************************************************************************
272 
273 
274 //*************************************************************************************************
283 template< typename T1 // Type of the left-hand side vector
284  , typename T2 > // Type of the right-hand side vector
285 inline decltype(auto) outer( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs )
286 {
287  return (~lhs) * (~rhs);
288 }
289 //*************************************************************************************************
290 
291 
292 //*************************************************************************************************
301 template< typename T1 // Type of the left-hand side vector
302  , typename T2 > // Type of the right-hand side vector
303 inline decltype(auto) outer( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs )
304 {
305  return trans(~lhs) * trans(~rhs);
306 }
307 //*************************************************************************************************
308 
309 
310 //*************************************************************************************************
319 template< typename T1 // Type of the left-hand side vector
320  , typename T2 > // Type of the right-hand side vector
321 inline decltype(auto) outer( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs )
322 {
323  return trans(~lhs) * (~rhs);
324 }
325 //*************************************************************************************************
326 
327 
328 //*************************************************************************************************
345 template< typename VT // Type of the vector
346  , bool TF > // Transpose flag
347 inline decltype(auto) reverse( const Vector<VT,TF>& v )
348 {
349  return elements( ~v, [max=(~v).size()-1UL]( size_t i ){ return max - i; }, (~v).size() );
350 }
351 //*************************************************************************************************
352 
353 
354 
355 
356 //=================================================================================================
357 //
358 // GLOBAL OPERATORS
359 //
360 //=================================================================================================
361 
362 //*************************************************************************************************
365 template< typename VT, bool TF >
366 std::ostream& operator<<( std::ostream& os, const Vector<VT,TF>& v );
368 //*************************************************************************************************
369 
370 
371 //*************************************************************************************************
379 template< typename VT // Type of the vector
380  , bool TF > // Transpose flag
381 inline std::ostream& operator<<( std::ostream& os, const Vector<VT,TF>& v )
382 {
383  CompositeType_t<VT> tmp( ~v );
384 
385  if( tmp.size() == 0UL ) {
386  os << "( )\n";
387  }
388  else if( TF == rowVector ) {
389  os << "(";
390  for( size_t i=0UL; i<tmp.size(); ++i )
391  os << " " << tmp[i];
392  os << " )\n";
393  }
394  else {
395  for( size_t i=0UL; i<tmp.size(); ++i )
396  os << "( " << std::setw( 11UL ) << tmp[i] << " )\n";
397  }
398 
399  return os;
400 }
401 //*************************************************************************************************
402 
403 } // namespace blaze
404 
405 #endif
decltype(auto) inner(const Vector< T1, false > &lhs, const Vector< T2, false > &rhs)
Multiplication operator for the scalar product (dot/inner product) of two vectors ( )...
Definition: Vector.h:155
Header file for auxiliary alias declarations.
decltype(auto) dot(const Vector< T1, TF1 > &lhs, const Vector< T2, TF2 > &rhs)
Multiplication operator for the scalar product (dot/inner product) of two vectors ( )...
Definition: Vector.h:229
constexpr bool rowVector
Transpose flag for row vectors.
Definition: TransposeFlag.h:73
Header file for the vector transpose flag types.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
decltype(auto) outer(const Vector< T1, false > &lhs, const Vector< T2, false > &rhs)
Multiplication operator for the outer product of two vectors ( ).
Definition: Vector.h:267
decltype(auto) reverse(const Matrix< MT, SO > &m)
Reverse the rows or columns of a matrix.
Definition: Matrix.h:755
decltype(auto) elements(Vector< VT, TF > &vector, REAs... args)
Creating a view on a selection of elements of the given vector.
Definition: Elements.h:135
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:1179
bool isUniform(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a uniform matrix.
Definition: DenseMatrix.h:849
Header file for the relaxation flag types.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
Header file for the implementation of the Elements view.
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:186
Header file for the Vector CRTP base class.