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>
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< UpperProxy<MT>, ElementType_<MT> >
100 {
101  private:
102  //**Type definitions****************************************************************************
105  //**********************************************************************************************
106 
107  public:
108  //**Type definitions****************************************************************************
112  //**********************************************************************************************
113 
114  //**Constructors********************************************************************************
117  explicit inline UpperProxy( MT& matrix, size_t row, size_t column );
118  inline UpperProxy( const UpperProxy& up );
120  //**********************************************************************************************
121 
122  //**Destructor**********************************************************************************
123  // No explicitly declared destructor.
124  //**********************************************************************************************
125 
126  //**Assignment operators************************************************************************
129  inline const UpperProxy& operator=( const UpperProxy& up ) const;
130 
131  template< typename T >
132  inline const UpperProxy& operator=( initializer_list<T> list ) const;
133 
134  template< typename T >
135  inline const UpperProxy& operator=( initializer_list< initializer_list<T> > list ) const;
136 
137  template< typename T > inline const UpperProxy& operator= ( const T& value ) const;
138  template< typename T > inline const UpperProxy& operator+=( const T& value ) const;
139  template< typename T > inline const UpperProxy& operator-=( const T& value ) const;
140  template< typename T > inline const UpperProxy& operator*=( const T& value ) const;
141  template< typename T > inline const UpperProxy& operator/=( const T& value ) const;
142  template< typename T > inline const UpperProxy& operator%=( const T& value ) const;
144  //**********************************************************************************************
145 
146  //**Utility functions***************************************************************************
149  inline RawReference get() const noexcept;
150  inline bool isRestricted() const noexcept;
152  //**********************************************************************************************
153 
154  //**Conversion operator*************************************************************************
157  inline operator ConstReference() const noexcept;
159  //**********************************************************************************************
160 
161  private:
162  //**Member variables****************************************************************************
166  const bool restricted_;
167 
171  //**********************************************************************************************
172 
173  //**Compile time checks*************************************************************************
186  //**********************************************************************************************
187 };
188 //*************************************************************************************************
189 
190 
191 
192 
193 //=================================================================================================
194 //
195 // CONSTRUCTORS
196 //
197 //=================================================================================================
198 
199 //*************************************************************************************************
206 template< typename MT > // Type of the adapted matrix
207 inline UpperProxy<MT>::UpperProxy( MT& matrix, size_t row, size_t column )
208  : value_ ( matrix( row, column ) ) // Reference to the accessed matrix element
209  , restricted_( column < row ) // Access flag for the accessed matrix element
210 {}
211 //*************************************************************************************************
212 
213 
214 //*************************************************************************************************
219 template< typename MT > // Type of the adapted matrix
221  : value_ ( up.value_ ) // Reference to the accessed matrix element
222  , restricted_( up.restricted_ ) // Access flag for the accessed matrix element
223 {}
224 //*************************************************************************************************
225 
226 
227 
228 
229 //=================================================================================================
230 //
231 // OPERATORS
232 //
233 //=================================================================================================
234 
235 //*************************************************************************************************
245 template< typename MT > // Type of the adapted matrix
246 inline const UpperProxy<MT>& UpperProxy<MT>::operator=( const UpperProxy& up ) const
247 {
248  if( restricted_ ) {
249  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
250  }
251 
252  value_ = up.value_;
253 
254  return *this;
255 }
256 //*************************************************************************************************
257 
258 
259 //*************************************************************************************************
269 template< typename MT > // Type of the adapted matrix
270 template< typename T > // Type of the right-hand side value
272 {
273  if( restricted_ ) {
274  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
275  }
276 
277  value_ = list;
278 
279  return *this;
280 }
281 //*************************************************************************************************
282 
283 
284 //*************************************************************************************************
294 template< typename MT > // Type of the adapted matrix
295 template< typename T > // Type of the right-hand side value
297 {
298  if( restricted_ ) {
299  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
300  }
301 
302  value_ = list;
303 
304  return *this;
305 }
306 //*************************************************************************************************
307 
308 
309 //*************************************************************************************************
319 template< typename MT > // Type of the adapted matrix
320 template< typename T > // Type of the right-hand side value
321 inline const UpperProxy<MT>& UpperProxy<MT>::operator=( const T& value ) const
322 {
323  if( restricted_ ) {
324  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
325  }
326 
327  value_ = value;
328 
329  return *this;
330 }
331 //*************************************************************************************************
332 
333 
334 //*************************************************************************************************
344 template< typename MT > // Type of the adapted matrix
345 template< typename T > // Type of the right-hand side value
346 inline const UpperProxy<MT>& UpperProxy<MT>::operator+=( const T& value ) const
347 {
348  if( restricted_ ) {
349  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
350  }
351 
352  value_ += value;
353 
354  return *this;
355 }
356 //*************************************************************************************************
357 
358 
359 //*************************************************************************************************
369 template< typename MT > // Type of the adapted matrix
370 template< typename T > // Type of the right-hand side value
371 inline const UpperProxy<MT>& UpperProxy<MT>::operator-=( const T& value ) const
372 {
373  if( restricted_ ) {
374  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
375  }
376 
377  value_ -= value;
378 
379  return *this;
380 }
381 //*************************************************************************************************
382 
383 
384 //*************************************************************************************************
394 template< typename MT > // Type of the adapted matrix
395 template< typename T > // Type of the right-hand side value
396 inline const UpperProxy<MT>& UpperProxy<MT>::operator*=( const T& value ) const
397 {
398  if( restricted_ ) {
399  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
400  }
401 
402  value_ *= value;
403 
404  return *this;
405 }
406 //*************************************************************************************************
407 
408 
409 //*************************************************************************************************
419 template< typename MT > // Type of the adapted matrix
420 template< typename T > // Type of the right-hand side value
421 inline const UpperProxy<MT>& UpperProxy<MT>::operator/=( const T& value ) const
422 {
423  if( restricted_ ) {
424  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
425  }
426 
427  value_ /= value;
428 
429  return *this;
430 }
431 //*************************************************************************************************
432 
433 
434 //*************************************************************************************************
444 template< typename MT > // Type of the adapted matrix
445 template< typename T > // Type of the right-hand side value
446 inline const UpperProxy<MT>& UpperProxy<MT>::operator%=( const T& value ) const
447 {
448  if( restricted_ ) {
449  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
450  }
451 
452  value_ %= value;
453 
454  return *this;
455 }
456 //*************************************************************************************************
457 
458 
459 
460 
461 //=================================================================================================
462 //
463 // UTILITY FUNCTIONS
464 //
465 //=================================================================================================
466 
467 //*************************************************************************************************
472 template< typename MT > // Type of the adapted matrix
473 inline typename UpperProxy<MT>::RawReference UpperProxy<MT>::get() const noexcept
474 {
475  return value_;
476 }
477 //*************************************************************************************************
478 
479 
480 //*************************************************************************************************
485 template< typename MT > // Type of the adapted matrix
486 inline bool UpperProxy<MT>::isRestricted() const noexcept
487 {
488  return restricted_;
489 }
490 //*************************************************************************************************
491 
492 
493 
494 
495 //=================================================================================================
496 //
497 // CONVERSION OPERATOR
498 //
499 //=================================================================================================
500 
501 //*************************************************************************************************
506 template< typename MT > // Type of the adapted matrix
508 {
509  return static_cast<ConstReference>( value_ );
510 }
511 //*************************************************************************************************
512 
513 
514 
515 
516 //=================================================================================================
517 //
518 // GLOBAL FUNCTIONS
519 //
520 //=================================================================================================
521 
522 //*************************************************************************************************
525 template< typename MT >
526 inline void reset( const UpperProxy<MT>& proxy );
527 
528 template< typename MT >
529 inline void clear( const UpperProxy<MT>& proxy );
530 
531 template< bool RF, typename MT >
532 inline bool isDefault( const UpperProxy<MT>& proxy );
533 
534 template< bool RF, typename MT >
535 inline bool isReal( const UpperProxy<MT>& proxy );
536 
537 template< bool RF, typename MT >
538 inline bool isZero( const UpperProxy<MT>& proxy );
539 
540 template< bool RF, typename MT >
541 inline bool isOne( const UpperProxy<MT>& proxy );
542 
543 template< typename MT >
544 inline bool isnan( const UpperProxy<MT>& proxy );
546 //*************************************************************************************************
547 
548 
549 //*************************************************************************************************
559 template< typename MT >
560 inline void reset( const UpperProxy<MT>& proxy )
561 {
562  using blaze::reset;
563 
564  reset( proxy.get() );
565 }
566 //*************************************************************************************************
567 
568 
569 //*************************************************************************************************
579 template< typename MT >
580 inline void clear( const UpperProxy<MT>& proxy )
581 {
582  using blaze::clear;
583 
584  clear( proxy.get() );
585 }
586 //*************************************************************************************************
587 
588 
589 //*************************************************************************************************
599 template< bool RF, typename MT >
600 inline bool isDefault( const UpperProxy<MT>& proxy )
601 {
602  using blaze::isDefault;
603 
604  return isDefault<RF>( proxy.get() );
605 }
606 //*************************************************************************************************
607 
608 
609 //*************************************************************************************************
621 template< bool RF, typename MT >
622 inline bool isReal( const UpperProxy<MT>& proxy )
623 {
624  using blaze::isReal;
625 
626  return isReal<RF>( proxy.get() );
627 }
628 //*************************************************************************************************
629 
630 
631 //*************************************************************************************************
641 template< bool RF, typename MT >
642 inline bool isZero( const UpperProxy<MT>& proxy )
643 {
644  using blaze::isZero;
645 
646  return isZero<RF>( proxy.get() );
647 }
648 //*************************************************************************************************
649 
650 
651 //*************************************************************************************************
661 template< bool RF, typename MT >
662 inline bool isOne( const UpperProxy<MT>& proxy )
663 {
664  using blaze::isOne;
665 
666  return isOne<RF>( proxy.get() );
667 }
668 //*************************************************************************************************
669 
670 
671 //*************************************************************************************************
681 template< typename MT >
682 inline bool isnan( const UpperProxy<MT>& proxy )
683 {
684  using blaze::isnan;
685 
686  return isnan( proxy.get() );
687 }
688 //*************************************************************************************************
689 
690 } // namespace blaze
691 
692 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:622
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.
Header file for basic type definitions.
RawReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: UpperProxy.h:473
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
typename AddConst< T >::Type AddConst_
Auxiliary alias declaration for the AddConst type trait.The AddConst_ alias declaration provides a co...
Definition: AddConst.h:95
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:560
#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
Column< MT > column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:124
Constraint on the data type.
Header file for the Proxy class.
bool isRestricted() const noexcept
Returns whether the proxy represents a restricted matrix element..
Definition: UpperProxy.h:486
Constraint on the data type.
Constraint on the data type.
Header file for the std::initializer_list aliases.
Row< MT > row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:124
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:642
const bool restricted_
Access flag for the accessed matrix element.
Definition: UpperProxy.h:166
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#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.
Header file for the isZero shim.
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Constraint on the data type.
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:682
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
AddReference_< ReferenceType > RawReference
Reference-to-non-const to the represented element.
Definition: UpperProxy.h:110
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:580
Header file for the isOne shim.
ElementType_< MT > RepresentedType
Type of the represented matrix element.
Definition: UpperProxy.h:109
ReferenceType value_
Reference to the accessed matrix element.
Definition: UpperProxy.h:165
#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
const UpperProxy & operator=(const UpperProxy &up) const
Copy assignment operator for UpperProxy.
Definition: UpperProxy.h:246
Constraint on the data type.
Constraint on the data type.
Header file for the reset shim.
#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, 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:662
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
UpperProxy(MT &matrix, size_t row, size_t column)
Initialization constructor for a UpperProxy.
Definition: UpperProxy.h:207
Access proxy for upper triangular matrices.The UpperProxy provides controlled access to the elements ...
Definition: UpperProxy.h:98
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.
AddConst_< typename MT::Reference > ReferenceType
Reference type of the underlying matrix type.
Definition: UpperProxy.h:104
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:600
#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
const RepresentedType & ConstReference
Reference-to-const to the represented element.
Definition: UpperProxy.h:111
Header file for the isReal shim.
typename AddReference< T >::Type AddReference_
Auxiliary alias declaration for the AddReference type trait.The AddReference_ alias declaration provi...
Definition: AddReference.h:95