DiagonalProxy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_DIAGONALPROXY_H_
36 #define _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_DIAGONALPROXY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
50 #include <blaze/math/Exception.h>
52 #include <blaze/math/proxy/Proxy.h>
53 #include <blaze/math/shims/Clear.h>
55 #include <blaze/math/shims/IsNaN.h>
56 #include <blaze/math/shims/IsOne.h>
59 #include <blaze/math/shims/Reset.h>
66 #include <blaze/util/Types.h>
67 
68 
69 namespace blaze {
70 
71 //=================================================================================================
72 //
73 // CLASS DEFINITION
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
97 template< typename MT > // Type of the adapted matrix
99  : public Proxy< DiagonalProxy<MT>, ElementType_t<MT> >
100 {
101  private:
102  //**Type definitions****************************************************************************
105  //**********************************************************************************************
106 
107  public:
108  //**Type definitions****************************************************************************
112  //**********************************************************************************************
113 
114  //**Constructors********************************************************************************
117  explicit inline DiagonalProxy( MT& matrix, size_t row, size_t column );
118  inline DiagonalProxy( const DiagonalProxy& dp );
120  //**********************************************************************************************
121 
122  //**Destructor**********************************************************************************
125  ~DiagonalProxy() = default;
127  //**********************************************************************************************
128 
129  //**Assignment operators************************************************************************
132  inline DiagonalProxy& operator=( const DiagonalProxy& dp );
133 
134  template< typename T >
136 
137  template< typename T >
139 
140  template< typename T > inline DiagonalProxy& operator= ( const T& value );
141  template< typename T > inline DiagonalProxy& operator+=( const T& value );
142  template< typename T > inline DiagonalProxy& operator-=( const T& value );
143  template< typename T > inline DiagonalProxy& operator*=( const T& value );
144  template< typename T > inline DiagonalProxy& operator/=( const T& value );
145  template< typename T > inline DiagonalProxy& operator%=( const T& value );
147  //**********************************************************************************************
148 
149  //**Access operators****************************************************************************
152  inline const DiagonalProxy* operator->() const noexcept;
154  //**********************************************************************************************
155 
156  //**Utility functions***************************************************************************
159  inline RawReference get() const noexcept;
160  inline bool isRestricted() const noexcept;
162  //**********************************************************************************************
163 
164  //**Conversion operator*************************************************************************
167  inline operator ConstReference() const noexcept;
169  //**********************************************************************************************
170 
171  private:
172  //**Member variables****************************************************************************
176  const bool restricted_;
177 
181  //**********************************************************************************************
182 
183  //**Compile time checks*************************************************************************
196  //**********************************************************************************************
197 };
198 //*************************************************************************************************
199 
200 
201 
202 
203 //=================================================================================================
204 //
205 // CONSTRUCTORS
206 //
207 //=================================================================================================
208 
209 //*************************************************************************************************
216 template< typename MT > // Type of the adapted matrix
217 inline DiagonalProxy<MT>::DiagonalProxy( MT& matrix, size_t row, size_t column )
218  : value_ ( matrix( row, column ) ) // Reference to the accessed matrix element
219  , restricted_( row != column ) // Access flag for the accessed matrix element
220 {}
221 //*************************************************************************************************
222 
223 
224 //*************************************************************************************************
229 template< typename MT > // Type of the adapted matrix
231  : value_ ( dp.value_ ) // Reference to the accessed matrix element
232  , restricted_( dp.restricted_ ) // Access flag for the accessed matrix element
233 {}
234 //*************************************************************************************************
235 
236 
237 
238 
239 //=================================================================================================
240 //
241 // OPERATORS
242 //
243 //=================================================================================================
244 
245 //*************************************************************************************************
255 template< typename MT > // Type of the adapted matrix
257 {
258  if( restricted_ ) {
259  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
260  }
261 
262  value_ = dp.value_;
263 
264  return *this;
265 }
266 //*************************************************************************************************
267 
268 
269 //*************************************************************************************************
279 template< typename MT > // Type of the adapted matrix
280 template< typename T > // Type of the right-hand side value
282 {
283  if( restricted_ ) {
284  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
285  }
286 
287  value_ = list;
288 
289  return *this;
290 }
291 //*************************************************************************************************
292 
293 
294 //*************************************************************************************************
304 template< typename MT > // Type of the adapted matrix
305 template< typename T > // Type of the right-hand side value
307 {
308  if( restricted_ ) {
309  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
310  }
311 
312  value_ = list;
313 
314  return *this;
315 }
316 //*************************************************************************************************
317 
318 
319 //*************************************************************************************************
329 template< typename MT > // Type of the adapted matrix
330 template< typename T > // Type of the right-hand side value
332 {
333  if( restricted_ ) {
334  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
335  }
336 
337  value_ = value;
338 
339  return *this;
340 }
341 //*************************************************************************************************
342 
343 
344 //*************************************************************************************************
354 template< typename MT > // Type of the adapted matrix
355 template< typename T > // Type of the right-hand side value
357 {
358  if( restricted_ ) {
359  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
360  }
361 
362  value_ += value;
363 
364  return *this;
365 }
366 //*************************************************************************************************
367 
368 
369 //*************************************************************************************************
379 template< typename MT > // Type of the adapted matrix
380 template< typename T > // Type of the right-hand side value
382 {
383  if( restricted_ ) {
384  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
385  }
386 
387  value_ -= value;
388 
389  return *this;
390 }
391 //*************************************************************************************************
392 
393 
394 //*************************************************************************************************
404 template< typename MT > // Type of the adapted matrix
405 template< typename T > // Type of the right-hand side value
407 {
408  if( restricted_ ) {
409  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
410  }
411 
412  value_ *= value;
413 
414  return *this;
415 }
416 //*************************************************************************************************
417 
418 
419 //*************************************************************************************************
429 template< typename MT > // Type of the adapted matrix
430 template< typename T > // Type of the right-hand side value
432 {
433  if( restricted_ ) {
434  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
435  }
436 
437  value_ /= value;
438 
439  return *this;
440 }
441 //*************************************************************************************************
442 
443 
444 //*************************************************************************************************
454 template< typename MT > // Type of the adapted matrix
455 template< typename T > // Type of the right-hand side value
457 {
458  if( restricted_ ) {
459  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
460  }
461 
462  value_ %= value;
463 
464  return *this;
465 }
466 //*************************************************************************************************
467 
468 
469 
470 
471 //=================================================================================================
472 //
473 // ACCESS OPERATORS
474 //
475 //=================================================================================================
476 
477 //*************************************************************************************************
482 template< typename MT > // Type of the adapted matrix
483 inline const DiagonalProxy<MT>* DiagonalProxy<MT>::operator->() const noexcept
484 {
485  return this;
486 }
487 //*************************************************************************************************
488 
489 
490 
491 
492 //=================================================================================================
493 //
494 // UTILITY FUNCTIONS
495 //
496 //=================================================================================================
497 
498 //*************************************************************************************************
503 template< typename MT > // Type of the adapted matrix
505 {
506  return value_;
507 }
508 //*************************************************************************************************
509 
510 
511 //*************************************************************************************************
516 template< typename MT > // Type of the adapted matrix
517 inline bool DiagonalProxy<MT>::isRestricted() const noexcept
518 {
519  return restricted_;
520 }
521 //*************************************************************************************************
522 
523 
524 
525 
526 //=================================================================================================
527 //
528 // CONVERSION OPERATOR
529 //
530 //=================================================================================================
531 
532 //*************************************************************************************************
537 template< typename MT > // Type of the adapted matrix
539 {
540  return static_cast<ConstReference>( value_ );
541 }
542 //*************************************************************************************************
543 
544 
545 
546 
547 //=================================================================================================
548 //
549 // GLOBAL FUNCTIONS
550 //
551 //=================================================================================================
552 
553 //*************************************************************************************************
556 template< typename MT >
557 void reset( const DiagonalProxy<MT>& proxy );
558 
559 template< typename MT >
560 void clear( const DiagonalProxy<MT>& proxy );
561 
562 template< bool RF, typename MT >
563 bool isDefault( const DiagonalProxy<MT>& proxy );
564 
565 template< bool RF, typename MT >
566 bool isReal( const DiagonalProxy<MT>& proxy );
567 
568 template< bool RF, typename MT >
569 bool isZero( const DiagonalProxy<MT>& proxy );
570 
571 template< bool RF, typename MT >
572 bool isOne( const DiagonalProxy<MT>& proxy );
573 
574 template< typename MT >
575 bool isnan( const DiagonalProxy<MT>& proxy );
577 //*************************************************************************************************
578 
579 
580 //*************************************************************************************************
590 template< typename MT >
591 inline void reset( const DiagonalProxy<MT>& proxy )
592 {
593  using blaze::reset;
594 
595  reset( proxy.get() );
596 }
597 //*************************************************************************************************
598 
599 
600 //*************************************************************************************************
610 template< typename MT >
611 inline void clear( const DiagonalProxy<MT>& proxy )
612 {
613  using blaze::clear;
614 
615  clear( proxy.get() );
616 }
617 //*************************************************************************************************
618 
619 
620 //*************************************************************************************************
630 template< bool RF, typename MT >
631 inline bool isDefault( const DiagonalProxy<MT>& proxy )
632 {
633  using blaze::isDefault;
634 
635  return isDefault<RF>( proxy.get() );
636 }
637 //*************************************************************************************************
638 
639 
640 //*************************************************************************************************
652 template< bool RF, typename MT >
653 inline bool isReal( const DiagonalProxy<MT>& proxy )
654 {
655  using blaze::isReal;
656 
657  return isReal<RF>( proxy.get() );
658 }
659 //*************************************************************************************************
660 
661 
662 //*************************************************************************************************
672 template< bool RF, typename MT >
673 inline bool isZero( const DiagonalProxy<MT>& proxy )
674 {
675  using blaze::isZero;
676 
677  return isZero<RF>( proxy.get() );
678 }
679 //*************************************************************************************************
680 
681 
682 //*************************************************************************************************
692 template< bool RF, typename MT >
693 inline bool isOne( const DiagonalProxy<MT>& proxy )
694 {
695  using blaze::isOne;
696 
697  return isOne<RF>( proxy.get() );
698 }
699 //*************************************************************************************************
700 
701 
702 //*************************************************************************************************
712 template< typename MT >
713 inline bool isnan( const DiagonalProxy<MT>& proxy )
714 {
715  using blaze::isnan;
716 
717  return isnan( proxy.get() );
718 }
719 //*************************************************************************************************
720 
721 } // namespace blaze
722 
723 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:653
Header file for the isnan shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:79
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for the AddConst type trait.
Header file for auxiliary alias declarations.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:133
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: DiagonalProxy.h:109
Header file for basic type definitions.
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
Header file for the isZero shim.
const RepresentedType & ConstReference
Reference-to-const to the represented element.
Definition: DiagonalProxy.h:111
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
Access proxy for diagonal matrices.The DiagonalProxy provides controlled access to the elements of a ...
Definition: DiagonalProxy.h:98
DiagonalProxy & operator=(const DiagonalProxy &dp)
Copy assignment operator for DiagonalProxy.
Definition: DiagonalProxy.h:256
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:3084
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:79
Header file for the reset shim.
Header file for the extended initializer_list functionality.
Constraint on the data type.
Header file for the Proxy class.
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
Constraint on the data type.
Constraint on the data type.
typename AddReference< T >::Type AddReference_t
Auxiliary alias declaration for the AddReference type trait.The AddReference_t alias declaration prov...
Definition: AddReference.h:95
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:673
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:79
Constraint on the data type.
RawReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: DiagonalProxy.h:504
const bool restricted_
Access flag for the accessed matrix element.
Definition: DiagonalProxy.h:176
Constraint on the data type.
bool isRestricted() const noexcept
Returns whether the proxy represents a restricted matrix element..
Definition: DiagonalProxy.h:517
typename AddConst< T >::Type AddConst_t
Auxiliary alias declaration for the AddConst type trait.The AddConst_t alias declaration provides a c...
Definition: AddConst.h:95
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:713
Header file for the exception macros of the math module.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a upper triangular matrix type...
Definition: Upper.h:81
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:611
Header file for the isOne shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
Constraint on the data type.
Constraint on the data type.
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:133
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower triangular matrix type...
Definition: Lower.h:81
ReferenceType value_
Reference to the accessed matrix element.
Definition: DiagonalProxy.h:175
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:79
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:693
Header file for the isDefault shim.
const DiagonalProxy * operator->() const noexcept
Direct access to the accessed matrix element.
Definition: DiagonalProxy.h:483
AddReference_t< ReferenceType > RawReference
Reference-to-non-const to the represented element.
Definition: DiagonalProxy.h:110
Constraint on the data type.
Constraint on the data type.
DiagonalProxy(MT &matrix, size_t row, size_t column)
Initialization constructor for a DiagonalProxy.
Definition: DiagonalProxy.h:217
AddConst_t< typename MT::Reference > ReferenceType
Reference type of the underlying matrix type.
Definition: DiagonalProxy.h:104
Initializer list type of the Blaze library.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE(T)
Constraint on the data type.In case the given data type T is an expression (i.e. a type derived from ...
Definition: Expression.h:81
Header file for the AddReference type trait.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:631
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is an Hermitian matrix type, a compilation error is created.
Definition: Hermitian.h:79
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a N-dimensional matrix type...
Definition: Matrix.h:61
Header file for the isReal shim.
Header file for the clear shim.