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 <ostream>
44 #include <stdexcept>
50 #include <blaze/math/proxy/Proxy.h>
51 #include <blaze/math/shims/Clear.h>
53 #include <blaze/math/shims/Reset.h>
60 #include <blaze/util/Types.h>
61 
62 
63 namespace blaze {
64 
65 //=================================================================================================
66 //
67 // CLASS DEFINITION
68 //
69 //=================================================================================================
70 
71 //*************************************************************************************************
91 template< typename MT > // Type of the adapted matrix
92 class UpperProxy : public Proxy< UpperProxy<MT>, typename MT::ElementType >
93 {
94  private:
95  //**Type definitions****************************************************************************
98  //**********************************************************************************************
99 
100  public:
101  //**Type definitions****************************************************************************
104 
107  //**********************************************************************************************
108 
109  //**Constructors********************************************************************************
112  explicit inline UpperProxy( MT& matrix, size_t row, size_t column );
113  inline UpperProxy( const UpperProxy& up );
115  //**********************************************************************************************
116 
117  //**Destructor**********************************************************************************
118  // No explicitly declared destructor.
119  //**********************************************************************************************
120 
121  //**Assignment operators************************************************************************
124  inline const UpperProxy& operator= ( const UpperProxy& up ) const;
125  template< typename T > inline const UpperProxy& operator= ( const T& value ) const;
126  template< typename T > inline const UpperProxy& operator+=( const T& value ) const;
127  template< typename T > inline const UpperProxy& operator-=( const T& value ) const;
128  template< typename T > inline const UpperProxy& operator*=( const T& value ) const;
129  template< typename T > inline const UpperProxy& operator/=( const T& value ) const;
131  //**********************************************************************************************
132 
133  //**Utility functions***************************************************************************
136  inline RawReference get() const;
137  inline bool isRestricted() const;
139  //**********************************************************************************************
140 
141  //**Conversion operator*************************************************************************
144  inline operator RawReference() const;
146  //**********************************************************************************************
147 
148  private:
149  //**Member variables****************************************************************************
152  ReferenceType value_;
153  const bool restricted_;
154 
158  //**********************************************************************************************
159 
160  //**Compile time checks*************************************************************************
172  //**********************************************************************************************
173 };
174 //*************************************************************************************************
175 
176 
177 
178 
179 //=================================================================================================
180 //
181 // CONSTRUCTORS
182 //
183 //=================================================================================================
184 
185 //*************************************************************************************************
192 template< typename MT > // Type of the adapted matrix
193 inline UpperProxy<MT>::UpperProxy( MT& matrix, size_t row, size_t column )
194  : value_ ( matrix( row, column ) ) // Reference to the accessed matrix element
195  , restricted_( column < row ) // Access flag for the accessed matrix element
196 {}
197 //*************************************************************************************************
198 
199 
200 //*************************************************************************************************
205 template< typename MT > // Type of the adapted matrix
207  : value_ ( up.value_ ) // Reference to the accessed matrix element
208  , restricted_( up.restricted_ ) // Access flag for the accessed matrix element
209 {}
210 //*************************************************************************************************
211 
212 
213 
214 
215 //=================================================================================================
216 //
217 // OPERATORS
218 //
219 //=================================================================================================
220 
221 //*************************************************************************************************
227 template< typename MT > // Type of the adapted matrix
228 inline const UpperProxy<MT>& UpperProxy<MT>::operator=( const UpperProxy& up ) const
229 {
230  value_ = up.value_;
231 
232  return *this;
233 }
234 //*************************************************************************************************
235 
236 
237 //*************************************************************************************************
247 template< typename MT > // Type of the adapted matrix
248 template< typename T > // Type of the right-hand side value
249 inline const UpperProxy<MT>& UpperProxy<MT>::operator=( const T& value ) const
250 {
251  if( restricted_ )
252  throw std::invalid_argument( "Invalid assignment to lower matrix element" );
253 
254  value_ = value;
255 
256  return *this;
257 }
258 //*************************************************************************************************
259 
260 
261 //*************************************************************************************************
271 template< typename MT > // Type of the adapted matrix
272 template< typename T > // Type of the right-hand side value
273 inline const UpperProxy<MT>& UpperProxy<MT>::operator+=( const T& value ) const
274 {
275  if( restricted_ )
276  throw std::invalid_argument( "Invalid assignment to lower matrix element" );
277 
278  value_ += value;
279 
280  return *this;
281 }
282 //*************************************************************************************************
283 
284 
285 //*************************************************************************************************
295 template< typename MT > // Type of the adapted matrix
296 template< typename T > // Type of the right-hand side value
297 inline const UpperProxy<MT>& UpperProxy<MT>::operator-=( const T& value ) const
298 {
299  if( restricted_ )
300  throw std::invalid_argument( "Invalid assignment to lower matrix element" );
301 
302  value_ -= value;
303 
304  return *this;
305 }
306 //*************************************************************************************************
307 
308 
309 //*************************************************************************************************
319 template< typename MT > // Type of the adapted matrix
320 template< typename T > // Type of the right-hand side value
321 inline const UpperProxy<MT>& UpperProxy<MT>::operator*=( const T& value ) const
322 {
323  if( restricted_ )
324  throw std::invalid_argument( "Invalid assignment to lower matrix element" );
325 
326  value_ *= value;
327 
328  return *this;
329 }
330 //*************************************************************************************************
331 
332 
333 //*************************************************************************************************
343 template< typename MT > // Type of the adapted matrix
344 template< typename T > // Type of the right-hand side value
345 inline const UpperProxy<MT>& UpperProxy<MT>::operator/=( const T& value ) const
346 {
347  if( restricted_ )
348  throw std::invalid_argument( "Invalid assignment to lower matrix element" );
349 
350  value_ /= value;
351 
352  return *this;
353 }
354 //*************************************************************************************************
355 
356 
357 
358 
359 //=================================================================================================
360 //
361 // UTILITY FUNCTIONS
362 //
363 //=================================================================================================
364 
365 //*************************************************************************************************
370 template< typename MT > // Type of the adapted matrix
372 {
373  return value_;
374 }
375 //*************************************************************************************************
376 
377 
378 //*************************************************************************************************
383 template< typename MT > // Type of the adapted matrix
384 inline bool UpperProxy<MT>::isRestricted() const
385 {
386  return restricted_;
387 }
388 //*************************************************************************************************
389 
390 
391 
392 
393 //=================================================================================================
394 //
395 // CONVERSION OPERATOR
396 //
397 //=================================================================================================
398 
399 //*************************************************************************************************
404 template< typename MT > // Type of the adapted matrix
406 {
407  return get();
408 }
409 //*************************************************************************************************
410 
411 
412 
413 
414 //=================================================================================================
415 //
416 // GLOBAL OPERATORS
417 //
418 //=================================================================================================
419 
420 //*************************************************************************************************
423 template< typename MT1, typename MT2 >
424 inline bool operator==( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs );
425 
426 template< typename MT, typename T >
427 inline bool operator==( const UpperProxy<MT>& lhs, const T& rhs );
428 
429 template< typename T, typename MT >
430 inline bool operator==( const T& lhs, const UpperProxy<MT>& rhs );
431 
432 template< typename MT1, typename MT2 >
433 inline bool operator!=( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs );
434 
435 template< typename MT, typename T >
436 inline bool operator!=( const UpperProxy<MT>& lhs, const T& rhs );
437 
438 template< typename T, typename MT >
439 inline bool operator!=( const T& lhs, const UpperProxy<MT>& rhs );
440 
441 template< typename MT1, typename MT2 >
442 inline bool operator<( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs );
443 
444 template< typename MT, typename T >
445 inline bool operator<( const UpperProxy<MT>& lhs, const T& rhs );
446 
447 template< typename T, typename MT >
448 inline bool operator<( const T& lhs, const UpperProxy<MT>& rhs );
449 
450 template< typename MT1, typename MT2 >
451 inline bool operator>( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs );
452 
453 template< typename MT, typename T >
454 inline bool operator>( const UpperProxy<MT>& lhs, const T& rhs );
455 
456 template< typename T, typename MT >
457 inline bool operator>( const T& lhs, const UpperProxy<MT>& rhs );
458 
459 template< typename MT1, typename MT2 >
460 inline bool operator<=( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs );
461 
462 template< typename MT, typename T >
463 inline bool operator<=( const UpperProxy<MT>& lhs, const T& rhs );
464 
465 template< typename T, typename MT >
466 inline bool operator<=( const T& lhs, const UpperProxy<MT>& rhs );
467 
468 template< typename MT1, typename MT2 >
469 inline bool operator>=( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs );
470 
471 template< typename MT, typename T >
472 inline bool operator>=( const UpperProxy<MT>& lhs, const T& rhs );
473 
474 template< typename T, typename MT >
475 inline bool operator>=( const T& lhs, const UpperProxy<MT>& rhs );
476 
477 template< typename MT >
478 inline std::ostream& operator<<( std::ostream& os, const UpperProxy<MT>& proxy );
480 //*************************************************************************************************
481 
482 
483 //*************************************************************************************************
491 template< typename MT1, typename MT2 >
492 inline bool operator==( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs )
493 {
494  return ( lhs.get() == rhs.get() );
495 }
496 //*************************************************************************************************
497 
498 
499 //*************************************************************************************************
507 template< typename MT, typename T >
508 inline bool operator==( const UpperProxy<MT>& lhs, const T& rhs )
509 {
510  return ( lhs.get() == rhs );
511 }
512 //*************************************************************************************************
513 
514 
515 //*************************************************************************************************
523 template< typename T, typename MT >
524 inline bool operator==( const T& lhs, const UpperProxy<MT>& rhs )
525 {
526  return ( lhs == rhs.get() );
527 }
528 //*************************************************************************************************
529 
530 
531 //*************************************************************************************************
539 template< typename MT1, typename MT2 >
540 inline bool operator!=( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs )
541 {
542  return ( lhs.get() != rhs.get() );
543 }
544 //*************************************************************************************************
545 
546 
547 //*************************************************************************************************
555 template< typename MT, typename T >
556 inline bool operator!=( const UpperProxy<MT>& lhs, const T& rhs )
557 {
558  return ( lhs.get() != rhs );
559 }
560 //*************************************************************************************************
561 
562 
563 //*************************************************************************************************
571 template< typename T, typename MT >
572 inline bool operator!=( const T& lhs, const UpperProxy<MT>& rhs )
573 {
574  return ( lhs != rhs.get() );
575 }
576 //*************************************************************************************************
577 
578 
579 //*************************************************************************************************
587 template< typename MT1, typename MT2 >
588 inline bool operator<( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs )
589 {
590  return ( lhs.get() < rhs.get() );
591 }
592 //*************************************************************************************************
593 
594 
595 //*************************************************************************************************
603 template< typename MT, typename T >
604 inline bool operator<( const UpperProxy<MT>& lhs, const T& rhs )
605 {
606  return ( lhs.get() < rhs );
607 }
608 //*************************************************************************************************
609 
610 
611 //*************************************************************************************************
619 template< typename T, typename MT >
620 inline bool operator<( const T& lhs, const UpperProxy<MT>& rhs )
621 {
622  return ( lhs < rhs.get() );
623 }
624 //*************************************************************************************************
625 
626 
627 //*************************************************************************************************
635 template< typename MT1, typename MT2 >
636 inline bool operator>( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs )
637 {
638  return ( lhs.get() > rhs.get() );
639 }
640 //*************************************************************************************************
641 
642 
643 //*************************************************************************************************
651 template< typename MT, typename T >
652 inline bool operator>( const UpperProxy<MT>& lhs, const T& rhs )
653 {
654  return ( lhs.get() > rhs );
655 }
656 //*************************************************************************************************
657 
658 
659 //*************************************************************************************************
667 template< typename T, typename MT >
668 inline bool operator>( const T& lhs, const UpperProxy<MT>& rhs )
669 {
670  return ( lhs > rhs.get() );
671 }
672 //*************************************************************************************************
673 
674 
675 //*************************************************************************************************
683 template< typename MT1, typename MT2 >
684 inline bool operator<=( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs )
685 {
686  return ( lhs.get() <= rhs.get() );
687 }
688 //*************************************************************************************************
689 
690 
691 //*************************************************************************************************
699 template< typename MT, typename T >
700 inline bool operator<=( const UpperProxy<MT>& lhs, const T& rhs )
701 {
702  return ( lhs.get() <= rhs );
703 }
704 //*************************************************************************************************
705 
706 
707 //*************************************************************************************************
715 template< typename T, typename MT >
716 inline bool operator<=( const T& lhs, const UpperProxy<MT>& rhs )
717 {
718  return ( lhs <= rhs.get() );
719 }
720 //*************************************************************************************************
721 
722 
723 //*************************************************************************************************
731 template< typename MT1, typename MT2 >
732 inline bool operator>=( const UpperProxy<MT1>& lhs, const UpperProxy<MT2>& rhs )
733 {
734  return ( lhs.get() >= rhs.get() );
735 }
736 //*************************************************************************************************
737 
738 
739 //*************************************************************************************************
747 template< typename MT, typename T >
748 inline bool operator>=( const UpperProxy<MT>& lhs, const T& rhs )
749 {
750  return ( lhs.get() >= rhs );
751 }
752 //*************************************************************************************************
753 
754 
755 //*************************************************************************************************
763 template< typename T, typename MT >
764 inline bool operator>=( const T& lhs, const UpperProxy<MT>& rhs )
765 {
766  return ( lhs >= rhs.get() );
767 }
768 //*************************************************************************************************
769 
770 
771 //*************************************************************************************************
779 template< typename MT >
780 inline std::ostream& operator<<( std::ostream& os, const UpperProxy<MT>& proxy )
781 {
782  return os << proxy.get();
783 }
784 //*************************************************************************************************
785 
786 
787 
788 
789 //=================================================================================================
790 //
791 // GLOBAL FUNCTIONS
792 //
793 //=================================================================================================
794 
795 //*************************************************************************************************
798 template< typename MT >
799 inline void reset( const UpperProxy<MT>& proxy );
800 
801 template< typename MT >
802 inline void clear( const UpperProxy<MT>& proxy );
803 
804 template< typename MT >
805 inline bool isDefault( const UpperProxy<MT>& proxy );
807 //*************************************************************************************************
808 
809 
810 //*************************************************************************************************
820 template< typename MT >
821 inline void reset( const UpperProxy<MT>& proxy )
822 {
823  using blaze::reset;
824 
825  reset( proxy.get() );
826 }
827 //*************************************************************************************************
828 
829 
830 //*************************************************************************************************
840 template< typename MT >
841 inline void clear( const UpperProxy<MT>& proxy )
842 {
843  using blaze::clear;
844 
845  clear( proxy.get() );
846 }
847 //*************************************************************************************************
848 
849 
850 //*************************************************************************************************
860 template< typename MT >
861 inline bool isDefault( const UpperProxy<MT>& proxy )
862 {
863  using blaze::isDefault;
864 
865  return isDefault( proxy.get() );
866 }
867 //*************************************************************************************************
868 
869 } // namespace blaze
870 
871 #endif
#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
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: Proxy.h:99
bool isRestricted() const
Returns whether the proxy represents a restricted matrix element..
Definition: UpperProxy.h:384
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
RawReference get() const
Returning the value of the accessed matrix element.
Definition: UpperProxy.h:371
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:103
bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:366
bool operator>=(const NegativeAccuracy< A > &, const T &rhs)
Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value...
Definition: Accuracy.h:442
#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:103
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
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
const bool restricted_
Access flag for the accessed matrix element.
Definition: UpperProxy.h:153
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.
AddReference< ReferenceType >::Type RawReference
Reference to the represented element.
Definition: UpperProxy.h:106
Constraint on the data type.
#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:2505
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:841
ReferenceType value_
Reference to the accessed matrix element.
Definition: UpperProxy.h:152
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:103
#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
Header file for the Proxy class.
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:193
Access proxy for upper triangular matrices.The UpperProxy provides controlled access to the elements ...
Definition: UpperProxy.h:92
const UpperProxy & operator=(const UpperProxy &up) const
Copy assignment operator for UpperProxy.
Definition: UpperProxy.h:228
#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 operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
Header file for the AddReference type trait.
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
#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
AddConst< typename MT::Reference >::Type ReferenceType
Reference type of the underlying matrix type.
Definition: UpperProxy.h:97