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
98 class UpperProxy : public Proxy< UpperProxy<MT>, ElementType_<MT> >
99 {
100  private:
101  //**Type definitions****************************************************************************
104  //**********************************************************************************************
105 
106  public:
107  //**Type definitions****************************************************************************
110  typedef const RepresentedType& ConstReference;
111  //**********************************************************************************************
112 
113  //**Constructors********************************************************************************
116  explicit inline UpperProxy( MT& matrix, size_t row, size_t column );
117  inline UpperProxy( const UpperProxy& up );
119  //**********************************************************************************************
120 
121  //**Destructor**********************************************************************************
122  // No explicitly declared destructor.
123  //**********************************************************************************************
124 
125  //**Assignment operators************************************************************************
128  inline const UpperProxy& operator=( const UpperProxy& up ) const;
129 
130  template< typename T >
131  inline const UpperProxy& operator=( initializer_list<T> list ) const;
132 
133  template< typename T >
134  inline const UpperProxy& operator=( initializer_list< initializer_list<T> > list ) const;
135 
136  template< typename T > inline const UpperProxy& operator= ( const T& value ) const;
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;
142  //**********************************************************************************************
143 
144  //**Utility functions***************************************************************************
147  inline RawReference get() const noexcept;
148  inline bool isRestricted() const noexcept;
150  //**********************************************************************************************
151 
152  //**Conversion operator*************************************************************************
155  inline operator ConstReference() const noexcept;
157  //**********************************************************************************************
158 
159  private:
160  //**Member variables****************************************************************************
163  ReferenceType value_;
164  const bool restricted_;
165 
169  //**********************************************************************************************
170 
171  //**Compile time checks*************************************************************************
184  //**********************************************************************************************
185 };
186 //*************************************************************************************************
187 
188 
189 
190 
191 //=================================================================================================
192 //
193 // CONSTRUCTORS
194 //
195 //=================================================================================================
196 
197 //*************************************************************************************************
204 template< typename MT > // Type of the adapted matrix
205 inline UpperProxy<MT>::UpperProxy( MT& matrix, size_t row, size_t column )
206  : value_ ( matrix( row, column ) ) // Reference to the accessed matrix element
207  , restricted_( column < row ) // Access flag for the accessed matrix element
208 {}
209 //*************************************************************************************************
210 
211 
212 //*************************************************************************************************
217 template< typename MT > // Type of the adapted matrix
219  : value_ ( up.value_ ) // Reference to the accessed matrix element
220  , restricted_( up.restricted_ ) // Access flag for the accessed matrix element
221 {}
222 //*************************************************************************************************
223 
224 
225 
226 
227 //=================================================================================================
228 //
229 // OPERATORS
230 //
231 //=================================================================================================
232 
233 //*************************************************************************************************
243 template< typename MT > // Type of the adapted matrix
244 inline const UpperProxy<MT>& UpperProxy<MT>::operator=( const UpperProxy& up ) const
245 {
246  if( restricted_ ) {
247  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
248  }
249 
250  value_ = up.value_;
251 
252  return *this;
253 }
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
267 template< typename MT > // Type of the adapted matrix
268 template< typename T > // Type of the right-hand side value
270 {
271  if( restricted_ ) {
272  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
273  }
274 
275  value_ = list;
276 
277  return *this;
278 }
279 //*************************************************************************************************
280 
281 
282 //*************************************************************************************************
292 template< typename MT > // Type of the adapted matrix
293 template< typename T > // Type of the right-hand side value
295 {
296  if( restricted_ ) {
297  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
298  }
299 
300  value_ = list;
301 
302  return *this;
303 }
304 //*************************************************************************************************
305 
306 
307 //*************************************************************************************************
317 template< typename MT > // Type of the adapted matrix
318 template< typename T > // Type of the right-hand side value
319 inline const UpperProxy<MT>& UpperProxy<MT>::operator=( const T& value ) const
320 {
321  if( restricted_ ) {
322  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
323  }
324 
325  value_ = value;
326 
327  return *this;
328 }
329 //*************************************************************************************************
330 
331 
332 //*************************************************************************************************
342 template< typename MT > // Type of the adapted matrix
343 template< typename T > // Type of the right-hand side value
344 inline const UpperProxy<MT>& UpperProxy<MT>::operator+=( const T& value ) const
345 {
346  if( restricted_ ) {
347  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
348  }
349 
350  value_ += value;
351 
352  return *this;
353 }
354 //*************************************************************************************************
355 
356 
357 //*************************************************************************************************
367 template< typename MT > // Type of the adapted matrix
368 template< typename T > // Type of the right-hand side value
369 inline const UpperProxy<MT>& UpperProxy<MT>::operator-=( const T& value ) const
370 {
371  if( restricted_ ) {
372  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
373  }
374 
375  value_ -= value;
376 
377  return *this;
378 }
379 //*************************************************************************************************
380 
381 
382 //*************************************************************************************************
392 template< typename MT > // Type of the adapted matrix
393 template< typename T > // Type of the right-hand side value
394 inline const UpperProxy<MT>& UpperProxy<MT>::operator*=( const T& value ) const
395 {
396  if( restricted_ ) {
397  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
398  }
399 
400  value_ *= value;
401 
402  return *this;
403 }
404 //*************************************************************************************************
405 
406 
407 //*************************************************************************************************
417 template< typename MT > // Type of the adapted matrix
418 template< typename T > // Type of the right-hand side value
419 inline const UpperProxy<MT>& UpperProxy<MT>::operator/=( const T& value ) const
420 {
421  if( restricted_ ) {
422  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
423  }
424 
425  value_ /= value;
426 
427  return *this;
428 }
429 //*************************************************************************************************
430 
431 
432 
433 
434 //=================================================================================================
435 //
436 // UTILITY FUNCTIONS
437 //
438 //=================================================================================================
439 
440 //*************************************************************************************************
445 template< typename MT > // Type of the adapted matrix
446 inline typename UpperProxy<MT>::RawReference UpperProxy<MT>::get() const noexcept
447 {
448  return value_;
449 }
450 //*************************************************************************************************
451 
452 
453 //*************************************************************************************************
458 template< typename MT > // Type of the adapted matrix
459 inline bool UpperProxy<MT>::isRestricted() const noexcept
460 {
461  return restricted_;
462 }
463 //*************************************************************************************************
464 
465 
466 
467 
468 //=================================================================================================
469 //
470 // CONVERSION OPERATOR
471 //
472 //=================================================================================================
473 
474 //*************************************************************************************************
479 template< typename MT > // Type of the adapted matrix
481 {
482  return static_cast<ConstReference>( value_ );
483 }
484 //*************************************************************************************************
485 
486 
487 
488 
489 //=================================================================================================
490 //
491 // GLOBAL FUNCTIONS
492 //
493 //=================================================================================================
494 
495 //*************************************************************************************************
498 template< typename MT >
499 inline void reset( const UpperProxy<MT>& proxy );
500 
501 template< typename MT >
502 inline void clear( const UpperProxy<MT>& proxy );
503 
504 template< typename MT >
505 inline bool isDefault( const UpperProxy<MT>& proxy );
506 
507 template< typename MT >
508 inline bool isReal( const UpperProxy<MT>& proxy );
509 
510 template< typename MT >
511 inline bool isZero( const UpperProxy<MT>& proxy );
512 
513 template< typename MT >
514 inline bool isOne( const UpperProxy<MT>& proxy );
515 
516 template< typename MT >
517 inline bool isnan( const UpperProxy<MT>& proxy );
519 //*************************************************************************************************
520 
521 
522 //*************************************************************************************************
532 template< typename MT >
533 inline void reset( const UpperProxy<MT>& proxy )
534 {
535  using blaze::reset;
536 
537  reset( proxy.get() );
538 }
539 //*************************************************************************************************
540 
541 
542 //*************************************************************************************************
552 template< typename MT >
553 inline void clear( const UpperProxy<MT>& proxy )
554 {
555  using blaze::clear;
556 
557  clear( proxy.get() );
558 }
559 //*************************************************************************************************
560 
561 
562 //*************************************************************************************************
572 template< typename MT >
573 inline bool isDefault( const UpperProxy<MT>& proxy )
574 {
575  using blaze::isDefault;
576 
577  return isDefault( proxy.get() );
578 }
579 //*************************************************************************************************
580 
581 
582 //*************************************************************************************************
594 template< typename MT >
595 inline bool isReal( const UpperProxy<MT>& proxy )
596 {
597  using blaze::isReal;
598 
599  return isReal( proxy.get() );
600 }
601 //*************************************************************************************************
602 
603 
604 //*************************************************************************************************
614 template< typename MT >
615 inline bool isZero( const UpperProxy<MT>& proxy )
616 {
617  using blaze::isZero;
618 
619  return isZero( proxy.get() );
620 }
621 //*************************************************************************************************
622 
623 
624 //*************************************************************************************************
634 template< typename MT >
635 inline bool isOne( const UpperProxy<MT>& proxy )
636 {
637  using blaze::isOne;
638 
639  return isOne( proxy.get() );
640 }
641 //*************************************************************************************************
642 
643 
644 //*************************************************************************************************
654 template< typename MT >
655 inline bool isnan( const UpperProxy<MT>& proxy )
656 {
657  using blaze::isnan;
658 
659  return isnan( proxy.get() );
660 }
661 //*************************************************************************************************
662 
663 } // namespace blaze
664 
665 #endif
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
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:635
Header file for the AddConst type trait.
Header file for auxiliary alias declarations.
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
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:595
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:533
#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
Constraint on the data type.
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT > >, ColumnExprTrait_< MT > > column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:126
Header file for the Proxy class.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
Constraint on the data type.
Constraint on the data type.
Header file for the std::initializer_list aliases.
const bool restricted_
Access flag for the accessed matrix element.
Definition: UpperProxy.h:164
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
ElementType_< MT > RepresentedType
Type of the represented matrix element.
Definition: UpperProxy.h:108
#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:655
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
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2645
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:553
Header file for the isOne shim.
AddReference_< ReferenceType > RawReference
Reference-to-non-const to the represented element.
Definition: UpperProxy.h:109
ReferenceType value_
Reference to the accessed matrix element.
Definition: UpperProxy.h:163
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT > >, RowExprTrait_< MT > > row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:126
#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.
bool isRestricted() const noexcept
Returns whether the proxy represents a restricted matrix element..
Definition: UpperProxy.h:459
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
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:205
Access proxy for upper triangular matrices.The UpperProxy provides controlled access to the elements ...
Definition: UpperProxy.h:98
const UpperProxy & operator=(const UpperProxy &up) const
Copy assignment operator for UpperProxy.
Definition: UpperProxy.h:244
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
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:615
Header file for the AddReference type trait.
RawReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: UpperProxy.h:446
const RepresentedType & ConstReference
Reference-to-const to the represented element.
Definition: UpperProxy.h:110
AddConst_< typename MT::Reference > ReferenceType
Reference type of the underlying matrix type.
Definition: UpperProxy.h:103
#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.
typename AddReference< T >::Type AddReference_
Auxiliary alias declaration for the AddReference type trait.The AddReference_ alias declaration provi...
Definition: AddReference.h:95