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  using IteratorCategory = std::random_access_iterator_tag;
63  using ValueType = Type;
64  using PointerType = Type*;
65  using ReferenceType = Type&;
67 
68  // STL iterator requirements
71  using pointer = PointerType;
74 
77  //**********************************************************************************************
78 
79  //**Constructors********************************************************************************
82  explicit inline constexpr DenseIterator() noexcept;
83  explicit inline constexpr DenseIterator( Type* ptr ) noexcept;
84 
85  template< typename Other, bool AF2 >
86  inline constexpr DenseIterator( const DenseIterator<Other,AF2>& it ) noexcept;
87 
88  DenseIterator( const DenseIterator& ) = default;
90  //**********************************************************************************************
91 
92  //**Destructor**********************************************************************************
95  ~DenseIterator() = default;
97  //**********************************************************************************************
98 
99  //**Assignment operators************************************************************************
102  inline constexpr DenseIterator& operator+=( ptrdiff_t inc ) noexcept;
103  inline constexpr DenseIterator& operator-=( ptrdiff_t inc ) noexcept;
104 
105  DenseIterator& operator=( const DenseIterator& ) = default;
107  //**********************************************************************************************
108 
109  //**Increment/decrement operators***************************************************************
112  inline constexpr DenseIterator& operator++() noexcept;
113  inline constexpr const DenseIterator operator++( int ) noexcept;
114  inline constexpr DenseIterator& operator--() noexcept;
115  inline constexpr const DenseIterator operator--( int ) noexcept;
117  //**********************************************************************************************
118 
119  //**Access operators****************************************************************************
122  inline constexpr ReferenceType operator[]( size_t index ) const noexcept;
123  inline constexpr ReferenceType operator* () const noexcept;
124  inline constexpr PointerType operator->() const noexcept;
126  //**********************************************************************************************
127 
128  //**Utility functions***************************************************************************
131  inline constexpr PointerType base() const noexcept;
133  //**********************************************************************************************
134 
135  //**Expression template evaluation functions****************************************************
138  inline const SIMDType load () const noexcept;
139  inline const SIMDType loada () const noexcept;
140  inline const SIMDType loadu () const noexcept;
141  inline void store ( const SIMDType& value ) const noexcept;
142  inline void storea( const SIMDType& value ) const noexcept;
143  inline void storeu( const SIMDType& value ) const noexcept;
144  inline void stream( const SIMDType& value ) const noexcept;
146  //**********************************************************************************************
147 
148  private:
149  //**Member variables****************************************************************************
153 
154  //**********************************************************************************************
155 };
156 //*************************************************************************************************
157 
158 
159 
160 
161 //=================================================================================================
162 //
163 // CONSTRUCTORS
164 //
165 //=================================================================================================
166 
167 //*************************************************************************************************
170 template< typename Type // Type of the elements
171  , bool AF > // Alignment flag
172 inline constexpr DenseIterator<Type,AF>::DenseIterator() noexcept
173  : ptr_( nullptr ) // Pointer to the current element
174 {}
175 //*************************************************************************************************
176 
177 
178 //*************************************************************************************************
183 template< typename Type // Type of the elements
184  , bool AF > // Alignment flag
185 inline constexpr DenseIterator<Type,AF>::DenseIterator( Type* ptr ) noexcept
186  : ptr_( ptr ) // Pointer to the current element
187 {}
188 //*************************************************************************************************
189 
190 
191 //*************************************************************************************************
196 template< typename Type // Type of the elements
197  , bool AF > // Alignment flag
198 template< typename Other // Type of the foreign elements
199  , bool AF2 > // Alignment flag of the foreign iterator
201  : ptr_( it.base() ) // Pointer to the current element
202 {}
203 //*************************************************************************************************
204 
205 
206 
207 
208 //=================================================================================================
209 //
210 // ASSIGNMENT OPERATORS
211 //
212 //=================================================================================================
213 
214 //*************************************************************************************************
220 template< typename Type // Type of the elements
221  , bool AF > // Alignment flag
222 inline constexpr DenseIterator<Type,AF>&
224 {
225  ptr_ += inc;
226  return *this;
227 }
228 //*************************************************************************************************
229 
230 
231 //*************************************************************************************************
237 template< typename Type // Type of the elements
238  , bool AF > // Alignment flag
239 inline constexpr DenseIterator<Type,AF>&
241 {
242  ptr_ -= dec;
243  return *this;
244 }
245 //*************************************************************************************************
246 
247 
248 
249 
250 //=================================================================================================
251 //
252 // INCREMENT/DECREMENT OPERATORS
253 //
254 //=================================================================================================
255 
256 //*************************************************************************************************
261 template< typename Type // Type of the elements
262  , bool AF > // Alignment flag
264 {
265  ++ptr_;
266  return *this;
267 }
268 //*************************************************************************************************
269 
270 
271 //*************************************************************************************************
276 template< typename Type // Type of the elements
277  , bool AF > // Alignment flag
278 inline constexpr const DenseIterator<Type,AF> DenseIterator<Type,AF>::operator++( int ) noexcept
279 {
280  return DenseIterator( ptr_++ );
281 }
282 //*************************************************************************************************
283 
284 
285 //*************************************************************************************************
290 template< typename Type // Type of the elements
291  , bool AF > // Alignment flag
293 {
294  --ptr_;
295  return *this;
296 }
297 //*************************************************************************************************
298 
299 
300 //*************************************************************************************************
305 template< typename Type // Type of the elements
306  , bool AF > // Alignment flag
307 inline constexpr const DenseIterator<Type,AF> DenseIterator<Type,AF>::operator--( int ) noexcept
308 {
309  return DenseIterator( ptr_-- );
310 }
311 //*************************************************************************************************
312 
313 
314 
315 
316 //=================================================================================================
317 //
318 // ACCESS OPERATORS
319 //
320 //=================================================================================================
321 
322 //*************************************************************************************************
328 template< typename Type // Type of the elements
329  , bool AF > // Alignment flag
330 inline constexpr typename DenseIterator<Type,AF>::ReferenceType
331  DenseIterator<Type,AF>::operator[]( size_t index ) const noexcept
332 {
333  return ptr_[index];
334 }
335 //*************************************************************************************************
336 
337 
338 //*************************************************************************************************
343 template< typename Type // Type of the elements
344  , bool AF > // Alignment flag
345 inline constexpr typename DenseIterator<Type,AF>::ReferenceType
347 {
348  return *ptr_;
349 }
350 //*************************************************************************************************
351 
352 
353 //*************************************************************************************************
358 template< typename Type // Type of the elements
359  , bool AF > // Alignment flag
360 inline constexpr typename DenseIterator<Type,AF>::PointerType
362 {
363  return ptr_;
364 }
365 //*************************************************************************************************
366 
367 
368 
369 
370 //=================================================================================================
371 //
372 // UTILITY FUNCTIONS
373 //
374 //=================================================================================================
375 
376 //*************************************************************************************************
381 template< typename Type // Type of the elements
382  , bool AF > // Alignment flag
383 inline constexpr typename DenseIterator<Type,AF>::PointerType
385 {
386  return ptr_;
387 }
388 //*************************************************************************************************
389 
390 
391 
392 
393 //=================================================================================================
394 //
395 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
396 //
397 //=================================================================================================
398 
399 //*************************************************************************************************
409 template< typename Type // Type of the elements
410  , bool AF > // Alignment flag
411 inline const typename DenseIterator<Type,AF>::SIMDType
413 {
414  if( AF )
415  return loada();
416  else
417  return loadu();
418 }
419 //*************************************************************************************************
420 
421 
422 //*************************************************************************************************
432 template< typename Type // Type of the elements
433  , bool AF > // Alignment flag
434 inline const typename DenseIterator<Type,AF>::SIMDType
436 {
437  BLAZE_INTERNAL_ASSERT( checkAlignment( ptr_ ), "Invalid alignment detected" );
438 
439  return blaze::loada( ptr_ );
440 }
441 //*************************************************************************************************
442 
443 
444 //*************************************************************************************************
454 template< typename Type // Type of the elements
455  , bool AF > // Alignment flag
456 inline const typename DenseIterator<Type,AF>::SIMDType
458 {
459  return blaze::loadu( ptr_ );
460 }
461 //*************************************************************************************************
462 
463 
464 //*************************************************************************************************
475 template< typename Type // Type of the elements
476  , bool AF > // Alignment flag
477 inline void DenseIterator<Type,AF>::store( const SIMDType& value ) const noexcept
478 {
479  if( AF )
480  storea( value );
481  else
482  storeu( value );
483 }
484 //*************************************************************************************************
485 
486 
487 //*************************************************************************************************
498 template< typename Type // Type of the elements
499  , bool AF > // Alignment flag
500 inline void DenseIterator<Type,AF>::storea( const SIMDType& value ) const noexcept
501 {
502  blaze::storea( ptr_, value );
503 }
504 //*************************************************************************************************
505 
506 
507 //*************************************************************************************************
518 template< typename Type // Type of the elements
519  , bool AF > // Alignment flag
520 inline void DenseIterator<Type,AF>::storeu( const SIMDType& value ) const noexcept
521 {
522  blaze::storeu( ptr_, value );
523 }
524 //*************************************************************************************************
525 
526 
527 //*************************************************************************************************
538 template< typename Type // Type of the elements
539  , bool AF > // Alignment flag
540 inline void DenseIterator<Type,AF>::stream( const SIMDType& value ) const noexcept
541 {
542  blaze::stream( ptr_, value );
543 }
544 //*************************************************************************************************
545 
546 
547 
548 
549 //=================================================================================================
550 //
551 // GLOBAL OPERATORS
552 //
553 //=================================================================================================
554 
555 //*************************************************************************************************
558 template< typename T1, bool AF1, typename T2, bool AF2 >
559 constexpr bool
560  operator==( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
561 
562 template< typename T1, bool AF1, typename T2, bool AF2 >
563 constexpr bool
564  operator!=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
565 
566 template< typename T1, bool AF1, typename T2, bool AF2 >
567 constexpr bool
568  operator<( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
569 
570 template< typename T1, bool AF1, typename T2, bool AF2 >
571 constexpr bool
572  operator>( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
573 
574 template< typename T1, bool AF1, typename T2, bool AF2 >
575 constexpr bool
576  operator<=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
577 
578 template< typename T1, bool AF1, typename T2, bool AF2 >
579 constexpr bool
580  operator>=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
581 
582 template< typename Type, bool AF >
583 constexpr const DenseIterator<Type,AF>
584  operator+( const DenseIterator<Type,AF>& it, ptrdiff_t inc ) noexcept;
585 
586 template< typename Type, bool AF >
587 constexpr const DenseIterator<Type,AF>
588  operator+( ptrdiff_t inc, const DenseIterator<Type,AF>& it ) noexcept;
589 
590 template< typename Type, bool AF >
591 constexpr const DenseIterator<Type,AF>
592  operator-( const DenseIterator<Type,AF>& it, ptrdiff_t inc ) noexcept;
593 
594 template< typename Type, bool AF >
595 constexpr ptrdiff_t
596  operator-( const DenseIterator<Type,AF>& lhs, const DenseIterator<Type,AF>& rhs ) noexcept;
598 //*************************************************************************************************
599 
600 
601 //*************************************************************************************************
608 template< typename T1 // Element type of the left-hand side iterator
609  , bool AF1 // Alignment flag of the left-hand side iterator
610  , typename T2 // Element type of the right-hand side iterator
611  , bool AF2 > // Alignment flag of the right-hand side iterator
612 inline constexpr bool operator==( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
613 {
614  return lhs.base() == rhs.base();
615 }
616 //*************************************************************************************************
617 
618 
619 //*************************************************************************************************
626 template< typename T1 // Element type of the left-hand side iterator
627  , bool AF1 // Alignment flag of the left-hand side iterator
628  , typename T2 // Element type of the right-hand side iterator
629  , bool AF2 > // Alignment flag of the right-hand side iterator
630 inline constexpr bool operator!=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
631 {
632  return lhs.base() != rhs.base();
633 }
634 //*************************************************************************************************
635 
636 
637 //*************************************************************************************************
644 template< typename T1 // Element type of the left-hand side iterator
645  , bool AF1 // Alignment flag of the left-hand side iterator
646  , typename T2 // Element type of the right-hand side iterator
647  , bool AF2 > // Alignment flag of the right-hand side iterator
648 inline constexpr bool operator<( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
649 {
650  return lhs.base() < rhs.base();
651 }
652 //*************************************************************************************************
653 
654 
655 //*************************************************************************************************
662 template< typename T1 // Element type of the left-hand side iterator
663  , bool AF1 // Alignment flag of the left-hand side iterator
664  , typename T2 // Element type of the right-hand side iterator
665  , bool AF2 > // Alignment flag of the right-hand side iterator
666 inline constexpr bool operator>( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
667 {
668  return lhs.base() > rhs.base();
669 }
670 //*************************************************************************************************
671 
672 
673 //*************************************************************************************************
680 template< typename T1 // Element type of the left-hand side iterator
681  , bool AF1 // Alignment flag of the left-hand side iterator
682  , typename T2 // Element type of the right-hand side iterator
683  , bool AF2 > // Alignment flag of the right-hand side iterator
684 inline constexpr bool operator<=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
685 {
686  return lhs.base() <= rhs.base();
687 }
688 //*************************************************************************************************
689 
690 
691 //*************************************************************************************************
698 template< typename T1 // Element type of the left-hand side iterator
699  , bool AF1 // Alignment flag of the left-hand side iterator
700  , typename T2 // Element type of the right-hand side iterator
701  , bool AF2 > // Alignment flag of the right-hand side iterator
702 inline constexpr bool operator>=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
703 {
704  return lhs.base() >= rhs.base();
705 }
706 //*************************************************************************************************
707 
708 
709 //*************************************************************************************************
716 template< typename Type // Element type of the iterator
717  , bool AF > // Alignment flag of the iterator
718 inline constexpr const DenseIterator<Type,AF> operator+( const DenseIterator<Type,AF>& it, ptrdiff_t inc ) noexcept
719 {
720  return DenseIterator<Type,AF>( it.base() + inc );
721 }
722 //*************************************************************************************************
723 
724 
725 //*************************************************************************************************
732 template< typename Type // Element type of the iterator
733  , bool AF > // Alignment flag of the iterator
734 inline constexpr const DenseIterator<Type,AF> operator+( ptrdiff_t inc, const DenseIterator<Type,AF>& it ) noexcept
735 {
736  return DenseIterator<Type,AF>( it.base() + inc );
737 }
738 //*************************************************************************************************
739 
740 
741 //*************************************************************************************************
748 template< typename Type // Element type of the iterator
749  , bool AF > // Alignment flag of the iterator
750 inline constexpr const DenseIterator<Type,AF> operator-( const DenseIterator<Type,AF>& it, ptrdiff_t dec ) noexcept
751 {
752  return DenseIterator<Type,AF>( it.base() - dec );
753 }
754 //*************************************************************************************************
755 
756 
757 //*************************************************************************************************
764 template< typename Type // Element type of the iterator
765  , bool AF > // Alignment flag of the iterator
766 inline constexpr ptrdiff_t operator-( const DenseIterator<Type,AF>& lhs, const DenseIterator<Type,AF>& rhs ) noexcept
767 {
768  return lhs.base() - rhs.base();
769 }
770 //*************************************************************************************************
771 
772 } // namespace blaze
773 
774 #endif
constexpr DenseIterator & operator-=(ptrdiff_t inc) noexcept
Subtraction assignment operator.
Definition: DenseIterator.h:240
Pointer difference type of the Blaze library.
Type ValueType
Type of the underlying elements.
Definition: DenseIterator.h:63
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: DenseIterator.h:62
ReferenceType reference
Reference return type.
Definition: DenseIterator.h:72
Header file for basic type definitions.
constexpr 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:750
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:412
constexpr ReferenceType operator*() const noexcept
Direct access to the element at the current iterator position.
Definition: DenseIterator.h:346
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > loadu(const T *address) noexcept
Loads a vector of 1-byte integral values.
Definition: Loadu.h:76
typename SIMDTrait< T >::Type SIMDTrait_t
Auxiliary alias declaration for the SIMDTrait class template.The SIMDTrait_t alias declaration provid...
Definition: SIMDTrait.h:315
const SIMDType loada() const noexcept
Aligned load of the SIMD element at the current iterator position.
Definition: DenseIterator.h:435
BLAZE_ALWAYS_INLINE EnableIf_t< IsIntegral_v< T1 > &&HasSize_v< T1, 1UL > > storeu(T1 *address, const SIMDi8< T2 > &value) noexcept
Unaligned store of a vector of 1-byte integral values.
Definition: Storeu.h:75
PointerType pointer
Pointer return type.
Definition: DenseIterator.h:71
SIMDTrait_t< Type > SIMDType
SIMD type of the elements.
Definition: DenseIterator.h:76
Type & ReferenceType
Reference return type.
Definition: DenseIterator.h:65
void storea(const SIMDType &value) const noexcept
Aligned store of the SIMD element at the current iterator position.
Definition: DenseIterator.h:500
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DenseIterator.h:66
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
constexpr DenseIterator & operator--() noexcept
Pre-decrement operator.
Definition: DenseIterator.h:292
constexpr bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:370
constexpr 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:446
void stream(const SIMDType &value) const noexcept
Aligned, non-temporal store of the SIMD element at the current iterator position. ...
Definition: DenseIterator.h:540
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:253
constexpr PointerType operator->() const noexcept
Direct access to the element at the current iterator position.
Definition: DenseIterator.h:361
Header file for all SIMD functionality.
void store(const SIMDType &value) const noexcept
Store of the SIMD element at the current iterator position.
Definition: DenseIterator.h:477
BLAZE_ALWAYS_INLINE EnableIf_t< IsIntegral_v< T1 > &&HasSize_v< T1, 1UL > > storea(T1 *address, const SIMDi8< T2 > &value) noexcept
Aligned store of a vector of 1-byte integral values.
Definition: Storea.h:78
const SIMDType loadu() const noexcept
Unaligned load of the SIMD element at the current iterator position.
Definition: DenseIterator.h:457
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
PointerType ptr_
Pointer to the current element.
Definition: DenseIterator.h:152
constexpr DenseIterator & operator++() noexcept
Pre-increment operator.
Definition: DenseIterator.h:263
Header file for run time assertion macros.
constexpr 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:718
constexpr DenseIterator() noexcept
Default constructor for the DenseIterator class.
Definition: DenseIterator.h:172
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > loada(const T *address) noexcept
Loads a vector of 1-byte integral values.
Definition: Loada.h:79
Implementation of a generic iterator for dense vectors and matrices.The DenseIterator represents a ge...
Definition: DenseIterator.h:58
BLAZE_ALWAYS_INLINE EnableIf_t< IsIntegral_v< T1 > &&HasSize_v< 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:74
BLAZE_ALWAYS_INLINE bool checkAlignment(const T *address)
Checks the alignment of the given address.
Definition: AlignmentCheck.h:68
constexpr ReferenceType operator[](size_t index) const noexcept
Direct access to the underlying elements.
Definition: DenseIterator.h:331
Header file for the alignment check function.
ValueType value_type
Type of the underlying elements.
Definition: DenseIterator.h:70
IteratorCategory iterator_category
The iterator category.
Definition: DenseIterator.h:69
constexpr PointerType base() const noexcept
Low-level access to the underlying member of the iterator.
Definition: DenseIterator.h:384
constexpr DenseIterator & operator+=(ptrdiff_t inc) noexcept
Addition assignment operator.
Definition: DenseIterator.h:223
#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
void storeu(const SIMDType &value) const noexcept
Unaligned store of the SIMD element at the current iterator position.
Definition: DenseIterator.h:520