C++QEDCore  v2 Milestone 10
a framework for simulating open quantum dynamics – core
ArrayBase.h
Go to the documentation of this file.
1 // Copyright András Vukics 2006–2014. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt)
2 // -*- C++ -*-
4 #ifndef CPPQEDCORE_QUANTUMDATA_ARRAYBASE_H_INCLUDED
5 #define CPPQEDCORE_QUANTUMDATA_ARRAYBASE_H_INCLUDED
6 
7 #include "ArrayBaseFwd.h"
8 
9 #include "BlitzArrayExtensions.h"
10 #include "CMatrix.h"
11 #include "ComplexArrayExtensions.h"
12 
13 #include <boost/utility.hpp>
14 
15 
16 namespace quantumdata {
17 
18 
20 template<int RANK>
21 class ArrayBase : private boost::noncopyable
22 {
23 protected:
25  typedef linalg::CVector CVector;
26 
27  explicit ArrayBase(const ArrayLow& arrayLow) : arrayLow_(arrayLow) {}
28 
29  virtual ~ArrayBase() {}
30 
32 
35  ArrayBase& operator=(const ArrayLow& arrayLow ) {arrayLow_=arrayLow; return *this;}
36 
38 
39  const ArrayLow& getArray() const {return arrayLow_;}
40  ArrayLow& getArray() {return const_cast<ArrayLow&>(static_cast<const ArrayBase*>(this)->getArray());}
42 
44 
45  void operator+=(const ArrayBase& arrayBase) {arrayLow_+=arrayBase.arrayLow_;}
46  void operator-=(const ArrayBase& arrayBase) {arrayLow_-=arrayBase.arrayLow_;}
48 
50 
51  template<typename OTHER>
52  void operator*=(const OTHER& dc) {arrayLow_*=dc;}
53 
54  template<typename OTHER>
55  void operator/=(const OTHER& dc) {arrayLow_/=dc;}
57 
59 
60 
66  const CVector vectorView() const {return blitzplusplus::unaryArray(arrayLow_);}
67  CVector vectorView() {return blitzplusplus::unaryArray(arrayLow_);}
68  // The usual technique of defining the non-const in terms of the const doesn't work here, because `CVector is not a pointer, reference, nor a pointer-to-data-member type'
70 
72 
76  double frobeniusNorm() const {return sqrt(sum(blitzplusplus::sqrAbs(arrayLow_)));}
77 
78 private:
79  ArrayLow arrayLow_;
80 
81 };
82 
83 
84 } // quantumdata
85 
86 
87 
88 #endif // CPPQEDCORE_QUANTUMDATA_ARRAYBASE_H_INCLUDED
Comprises the common functionalities of StateVector and DensityOperator.
Definition: ArrayBase.h:21
ArrayBase & operator=(const ArrayLow &arrayLow)
Assignment with by-value semantics (like the assignment of a blitz::Array).
Definition: ArrayBase.h:35
Comprises classes representing the state of composite quantum systems and providing various interface...
Definition: ArrayBase.h:16
const CVector vectorView() const
1d view created on the fly via blitzplusplus::unaryArray.
Definition: ArrayBase.h:66
blitz::Array< dcomp,RANK > CArray
A complex array of arbitrary arity.
Definition: BlitzArray.h:16
CArray< 1 > CVector
Complex vector.
Definition: CVector.h:13
ArrayBase(const ArrayLow &arrayLow)
By-reference semantics (basically the copy of a blitz::Array). Apart from this, copying is not possib...
Definition: ArrayBase.h:27
defines the typedef linalg::CMatrix and some helpers
const blitz::Array< T, 1 > unaryArray(const blitz::Array< T, RANK > &)
Returns a unary view of array
double frobeniusNorm() const
The entrywise array norm.
Definition: ArrayBase.h:76
Declares extensions for creating vector & matrix views of blitz::Arrays.
CArray< RANK > ArrayLow
The underlying storage.
Definition: ArrayBase.h:24
CVector vectorView()
Definition: ArrayBase.h:67
Helpers for complex blitz::Arrays, e.g. Hermitian conjugation of multi-matrices.