UniUpperValue.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_UNIUPPERMATRIX_UNIUPPERVALUE_H_
36 #define _BLAZE_MATH_ADAPTORS_UNIUPPERMATRIX_UNIUPPERVALUE_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 //*************************************************************************************************
104 template< typename MT > // Type of the adapted matrix
105 class UniUpperValue : public Proxy< UniUpperValue<MT> >
106 {
107  private:
108  //**struct BuiltinType**************************************************************************
112  template< typename T >
113  struct BuiltinType { typedef INVALID_TYPE Type; };
115  //**********************************************************************************************
116 
117  //**struct ComplexType**************************************************************************
121  template< typename T >
122  struct ComplexType { typedef typename T::value_type Type; };
124  //**********************************************************************************************
125 
126  public:
127  //**Type definitions****************************************************************************
129 
131  typedef typename If_< IsComplex<RepresentedType>
132  , ComplexType<RepresentedType>
133  , BuiltinType<RepresentedType> >::Type ValueType;
134 
135  typedef ValueType value_type;
136  //**********************************************************************************************
137 
138  //**Constructors********************************************************************************
141  inline UniUpperValue( RepresentedType& value, bool diagonal );
143  //**********************************************************************************************
144 
145  //**Assignment operators************************************************************************
148  inline UniUpperValue& operator= ( const UniUpperValue& uuv );
149  template< typename T > inline UniUpperValue& operator= ( const T& value );
150  template< typename T > inline UniUpperValue& operator+=( const T& value );
151  template< typename T > inline UniUpperValue& operator-=( const T& value );
152  template< typename T > inline UniUpperValue& operator*=( const T& value );
153  template< typename T > inline UniUpperValue& operator/=( const T& value );
155  //**********************************************************************************************
156 
157  //**Utility functions***************************************************************************
160  inline void reset () const;
161  inline void clear () const;
162  inline void invert() const;
163 
164  inline RepresentedType get() const noexcept;
165  inline bool isRestricted() const noexcept;
167  //**********************************************************************************************
168 
169  //**Conversion operator*************************************************************************
172  inline operator RepresentedType() const noexcept;
174  //**********************************************************************************************
175 
176  //**Complex data access functions***************************************************************
179  inline ValueType real() const;
180  inline void real( ValueType value ) const;
181  inline ValueType imag() const;
182  inline void imag( ValueType value ) const;
184  //**********************************************************************************************
185 
186  private:
187  //**Member variables****************************************************************************
188  RepresentedType* value_;
189  bool diagonal_;
190  //**********************************************************************************************
191 
192  //**Compile time checks*************************************************************************
204  BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( RepresentedType );
206  //**********************************************************************************************
207 };
208 //*************************************************************************************************
209 
210 
211 
212 
213 //=================================================================================================
214 //
215 // CONSTRUCTORS
216 //
217 //=================================================================================================
218 
219 //*************************************************************************************************
225 template< typename MT > // Type of the adapted matrix
226 inline UniUpperValue<MT>::UniUpperValue( RepresentedType& value, bool diagonal )
227  : value_ ( &value ) // The represented value.
228  , diagonal_( diagonal ) // true in case the element is on the diagonal, false if not
229 {}
230 //*************************************************************************************************
231 
232 
233 
234 
235 //=================================================================================================
236 //
237 // OPERATORS
238 //
239 //=================================================================================================
240 
241 //*************************************************************************************************
248 template< typename MT > // Type of the adapted matrix
250 {
251  if( diagonal_ ) {
252  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
253  }
254 
255  *value_ = *uuv.value;
256 
257  return *this;
258 }
259 //*************************************************************************************************
260 
261 
262 //*************************************************************************************************
269 template< typename MT > // Type of the adapted matrix
270 template< typename T > // Type of the right-hand side value
272 {
273  if( diagonal_ ) {
274  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
275  }
276 
277  *value_ = value;
278 
279  return *this;
280 }
281 //*************************************************************************************************
282 
283 
284 //*************************************************************************************************
291 template< typename MT > // Type of the adapted matrix
292 template< typename T > // Type of the right-hand side value
294 {
295  if( diagonal_ ) {
296  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
297  }
298 
299  *value_ += value;
300 
301  return *this;
302 }
303 //*************************************************************************************************
304 
305 
306 //*************************************************************************************************
313 template< typename MT > // Type of the adapted matrix
314 template< typename T > // Type of the right-hand side value
316 {
317  if( diagonal_ ) {
318  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
319  }
320 
321  *value_ -= value;
322 
323  return *this;
324 }
325 //*************************************************************************************************
326 
327 
328 //*************************************************************************************************
335 template< typename MT > // Type of the adapted matrix
336 template< typename T > // Type of the right-hand side value
338 {
339  if( diagonal_ ) {
340  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
341  }
342 
343  *value_ *= value;
344 
345  return *this;
346 }
347 //*************************************************************************************************
348 
349 
350 //*************************************************************************************************
357 template< typename MT > // Type of the adapted matrix
358 template< typename T > // Type of the right-hand side value
360 {
361  if( diagonal_ ) {
362  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
363  }
364 
365  *value_ /= value;
366 
367  return *this;
368 }
369 //*************************************************************************************************
370 
371 
372 
373 
374 //=================================================================================================
375 //
376 // UTILITY FUNCTIONS
377 //
378 //=================================================================================================
379 
380 //*************************************************************************************************
387 template< typename MT > // Type of the adapted matrix
388 inline void UniUpperValue<MT>::reset() const
389 {
390  using blaze::reset;
391 
392  if( !diagonal_ )
393  reset( *value_ );
394 }
395 //*************************************************************************************************
396 
397 
398 //*************************************************************************************************
405 template< typename MT > // Type of the adapted matrix
406 inline void UniUpperValue<MT>::clear() const
407 {
408  using blaze::clear;
409 
410  if( !diagonal_ )
411  clear( *value_ );
412 }
413 //*************************************************************************************************
414 
415 
416 //*************************************************************************************************
421 template< typename MT > // Type of the adapted matrix
422 inline void UniUpperValue<MT>::invert() const
423 {
424  using blaze::invert;
425 
426  if( !diagonal_ )
427  invert( *value_ );
428 }
429 //*************************************************************************************************
430 
431 
432 //*************************************************************************************************
437 template< typename MT > // Type of the adapted matrix
439 {
440  return *value_;
441 }
442 //*************************************************************************************************
443 
444 
445 //*************************************************************************************************
450 template< typename MT > // Type of the adapted matrix
451 inline bool UniUpperValue<MT>::isRestricted() const noexcept
452 {
453  return diagonal_;
454 }
455 //*************************************************************************************************
456 
457 
458 
459 
460 //=================================================================================================
461 //
462 // CONVERSION OPERATOR
463 //
464 //=================================================================================================
465 
466 //*************************************************************************************************
471 template< typename MT > // Type of the adapted matrix
473 {
474  return *value_;
475 }
476 //*************************************************************************************************
477 
478 
479 
480 
481 //=================================================================================================
482 //
483 // COMPLEX DATA ACCESS FUNCTIONS
484 //
485 //=================================================================================================
486 
487 //*************************************************************************************************
495 template< typename MT > // Type of the adapted matrix
497 {
498  return value_->real();
499 }
500 //*************************************************************************************************
501 
502 
503 //*************************************************************************************************
512 template< typename MT > // Type of the adapted matrix
513 inline void UniUpperValue<MT>::real( ValueType value ) const
514 {
515  if( isRestricted() ) {
516  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setting for diagonal matrix element" );
517  }
518 
519  value_->real( value );
520 }
521 //*************************************************************************************************
522 
523 
524 //*************************************************************************************************
532 template< typename MT > // Type of the adapted matrix
534 {
535  return value_->imag();
536 }
537 //*************************************************************************************************
538 
539 
540 //*************************************************************************************************
551 template< typename MT > // Type of the adapted matrix
552 inline void UniUpperValue<MT>::imag( ValueType value ) const
553 {
554  if( isRestricted() ) {
555  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setting for diagonal matrix element" );
556  }
557 
558  value_->imag( value );
559 }
560 //*************************************************************************************************
561 
562 
563 
564 
565 //=================================================================================================
566 //
567 // GLOBAL FUNCTIONS
568 //
569 //=================================================================================================
570 
571 //*************************************************************************************************
574 template< typename MT >
575 inline void reset( const UniUpperValue<MT>& value );
576 
577 template< typename MT >
578 inline void clear( const UniUpperValue<MT>& value );
579 
580 template< typename MT >
581 inline void invert( const UniUpperValue<MT>& value );
582 
583 template< typename MT >
584 inline bool isDefault( const UniUpperValue<MT>& value );
585 
586 template< typename MT >
587 inline bool isReal( const UniUpperValue<MT>& value );
588 
589 template< typename MT >
590 inline bool isZero( const UniUpperValue<MT>& value );
591 
592 template< typename MT >
593 inline bool isOne( const UniUpperValue<MT>& value );
594 
595 template< typename MT >
596 inline bool isnan( const UniUpperValue<MT>& value );
598 //*************************************************************************************************
599 
600 
601 //*************************************************************************************************
610 template< typename MT >
611 inline void reset( const UniUpperValue<MT>& value )
612 {
613  value.reset();
614 }
615 //*************************************************************************************************
616 
617 
618 //*************************************************************************************************
627 template< typename MT >
628 inline void clear( const UniUpperValue<MT>& value )
629 {
630  value.clear();
631 }
632 //*************************************************************************************************
633 
634 
635 //*************************************************************************************************
642 template< typename MT >
643 inline void invert( const UniUpperValue<MT>& value )
644 {
645  value.invert();
646 }
647 //*************************************************************************************************
648 
649 
650 //*************************************************************************************************
660 template< typename MT >
661 inline bool isDefault( const UniUpperValue<MT>& value )
662 {
663  using blaze::isDefault;
664 
665  return isDefault( value.get() );
666 }
667 //*************************************************************************************************
668 
669 
670 //*************************************************************************************************
682 template< typename MT >
683 inline bool isReal( const UniUpperValue<MT>& value )
684 {
685  using blaze::isReal;
686 
687  return isReal( value.get() );
688 }
689 //*************************************************************************************************
690 
691 
692 //*************************************************************************************************
702 template< typename MT >
703 inline bool isZero( const UniUpperValue<MT>& value )
704 {
705  using blaze::isZero;
706 
707  return isZero( value.get() );
708 }
709 //*************************************************************************************************
710 
711 
712 //*************************************************************************************************
722 template< typename MT >
723 inline bool isOne( const UniUpperValue<MT>& value )
724 {
725  using blaze::isOne;
726 
727  return isOne( value.get() );
728 }
729 //*************************************************************************************************
730 
731 
732 //*************************************************************************************************
742 template< typename MT >
743 inline bool isnan( const UniUpperValue<MT>& value )
744 {
745  using blaze::isnan;
746 
747  return isnan( value.get() );
748 }
749 //*************************************************************************************************
750 
751 } // namespace blaze
752 
753 #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 auxiliary alias declarations.
Constraint on the data type.
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
RepresentedType * value_
The represented value.
Definition: UniUpperValue.h:188
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
Header file for the invert shim.
If_< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: UniUpperValue.h:133
Constraint on the data type.
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.
ValueType value_type
Value type of the represented complex element.
Definition: UniUpperValue.h:135
ValueType real() const
Returns the real part of the represented complex number.
Definition: UniUpperValue.h:496
Constraint on the data type.
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:741
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: UniUpperValue.h:533
#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
UniUpperValue & operator=(const UniUpperValue &uuv)
Copy assignment operator for UniUpperValue.
Definition: UniUpperValue.h:249
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
UniUpperValue(RepresentedType &value, bool diagonal)
Constructor for the UniUpperValue class.
Definition: UniUpperValue.h:226
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:553
Header file for the isOne shim.
bool isRestricted() const noexcept
Returns whether the value represents a restricted matrix element..
Definition: UniUpperValue.h:451
#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
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.
Constraint on the data type.
Constraint on the data type.
ElementType_< MT > RepresentedType
Type of the represented matrix element.
Definition: UniUpperValue.h:128
bool diagonal_
true in case the element is on the diagonal, false if not.
Definition: UniUpperValue.h:189
#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
void invert() const
In-place inversion of the uniupper value.
Definition: UniUpperValue.h:422
Header file for the IsComplex type trait.
Representation of a value within a sparse upper unitriangular matrix.The UniUpperValue class represen...
Definition: UniUpperValue.h:105
#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
void reset() const
Reset the uniupper value to its default initial value.
Definition: UniUpperValue.h:388
Header file for the isReal shim.
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:61
RepresentedType get() const noexcept
Access to the represented value.
Definition: UniUpperValue.h:438
void clear() const
Clearing the uniupper value.
Definition: UniUpperValue.h:406