RowsData.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_VIEWS_ROWS_ROWSDATA_H_
36 #define _BLAZE_MATH_VIEWS_ROWS_ROWSDATA_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/system/Standard.h>
45 #include <blaze/util/Assert.h>
46 #include <blaze/util/SmallArray.h>
47 #include <blaze/util/Types.h>
48 #include <blaze/util/Unused.h>
49 
50 
51 namespace blaze {
52 
53 //=================================================================================================
54 //
55 // CLASS DEFINITION
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
69 template< typename... CRAs > // Compile time row arguments
70 struct RowsData
71 {};
73 //*************************************************************************************************
74 
75 
76 
77 
78 //=================================================================================================
79 //
80 // CLASS TEMPLATE SPECIALIZATION FOR INDEX SEQUENCES
81 //
82 //=================================================================================================
83 
84 //*************************************************************************************************
92 template< size_t I // First row index
93  , size_t... Is > // Remaining row indices
94 struct RowsData< index_sequence<I,Is...> >
95 {
96  protected:
97  //**Compile time flags**************************************************************************
98  static constexpr size_t N = sizeof...( Is ) + 1UL;
99  //**********************************************************************************************
100 
101  public:
102  //**Constructors********************************************************************************
105  template< typename... RRAs >
106  explicit inline RowsData( RRAs... args ) noexcept;
107 
108  RowsData( const RowsData& ) = default;
110  //**********************************************************************************************
111 
112  //**Destructor**********************************************************************************
115  ~RowsData() = default;
117  //**********************************************************************************************
118 
119  //**Assignment operators************************************************************************
122  RowsData& operator=( const RowsData& ) = delete;
124  //**********************************************************************************************
125 
126  //**Utility functions***************************************************************************
129  inline static constexpr decltype(auto) idces() noexcept;
130  inline static constexpr size_t idx ( size_t i ) noexcept;
131  inline static constexpr size_t rows () noexcept;
133  //**********************************************************************************************
134 
135  private:
136  //**Type definitions****************************************************************************
137  using Indices = std::array<size_t,N>;
138  //**********************************************************************************************
139 
140  //**Member variables****************************************************************************
143  static constexpr Indices indices_{ { I, Is... } };
144 
145  //**********************************************************************************************
146 };
148 //*************************************************************************************************
149 
150 
151 //*************************************************************************************************
153 #if BLAZE_CPP14_MODE
154 // Definition and initialization of the static member variables
155 template< size_t I // First row index
156  , size_t... Is > // Remaining row indices
157 constexpr typename RowsData< index_sequence<I,Is...> >::Indices
158  RowsData< index_sequence<I,Is...> >::indices_;
159 #endif
160 
161 //*************************************************************************************************
162 
163 
164 //*************************************************************************************************
170 template< size_t I // First row index
171  , size_t... Is > // Remaining row indices
172 template< typename... RRAs > // Optional row arguments
173 inline RowsData< index_sequence<I,Is...> >::RowsData( RRAs... args ) noexcept
174 {
175  UNUSED_PARAMETER( args... );
176 }
178 //*************************************************************************************************
179 
180 
181 //*************************************************************************************************
187 template< size_t I // First row index
188  , size_t... Is > // Remaining row indices
189 inline constexpr decltype(auto) RowsData< index_sequence<I,Is...> >::idces() noexcept
190 {
191  return index_sequence<I,Is...>();
192 }
194 //*************************************************************************************************
195 
196 
197 //*************************************************************************************************
204 template< size_t I // First row index
205  , size_t... Is > // Remaining row indices
206 inline constexpr size_t RowsData< index_sequence<I,Is...> >::idx( size_t i ) noexcept
207 {
208  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
209  return indices_[i];
210 }
212 //*************************************************************************************************
213 
214 
215 //*************************************************************************************************
221 template< size_t I // First row index
222  , size_t... Is > // Remaining row indices
223 inline constexpr size_t RowsData< index_sequence<I,Is...> >::rows() noexcept
224 {
225  return N;
226 }
228 //*************************************************************************************************
229 
230 
231 
232 
233 //=================================================================================================
234 //
235 // CLASS TEMPLATE SPECIALIZATION FOR INDEX PRODUCING CALLABLES
236 //
237 //=================================================================================================
238 
239 //*************************************************************************************************
247 template< typename P > // Type of the index producer
248 struct RowsData<P>
249 {
250  protected:
251  //**Compile time flags**************************************************************************
252  static constexpr size_t N = 0UL;
253  //**********************************************************************************************
254 
255  public:
256  //**Constructors********************************************************************************
259  template< typename... RRAs >
260  explicit inline RowsData( P p, size_t n, RRAs... args ) noexcept;
261 
262  RowsData( const RowsData& ) = default;
263  RowsData( RowsData&& ) = default;
265  //**********************************************************************************************
266 
267  //**Destructor**********************************************************************************
270  ~RowsData() = default;
272  //**********************************************************************************************
273 
274  //**Assignment operators************************************************************************
277  RowsData& operator=( const RowsData& ) = delete;
278  RowsData& operator=( RowsData&& ) = delete;
280  //**********************************************************************************************
281 
282  //**Utility functions***************************************************************************
285  inline decltype(auto) idces() const noexcept;
286  inline size_t idx ( size_t i ) const noexcept;
287  inline size_t rows () const noexcept;
289  //**********************************************************************************************
290 
291  private:
292  //**Member variables****************************************************************************
295  P p_;
296  size_t n_;
297 
298  //**********************************************************************************************
299 };
301 //*************************************************************************************************
302 
303 
304 //*************************************************************************************************
312 template< typename P > // Type of the index producer
313 template< typename... RRAs > // Optional row arguments
314 inline RowsData<P>::RowsData( P p, size_t n, RRAs... args ) noexcept
315  : p_( p )
316  , n_( n )
317 {
318  UNUSED_PARAMETER( args... );
319 }
321 //*************************************************************************************************
322 
323 
324 //*************************************************************************************************
330 template< typename P > // Type of the index producer
331 inline decltype(auto) RowsData<P>::idces() const noexcept
332 {
333  return std::make_pair( p_, n_ );
334 }
336 //*************************************************************************************************
337 
338 
339 //*************************************************************************************************
346 template< typename P > // Type of the index producer
347 inline size_t RowsData<P>::idx( size_t i ) const noexcept
348 {
349  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
350  return p_(i);
351 }
353 //*************************************************************************************************
354 
355 
356 //*************************************************************************************************
362 template< typename P > // Type of the index producer
363 inline size_t RowsData<P>::rows() const noexcept
364 {
365  return n_;
366 }
368 //*************************************************************************************************
369 
370 
371 
372 
373 //=================================================================================================
374 //
375 // CLASS TEMPLATE SPECIALIZATION FOR ZERO COMPILE TIME ROW ARGUMENTS
376 //
377 //=================================================================================================
378 
379 //*************************************************************************************************
387 template<>
388 struct RowsData<>
389 {
390  protected:
391  //**Compile time flags**************************************************************************
392  static constexpr size_t N = 0UL;
393  //**********************************************************************************************
394 
395  public:
396  //**Constructors********************************************************************************
399  template< typename T, typename... RRAs >
400  explicit inline RowsData( const T* indices, size_t n, RRAs... args );
401 
402  RowsData( const RowsData& ) = default;
403  RowsData( RowsData&& ) = default;
405  //**********************************************************************************************
406 
407  //**Destructor**********************************************************************************
410  ~RowsData() = default;
412  //**********************************************************************************************
413 
414  //**Assignment operators************************************************************************
417  RowsData& operator=( const RowsData& ) = delete;
419  //**********************************************************************************************
420 
421  //**Utility functions***************************************************************************
424  inline decltype(auto) idces() const noexcept;
425  inline size_t idx ( size_t i ) const noexcept;
426  inline size_t rows () const noexcept;
428  //**********************************************************************************************
429 
430  private:
431  //**Type definitions****************************************************************************
432  using Indices = SmallArray<size_t,8UL>;
433  //**********************************************************************************************
434 
435  //**Member variables****************************************************************************
438  Indices indices_;
439 
440  //**********************************************************************************************
441 };
443 //*************************************************************************************************
444 
445 
446 //*************************************************************************************************
454 template< typename T // Type of the row indices
455  , typename... RRAs > // Optional row arguments
456 inline RowsData<>::RowsData( const T* indices, size_t n, RRAs... args )
457  : indices_( indices, indices+n ) // The indices of the rows in the matrix
458 {
459  UNUSED_PARAMETER( args... );
460 }
462 //*************************************************************************************************
463 
464 
465 //*************************************************************************************************
471 inline decltype(auto) RowsData<>::idces() const noexcept
472 {
473  return const_cast<const Indices&>( indices_ );
474 }
476 //*************************************************************************************************
477 
478 
479 //*************************************************************************************************
488 inline size_t RowsData<>::idx( size_t i ) const noexcept
489 {
490  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
491  return indices_[i];
492 }
494 //*************************************************************************************************
495 
496 
497 //*************************************************************************************************
503 inline size_t RowsData<>::rows() const noexcept
504 {
505  return indices_.size();
506 }
508 //*************************************************************************************************
509 
510 
511 
512 
513 //=================================================================================================
514 //
515 // GLOBAL FUNCTIONS
516 //
517 //=================================================================================================
518 
519 //*************************************************************************************************
528 template< typename... CRAs1, typename... CRAs2 >
529 inline constexpr bool
530  compareIndices( const RowsData<CRAs1...>& lhs, const RowsData<CRAs2...>& rhs ) noexcept
531 {
532  if( lhs.rows() != rhs.rows() )
533  return false;
534 
535  for( size_t i=0UL; i<lhs.rows(); ++i ) {
536  if( lhs.idx(i) != rhs.idx(i) )
537  return false;
538  }
539 
540  return true;
541 }
543 //*************************************************************************************************
544 
545 } // namespace blaze
546 
547 #endif
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Header file for the UNUSED_PARAMETER function template.
Header file for basic type definitions.
constexpr void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
STL namespace.
Header file for the SmallArray implementation.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for run time assertion macros.
Header file for the integer_sequence and index_sequence aliases.
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
size_t n_
The current number of columns of the compressed matrix.
Definition: CompressedMatrix.h:3290
C++-standard-specific system settings.