Blaze 3.9
DenseMatrix.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DENSEMATRIX_H_
36#define _BLAZE_MATH_EXPRESSIONS_DENSEMATRIX_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
50#include <blaze/system/Inline.h>
52#include <blaze/util/EnableIf.h>
54
55
56namespace blaze {
57
58//=================================================================================================
59//
60// CLASS DEFINITION
61//
62//=================================================================================================
63
64//*************************************************************************************************
78template< typename MT // Type of the dense matrix
79 , bool SO > // Storage order
81 : public Matrix<MT,SO>
82{
83 protected:
84 //**Special member functions********************************************************************
87 DenseMatrix() = default;
88 DenseMatrix( const DenseMatrix& ) = default;
89 DenseMatrix( DenseMatrix&& ) = default;
90 ~DenseMatrix() = default;
91 DenseMatrix& operator=( const DenseMatrix& ) = default;
92 DenseMatrix& operator=( DenseMatrix&& ) = default;
94 //**********************************************************************************************
95};
96//*************************************************************************************************
97
98
99
100
101//=================================================================================================
102//
103// GLOBAL FUNCTIONS
104//
105//=================================================================================================
106
107//*************************************************************************************************
110template< typename MT, bool SO >
111typename MT::ElementType* data( DenseMatrix<MT,SO>& dm ) noexcept;
112
113template< typename MT, bool SO >
114const typename MT::ElementType* data( const DenseMatrix<MT,SO>& dm ) noexcept;
115
116template< typename MT, bool SO >
117size_t spacing( const DenseMatrix<MT,SO>& dm ) noexcept;
119//*************************************************************************************************
120
121
122//*************************************************************************************************
133template< typename MT // Type of the matrix
134 , bool SO > // Storage order of the matrix
135BLAZE_ALWAYS_INLINE auto data_backend( DenseMatrix<MT,SO>& dm ) noexcept
136 -> DisableIf_t< HasMutableDataAccess_v<MT>, typename MT::ElementType* >
137{
138 MAYBE_UNUSED( dm );
139
140 return nullptr;
141}
143//*************************************************************************************************
144
145
146//*************************************************************************************************
156template< typename MT // Type of the matrix
157 , bool SO > // Storage order of the matrix
158BLAZE_ALWAYS_INLINE auto data_backend( DenseMatrix<MT,SO>& dm ) noexcept
159 -> EnableIf_t< HasMutableDataAccess_v<MT>, typename MT::ElementType* >
160{
161 return (*dm).data();
162}
164//*************************************************************************************************
165
166
167//*************************************************************************************************
180template< typename MT // Type of the matrix
181 , bool SO > // Storage order of the matrix
182BLAZE_ALWAYS_INLINE typename MT::ElementType* data( DenseMatrix<MT,SO>& dm ) noexcept
183{
184 return data_backend( *dm );
185}
186//*************************************************************************************************
187
188
189//*************************************************************************************************
200template< typename MT // Type of the matrix
201 , bool SO > // Storage order of the matrix
202BLAZE_ALWAYS_INLINE auto data_backend( const DenseMatrix<MT,SO>& dm ) noexcept
203 -> DisableIf_t< HasConstDataAccess_v<MT>, const typename MT::ElementType* >
204{
205 MAYBE_UNUSED( dm );
206
207 return nullptr;
208}
210//*************************************************************************************************
211
212
213//*************************************************************************************************
223template< typename MT // Type of the matrix
224 , bool SO > // Storage order of the matrix
225BLAZE_ALWAYS_INLINE auto data_backend( const DenseMatrix<MT,SO>& dm ) noexcept
226 -> EnableIf_t< HasConstDataAccess_v<MT>, const typename MT::ElementType* >
227{
228 return (*dm).data();
229}
231//*************************************************************************************************
232
233
234//*************************************************************************************************
247template< typename MT // Type of the matrix
248 , bool SO > // Storage order of the matrix
249BLAZE_ALWAYS_INLINE const typename MT::ElementType* data( const DenseMatrix<MT,SO>& dm ) noexcept
250{
251 return data_backend( *dm );
252}
253//*************************************************************************************************
254
255
256//*************************************************************************************************
263template< typename MT // Type of the matrix
264 , bool SO > // Storage order of the matrix
266{
267 return (*dm).spacing();
268}
269//*************************************************************************************************
270
271
272//*************************************************************************************************
283template< typename MT > // Type of the matrix
284inline auto resetLower_backend( DenseMatrix<MT,false>& dm )
285 -> DisableIf_t< IsUniform_v<MT> || IsUpper_v<MT> >
286{
287 using blaze::reset;
288
289 const size_t m( (*dm).rows() );
290 const size_t n( (*dm).columns() );
291
292 for( size_t i=1UL; i<m; ++i ) {
293 const size_t jend( min( i, n ) );
294 for( size_t j=0UL; j<jend; ++j ) {
295 reset( (*dm)(i,j) );
296 }
297 }
298}
300//*************************************************************************************************
301
302
303//*************************************************************************************************
314template< typename MT > // Type of the matrix
315inline auto resetLower_backend( DenseMatrix<MT,true>& dm )
316 -> DisableIf_t< IsUniform_v<MT> || IsUpper_v<MT> >
317{
318 using blaze::reset;
319
320 const size_t m ( (*dm).rows() );
321 const size_t n ( (*dm).columns() );
322 const size_t jend( min( m, n ) );
323
324 for( size_t j=0UL; j<jend; ++j ) {
325 for( size_t i=j+1UL; i<m; ++i ) {
326 reset( (*dm)(i,j) );
327 }
328 }
329}
331//*************************************************************************************************
332
333
334//*************************************************************************************************
344template< typename MT // Type of the matrix
345 , bool SO > // Storage order of the matrix
346inline auto resetLower_backend( DenseMatrix<MT,SO>& dm )
347 -> EnableIf_t< IsUniform_v<MT> && !IsUpper_v<MT> >
348{
349 using blaze::reset;
350
351 reset( *dm );
352}
354//*************************************************************************************************
355
356
357//*************************************************************************************************
367template< typename MT // Type of the matrix
368 , bool SO > // Storage order of the matrix
369inline auto resetLower_backend( DenseMatrix<MT,SO>& dm )
370 -> EnableIf_t< IsUpper_v<MT> >
371{
372 MAYBE_UNUSED( dm );
373}
375//*************************************************************************************************
376
377
378//*************************************************************************************************
388template< typename MT // Type of the matrix
389 , bool SO > // Storage order of the matrix
390inline void resetLower( DenseMatrix<MT,SO>& dm )
391{
392 resetLower_backend( *dm );
393}
395//*************************************************************************************************
396
397
398//*************************************************************************************************
409template< typename MT > // Type of the matrix
410inline auto resetUpper_backend( DenseMatrix<MT,false>& dm )
411 -> DisableIf_t< IsUniform_v<MT> || IsLower_v<MT> >
412{
413 using blaze::reset;
414
415 const size_t m ( (*dm).rows() );
416 const size_t n ( (*dm).columns() );
417 const size_t iend( min( m, n ) );
418
419 for( size_t i=0UL; i<iend; ++i ) {
420 for( size_t j=i+1UL; j<n; ++j ) {
421 reset( (*dm)(i,j) );
422 }
423 }
424}
426//*************************************************************************************************
427
428
429//*************************************************************************************************
440template< typename MT > // Type of the matrix
441inline auto resetUpper_backend( DenseMatrix<MT,true>& dm )
442 -> DisableIf_t< IsUniform_v<MT> || IsLower_v<MT> >
443{
444 using blaze::reset;
445
446 const size_t m( (*dm).rows() );
447 const size_t n( (*dm).columns() );
448
449 for( size_t j=1UL; j<n; ++j ) {
450 const size_t iend( min( j, m ) );
451 for( size_t i=0UL; i<iend; ++i ) {
452 reset( (*dm)(i,j) );
453 }
454 }
455}
457//*************************************************************************************************
458
459
460//*************************************************************************************************
470template< typename MT // Type of the matrix
471 , bool SO > // Storage order of the matrix
472inline auto resetUpper_backend( DenseMatrix<MT,SO>& dm )
473 -> EnableIf_t< IsUniform_v<MT> || !IsLower_v<MT> >
474{
475 using blaze::reset;
476
477 reset( *dm );
478}
480//*************************************************************************************************
481
482
483//*************************************************************************************************
493template< typename MT // Type of the matrix
494 , bool SO > // Storage order of the matrix
495inline auto resetUpper_backend( DenseMatrix<MT,SO>& dm )
496 -> EnableIf_t< IsLower_v<MT> >
497{
498 MAYBE_UNUSED( dm );
499}
501//*************************************************************************************************
502
503
504//*************************************************************************************************
514template< typename MT // Type of the matrix
515 , bool SO > // Storage order of the matrix
516inline void resetUpper( DenseMatrix<MT,SO>& dm )
517{
518 resetUpper_backend( *dm );
519}
521//*************************************************************************************************
522
523} // namespace blaze
524
525#endif
Header file for the EnableIf class template.
Header file for the HasConstDataAccess type trait.
Header file for the HasMutableDataAccess type trait.
Header file for the IsLower type trait.
Header file for the IsUniform type trait.
Header file for the IsUpper type trait.
Header file for the MAYBE_UNUSED function template.
Base class for dense matrices.
Definition: DenseMatrix.h:82
Base class for matrices.
Definition: Matrix.h:85
Header file for the Matrix base class.
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1339
BLAZE_ALWAYS_INLINE const MT::ElementType * data(const DenseMatrix< MT, SO > &dm) noexcept
Low-level data access to the dense matrix elements.
Definition: DenseMatrix.h:249
BLAZE_ALWAYS_INLINE size_t spacing(const DenseMatrix< MT, SO > &dm) noexcept
Returns the spacing between the beginning of two rows/columns.
Definition: DenseMatrix.h:265
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:175
Header file for the reset shim.
System settings for the inline keywords.
Header file for the generic min algorithm.