UniUpperProxy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_UNIUPPERMATRIX_UPPERPROXY_H_
36 #define _BLAZE_MATH_ADAPTORS_UNIUPPERMATRIX_UPPERPROXY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
50 #include <blaze/math/Exception.h>
51 #include <blaze/math/proxy/Proxy.h>
52 #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>
65 #include <blaze/util/InvalidType.h>
66 #include <blaze/util/mpl/If.h>
67 #include <blaze/util/Types.h>
69 
70 
71 namespace blaze {
72 
73 //=================================================================================================
74 //
75 // CLASS DEFINITION
76 //
77 //=================================================================================================
78 
79 //*************************************************************************************************
100 template< typename MT > // Type of the adapted matrix
101 class UniUpperProxy : public Proxy< UniUpperProxy<MT> >
102 {
103  private:
104  //**Type definitions****************************************************************************
106  typedef typename MT::Reference ReferenceType;
107  //**********************************************************************************************
108 
109  //**struct BuiltinType**************************************************************************
113  template< typename T >
114  struct BuiltinType { typedef INVALID_TYPE Type; };
116  //**********************************************************************************************
117 
118  //**struct ComplexType**************************************************************************
122  template< typename T >
123  struct ComplexType { typedef typename T::value_type Type; };
125  //**********************************************************************************************
126 
127  public:
128  //**Type definitions****************************************************************************
131 
133  typedef typename If_< IsComplex<RepresentedType>
134  , ComplexType<RepresentedType>
135  , BuiltinType<RepresentedType> >::Type ValueType;
136 
137  typedef ValueType value_type;
138  //**********************************************************************************************
139 
140  //**Constructors********************************************************************************
143  explicit inline UniUpperProxy( MT& matrix, size_t row, size_t column );
144  inline UniUpperProxy( const UniUpperProxy& uup );
146  //**********************************************************************************************
147 
148  //**Destructor**********************************************************************************
149  // No explicitly declared destructor.
150  //**********************************************************************************************
151 
152  //**Assignment operators************************************************************************
155  inline const UniUpperProxy& operator= ( const UniUpperProxy& uup ) const;
156  template< typename T > inline const UniUpperProxy& operator= ( const T& value ) const;
157  template< typename T > inline const UniUpperProxy& operator+=( const T& value ) const;
158  template< typename T > inline const UniUpperProxy& operator-=( const T& value ) const;
159  template< typename T > inline const UniUpperProxy& operator*=( const T& value ) const;
160  template< typename T > inline const UniUpperProxy& operator/=( const T& value ) const;
162  //**********************************************************************************************
163 
164  //**Utility functions***************************************************************************
167  inline void reset () const;
168  inline void clear () const;
169  inline void invert() const;
170 
171  inline RepresentedType get() const noexcept;
172  inline bool isRestricted() const noexcept;
174  //**********************************************************************************************
175 
176  //**Conversion operator*************************************************************************
179  inline operator RepresentedType() const noexcept;
181  //**********************************************************************************************
182 
183  //**Complex data access functions***************************************************************
186  inline ValueType real() const;
187  inline void real( ValueType value ) const;
188  inline ValueType imag() const;
189  inline void imag( ValueType value ) const;
191  //**********************************************************************************************
192 
193  private:
194  //**Member variables****************************************************************************
197  ReferenceType value_;
198  size_t row_;
199  size_t column_;
200 
201  //**********************************************************************************************
202 
203  //**Compile time checks*************************************************************************
215  BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( RepresentedType );
217  //**********************************************************************************************
218 };
219 //*************************************************************************************************
220 
221 
222 
223 
224 //=================================================================================================
225 //
226 // CONSTRUCTORS
227 //
228 //=================================================================================================
229 
230 //*************************************************************************************************
237 template< typename MT > // Type of the adapted matrix
238 inline UniUpperProxy<MT>::UniUpperProxy( MT& matrix, size_t row, size_t column )
239  : value_ ( matrix( row, column ) ) // Reference to the accessed matrix element
240  , row_ ( row ) // Row index of the accessed matrix element
241  , column_( column ) // Column index of the accessed matrix element
242 {}
243 //*************************************************************************************************
244 
245 
246 //*************************************************************************************************
251 template< typename MT > // Type of the adapted matrix
253  : value_ ( uup.value_ ) // Reference to the accessed matrix element
254  , row_ ( uup.row_ ) // Row index of the accessed matrix element
255  , column_( uup.column_ ) // Column index of the accessed matrix element
256 {}
257 //*************************************************************************************************
258 
259 
260 
261 
262 //=================================================================================================
263 //
264 // OPERATORS
265 //
266 //=================================================================================================
267 
268 //*************************************************************************************************
278 template< typename MT > // Type of the adapted matrix
280 {
281  if( isRestricted() ) {
282  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal or lower matrix element" );
283  }
284 
285  value_ = uup.value_;
286 
287  return *this;
288 }
289 //*************************************************************************************************
290 
291 
292 //*************************************************************************************************
302 template< typename MT > // Type of the adapted matrix
303 template< typename T > // Type of the right-hand side value
304 inline const UniUpperProxy<MT>& UniUpperProxy<MT>::operator=( const T& value ) const
305 {
306  if( isRestricted() ) {
307  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal or lower matrix element" );
308  }
309 
310  value_ = value;
311 
312  return *this;
313 }
314 //*************************************************************************************************
315 
316 
317 //*************************************************************************************************
327 template< typename MT > // Type of the adapted matrix
328 template< typename T > // Type of the right-hand side value
329 inline const UniUpperProxy<MT>& UniUpperProxy<MT>::operator+=( const T& value ) const
330 {
331  if( isRestricted() ) {
332  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal or lower matrix element" );
333  }
334 
335  value_ += value;
336 
337  return *this;
338 }
339 //*************************************************************************************************
340 
341 
342 //*************************************************************************************************
352 template< typename MT > // Type of the adapted matrix
353 template< typename T > // Type of the right-hand side value
354 inline const UniUpperProxy<MT>& UniUpperProxy<MT>::operator-=( const T& value ) const
355 {
356  if( isRestricted() ) {
357  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal or lower matrix element" );
358  }
359 
360  value_ -= value;
361 
362  return *this;
363 }
364 //*************************************************************************************************
365 
366 
367 //*************************************************************************************************
377 template< typename MT > // Type of the adapted matrix
378 template< typename T > // Type of the right-hand side value
379 inline const UniUpperProxy<MT>& UniUpperProxy<MT>::operator*=( const T& value ) const
380 {
381  if( isRestricted() ) {
382  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal or lower matrix element" );
383  }
384 
385  value_ *= value;
386 
387  return *this;
388 }
389 //*************************************************************************************************
390 
391 
392 //*************************************************************************************************
402 template< typename MT > // Type of the adapted matrix
403 template< typename T > // Type of the right-hand side value
404 inline const UniUpperProxy<MT>& UniUpperProxy<MT>::operator/=( const T& value ) const
405 {
406  if( isRestricted() ) {
407  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal or lower matrix element" );
408  }
409 
410  value_ /= value;
411 
412  return *this;
413 }
414 //*************************************************************************************************
415 
416 
417 
418 
419 //=================================================================================================
420 //
421 // UTILITY FUNCTIONS
422 //
423 //=================================================================================================
424 
425 //*************************************************************************************************
432 template< typename MT > // Type of the adapted matrix
433 inline void UniUpperProxy<MT>::reset() const
434 {
435  using blaze::reset;
436 
437  if( row_ < column_ )
438  reset( value_ );
439 }
440 //*************************************************************************************************
441 
442 
443 //*************************************************************************************************
450 template< typename MT > // Type of the adapted matrix
451 inline void UniUpperProxy<MT>::clear() const
452 {
453  using blaze::clear;
454 
455  if( row_ < column_ )
456  clear( value_ );
457 }
458 //*************************************************************************************************
459 
460 
461 //*************************************************************************************************
469 template< typename MT > // Type of the adapted matrix
470 inline void UniUpperProxy<MT>::invert() const
471 {
472  using blaze::invert;
473 
474  if( column_ < row_ ) {
475  BLAZE_THROW_INVALID_ARGUMENT( "Invalid inversion of lower matrix element" );
476  }
477 
478  if( row_ < column_ )
479  invert( value_ );
480 }
481 //*************************************************************************************************
482 
483 
484 //*************************************************************************************************
489 template< typename MT > // Type of the adapted matrix
491 {
492  return value_;
493 }
494 //*************************************************************************************************
495 
496 
497 //*************************************************************************************************
502 template< typename MT > // Type of the adapted matrix
503 inline bool UniUpperProxy<MT>::isRestricted() const noexcept
504 {
505  return column_ <= row_;
506 }
507 //*************************************************************************************************
508 
509 
510 
511 
512 //=================================================================================================
513 //
514 // CONVERSION OPERATOR
515 //
516 //=================================================================================================
517 
518 //*************************************************************************************************
523 template< typename MT > // Type of the adapted matrix
524 inline UniUpperProxy<MT>::operator RepresentedType() const noexcept
525 {
526  return get();
527 }
528 //*************************************************************************************************
529 
530 
531 
532 
533 //=================================================================================================
534 //
535 // COMPLEX DATA ACCESS FUNCTIONS
536 //
537 //=================================================================================================
538 
539 //*************************************************************************************************
547 template< typename MT > // Type of the adapted matrix
549 {
550  return value_.real();
551 }
552 //*************************************************************************************************
553 
554 
555 //*************************************************************************************************
566 template< typename MT > // Type of the adapted matrix
567 inline void UniUpperProxy<MT>::real( ValueType value ) const
568 {
569  if( isRestricted() ) {
570  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setting for diagonal or lower matrix element" );
571  }
572 
573  value_.real( value );
574 }
575 //*************************************************************************************************
576 
577 
578 //*************************************************************************************************
586 template< typename MT > // Type of the adapted matrix
588 {
589  return value_.imag();
590 }
591 //*************************************************************************************************
592 
593 
594 //*************************************************************************************************
605 template< typename MT > // Type of the adapted matrix
606 inline void UniUpperProxy<MT>::imag( ValueType value ) const
607 {
608  if( isRestricted() ) {
609  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setting for diagonal or lower matrix element" );
610  }
611 
612  value_.imag( value );
613 }
614 //*************************************************************************************************
615 
616 
617 
618 
619 //=================================================================================================
620 //
621 // GLOBAL FUNCTIONS
622 //
623 //=================================================================================================
624 
625 //*************************************************************************************************
628 template< typename MT >
629 inline void reset( const UniUpperProxy<MT>& proxy );
630 
631 template< typename MT >
632 inline void clear( const UniUpperProxy<MT>& proxy );
633 
634 template< typename MT >
635 inline void invert( const UniUpperProxy<MT>& proxy );
636 
637 template< typename MT >
638 inline bool isDefault( const UniUpperProxy<MT>& proxy );
639 
640 template< typename MT >
641 inline bool isReal( const UniUpperProxy<MT>& proxy );
642 
643 template< typename MT >
644 inline bool isZero( const UniUpperProxy<MT>& proxy );
645 
646 template< typename MT >
647 inline bool isOne( const UniUpperProxy<MT>& proxy );
648 
649 template< typename MT >
650 inline bool isnan( const UniUpperProxy<MT>& proxy );
652 //*************************************************************************************************
653 
654 
655 //*************************************************************************************************
665 template< typename MT >
666 inline void reset( const UniUpperProxy<MT>& proxy )
667 {
668  proxy.reset();
669 }
670 //*************************************************************************************************
671 
672 
673 //*************************************************************************************************
683 template< typename MT >
684 inline void clear( const UniUpperProxy<MT>& proxy )
685 {
686  proxy.clear();
687 }
688 //*************************************************************************************************
689 
690 
691 //*************************************************************************************************
698 template< typename MT >
699 inline void invert( const UniUpperProxy<MT>& proxy )
700 {
701  proxy.invert();
702 }
703 //*************************************************************************************************
704 
705 
706 //*************************************************************************************************
716 template< typename MT >
717 inline bool isDefault( const UniUpperProxy<MT>& proxy )
718 {
719  using blaze::isDefault;
720 
721  return isDefault( proxy.get() );
722 }
723 //*************************************************************************************************
724 
725 
726 //*************************************************************************************************
738 template< typename MT >
739 inline bool isReal( const UniUpperProxy<MT>& proxy )
740 {
741  using blaze::isReal;
742 
743  return isReal( proxy.get() );
744 }
745 //*************************************************************************************************
746 
747 
748 //*************************************************************************************************
758 template< typename MT >
759 inline bool isZero( const UniUpperProxy<MT>& proxy )
760 {
761  using blaze::isZero;
762 
763  return isZero( proxy.get() );
764 }
765 //*************************************************************************************************
766 
767 
768 //*************************************************************************************************
778 template< typename MT >
779 inline bool isOne( const UniUpperProxy<MT>& proxy )
780 {
781  using blaze::isOne;
782 
783  return isOne( proxy.get() );
784 }
785 //*************************************************************************************************
786 
787 
788 //*************************************************************************************************
798 template< typename MT >
799 inline bool isnan( const UniUpperProxy<MT>& proxy )
800 {
801  using blaze::isnan;
802 
803  return isnan( proxy.get() );
804 }
805 //*************************************************************************************************
806 
807 } // namespace blaze
808 
809 #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
size_t row_
Row index of the accessed matrix element.
Definition: UniUpperProxy.h:198
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:635
Access proxy for upper unitriangular matrices.The UniUpperProxy provides controlled access to the ele...
Definition: UniUpperProxy.h:101
Header file for auxiliary alias declarations.
Constraint on the data type.
MT::Reference ReferenceType
Reference type of the underlying matrix type.
Definition: UniUpperProxy.h:106
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
Constraint on the data type.
size_t column_
Column index of the accessed matrix element.
Definition: UniUpperProxy.h:199
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
Header file for the invert shim.
ElementType_< MT > RepresentedType
Type of the represented matrix element.
Definition: UniUpperProxy.h:130
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.
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:741
ReferenceType value_
Reference to the accessed matrix element.
Definition: UniUpperProxy.h:197
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
void reset() const
Reset the represented element to its default initial value.
Definition: UniUpperProxy.h:433
Header file for the If class template.
#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 isRestricted() const noexcept
Returns whether the proxy represents a restricted matrix element..
Definition: UniUpperProxy.h:503
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
ValueType value_type
Value type of the represented complex element.
Definition: UniUpperProxy.h:137
const UniUpperProxy & operator=(const UniUpperProxy &uup) const
Copy assignment operator for UniUpperProxy.
Definition: UniUpperProxy.h:279
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:553
Header file for the isOne shim.
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
UniUpperProxy(MT &matrix, size_t row, size_t column)
Initialization constructor for a UniUpperProxy.
Definition: UniUpperProxy.h:238
Utility type for generic codes.
Constraint on the data type.
Constraint on the data type.
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:160
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:61
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.
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: UniUpperProxy.h:587
Constraint on the data type.
Constraint on the data type.
void clear() const
Clearing the represented element.
Definition: UniUpperProxy.h:451
If_< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: UniUpperProxy.h:135
void invert() const
In-place inversion of the represented element.
Definition: UniUpperProxy.h:470
#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
ValueType real() const
Returns the real part of the represented complex number.
Definition: UniUpperProxy.h:548
RepresentedType get() const noexcept
Returning the value of the accessed matrix element.
Definition: UniUpperProxy.h:490
Header file for the IsComplex type trait.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2644
#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.