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******************************************************************
98  BLAZE_ALWAYS_INLINE const VectorType& operator~() const {
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 // Type of the vector
172  , bool TF > // Transpose flag of the vector
174 {
175  return (~vector).begin();
176 }
177 //*************************************************************************************************
178 
179 
180 //*************************************************************************************************
186 template< typename VT // Type of the vector
187  , bool TF > // Transpose flag of the vector
189 {
190  return (~vector).begin();
191 }
192 //*************************************************************************************************
193 
194 
195 //*************************************************************************************************
201 template< typename VT // Type of the vector
202  , bool TF > // Transpose flag of the vector
204 {
205  return (~vector).begin();
206 }
207 //*************************************************************************************************
208 
209 
210 //*************************************************************************************************
216 template< typename VT // Type of the vector
217  , bool TF > // Transpose flag of the vector
219 {
220  return (~vector).end();
221 }
222 //*************************************************************************************************
223 
224 
225 //*************************************************************************************************
231 template< typename VT // Type of the vector
232  , bool TF > // Transpose flag of the vector
234 {
235  return (~vector).end();
236 }
237 //*************************************************************************************************
238 
239 
240 //*************************************************************************************************
246 template< typename VT // Type of the vector
247  , bool TF > // Transpose flag of the vector
249 {
250  return (~vector).end();
251 }
252 //*************************************************************************************************
253 
254 
255 //*************************************************************************************************
262 template< typename VT // Type of the vector
263  , bool TF > // Transpose flag of the vector
264 BLAZE_ALWAYS_INLINE size_t size( const Vector<VT,TF>& vector )
265 {
266  return (~vector).size();
267 }
268 //*************************************************************************************************
269 
270 
271 //*************************************************************************************************
278 template< typename VT // Type of the vector
279  , bool TF > // Transpose flag of the vector
281 {
282  return (~vector).capacity();
283 }
284 //*************************************************************************************************
285 
286 
287 //*************************************************************************************************
297 template< typename VT // Type of the vector
298  , bool TF > // Transpose flag of the vector
300 {
301  return (~vector).nonZeros();
302 }
303 //*************************************************************************************************
304 
305 
306 //*************************************************************************************************
320 template< typename VT // Type of the vector
321  , bool TF > // Transpose flag of the vector
322 BLAZE_ALWAYS_INLINE typename DisableIf< IsResizable<VT> >::Type
323  resize_backend( Vector<VT,TF>& vector, size_t n, bool preserve )
324 {
325  UNUSED_PARAMETER( preserve );
326 
327  if( (~vector).size() != n )
328  throw std::invalid_argument( "Vector cannot be resized" );
329 }
331 //*************************************************************************************************
332 
333 
334 //*************************************************************************************************
345 template< typename VT // Type of the vector
346  , bool TF > // Transpose flag of the vector
347 BLAZE_ALWAYS_INLINE typename EnableIf< IsResizable<VT> >::Type
348  resize_backend( Vector<VT,TF>& vector, size_t n, bool preserve )
349 {
350  (~vector).resize( n, preserve );
351 }
353 //*************************************************************************************************
354 
355 
356 //*************************************************************************************************
384 template< typename VT // Type of the vector
385  , bool TF > // Transpose flag of the vector
386 BLAZE_ALWAYS_INLINE void resize( Vector<VT,TF>& vector, size_t n, bool preserve )
387 {
388  resize_backend( vector, n, preserve );
389 }
390 //*************************************************************************************************
391 
392 
393 //*************************************************************************************************
407 template< typename VT1 // Type of the left-hand side vector
408  , bool TF1 // Transpose flag of the left-hand side vector
409  , typename VT2 // Type of the right-hand side vector
410  , bool TF2 > // Transpose flag of the right-hand side vector
412 {
414 
415  BLAZE_INTERNAL_ASSERT( (~lhs).size() == (~rhs).size(), "Invalid vector sizes" );
416  (~lhs).assign( ~rhs );
417 }
418 //*************************************************************************************************
419 
420 
421 //*************************************************************************************************
435 template< typename VT1 // Type of the left-hand side vector
436  , bool TF1 // Transpose flag of the left-hand side vector
437  , typename VT2 // Type of the right-hand side vector
438  , bool TF2 > // Transpose flag of the right-hand side vector
440 {
442 
443  BLAZE_INTERNAL_ASSERT( (~lhs).size() == (~rhs).size(), "Invalid vector sizes" );
444  (~lhs).addAssign( ~rhs );
445 }
446 //*************************************************************************************************
447 
448 
449 //*************************************************************************************************
463 template< typename VT1 // Type of the left-hand side vector
464  , bool TF1 // Transpose flag of the left-hand side vector
465  , typename VT2 // Type of the right-hand side vector
466  , bool TF2 > // Transpose flag of the right-hand side vector
468 {
470 
471  BLAZE_INTERNAL_ASSERT( (~lhs).size() == (~rhs).size(), "Invalid vector sizes" );
472  (~lhs).subAssign( ~rhs );
473 }
474 //*************************************************************************************************
475 
476 
477 //*************************************************************************************************
491 template< typename VT1 // Type of the left-hand side vector
492  , bool TF1 // Transpose flag of the left-hand side vector
493  , typename VT2 // Type of the right-hand side vector
494  , bool TF2 > // Transpose flag of the right-hand side vector
496 {
498 
499  BLAZE_INTERNAL_ASSERT( (~lhs).size() == (~rhs).size(), "Invalid vector sizes" );
500  (~lhs).multAssign( ~rhs );
501 }
502 //*************************************************************************************************
503 
504 
505 //*************************************************************************************************
538 template< typename VT1 // Type of the left-hand side vector
539  , bool TF1 // Transpose flag of the left-hand side vector
540  , typename VT2 // Type of the right-hand side vector
541  , bool TF2 > // Transpose flag of the right-hand side vector
543 {
544  return ( IsSame<VT1,VT2>::value &&
545  reinterpret_cast<const void*>( &a ) == reinterpret_cast<const void*>( &b ) );
546 }
547 //*************************************************************************************************
548 
549 
550 //*************************************************************************************************
565 template< typename VT // Type of the vector
566  , bool TF > // Transpose flag of the vector
567 BLAZE_ALWAYS_INLINE VT& derestrict( Vector<VT,TF>& vector )
568 {
569  return ~vector;
570 }
572 //*************************************************************************************************
573 
574 } // namespace blaze
575 
576 #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.
Header file for basic type definitions.
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:264
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
VT VectorType
Type of the vector.
Definition: Vector.h:80
BLAZE_ALWAYS_INLINE VectorType & operator~()
Conversion operator for non-constant vectors.
Definition: Vector.h:88
Header file for the DisableIf class template.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#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:2511
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.
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
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2510
BLAZE_ALWAYS_INLINE const VectorType & operator~() const
Conversion operator for constant vectors.
Definition: Vector.h:98
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:151
#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 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