Blaze  3.6
UpperProxy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_UPPERMATRIX_UPPERPROXY_H_
36 #define _BLAZE_MATH_ADAPTORS_UPPERMATRIX_UPPERPROXY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
52 #include <blaze/math/Exception.h>
54 #include <blaze/math/proxy/Proxy.h>
55 #include <blaze/math/shims/Clear.h>
57 #include <blaze/math/shims/IsNaN.h>
58 #include <blaze/math/shims/IsOne.h>
61 #include <blaze/math/shims/Reset.h>
68 #include <blaze/util/Types.h>
69 
70 
71 namespace blaze {
72 
73 //=================================================================================================
74 //
75 // CLASS DEFINITION
76 //
77 //=================================================================================================
78 
79 //*************************************************************************************************
99 template< typename MT > // Type of the adapted matrix
101  : public Proxy< UpperProxy<MT>, ElementType_t<MT> >
102 {
103  private:
104  //**Type definitions****************************************************************************
107  //**********************************************************************************************
108 
109  public:
110  //**Type definitions****************************************************************************
114  //**********************************************************************************************
115 
116  //**Constructors********************************************************************************
119  explicit inline UpperProxy( MT& matrix, size_t row, size_t column );
120  inline UpperProxy( const UpperProxy& up );
122  //**********************************************************************************************
123 
124  //**Destructor**********************************************************************************
127  ~UpperProxy() = default;
129  //**********************************************************************************************
130 
131  //**Assignment operators************************************************************************
134  inline const UpperProxy& operator=( const UpperProxy& up ) const;
135 
136  template< typename T >
137  inline const UpperProxy& operator=( initializer_list<T> list ) const;
138 
139  template< typename T >
140  inline const UpperProxy& operator=( initializer_list< initializer_list<T> > list ) const;
141 
142  template< typename T > inline const UpperProxy& operator= ( const T& value ) const;
143  template< typename T > inline const UpperProxy& operator+=( const T& value ) const;
144  template< typename T > inline const UpperProxy& operator-=( const T& value ) const;
145  template< typename T > inline const UpperProxy& operator*=( const T& value ) const;
146  template< typename T > inline const UpperProxy& operator/=( const T& value ) const;
147  template< typename T > inline const UpperProxy& operator%=( const T& value ) const;
149  //**********************************************************************************************
150 
151  //**Access operators****************************************************************************
154  inline const UpperProxy* operator->() const noexcept;
156  //**********************************************************************************************
157 
158  //**Utility functions***************************************************************************
161  inline RawReference get() const noexcept;
162  inline bool isRestricted() const noexcept;
164  //**********************************************************************************************
165 
166  //**Conversion operator*************************************************************************
169  inline operator ConstReference() const noexcept;
171  //**********************************************************************************************
172 
173  private:
174  //**Member variables****************************************************************************
178  const bool restricted_;
179 
183  //**********************************************************************************************
184 
185  //**Compile time checks*************************************************************************
200  //**********************************************************************************************
201 };
202 //*************************************************************************************************
203 
204 
205 
206 
207 //=================================================================================================
208 //
209 // CONSTRUCTORS
210 //
211 //=================================================================================================
212 
213 //*************************************************************************************************
220 template< typename MT > // Type of the adapted matrix
221 inline UpperProxy<MT>::UpperProxy( MT& matrix, size_t row, size_t column )
222  : value_ ( matrix( row, column ) ) // Reference to the accessed matrix element
223  , restricted_( column < row ) // Access flag for the accessed matrix element
224 {}
225 //*************************************************************************************************
226 
227 
228 //*************************************************************************************************
233 template< typename MT > // Type of the adapted matrix
235  : value_ ( up.value_ ) // Reference to the accessed matrix element
236  , restricted_( up.restricted_ ) // Access flag for the accessed matrix element
237 {}
238 //*************************************************************************************************
239 
240 
241 
242 
243 //=================================================================================================
244 //
245 // OPERATORS
246 //
247 //=================================================================================================
248 
249 //*************************************************************************************************
259 template< typename MT > // Type of the adapted matrix
260 inline const UpperProxy<MT>& UpperProxy<MT>::operator=( const UpperProxy& up ) const
261 {
262  if( restricted_ ) {
263  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
264  }
265 
266  value_ = up.value_;
267 
268  return *this;
269 }
270 //*************************************************************************************************
271 
272 
273 //*************************************************************************************************
283 template< typename MT > // Type of the adapted matrix
284 template< typename T > // Type of the right-hand side value
286 {
287  if( restricted_ ) {
288  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
289  }
290 
291  value_ = list;
292 
293  return *this;
294 }
295 //*************************************************************************************************
296 
297 
298 //*************************************************************************************************
308 template< typename MT > // Type of the adapted matrix
309 template< typename T > // Type of the right-hand side value
311 {
312  if( restricted_ ) {
313  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
314  }
315 
316  value_ = list;
317 
318  return *this;
319 }
320 //*************************************************************************************************
321 
322 
323 //*************************************************************************************************
333 template< typename MT > // Type of the adapted matrix
334 template< typename T > // Type of the right-hand side value
335 inline const UpperProxy<MT>& UpperProxy<MT>::operator=( const T& value ) const
336 {
337  if( restricted_ ) {
338  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
339  }
340 
341  value_ = value;
342 
343  return *this;
344 }
345 //*************************************************************************************************
346 
347 
348 //*************************************************************************************************
358 template< typename MT > // Type of the adapted matrix
359 template< typename T > // Type of the right-hand side value
360 inline const UpperProxy<MT>& UpperProxy<MT>::operator+=( const T& value ) const
361 {
362  if( restricted_ ) {
363  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
364  }
365 
366  value_ += value;
367 
368  return *this;
369 }
370 //*************************************************************************************************
371 
372 
373 //*************************************************************************************************
383 template< typename MT > // Type of the adapted matrix
384 template< typename T > // Type of the right-hand side value
385 inline const UpperProxy<MT>& UpperProxy<MT>::operator-=( const T& value ) const
386 {
387  if( restricted_ ) {
388  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
389  }
390 
391  value_ -= value;
392 
393  return *this;
394 }
395 //*************************************************************************************************
396 
397 
398 //*************************************************************************************************
408 template< typename MT > // Type of the adapted matrix
409 template< typename T > // Type of the right-hand side value
410 inline const UpperProxy<MT>& UpperProxy<MT>::operator*=( const T& value ) const
411 {
412  if( restricted_ ) {
413  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
414  }
415 
416  value_ *= value;
417 
418  return *this;
419 }
420 //*************************************************************************************************
421 
422 
423 //*************************************************************************************************
433 template< typename MT > // Type of the adapted matrix
434 template< typename T > // Type of the right-hand side value
435 inline const UpperProxy<MT>& UpperProxy<MT>::operator/=( const T& value ) const
436 {
437  if( restricted_ ) {
438  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
439  }
440 
441  value_ /= value;
442 
443  return *this;
444 }
445 //*************************************************************************************************
446 
447 
448 //*************************************************************************************************
458 template< typename MT > // Type of the adapted matrix
459 template< typename T > // Type of the right-hand side value
460 inline const UpperProxy<MT>& UpperProxy<MT>::operator%=( const T& value ) const
461 {
462  if( restricted_ ) {
463  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
464  }
465 
466  value_ %= value;
467 
468  return *this;
469 }
470 //*************************************************************************************************
471 
472 
473 
474 
475 //=================================================================================================
476 //
477 // ACCESS OPERATORS
478 //
479 //=================================================================================================
480 
481 //*************************************************************************************************
486 template< typename MT > // Type of the adapted matrix
487 inline const UpperProxy<MT>* UpperProxy<MT>::operator->() const noexcept
488 {
489  return this;
490 }
491 //*************************************************************************************************
492 
493 
494 
495 
496 //=================================================================================================
497 //
498 // UTILITY FUNCTIONS
499 //
500 //=================================================================================================
501 
502 //*************************************************************************************************
507 template< typename MT > // Type of the adapted matrix
508 inline typename UpperProxy<MT>::RawReference UpperProxy<MT>::get() const noexcept
509 {
510  return value_;
511 }
512 //*************************************************************************************************
513 
514 
515 //*************************************************************************************************
520 template< typename MT > // Type of the adapted matrix
521 inline bool UpperProxy<MT>::isRestricted() const noexcept
522 {
523  return restricted_;
524 }
525 //*************************************************************************************************
526 
527 
528 
529 
530 //=================================================================================================
531 //
532 // CONVERSION OPERATOR
533 //
534 //=================================================================================================
535 
536 //*************************************************************************************************
541 template< typename MT > // Type of the adapted matrix
543 {
544  return static_cast<ConstReference>( value_ );
545 }
546 //*************************************************************************************************
547 
548 
549 
550 
551 //=================================================================================================
552 //
553 // GLOBAL FUNCTIONS
554 //
555 //=================================================================================================
556 
557 //*************************************************************************************************
560 template< typename MT >
561 void reset( const UpperProxy<MT>& proxy );
562 
563 template< typename MT >
564 void clear( const UpperProxy<MT>& proxy );
565 
566 template< bool RF, typename MT >
567 bool isDefault( const UpperProxy<MT>& proxy );
568 
569 template< bool RF, typename MT >
570 bool isReal( const UpperProxy<MT>& proxy );
571 
572 template< bool RF, typename MT >
573 bool isZero( const UpperProxy<MT>& proxy );
574 
575 template< bool RF, typename MT >
576 bool isOne( const UpperProxy<MT>& proxy );
577 
578 template< typename MT >
579 bool isnan( const UpperProxy<MT>& proxy );
581 //*************************************************************************************************
582 
583 
584 //*************************************************************************************************
594 template< typename MT >
595 inline void reset( const UpperProxy<MT>& proxy )
596 {
597  using blaze::reset;
598 
599  reset( proxy.get() );
600 }
601 //*************************************************************************************************
602 
603 
604 //*************************************************************************************************
614 template< typename MT >
615 inline void clear( const UpperProxy<MT>& proxy )
616 {
617  using blaze::clear;
618 
619  clear( proxy.get() );
620 }
621 //*************************************************************************************************
622 
623 
624 //*************************************************************************************************
634 template< bool RF, typename MT >
635 inline bool isDefault( const UpperProxy<MT>& proxy )
636 {
637  using blaze::isDefault;
638 
639  return isDefault<RF>( proxy.get() );
640 }
641 //*************************************************************************************************
642 
643 
644 //*************************************************************************************************
656 template< bool RF, typename MT >
657 inline bool isReal( const UpperProxy<MT>& proxy )
658 {
659  using blaze::isReal;
660 
661  return isReal<RF>( proxy.get() );
662 }
663 //*************************************************************************************************
664 
665 
666 //*************************************************************************************************
676 template< bool RF, typename MT >
677 inline bool isZero( const UpperProxy<MT>& proxy )
678 {
679  using blaze::isZero;
680 
681  return isZero<RF>( proxy.get() );
682 }
683 //*************************************************************************************************
684 
685 
686 //*************************************************************************************************
696 template< bool RF, typename MT >
697 inline bool isOne( const UpperProxy<MT>& proxy )
698 {
699  using blaze::isOne;
700 
701  return isOne<RF>( proxy.get() );
702 }
703 //*************************************************************************************************
704 
705 
706 //*************************************************************************************************
716 template< typename MT >
717 inline bool isnan( const UpperProxy<MT>& proxy )
718 {
719  using blaze::isnan;
720 
721  return isnan( proxy.get() );
722 }
723 //*************************************************************************************************
724 
725 } // namespace blaze
726 
727 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:657
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.In case the given data type T is a transformation expression (i....
Definition: Transformation.h:81
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,...
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
Constraint on the data type.
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
Constraint on the data type.
Header file for basic type definitions.
AddReference_t< ReferenceType > RawReference
Reference-to-non-const to the represented element.
Definition: UpperProxy.h:112
RawReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: UpperProxy.h:508
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.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i....
Definition: Computation.h:81
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: UpperProxy.h:111
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type,...
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
bool isRestricted() const noexcept
Returns whether the proxy represents a restricted matrix element..
Definition: UpperProxy.h:521
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:677
const bool restricted_
Access flag for the accessed matrix element.
Definition: UpperProxy.h:178
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.
Constraint on the data type.
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:717
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:615
Header file for the isOne shim.
ReferenceType value_
Reference to the accessed matrix element.
Definition: UpperProxy.h:177
#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,...
Definition: Symmetric.h:79
const UpperProxy & operator=(const UpperProxy &up) const
Copy assignment operator for UpperProxy.
Definition: UpperProxy.h:260
Constraint on the data type.
AddConst_t< typename MT::Reference > ReferenceType
Reference type of the underlying matrix type.
Definition: UpperProxy.h:106
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
const UpperProxy * operator->() const noexcept
Direct access to the accessed matrix element.
Definition: UpperProxy.h:487
#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
#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,...
Definition: Reference.h:79
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:697
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VIEW_TYPE(T)
Constraint on the data type.In case the given data type T is a view type (i.e. a subvector,...
Definition: View.h:81
UpperProxy(MT &matrix, size_t row, size_t column)
Initialization constructor for a UpperProxy.
Definition: UpperProxy.h:221
Access proxy for upper triangular matrices.The UpperProxy provides controlled access to the elements ...
Definition: UpperProxy.h:100
Initializer list type of the Blaze library.
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:635
#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,...
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
const RepresentedType & ConstReference
Reference-to-const to the represented element.
Definition: UpperProxy.h:113
Constraint on the data type.
Header file for the isReal shim.
Header file for the clear shim.