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 <ostream>
45 #include <blaze/math/Aliases.h>
49 
50 
51 namespace blaze {
52 
53 //=================================================================================================
54 //
55 // GLOBAL OPERATORS
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
62 template< typename T1, typename T2 >
63 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
64  inner( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs );
65 
66 template< typename T1, typename T2 >
67 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
68  inner( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs );
69 
70 template< typename T1, typename T2 >
71 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
72  inner( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs );
73 
74 template< typename T1, typename T2 >
75 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
76  inner( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs );
77 
78 template< typename T1, bool TF1, typename T2, bool TF2 >
79 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
80  dot( const Vector<T1,TF1>& lhs, const Vector<T2,TF2>& rhs );
81 
82 template< typename T1, bool TF1, typename T2, bool TF2 >
83 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
84  operator,( const Vector<T1,TF1>& lhs, const Vector<T2,TF2>& rhs );
85 
86 template< typename T1, typename T2 >
87 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
88  outer( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs );
89 
90 template< typename T1, typename T2 >
91 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
92  outer( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs );
93 
94 template< typename T1, typename T2 >
95 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
96  outer( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs );
97 
98 template< typename T1, typename T2 >
99 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
100  outer( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs );
101 
102 template< typename VT, bool TF >
103 inline std::ostream& operator<<( std::ostream& os, const Vector<VT,TF>& v );
105 //*************************************************************************************************
106 
107 
108 //*************************************************************************************************
117 template< typename T1 // Type of the left-hand side vector
118  , typename T2 > // Type of the right-hand side vector
119 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
120  inner( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs )
121 {
122  return trans(~lhs) * (~rhs);
123 }
124 //*************************************************************************************************
125 
126 
127 //*************************************************************************************************
136 template< typename T1 // Type of the left-hand side vector
137  , typename T2 > // Type of the right-hand side vector
138 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
139  inner( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs )
140 {
141  return trans(~lhs) * trans(~rhs);
142 }
143 //*************************************************************************************************
144 
145 
146 //*************************************************************************************************
155 template< typename T1 // Type of the left-hand side vector
156  , typename T2 > // Type of the right-hand side vector
157 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
158  inner( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs )
159 {
160  return (~lhs) * (~rhs);
161 }
162 //*************************************************************************************************
163 
164 
165 //*************************************************************************************************
174 template< typename T1 // Type of the left-hand side vector
175  , typename T2 > // Type of the right-hand side vector
176 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
177  inner( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs )
178 {
179  return (~lhs) * trans(~rhs);
180 }
181 //*************************************************************************************************
182 
183 
184 //*************************************************************************************************
193 template< typename T1 // Type of the left-hand side vector
194  , bool TF1 // Transpose flag of the left-hand side vector
195  , typename T2 // Type of the right-hand side vector
196  , bool TF2 > // Transpose flag of the right-hand side vector
197 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
198  dot( const Vector<T1,TF1>& lhs, const Vector<T2,TF2>& rhs )
199 {
200  return inner( ~lhs, ~rhs );
201 }
202 //*************************************************************************************************
203 
204 
205 //*************************************************************************************************
214 template< typename T1 // Type of the left-hand side vector
215  , bool TF1 // Transpose flag of the left-hand side vector
216  , typename T2 // Type of the right-hand side vector
217  , bool TF2 > // Transpose flag of the right-hand side vector
218 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
219  operator,( const Vector<T1,TF1>& lhs, const Vector<T2,TF2>& rhs )
220 {
221  return inner( ~lhs, ~rhs );
222 }
223 //*************************************************************************************************
224 
225 
226 //*************************************************************************************************
235 template< typename T1 // Type of the left-hand side vector
236  , typename T2 > // Type of the right-hand side vector
237 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
238  outer( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs )
239 {
240  return (~lhs) * trans(~rhs);
241 }
242 //*************************************************************************************************
243 
244 
245 //*************************************************************************************************
254 template< typename T1 // Type of the left-hand side vector
255  , typename T2 > // Type of the right-hand side vector
256 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
257  outer( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs )
258 {
259  return (~lhs) * (~rhs);
260 }
261 //*************************************************************************************************
262 
263 
264 //*************************************************************************************************
273 template< typename T1 // Type of the left-hand side vector
274  , typename T2 > // Type of the right-hand side vector
275 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
276  outer( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs )
277 {
278  return trans(~lhs) * trans(~rhs);
279 }
280 //*************************************************************************************************
281 
282 
283 //*************************************************************************************************
292 template< typename T1 // Type of the left-hand side vector
293  , typename T2 > // Type of the right-hand side vector
294 inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
295  outer( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs )
296 {
297  return trans(~lhs) * (~rhs);
298 }
299 //*************************************************************************************************
300 
301 
302 //*************************************************************************************************
310 template< typename VT // Type of the vector
311  , bool TF > // Transpose flag
312 inline std::ostream& operator<<( std::ostream& os, const Vector<VT,TF>& v )
313 {
314  CompositeType_<VT> tmp( ~v );
315 
316  if( tmp.size() == 0UL ) {
317  os << "( )\n";
318  }
319  else if( TF == rowVector ) {
320  os << "(";
321  for( size_t i=0UL; i<tmp.size(); ++i )
322  os << " " << tmp[i];
323  os << " )\n";
324  }
325  else {
326  for( size_t i=0UL; i<tmp.size(); ++i )
327  os << "( " << std::setw( 11UL ) << tmp[i] << " )\n";
328  }
329 
330  return os;
331 }
332 //*************************************************************************************************
333 
334 } // namespace blaze
335 
336 #endif
Header file for auxiliary alias declarations.
const bool rowVector
Transpose flag for row vectors.
Definition: TransposeFlag.h:73
Header file for the vector transpose flag types.
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
const MultTrait_< ElementType_< T1 >, ElementType_< T2 > > 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:120
const MultTrait_< ElementType_< T1 >, ElementType_< T2 > > 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:198
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:790
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:177
const MultTrait_< ElementType_< T1 >, ElementType_< T2 > > outer(const Vector< T1, false > &lhs, const Vector< T2, false > &rhs)
Multiplication operator for the outer product of two vectors ( ).
Definition: Vector.h:238
const MultTrait_< ElementType_< T1 >, ElementType_< T2 > > operator,(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:219
Header file for the Vector CRTP base class.