C++QEDCore  2.100.2 (v2 Milestone 10 Development branch)
a framework for simulating open quantum dynamics – core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BlitzArrayTraits.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)
3 // -*- C++ -*-
4 #ifndef CPPQEDCORE_UTILS_BLITZARRAYTRAITS_H_INCLUDED
5 #define CPPQEDCORE_UTILS_BLITZARRAYTRAITS_H_INCLUDED
6 
7 #include "ArrayTraits.h"
8 #include "BlitzArray.h"
9 
10 #include <boost/mpl/int.hpp>
11 
12 
13 namespace cpputils {
14 
15 
18 template<typename Numtype, int RANK>
19 struct Rank<blitz::Array<Numtype,RANK> > : boost::mpl::int_<RANK> {};
20 
21 template<int RANK>
22 struct TypeID<DArray<RANK> >
23 {
24  static const std::string value;
25 };
26 
27 template<int RANK>
28 const std::string TypeID<DArray<RANK> >::value="DArray";
29 
30 
31 template<int RANK>
32 struct TypeID<CArray<RANK> >
33 {
34  static const std::string value;
35 };
36 
37 template<int RANK>
38 const std::string TypeID<CArray<RANK> >::value="CArray";
39 
43 
45 
46 template<int n>
47 inline bool isStorageContiguous(const DArray<n>& a) {return a.isStorageContiguous();}
48 
49 
50 template<int n>
51 inline size_t size(const DArray<n>& a) {return a.size();}
52 
53 
54 template<int n>
55 inline std::vector<size_t> dimensions(const DArray<n>& a) {return std::vector<size_t>(a.extent().begin(),a.extent().end());}
56 
57 
58 template<int n>
59 inline const double* data(const DArray<n>& a) {return a.size() ? a.data() : 0;}
60 
61 template<int n>
62 inline double* data( DArray<n>& a) {return const_cast<double*>(data(static_cast<const DArray<n>&>(a)));}
63 
64 
65 template<int n>
66 inline DArray<n> create( double* y, const DArray<n>& a) {return DArray<n>(y,a.shape(),blitz::neverDeleteData);}
67 
68 template<int n>
69 inline const DArray<n> create(const double* y, const DArray<n>& a) {return create(const_cast<double*>(y),a);}
70 
71 
72 template<int n>
73 inline DArray<n> create(const DArray<n>& a) {return DArray<n>(a.shape());}
74 
76 
77 
79 
80 
81 template<int n>
82 inline bool isStorageContiguous(const CArray<n>& a) {return a.isStorageContiguous();}
83 
84 
85 template<int n>
86 inline size_t size(const CArray<n>& a) {return a.size()<<1;} // The size of the underlying double* storage!!!
87 
88 
89 template<int n>
90 inline std::vector<size_t> dimensions(const CArray<n>& a) {return std::vector<size_t>(a.extent().begin(),a.extent().end());}
91 
92 
93 template<int n>
94 inline const double* data(const CArray<n>& a) {return a.size() ? real(a).data() : 0;}
95 
96 template<int n>
97 inline double* data( CArray<n>& a) {return const_cast<double*>(data(static_cast<const CArray<n>&>(a)));}
98 
99 
100 template<int n>
101 inline CArray<n> create( double* y, const CArray<n>& a) {return CArray<n>(reinterpret_cast<dcomp*>(y),a.shape(),blitz::neverDeleteData);}
102 
103 template<int n>
104 inline const CArray<n> create(const double* y, const CArray<n>& a) {return create(const_cast<double*>(y),a);}
105 
106 
107 template<int n>
108 inline CArray<n> create(const CArray<n>& a) {return CArray<n>(a.shape());}
110 
111 
112 
114 
115 
116 inline const double& subscript(const DArray<1>& a, size_t i) {return a(i);}
117 inline double& subscript( DArray<1>& a, size_t i) {return const_cast<double&>(subscript(static_cast<const DArray<1>&>(a),i));}
118 
119 inline size_t subscriptLimit(const DArray<1>& a) {return a.size();}
120 
121 
122 inline const dcomp& subscript(const CArray<1>& a, size_t i) {return a(i);}
123 inline dcomp& subscript( CArray<1>& a, size_t i) {return const_cast<dcomp&>(subscript(static_cast<const CArray<1>&>(a),i));}
124 
125 inline size_t subscriptLimit(const CArray<1>& a) {return a.size();}
126 
127 inline size_t stride(const CArray<1>& a) {return a.stride(0);}
129 
130 
131 
133 
134 
138 template<int n>
139 inline const dcomp& subscript(const CArray<n>& a, size_t i) {return *(a.begin()+i);}
140 
141 template<int n>
142 inline dcomp& subscript( CArray<n>& a, size_t i) {return const_cast<dcomp&>(subscript(static_cast<const CArray<n>&>(a),i));}
143 
144 template<int n>
145 inline size_t subscriptLimit(const CArray<n>& a) {return a.size();}
147 
148 } // cpputils
149 
150 #endif // CPPQEDCORE_UTILS_BLITZARRAYTRAITS_H_INCLUDED
Namespace comprising otherwise hard-to-classify generic utilities.
Definition: Algorithm.h:10
blitz::Array< dcomp,RANK > CArray
A complex array of arbitrary arity.
Definition: BlitzArray.h:16
A create(double *y, const A &a)
Clone (create a non-owning array of data y of the same memory layout as a)
blitz::Array< double, RANK > DArray
An array of doubles of arbitrary arity.
Definition: BlitzArray.h:13
Declarations of traits functions for adapting array types to generic functions.
const A::element_type & subscript(const A &a, size_t i)
subscription of a (which might be a multi-array) with a single integer
std::complex< double > dcomp
Double-precision complex number.
Defines template aliases for real and complex arrays.