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 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;
87 
88  // No explicitly declared copy constructor.
90  //**********************************************************************************************
91 
92  //**Destructor**********************************************************************************
93  // No explicitly declared destructor.
94  //**********************************************************************************************
95 
96  //**Assignment operators************************************************************************
99  // No explicitly declared copy assignment operator.
100  inline DenseIterator& operator+=( ptrdiff_t inc ) noexcept;
101  inline DenseIterator& operator-=( ptrdiff_t inc ) noexcept;
103  //**********************************************************************************************
104 
105  //**Increment/decrement operators***************************************************************
108  inline DenseIterator& operator++() noexcept;
109  inline const DenseIterator operator++( int ) noexcept;
110  inline DenseIterator& operator--() noexcept;
111  inline const DenseIterator operator--( int ) noexcept;
113  //**********************************************************************************************
114 
115  //**Access operators****************************************************************************
118  inline ReferenceType operator[]( size_t index ) const noexcept;
119  inline ReferenceType operator* () const noexcept;
120  inline PointerType operator->() const noexcept;
122  //**********************************************************************************************
123 
124  //**Utility functions***************************************************************************
127  inline PointerType base() const noexcept;
129  //**********************************************************************************************
130 
131  //**Expression template evaluation functions****************************************************
134  inline const SIMDType load () const noexcept;
135  inline const SIMDType loada () const noexcept;
136  inline const SIMDType loadu () const noexcept;
137  inline void store ( const SIMDType& value ) const noexcept;
138  inline void storea( const SIMDType& value ) const noexcept;
139  inline void storeu( const SIMDType& value ) const noexcept;
140  inline void stream( const SIMDType& value ) const noexcept;
142  //**********************************************************************************************
143 
144  private:
145  //**Member variables****************************************************************************
149 
150  //**********************************************************************************************
151 };
152 //*************************************************************************************************
153 
154 
155 
156 
157 //=================================================================================================
158 //
159 // CONSTRUCTORS
160 //
161 //=================================================================================================
162 
163 //*************************************************************************************************
166 template< typename Type // Type of the elements
167  , bool AF > // Alignment flag
168 inline DenseIterator<Type,AF>::DenseIterator() noexcept
169  : ptr_( nullptr ) // Pointer to the current element
170 {}
171 //*************************************************************************************************
172 
173 
174 //*************************************************************************************************
179 template< typename Type // Type of the elements
180  , bool AF > // Alignment flag
181 inline DenseIterator<Type,AF>::DenseIterator( Type* ptr ) noexcept
182  : ptr_( ptr ) // Pointer to the current element
183 {}
184 //*************************************************************************************************
185 
186 
187 //*************************************************************************************************
192 template< typename Type // Type of the elements
193  , bool AF > // Alignment flag
194 template< typename Other // Type of the foreign elements
195  , bool AF2 > // Alignment flag of the foreign iterator
197  : ptr_( it.base() ) // Pointer to the current element
198 {}
199 //*************************************************************************************************
200 
201 
202 
203 
204 //=================================================================================================
205 //
206 // ASSIGNMENT OPERATORS
207 //
208 //=================================================================================================
209 
210 //*************************************************************************************************
216 template< typename Type // Type of the elements
217  , bool AF > // Alignment flag
219 {
220  ptr_ += inc;
221  return *this;
222 }
223 //*************************************************************************************************
224 
225 
226 //*************************************************************************************************
232 template< typename Type // Type of the elements
233  , bool AF > // Alignment flag
235 {
236  ptr_ -= dec;
237  return *this;
238 }
239 //*************************************************************************************************
240 
241 
242 
243 
244 //=================================================================================================
245 //
246 // INCREMENT/DECREMENT OPERATORS
247 //
248 //=================================================================================================
249 
250 //*************************************************************************************************
255 template< typename Type // Type of the elements
256  , bool AF > // Alignment flag
258 {
259  ++ptr_;
260  return *this;
261 }
262 //*************************************************************************************************
263 
264 
265 //*************************************************************************************************
270 template< typename Type // Type of the elements
271  , bool AF > // Alignment flag
273 {
274  return DenseIterator( ptr_++ );
275 }
276 //*************************************************************************************************
277 
278 
279 //*************************************************************************************************
284 template< typename Type // Type of the elements
285  , bool AF > // Alignment flag
287 {
288  --ptr_;
289  return *this;
290 }
291 //*************************************************************************************************
292 
293 
294 //*************************************************************************************************
299 template< typename Type // Type of the elements
300  , bool AF > // Alignment flag
302 {
303  return DenseIterator( ptr_-- );
304 }
305 //*************************************************************************************************
306 
307 
308 
309 
310 //=================================================================================================
311 //
312 // ACCESS OPERATORS
313 //
314 //=================================================================================================
315 
316 //*************************************************************************************************
322 template< typename Type // Type of the elements
323  , bool AF > // Alignment flag
325  DenseIterator<Type,AF>::operator[]( size_t index ) const noexcept
326 {
327  return ptr_[index];
328 }
329 //*************************************************************************************************
330 
331 
332 //*************************************************************************************************
337 template< typename Type // Type of the elements
338  , bool AF > // Alignment flag
341 {
342  return *ptr_;
343 }
344 //*************************************************************************************************
345 
346 
347 //*************************************************************************************************
352 template< typename Type // Type of the elements
353  , bool AF > // Alignment flag
356 {
357  return ptr_;
358 }
359 //*************************************************************************************************
360 
361 
362 
363 
364 //=================================================================================================
365 //
366 // UTILITY FUNCTIONS
367 //
368 //=================================================================================================
369 
370 //*************************************************************************************************
375 template< typename Type // Type of the elements
376  , bool AF > // Alignment flag
378 {
379  return ptr_;
380 }
381 //*************************************************************************************************
382 
383 
384 
385 
386 //=================================================================================================
387 //
388 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
389 //
390 //=================================================================================================
391 
392 //*************************************************************************************************
402 template< typename Type // Type of the elements
403  , bool AF > // Alignment flag
404 inline const typename DenseIterator<Type,AF>::SIMDType
406 {
407  if( AF )
408  return loada();
409  else
410  return loadu();
411 }
412 //*************************************************************************************************
413 
414 
415 //*************************************************************************************************
425 template< typename Type // Type of the elements
426  , bool AF > // Alignment flag
427 inline const typename DenseIterator<Type,AF>::SIMDType
429 {
430  BLAZE_INTERNAL_ASSERT( checkAlignment( ptr_ ), "Invalid alignment detected" );
431 
432  return blaze::loada( ptr_ );
433 }
434 //*************************************************************************************************
435 
436 
437 //*************************************************************************************************
447 template< typename Type // Type of the elements
448  , bool AF > // Alignment flag
449 inline const typename DenseIterator<Type,AF>::SIMDType
451 {
452  return blaze::loadu( ptr_ );
453 }
454 //*************************************************************************************************
455 
456 
457 //*************************************************************************************************
468 template< typename Type // Type of the elements
469  , bool AF > // Alignment flag
470 inline void DenseIterator<Type,AF>::store( const SIMDType& value ) const noexcept
471 {
472  if( AF )
473  storea( value );
474  else
475  storeu( value );
476 }
477 //*************************************************************************************************
478 
479 
480 //*************************************************************************************************
491 template< typename Type // Type of the elements
492  , bool AF > // Alignment flag
493 inline void DenseIterator<Type,AF>::storea( const SIMDType& value ) const noexcept
494 {
495  blaze::storea( ptr_, value );
496 }
497 //*************************************************************************************************
498 
499 
500 //*************************************************************************************************
511 template< typename Type // Type of the elements
512  , bool AF > // Alignment flag
513 inline void DenseIterator<Type,AF>::storeu( const SIMDType& value ) const noexcept
514 {
515  blaze::storeu( ptr_, value );
516 }
517 //*************************************************************************************************
518 
519 
520 //*************************************************************************************************
531 template< typename Type // Type of the elements
532  , bool AF > // Alignment flag
533 inline void DenseIterator<Type,AF>::stream( const SIMDType& value ) const noexcept
534 {
535  blaze::stream( ptr_, value );
536 }
537 //*************************************************************************************************
538 
539 
540 
541 
542 //=================================================================================================
543 //
544 // GLOBAL OPERATORS
545 //
546 //=================================================================================================
547 
548 //*************************************************************************************************
551 template< typename T1, bool AF1, typename T2, bool AF2 >
552 inline bool operator==( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
553 
554 template< typename T1, bool AF1, typename T2, bool AF2 >
555 inline bool operator!=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
556 
557 template< typename T1, bool AF1, typename T2, bool AF2 >
558 inline bool operator<( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
559 
560 template< typename T1, bool AF1, typename T2, bool AF2 >
561 inline bool operator>( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
562 
563 template< typename T1, bool AF1, typename T2, bool AF2 >
564 inline bool operator<=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
565 
566 template< typename T1, bool AF1, typename T2, bool AF2 >
567 inline bool operator>=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept;
568 
569 template< typename Type, bool AF >
570 inline const DenseIterator<Type,AF> operator+( const DenseIterator<Type,AF>& it, ptrdiff_t inc ) noexcept;
571 
572 template< typename Type, bool AF >
573 inline const DenseIterator<Type,AF> operator+( ptrdiff_t inc, const DenseIterator<Type,AF>& it ) noexcept;
574 
575 template< typename Type, bool AF >
576 inline const DenseIterator<Type,AF> operator-( const DenseIterator<Type,AF>& it, ptrdiff_t inc ) noexcept;
577 
578 template< typename Type, bool AF >
579 inline ptrdiff_t operator-( const DenseIterator<Type,AF>& lhs, const DenseIterator<Type,AF>& rhs ) noexcept;
581 //*************************************************************************************************
582 
583 
584 //*************************************************************************************************
591 template< typename T1 // Element type of the left-hand side iterator
592  , bool AF1 // Alignment flag of the left-hand side iterator
593  , typename T2 // Element type of the right-hand side iterator
594  , bool AF2 > // Alignment flag of the right-hand side iterator
595 inline bool operator==( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
596 {
597  return lhs.base() == rhs.base();
598 }
599 //*************************************************************************************************
600 
601 
602 //*************************************************************************************************
609 template< typename T1 // Element type of the left-hand side iterator
610  , bool AF1 // Alignment flag of the left-hand side iterator
611  , typename T2 // Element type of the right-hand side iterator
612  , bool AF2 > // Alignment flag of the right-hand side iterator
613 inline bool operator!=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
614 {
615  return lhs.base() != rhs.base();
616 }
617 //*************************************************************************************************
618 
619 
620 //*************************************************************************************************
627 template< typename T1 // Element type of the left-hand side iterator
628  , bool AF1 // Alignment flag of the left-hand side iterator
629  , typename T2 // Element type of the right-hand side iterator
630  , bool AF2 > // Alignment flag of the right-hand side iterator
631 inline bool operator<( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
632 {
633  return lhs.base() < rhs.base();
634 }
635 //*************************************************************************************************
636 
637 
638 //*************************************************************************************************
645 template< typename T1 // Element type of the left-hand side iterator
646  , bool AF1 // Alignment flag of the left-hand side iterator
647  , typename T2 // Element type of the right-hand side iterator
648  , bool AF2 > // Alignment flag of the right-hand side iterator
649 inline bool operator>( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
650 {
651  return lhs.base() > rhs.base();
652 }
653 //*************************************************************************************************
654 
655 
656 //*************************************************************************************************
663 template< typename T1 // Element type of the left-hand side iterator
664  , bool AF1 // Alignment flag of the left-hand side iterator
665  , typename T2 // Element type of the right-hand side iterator
666  , bool AF2 > // Alignment flag of the right-hand side iterator
667 inline bool operator<=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
668 {
669  return lhs.base() <= rhs.base();
670 }
671 //*************************************************************************************************
672 
673 
674 //*************************************************************************************************
681 template< typename T1 // Element type of the left-hand side iterator
682  , bool AF1 // Alignment flag of the left-hand side iterator
683  , typename T2 // Element type of the right-hand side iterator
684  , bool AF2 > // Alignment flag of the right-hand side iterator
685 inline bool operator>=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs ) noexcept
686 {
687  return lhs.base() >= rhs.base();
688 }
689 //*************************************************************************************************
690 
691 
692 //*************************************************************************************************
699 template< typename Type // Element type of the iterator
700  , bool AF > // Alignment flag of the iterator
701 inline const DenseIterator<Type,AF> operator+( const DenseIterator<Type,AF>& it, ptrdiff_t inc ) noexcept
702 {
703  return DenseIterator<Type,AF>( it.base() + inc );
704 }
705 //*************************************************************************************************
706 
707 
708 //*************************************************************************************************
715 template< typename Type // Element type of the iterator
716  , bool AF > // Alignment flag of the iterator
717 inline const DenseIterator<Type,AF> operator+( ptrdiff_t inc, const DenseIterator<Type,AF>& it ) noexcept
718 {
719  return DenseIterator<Type,AF>( it.base() + inc );
720 }
721 //*************************************************************************************************
722 
723 
724 //*************************************************************************************************
731 template< typename Type // Element type of the iterator
732  , bool AF > // Alignment flag of the iterator
733 inline const DenseIterator<Type,AF> operator-( const DenseIterator<Type,AF>& it, ptrdiff_t dec ) noexcept
734 {
735  return DenseIterator<Type,AF>( it.base() - dec );
736 }
737 //*************************************************************************************************
738 
739 
740 //*************************************************************************************************
747 template< typename Type // Element type of the iterator
748  , bool AF > // Alignment flag of the iterator
749 inline ptrdiff_t operator-( const DenseIterator<Type,AF>& lhs, const DenseIterator<Type,AF>& rhs ) noexcept
750 {
751  return lhs.base() - rhs.base();
752 }
753 //*************************************************************************************************
754 
755 } // namespace blaze
756 
757 #endif
ReferenceType operator*() const noexcept
Direct access to the element at the current iterator position.
Definition: DenseIterator.h:340
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.
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:405
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:316
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:701
const SIMDType loada() const noexcept
Aligned load of the SIMD element at the current iterator position.
Definition: DenseIterator.h:428
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:733
PointerType pointer
Pointer return type.
Definition: DenseIterator.h:71
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:168
SIMDTrait_< 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:493
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DenseIterator.h:66
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
DenseIterator & operator-=(ptrdiff_t inc) noexcept
Subtraction assignment operator.
Definition: DenseIterator.h:234
DenseIterator & operator--() noexcept
Pre-decrement operator.
Definition: DenseIterator.h:286
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:367
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:443
void stream(const SIMDType &value) const noexcept
Aligned, non-temporal store of the SIMD element at the current iterator position. ...
Definition: DenseIterator.h:533
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:250
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:470
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
const SIMDType loadu() const noexcept
Unaligned load of the SIMD element at the current iterator position.
Definition: DenseIterator.h:450
DenseIterator & operator++() noexcept
Pre-increment operator.
Definition: DenseIterator.h:257
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:290
PointerType ptr_
Pointer to the current element.
Definition: DenseIterator.h:148
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
Header file for run time assertion macros.
PointerType base() const noexcept
Low-level access to the underlying member of the iterator.
Definition: DenseIterator.h:377
PointerType operator->() const noexcept
Direct access to the element at the current iterator position.
Definition: DenseIterator.h:355
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
ReferenceType operator[](size_t index) const noexcept
Direct access to the underlying elements.
Definition: DenseIterator.h:325
Header file for the alignment check function.
DenseIterator & operator+=(ptrdiff_t inc) noexcept
Addition assignment operator.
Definition: DenseIterator.h:218
ValueType value_type
Type of the underlying elements.
Definition: DenseIterator.h:70
IteratorCategory iterator_category
The iterator category.
Definition: DenseIterator.h:69
#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:513