All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vector.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_VECTOR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_VECTOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <stdexcept>
45 #include <blaze/system/Inline.h>
46 #include <blaze/util/Assert.h>
47 #include <blaze/util/DisableIf.h>
48 #include <blaze/util/EnableIf.h>
50 #include <blaze/util/Types.h>
52 #include <blaze/util/Unused.h>
53 
54 
55 namespace blaze {
56 
57 //=================================================================================================
58 //
59 // CLASS DEFINITION
60 //
61 //=================================================================================================
62 
63 //*************************************************************************************************
75 template< typename VT // Type of the vector
76  , bool TF > // Transpose flag
77 struct Vector
78 {
79  //**Type definitions****************************************************************************
80  typedef VT VectorType;
81  //**********************************************************************************************
82 
83  //**Non-const conversion operator***************************************************************
89  return *static_cast<VectorType*>( this );
90  }
91  //**********************************************************************************************
92 
93  //**Const conversion operators******************************************************************
99  return *static_cast<const VectorType*>( this );
100  }
101  //**********************************************************************************************
102 };
103 //*************************************************************************************************
104 
105 
106 
107 
108 //=================================================================================================
109 //
110 // GLOBAL FUNCTIONS
111 //
112 //=================================================================================================
113 
114 //*************************************************************************************************
117 template< typename VT, bool TF >
118 BLAZE_ALWAYS_INLINE typename VT::Iterator begin( Vector<VT,TF>& vector );
119 
120 template< typename VT, bool TF >
121 BLAZE_ALWAYS_INLINE typename VT::ConstIterator begin( const Vector<VT,TF>& vector );
122 
123 template< typename VT, bool TF >
124 BLAZE_ALWAYS_INLINE typename VT::ConstIterator cbegin( const Vector<VT,TF>& vector );
125 
126 template< typename VT, bool TF >
127 BLAZE_ALWAYS_INLINE typename VT::Iterator end( Vector<VT,TF>& vector );
128 
129 template< typename VT, bool TF >
130 BLAZE_ALWAYS_INLINE typename VT::ConstIterator end( const Vector<VT,TF>& vector );
131 
132 template< typename VT, bool TF >
133 BLAZE_ALWAYS_INLINE typename VT::ConstIterator cend( const Vector<VT,TF>& vector );
134 
135 template< typename VT, bool TF >
136 BLAZE_ALWAYS_INLINE size_t size( const Vector<VT,TF>& vector );
137 
138 template< typename VT, bool TF >
139 BLAZE_ALWAYS_INLINE size_t capacity( const Vector<VT,TF>& vector );
140 
141 template< typename VT, bool TF >
142 BLAZE_ALWAYS_INLINE size_t nonZeros( const Vector<VT,TF>& vector );
143 
144 template< typename VT, bool TF >
145 BLAZE_ALWAYS_INLINE void resize( Vector<VT,TF>& vector, size_t n, bool preserve=true );
146 
147 template< typename VT1, bool TF1, typename VT2, bool TF2 >
148 BLAZE_ALWAYS_INLINE void assign( Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs );
149 
150 template< typename VT1, bool TF1, typename VT2, bool TF2 >
151 BLAZE_ALWAYS_INLINE void addAssign( Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs );
152 
153 template< typename VT1, bool TF1, typename VT2, bool TF2 >
154 BLAZE_ALWAYS_INLINE void subAssign( Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs );
155 
156 template< typename VT1, bool TF1, typename VT2, bool TF2 >
157 BLAZE_ALWAYS_INLINE void multAssign( Vector<VT1,TF1>& lhs, const Vector<VT2,TF2>& rhs );
158 
159 template< typename VT1, bool TF1, typename VT2, bool TF2 >
160 BLAZE_ALWAYS_INLINE bool isSame( const Vector<VT1,TF1>& a, const Vector<VT2,TF2>& b );
162 //*************************************************************************************************
163 
164 
165 //*************************************************************************************************
171 template< typename VT, bool TF >
173 {
174  return (~vector).begin();
175 }
176 //*************************************************************************************************
177 
178 
179 //*************************************************************************************************
185 template< typename VT, bool TF >
187 {
188  return (~vector).begin();
189 }
190 //*************************************************************************************************
191 
192 
193 //*************************************************************************************************
199 template< typename VT, bool TF >
201 {
202  return (~vector).begin();
203 }
204 //*************************************************************************************************
205 
206 
207 //*************************************************************************************************
213 template< typename VT, bool TF >
215 {
216  return (~vector).end();
217 }
218 //*************************************************************************************************
219 
220 
221 //*************************************************************************************************
227 template< typename VT, bool TF >
229 {
230  return (~vector).end();
231 }
232 //*************************************************************************************************
233 
234 
235 //*************************************************************************************************
241 template< typename VT, bool TF >
243 {
244  return (~vector).end();
245 }
246 //*************************************************************************************************
247 
248 
249 //*************************************************************************************************
256 template< typename VT // Type of the vector
257  , bool TF > // Transpose flag of the vector
258 BLAZE_ALWAYS_INLINE size_t size( const Vector<VT,TF>& vector )
259 {
260  return (~vector).size();
261 }
262 //*************************************************************************************************
263 
264 
265 //*************************************************************************************************
272 template< typename VT // Type of the vector
273  , bool TF > // Transpose flag of the vector
275 {
276  return (~vector).capacity();
277 }
278 //*************************************************************************************************
279 
280 
281 //*************************************************************************************************
291 template< typename VT // Type of the vector
292  , bool TF > // Transpose flag of the vector
294 {
295  return (~vector).nonZeros();
296 }
297 //*************************************************************************************************
298 
299 
300 //*************************************************************************************************
314 template< typename VT // Type of the vector
315  , bool TF > // Transpose flag of the vector
316 BLAZE_ALWAYS_INLINE typename DisableIf< IsResizable<VT> >::Type
317  resize_backend( Vector<VT,TF>& vector, size_t n, bool preserve )
318 {
319  UNUSED_PARAMETER( preserve );
320 
321  if( (~vector).size() != n )
322  throw std::invalid_argument( "Vector cannot be resized" );
323 }
325 //*************************************************************************************************
326 
327 
328 //*************************************************************************************************
339 template< typename VT // Type of the vector
340  , bool TF > // Transpose flag of the vector
341 BLAZE_ALWAYS_INLINE typename EnableIf< IsResizable<VT> >::Type
342  resize_backend( Vector<VT,TF>& vector, size_t n, bool preserve )
343 {
344  (~vector).resize( n, preserve );
345 }
347 //*************************************************************************************************
348 
349 
350 //*************************************************************************************************
378 template< typename VT // Type of the vector
379  , bool TF > // Transpose flag of the vector
380 BLAZE_ALWAYS_INLINE void resize( Vector<VT,TF>& vector, size_t n, bool preserve )
381 {
382  resize_backend( vector, n, preserve );
383 }
384 //*************************************************************************************************
385 
386 
387 //*************************************************************************************************
401 template< typename VT1 // Type of the left-hand side vector
402  , bool TF1 // Transpose flag of the left-hand side vector
403  , typename VT2 // Type of the right-hand side vector
404  , bool TF2 > // Transpose flag of the right-hand side vector
406 {
408 
409  BLAZE_INTERNAL_ASSERT( (~lhs).size() == (~rhs).size(), "Invalid vector sizes" );
410  (~lhs).assign( ~rhs );
411 }
412 //*************************************************************************************************
413 
414 
415 //*************************************************************************************************
429 template< typename VT1 // Type of the left-hand side vector
430  , bool TF1 // Transpose flag of the left-hand side vector
431  , typename VT2 // Type of the right-hand side vector
432  , bool TF2 > // Transpose flag of the right-hand side vector
434 {
436 
437  BLAZE_INTERNAL_ASSERT( (~lhs).size() == (~rhs).size(), "Invalid vector sizes" );
438  (~lhs).addAssign( ~rhs );
439 }
440 //*************************************************************************************************
441 
442 
443 //*************************************************************************************************
457 template< typename VT1 // Type of the left-hand side vector
458  , bool TF1 // Transpose flag of the left-hand side vector
459  , typename VT2 // Type of the right-hand side vector
460  , bool TF2 > // Transpose flag of the right-hand side vector
462 {
464 
465  BLAZE_INTERNAL_ASSERT( (~lhs).size() == (~rhs).size(), "Invalid vector sizes" );
466  (~lhs).subAssign( ~rhs );
467 }
468 //*************************************************************************************************
469 
470 
471 //*************************************************************************************************
485 template< typename VT1 // Type of the left-hand side vector
486  , bool TF1 // Transpose flag of the left-hand side vector
487  , typename VT2 // Type of the right-hand side vector
488  , bool TF2 > // Transpose flag of the right-hand side vector
490 {
492 
493  BLAZE_INTERNAL_ASSERT( (~lhs).size() == (~rhs).size(), "Invalid vector sizes" );
494  (~lhs).multAssign( ~rhs );
495 }
496 //*************************************************************************************************
497 
498 
499 //*************************************************************************************************
532 template< typename VT1 // Type of the left-hand side vector
533  , bool TF1 // Transpose flag of the left-hand side vector
534  , typename VT2 // Type of the right-hand side vector
535  , bool TF2 > // Transpose flag of the right-hand side vector
537 {
538  return ( IsSame<VT1,VT2>::value &&
539  reinterpret_cast<const void*>( &a ) == reinterpret_cast<const void*>( &b ) );
540 }
541 //*************************************************************************************************
542 
543 } // namespace blaze
544 
545 #endif
BLAZE_ALWAYS_INLINE void multAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the multiplication assignment of a matrix to a matrix.
Definition: Matrix.h:879
Header file for the UNUSED_PARAMETER function template.
BLAZE_ALWAYS_INLINE MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:237
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:258
BLAZE_ALWAYS_INLINE MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:300
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:258
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b)
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:946
Header file for the IsSame and IsStrictlySame type traits.
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:386
Type relationship analysis.This class tests if the two data types A and B are equal. For this type comparison, the cv-qualifiers of both data types are ignored. If A and B are the same data type (ignoring the cv-qualifiers), then the value member enumeration is set to 1, the nested type definition Type is TrueType, and the class derives from TrueType. Otherwise value is set to 0, Type is FalseType, and the class derives from FalseType.
Definition: IsSame.h:158
Header file for the DisableIf class template.
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2482
BLAZE_ALWAYS_INLINE void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:635
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:195
BLAZE_ALWAYS_INLINE void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:535
Header file for the EnableIf class template.
BLAZE_ALWAYS_INLINE VectorType & operator~()
Conversion operator for non-constant vectors.
Definition: Vector.h:88
Header file for run time assertion macros.
BLAZE_ALWAYS_INLINE void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:742
BLAZE_ALWAYS_INLINE const VectorType & operator~() const
Conversion operator for constant vectors.
Definition: Vector.h:98
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2481
VT VectorType
Type of the vector.
Definition: Vector.h:80
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
Header file for basic type definitions.
Header file for the IsResizable type trait.
System settings for the inline keywords.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Header file for the FunctionTrace class.
BLAZE_ALWAYS_INLINE void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:849