DenseIterator.h
Go to the documentation of this file.
1 //=================================================================================================
24 //=================================================================================================
25 
26 #ifndef _BLAZE_MATH_DENSE_DENSEITERATOR_H_
27 #define _BLAZE_MATH_DENSE_DENSEITERATOR_H_
28 
29 
30 //*************************************************************************************************
31 // Includes
32 //*************************************************************************************************
33 
34 #include <iterator>
35 #include <blaze/math/SIMD.h>
37 #include <blaze/util/Assert.h>
38 #include <blaze/util/Types.h>
39 
40 
41 namespace blaze {
42 
43 //=================================================================================================
44 //
45 // CLASS DEFINITION
46 //
47 //=================================================================================================
48 
49 //*************************************************************************************************
56 template< typename Type // Type of the elements
57  , bool AF > // Alignment flag
59 {
60  public:
61  //**Type definitions****************************************************************************
62  typedef std::random_access_iterator_tag IteratorCategory;
63  typedef Type ValueType;
64  typedef Type* PointerType;
65  typedef Type& ReferenceType;
67 
68  // STL iterator requirements
69  typedef IteratorCategory iterator_category;
70  typedef ValueType value_type;
71  typedef PointerType pointer;
72  typedef ReferenceType reference;
73  typedef DifferenceType difference_type;
74 
77  //**********************************************************************************************
78 
79  //**Constructors********************************************************************************
82  explicit inline DenseIterator() noexcept;
83  explicit inline DenseIterator( Type* ptr ) noexcept;
84 
85  template< typename Other, bool AF2 >
86  inline DenseIterator( const DenseIterator<Other,AF2>& it ) noexcept;
88  //**********************************************************************************************
89 
90  //**Destructor**********************************************************************************
91  // No explicitly declared destructor.
92  //**********************************************************************************************
93 
94  //**Assignment operators************************************************************************
97  // No explicitly declared copy assignment operator.
98  inline DenseIterator& operator+=( ptrdiff_t inc ) noexcept;
99  inline DenseIterator& operator-=( ptrdiff_t inc ) noexcept;
101  //**********************************************************************************************
102 
103  //**Increment/decrement operators***************************************************************
106  inline DenseIterator& operator++() noexcept;
107  inline const DenseIterator operator++( int ) noexcept;
108  inline DenseIterator& operator--() noexcept;
109  inline const DenseIterator operator--( int ) noexcept;
111  //**********************************************************************************************
112 
113  //**Access operators****************************************************************************
116  inline ReferenceType operator[]( size_t index ) const noexcept;
117  inline ReferenceType operator* () const noexcept;
118  inline PointerType operator->() const noexcept;
120  //**********************************************************************************************
121 
122  //**Utility functions***************************************************************************
125  inline PointerType base() const noexcept;
127  //**********************************************************************************************
128 
129  //**Expression template evaluation functions****************************************************
132  inline const SIMDType load () const noexcept;
133  inline const SIMDType loada () const noexcept;
134  inline const SIMDType loadu () const noexcept;
135  inline void store ( const SIMDType& value ) const noexcept;
136  inline void storea( const SIMDType& value ) const noexcept;
137  inline void storeu( const SIMDType& value ) const noexcept;
138  inline void stream( const SIMDType& value ) const noexcept;
140  //**********************************************************************************************
141 
142  private:
143  //**Member variables****************************************************************************
146  PointerType ptr_;
147 
148  //**********************************************************************************************
149 };
150 //*************************************************************************************************
151 
152 
153 
154 
155 //=================================================================================================
156 //
157 // CONSTRUCTORS
158 //
159 //=================================================================================================
160 
161 //*************************************************************************************************
164 template< typename Type // Type of the elements
165  , bool AF > // Alignment flag
166 inline DenseIterator<Type,AF>::DenseIterator() noexcept
167  : ptr_( nullptr ) // Pointer to the current element
168 {}
169 //*************************************************************************************************
170 
171 
172 //*************************************************************************************************
177 template< typename Type // Type of the elements
178  , bool AF > // Alignment flag
179 inline DenseIterator<Type,AF>::DenseIterator( Type* ptr ) noexcept
180  : ptr_( ptr ) // Pointer to the current element
181 {}
182 //*************************************************************************************************
183 
184 
185 //*************************************************************************************************
190 template< typename Type // Type of the elements
191  , bool AF > // Alignment flag
192 template< typename Other // Type of the foreign elements
193  , bool AF2 > // Alignment flag of the foreign iterator
195  : ptr_( it.base() ) // Pointer to the current element
196 {}
197 //*************************************************************************************************
198 
199 
200 
201 
202 //=================================================================================================
203 //
204 // ASSIGNMENT OPERATORS
205 //
206 //=================================================================================================
207 
208 //*************************************************************************************************
214 template< typename Type // Type of the elements
215  , bool AF > // Alignment flag
217 {
218  ptr_ += inc;
219  return *this;
220 }
221 //*************************************************************************************************
222 
223 
224 //*************************************************************************************************
230 template< typename Type // Type of the elements
231  , bool AF > // Alignment flag
233 {
234  ptr_ -= dec;
235  return *this;
236 }
237 //*************************************************************************************************
238 
239 
240 
241 
242 //=================================================================================================
243 //
244 // INCREMENT/DECREMENT OPERATORS
245 //
246 //=================================================================================================
247 
248 //*************************************************************************************************
253 template< typename Type // Type of the elements
254  , bool AF > // Alignment flag
256 {
257  ++ptr_;
258  return *this;
259 }
260 //*************************************************************************************************
261 
262 
263 //*************************************************************************************************
268 template< typename Type // Type of the elements
269  , bool AF > // Alignment flag
271 {
272  return DenseIterator( ptr_++ );
273 }
274 //*************************************************************************************************
275 
276 
277 //*************************************************************************************************
282 template< typename Type // Type of the elements
283  , bool AF > // Alignment flag
285 {
286  --ptr_;
287  return *this;
288 }
289 //*************************************************************************************************
290 
291 
292 //*************************************************************************************************
297 template< typename Type // Type of the elements
298  , bool AF > // Alignment flag
300 {
301  return DenseIterator( ptr_-- );
302 }
303 //*************************************************************************************************
304 
305 
306 
307 
308 //=================================================================================================
309 //
310 // OPERATORS
311 //
312 //=================================================================================================
313 
314 //*************************************************************************************************
320 template< typename Type // Type of the elements
321  , bool AF > // Alignment flag
323  DenseIterator<Type,AF>::operator[]( size_t index ) const noexcept
324 {
325  return ptr_[index];
326 }
327 //*************************************************************************************************
328 
329 
330 //*************************************************************************************************
335 template< typename Type // Type of the elements
336  , bool AF > // Alignment flag
339 {
340  return *ptr_;
341 }
342 //*************************************************************************************************
343 
344 
345 //*************************************************************************************************
350 template< typename Type // Type of the elements
351  , bool AF > // Alignment flag
354 {
355  return ptr_;
356 }
357 //*************************************************************************************************
358 
359 
360 
361 
362 //=================================================================================================
363 //
364 // UTILITY FUNCTIONS
365 //
366 //=================================================================================================
367 
368 //*************************************************************************************************
373 template< typename Type // Type of the elements
374  , bool AF > // Alignment flag
376 {
377  return ptr_;
378 }
379 //*************************************************************************************************
380 
381 
382 
383 
384 //=================================================================================================
385 //
386 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
387 //
388 //=================================================================================================
389 
390 //*************************************************************************************************
400 template< typename Type // Type of the elements
401  , bool AF > // Alignment flag
402 inline const typename DenseIterator<Type,AF>::SIMDType
404 {
405  if( AF )
406  return loada();
407  else
408  return loadu();
409 }
410 //*************************************************************************************************
411 
412 
413 //*************************************************************************************************
423 template< typename Type // Type of the elements
424  , bool AF > // Alignment flag
425 inline const typename DenseIterator<Type,AF>::SIMDType
427 {
428  BLAZE_INTERNAL_ASSERT( checkAlignment( ptr_ ), "Invalid alignment detected" );
429 
430  return blaze::loada( ptr_ );
431 }
432 //*************************************************************************************************
433 
434 
435 //*************************************************************************************************
445 template< typename Type // Type of the elements
446  , bool AF > // Alignment flag
447 inline const typename DenseIterator<Type,AF>::SIMDType
449 {
450  return blaze::loadu( ptr_ );
451 }
452 //*************************************************************************************************
453 
454 
455 //*************************************************************************************************
466 template< typename Type // Type of the elements
467  , bool AF > // Alignment flag
468 inline void DenseIterator<Type,AF>::store( const SIMDType& value ) const noexcept
469 {
470  if( AF )
471  storea( value );
472  else
473  storeu( value );
474 }
475 //*************************************************************************************************
476 
477 
478 //*************************************************************************************************
489 template< typename Type // Type of the elements
490  , bool AF > // Alignment flag
491 inline void DenseIterator<Type,AF>::storea( const SIMDType& value ) const noexcept
492 {
493  blaze::storea( ptr_, value );
494 }
495 //*************************************************************************************************
496 
497 
498 //*************************************************************************************************
509 template< typename Type // Type of the elements
510  , bool AF > // Alignment flag
511 inline void DenseIterator<Type,AF>::storeu( const SIMDType& value ) const noexcept
512 {
513  blaze::storeu( ptr_, value );
514 }
515 //*************************************************************************************************
516 
517 
518 //*************************************************************************************************
529 template< typename Type // Type of the elements
530  , bool AF > // Alignment flag
531 inline void DenseIterator<Type,AF>::stream( const SIMDType& value ) const noexcept
532 {
533  blaze::stream( ptr_, value );
534 }
535 //*************************************************************************************************
536 
537 
538 
539 
540 //=================================================================================================
541 //
542 // GLOBAL OPERATORS
543 //
544 //=================================================================================================
545 
546 //*************************************************************************************************
549 template< typename T1, bool AF1, typename T2, bool AF2 >
550 inline bool operator==( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
551 
552 template< typename T1, bool AF1, typename T2, bool AF2 >
553 inline bool operator!=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
554 
555 template< typename T1, bool AF1, typename T2, bool AF2 >
556 inline bool operator<( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
557 
558 template< typename T1, bool AF1, typename T2, bool AF2 >
559 inline bool operator>( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
560 
561 template< typename T1, bool AF1, typename T2, bool AF2 >
562 inline bool operator<=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
563 
564 template< typename T1, bool AF1, typename T2, bool AF2 >
565 inline bool operator>=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
566 
567 template< typename Type, bool AF >
568 inline const DenseIterator<Type,AF> operator+( const DenseIterator<Type,AF>& it, ptrdiff_t inc ) noexcept;
569 
570 template< typename Type, bool AF >
571 inline const DenseIterator<Type,AF> operator+( ptrdiff_t inc, const DenseIterator<Type,AF>& it ) noexcept;
572 
573 template< typename Type, bool AF >
574 inline const DenseIterator<Type,AF> operator-( const DenseIterator<Type,AF>& it, ptrdiff_t inc ) noexcept;
575 
576 template< typename Type, bool AF >
577 inline ptrdiff_t operator-( const DenseIterator<Type,AF>& lhs, const DenseIterator<Type,AF>& rhs ) noexcept;
579 //*************************************************************************************************
580 
581 
582 //*************************************************************************************************
589 template< typename T1 // Element type of the left-hand side iterator
590  , bool AF1 // Alignment flag of the left-hand side iterator
591  , typename T2 // Element type of the right-hand side iterator
592  , bool AF2 > // Alignment flag of the right-hand side iterator
593 inline bool operator==( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
594 {
595  return lhs.base() == rhs.base();
596 }
597 //*************************************************************************************************
598 
599 
600 //*************************************************************************************************
607 template< typename T1 // Element type of the left-hand side iterator
608  , bool AF1 // Alignment flag of the left-hand side iterator
609  , typename T2 // Element type of the right-hand side iterator
610  , bool AF2 > // Alignment flag of the right-hand side iterator
611 inline bool operator!=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
612 {
613  return lhs.base() != rhs.base();
614 }
615 //*************************************************************************************************
616 
617 
618 //*************************************************************************************************
625 template< typename T1 // Element type of the left-hand side iterator
626  , bool AF1 // Alignment flag of the left-hand side iterator
627  , typename T2 // Element type of the right-hand side iterator
628  , bool AF2 > // Alignment flag of the right-hand side iterator
629 inline bool operator<( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
630 {
631  return lhs.base() < rhs.base();
632 }
633 //*************************************************************************************************
634 
635 
636 //*************************************************************************************************
643 template< typename T1 // Element type of the left-hand side iterator
644  , bool AF1 // Alignment flag of the left-hand side iterator
645  , typename T2 // Element type of the right-hand side iterator
646  , bool AF2 > // Alignment flag of the right-hand side iterator
647 inline bool operator>( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
648 {
649  return lhs.base() > rhs.base();
650 }
651 //*************************************************************************************************
652 
653 
654 //*************************************************************************************************
661 template< typename T1 // Element type of the left-hand side iterator
662  , bool AF1 // Alignment flag of the left-hand side iterator
663  , typename T2 // Element type of the right-hand side iterator
664  , bool AF2 > // Alignment flag of the right-hand side iterator
665 inline bool operator<=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
666 {
667  return lhs.base() <= rhs.base();
668 }
669 //*************************************************************************************************
670 
671 
672 //*************************************************************************************************
679 template< typename T1 // Element type of the left-hand side iterator
680  , bool AF1 // Alignment flag of the left-hand side iterator
681  , typename T2 // Element type of the right-hand side iterator
682  , bool AF2 > // Alignment flag of the right-hand side iterator
683 inline bool operator>=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
684 {
685  return lhs.base() >= rhs.base();
686 }
687 //*************************************************************************************************
688 
689 
690 //*************************************************************************************************
697 template< typename Type // Element type of the iterator
698  , bool AF > // Alignment flag of the iterator
699 inline const DenseIterator<Type,AF> operator+( const DenseIterator<Type,AF>& it, ptrdiff_t inc ) noexcept
700 {
701  return DenseIterator<Type,AF>( it.base() + inc );
702 }
703 //*************************************************************************************************
704 
705 
706 //*************************************************************************************************
713 template< typename Type // Element type of the iterator
714  , bool AF > // Alignment flag of the iterator
715 inline const DenseIterator<Type,AF> operator+( ptrdiff_t inc, const DenseIterator<Type,AF>& it ) noexcept
716 {
717  return DenseIterator<Type,AF>( it.base() + inc );
718 }
719 //*************************************************************************************************
720 
721 
722 //*************************************************************************************************
729 template< typename Type // Element type of the iterator
730  , bool AF > // Alignment flag of the iterator
731 inline const DenseIterator<Type,AF> operator-( const DenseIterator<Type,AF>& it, ptrdiff_t dec ) noexcept
732 {
733  return DenseIterator<Type,AF>( it.base() - dec );
734 }
735 //*************************************************************************************************
736 
737 
738 //*************************************************************************************************
745 template< typename Type // Element type of the iterator
746  , bool AF > // Alignment flag of the iterator
747 inline ptrdiff_t operator-( const DenseIterator<Type,AF>& lhs, const DenseIterator<Type,AF>& rhs ) noexcept
748 {
749  return lhs.base() - rhs.base();
750 }
751 //*************************************************************************************************
752 
753 } // namespace blaze
754 
755 #endif
Pointer difference type of the Blaze library.
ValueType value_type
Type of the underlying elements.
Definition: DenseIterator.h:70
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE EnableIf_< And< IsIntegral< T1 >, HasSize< T1, 1UL > > > storea(T1 *address, const SIMDi8< T2 > &value) noexcept
Aligned store of a vector of 1-byte integral values.
Definition: Storea.h:79
typename SIMDTrait< T >::Type SIMDTrait_
Auxiliary alias declaration for the SIMDTrait class template.The SIMDTrait_ alias declaration provide...
Definition: SIMDTrait.h:315
const DenseIterator< Type, AF > operator+(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Addition between a DenseIterator and an integral value.
Definition: DenseIterator.h:699
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DenseIterator.h:66
bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:366
const SIMDType loada() const noexcept
Aligned load of the SIMD element at the current iterator position.
Definition: DenseIterator.h:426
bool operator>=(const NegativeAccuracy< A > &, const T &rhs)
Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value...
Definition: Accuracy.h:442
const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:731
SIMDTrait_< Type > SIMDType
SIMD type of the elements.
Definition: DenseIterator.h:76
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > loadu(const T *address) noexcept
Loads a vector of 1-byte integral values.
Definition: Loadu.h:77
DenseIterator() noexcept
Default constructor for the DenseIterator class.
Definition: DenseIterator.h:166
Type ValueType
Type of the underlying elements.
Definition: DenseIterator.h:63
ReferenceType operator*() const noexcept
Direct access to the element at the current iterator position.
Definition: DenseIterator.h:338
const SIMDType loadu() const noexcept
Unaligned load of the SIMD element at the current iterator position.
Definition: DenseIterator.h:448
PointerType base() const noexcept
Low-level access to the underlying member of the iterator.
Definition: DenseIterator.h:375
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Type & ReferenceType
Reference return type.
Definition: DenseIterator.h:65
DenseIterator & operator-=(ptrdiff_t inc) noexcept
Subtraction assignment operator.
Definition: DenseIterator.h:232
DenseIterator & operator--() noexcept
Pre-decrement operator.
Definition: DenseIterator.h:284
void stream(const SIMDType &value) const noexcept
Aligned, non-temporal store of the SIMD element at the current iterator position. ...
Definition: DenseIterator.h:531
void storea(const SIMDType &value) const noexcept
Aligned store of the SIMD element at the current iterator position.
Definition: DenseIterator.h:491
Header file for all SIMD functionality.
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > loada(const T *address) noexcept
Loads a vector of 1-byte integral values.
Definition: Loada.h:80
void storeu(const SIMDType &value) const noexcept
Unaligned store of the SIMD element at the current iterator position.
Definition: DenseIterator.h:511
DenseIterator & operator++() noexcept
Pre-increment operator.
Definition: DenseIterator.h:255
ReferenceType reference
Reference return type.
Definition: DenseIterator.h:72
PointerType ptr_
Pointer to the current element.
Definition: DenseIterator.h:146
BLAZE_ALWAYS_INLINE EnableIf_< And< IsIntegral< T1 >, HasSize< T1, 1UL > > > stream(T1 *address, const SIMDi8< T2 > &value) noexcept
Aligned, non-temporal store of a vector of 1-byte integral values.
Definition: Stream.h:75
IteratorCategory iterator_category
The iterator category.
Definition: DenseIterator.h:69
Header file for run time assertion macros.
Type * PointerType
Pointer return type.
Definition: DenseIterator.h:64
const SIMDType load() const noexcept
Load of the SIMD element at the current iterator position.
Definition: DenseIterator.h:403
ReferenceType operator[](size_t index) const noexcept
Direct access to the underlying elements.
Definition: DenseIterator.h:323
PointerType pointer
Pointer return type.
Definition: DenseIterator.h:71
DifferenceType difference_type
Difference between two iterators.
Definition: DenseIterator.h:73
Implementation of a generic iterator for dense vectors and matrices.The DenseIterator represents a ge...
Definition: DenseIterator.h:58
BLAZE_ALWAYS_INLINE EnableIf_< And< IsIntegral< T1 >, HasSize< T1, 1UL > > > storeu(T1 *address, const SIMDi8< T2 > &value) noexcept
Unaligned store of a vector of 1-byte integral values.
Definition: Storeu.h:76
BLAZE_ALWAYS_INLINE bool checkAlignment(const T *address)
Checks the alignment of the given address.
Definition: AlignmentCheck.h:68
PointerType operator->() const noexcept
Direct access to the element at the current iterator position.
Definition: DenseIterator.h:353
Header file for the alignment check function.
DenseIterator & operator+=(ptrdiff_t inc) noexcept
Addition assignment operator.
Definition: DenseIterator.h:216
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: DenseIterator.h:62
void store(const SIMDType &value) const noexcept
Store of the SIMD element at the current iterator position.
Definition: DenseIterator.h:468
#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