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 
49 #include <blaze/math/proxy/Proxy.h>
50 #include <blaze/math/shims/Clear.h>
53 #include <blaze/math/shims/IsNaN.h>
54 #include <blaze/math/shims/IsOne.h>
57 #include <blaze/math/shims/Reset.h>
63 #include <blaze/util/Exception.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>, typename MT::ElementType >
99 {
100  private:
101  //**Type definitions****************************************************************************
104  //**********************************************************************************************
105 
106  public:
107  //**Type definitions****************************************************************************
110 
113 
115  typedef const RepresentedType& ConstReference;
116  //**********************************************************************************************
117 
118  //**Constructors********************************************************************************
121  explicit inline UpperProxy( MT& matrix, size_t row, size_t column );
122  inline UpperProxy( const UpperProxy& up );
124  //**********************************************************************************************
125 
126  //**Destructor**********************************************************************************
127  // No explicitly declared destructor.
128  //**********************************************************************************************
129 
130  //**Assignment operators************************************************************************
133  inline const UpperProxy& operator= ( const UpperProxy& up ) const;
134  template< typename T > inline const UpperProxy& operator= ( const T& value ) const;
135  template< typename T > inline const UpperProxy& operator+=( const T& value ) const;
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;
140  //**********************************************************************************************
141 
142  //**Utility functions***************************************************************************
145  inline RawReference get() const;
146  inline bool isRestricted() const;
148  //**********************************************************************************************
149 
150  //**Conversion operator*************************************************************************
153  inline operator ConstReference() const;
155  //**********************************************************************************************
156 
157  private:
158  //**Member variables****************************************************************************
161  ReferenceType value_;
162  const bool restricted_;
163 
167  //**********************************************************************************************
168 
169  //**Compile time checks*************************************************************************
182  //**********************************************************************************************
183 };
184 //*************************************************************************************************
185 
186 
187 
188 
189 //=================================================================================================
190 //
191 // CONSTRUCTORS
192 //
193 //=================================================================================================
194 
195 //*************************************************************************************************
202 template< typename MT > // Type of the adapted matrix
203 inline UpperProxy<MT>::UpperProxy( MT& matrix, size_t row, size_t column )
204  : value_ ( matrix( row, column ) ) // Reference to the accessed matrix element
205  , restricted_( column < row ) // Access flag for the accessed matrix element
206 {}
207 //*************************************************************************************************
208 
209 
210 //*************************************************************************************************
215 template< typename MT > // Type of the adapted matrix
217  : value_ ( up.value_ ) // Reference to the accessed matrix element
218  , restricted_( up.restricted_ ) // Access flag for the accessed matrix element
219 {}
220 //*************************************************************************************************
221 
222 
223 
224 
225 //=================================================================================================
226 //
227 // OPERATORS
228 //
229 //=================================================================================================
230 
231 //*************************************************************************************************
241 template< typename MT > // Type of the adapted matrix
242 inline const UpperProxy<MT>& UpperProxy<MT>::operator=( const UpperProxy& up ) const
243 {
244  if( restricted_ ) {
245  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
246  }
247 
248  value_ = up.value_;
249 
250  return *this;
251 }
252 //*************************************************************************************************
253 
254 
255 //*************************************************************************************************
265 template< typename MT > // Type of the adapted matrix
266 template< typename T > // Type of the right-hand side value
267 inline const UpperProxy<MT>& UpperProxy<MT>::operator=( const T& value ) const
268 {
269  if( restricted_ ) {
270  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
271  }
272 
273  value_ = value;
274 
275  return *this;
276 }
277 //*************************************************************************************************
278 
279 
280 //*************************************************************************************************
290 template< typename MT > // Type of the adapted matrix
291 template< typename T > // Type of the right-hand side value
292 inline const UpperProxy<MT>& UpperProxy<MT>::operator+=( const T& value ) const
293 {
294  if( restricted_ ) {
295  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
296  }
297 
298  value_ += value;
299 
300  return *this;
301 }
302 //*************************************************************************************************
303 
304 
305 //*************************************************************************************************
315 template< typename MT > // Type of the adapted matrix
316 template< typename T > // Type of the right-hand side value
317 inline const UpperProxy<MT>& UpperProxy<MT>::operator-=( const T& value ) const
318 {
319  if( restricted_ ) {
320  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
321  }
322 
323  value_ -= value;
324 
325  return *this;
326 }
327 //*************************************************************************************************
328 
329 
330 //*************************************************************************************************
340 template< typename MT > // Type of the adapted matrix
341 template< typename T > // Type of the right-hand side value
342 inline const UpperProxy<MT>& UpperProxy<MT>::operator*=( const T& value ) const
343 {
344  if( restricted_ ) {
345  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
346  }
347 
348  value_ *= value;
349 
350  return *this;
351 }
352 //*************************************************************************************************
353 
354 
355 //*************************************************************************************************
365 template< typename MT > // Type of the adapted matrix
366 template< typename T > // Type of the right-hand side value
367 inline const UpperProxy<MT>& UpperProxy<MT>::operator/=( const T& value ) const
368 {
369  if( restricted_ ) {
370  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to lower matrix element" );
371  }
372 
373  value_ /= value;
374 
375  return *this;
376 }
377 //*************************************************************************************************
378 
379 
380 
381 
382 //=================================================================================================
383 //
384 // UTILITY FUNCTIONS
385 //
386 //=================================================================================================
387 
388 //*************************************************************************************************
393 template< typename MT > // Type of the adapted matrix
395 {
396  return value_;
397 }
398 //*************************************************************************************************
399 
400 
401 //*************************************************************************************************
406 template< typename MT > // Type of the adapted matrix
407 inline bool UpperProxy<MT>::isRestricted() const
408 {
409  return restricted_;
410 }
411 //*************************************************************************************************
412 
413 
414 
415 
416 //=================================================================================================
417 //
418 // CONVERSION OPERATOR
419 //
420 //=================================================================================================
421 
422 //*************************************************************************************************
427 template< typename MT > // Type of the adapted matrix
429 {
430  return static_cast<ConstReference>( value_ );
431 }
432 //*************************************************************************************************
433 
434 
435 
436 
437 //=================================================================================================
438 //
439 // GLOBAL FUNCTIONS
440 //
441 //=================================================================================================
442 
443 //*************************************************************************************************
446 template< typename MT >
448  conj( const UpperProxy<MT>& proxy );
449 
450 template< typename MT >
451 inline void reset( const UpperProxy<MT>& proxy );
452 
453 template< typename MT >
454 inline void clear( const UpperProxy<MT>& proxy );
455 
456 template< typename MT >
457 inline bool isDefault( const UpperProxy<MT>& proxy );
458 
459 template< typename MT >
460 inline bool isReal( const UpperProxy<MT>& proxy );
461 
462 template< typename MT >
463 inline bool isZero( const UpperProxy<MT>& proxy );
464 
465 template< typename MT >
466 inline bool isOne( const UpperProxy<MT>& proxy );
467 
468 template< typename MT >
469 inline bool isnan( const UpperProxy<MT>& proxy );
471 //*************************************************************************************************
472 
473 
474 //*************************************************************************************************
485 template< typename MT >
487  conj( const UpperProxy<MT>& proxy )
488 {
489  using blaze::conj;
490 
491  return conj( (~proxy).get() );
492 }
493 //*************************************************************************************************
494 
495 
496 //*************************************************************************************************
506 template< typename MT >
507 inline void reset( const UpperProxy<MT>& proxy )
508 {
509  using blaze::reset;
510 
511  reset( proxy.get() );
512 }
513 //*************************************************************************************************
514 
515 
516 //*************************************************************************************************
526 template< typename MT >
527 inline void clear( const UpperProxy<MT>& proxy )
528 {
529  using blaze::clear;
530 
531  clear( proxy.get() );
532 }
533 //*************************************************************************************************
534 
535 
536 //*************************************************************************************************
546 template< typename MT >
547 inline bool isDefault( const UpperProxy<MT>& proxy )
548 {
549  using blaze::isDefault;
550 
551  return isDefault( proxy.get() );
552 }
553 //*************************************************************************************************
554 
555 
556 //*************************************************************************************************
568 template< typename MT >
569 inline bool isReal( const UpperProxy<MT>& proxy )
570 {
571  using blaze::isReal;
572 
573  return isReal( proxy.get() );
574 }
575 //*************************************************************************************************
576 
577 
578 //*************************************************************************************************
588 template< typename MT >
589 inline bool isZero( const UpperProxy<MT>& proxy )
590 {
591  using blaze::isZero;
592 
593  return isZero( proxy.get() );
594 }
595 //*************************************************************************************************
596 
597 
598 //*************************************************************************************************
608 template< typename MT >
609 inline bool isOne( const UpperProxy<MT>& proxy )
610 {
611  using blaze::isOne;
612 
613  return isOne( proxy.get() );
614 }
615 //*************************************************************************************************
616 
617 
618 //*************************************************************************************************
628 template< typename MT >
629 inline bool isnan( const UpperProxy<MT>& proxy )
630 {
631  using blaze::isnan;
632 
633  return isnan( proxy.get() );
634 }
635 //*************************************************************************************************
636 
637 } // namespace blaze
638 
639 #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:116
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:609
Header file for the AddConst type trait.
Header file for basic type definitions.
Addition of a top level 'const' qualifier.The AddConst type trait adds a top level 'const' qualifier ...
Definition: AddConst.h:69
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:569
bool isRestricted() const
Returns whether the proxy represents a restricted matrix element..
Definition: UpperProxy.h:407
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
RawReference get() const
Returning the value of the accessed matrix element.
Definition: UpperProxy.h:394
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:107
#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:116
Constraint on the data type.
MT::ElementType RepresentedType
Type of the represented matrix element.
Definition: UpperProxy.h:109
Header file for the Proxy class.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
Constraint on the data type.
Addition of a top level reference.In case the given type T is not a reference type, the AddReference type trait adds a top level reference to the given type T. Else the resulting type Type is T.
Definition: AddReference.h:69
ConjExprTrait< typename DiagonalProxy< MT >::RepresentedType >::Type conj(const DiagonalProxy< MT > &proxy)
Computing the complex conjugate of the represented element.
Definition: DiagonalProxy.h:487
const bool restricted_
Access flag for the accessed matrix element.
Definition: UpperProxy.h:162
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:116
Constraint on the data type.
Header file for the isZero shim.
AddReference< ReferenceType >::Type RawReference
Reference-to-non-const to the represented element.
Definition: UpperProxy.h:112
Constraint on the data type.
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:629
#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:118
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2590
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
Header file for the isOne shim.
Header file for the conjugate shim.
ReferenceType value_
Reference to the accessed matrix element.
Definition: UpperProxy.h:161
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:107
Evaluation of the return type of a complex conjugate expression.Via this type trait it is possible to...
Definition: ConjExprTrait.h:87
#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:116
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:118
#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:116
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:203
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:242
#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:118
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:589
Header file for the AddReference type trait.
const RepresentedType & ConstReference
Reference-to-const to the represented element.
Definition: UpperProxy.h:115
#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:116
#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:79
Header file for exception macros.
AddConst< typename MT::Reference >::Type ReferenceType
Reference type of the underlying matrix type.
Definition: UpperProxy.h:103
Header file for the ConjExprTrait class template.
Header file for the isReal shim.