MADNESS  version 0.9
type_data.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31 
32  $Id$
33 */
34 
35 
36 #ifndef MADNESS_TENSOR_TYPE_DATA_H__INCLUDED
37 #define MADNESS_TENSOR_TYPE_DATA_H__INCLUDED
38 
41 
42 namespace madness {
43 
45 
55  template <class T>
57  public:
58  enum {id = -1};
59  enum {supported = false};
60  enum {iscomplex = false};
61  enum {memcopyok = false};
62  typedef T type;
63  //typedef T scalar_type;
64  };
65 
67  template <int id>
69  public:
70  typedef long type;
71  };
72 
73  // id=unique and sequential identifier for each type
74  //
75  // supported=true for all supported scalar numeric types
76  //
77  // iscomplex=true if a complex type
78  //
79  // memcopyok=true if memcpy can be used to copy an array
80  // of the type ... it should be true for all native types
81  // and probably false for all types that require a
82  // special constructor or assignment operator.
83  //
84  // type=the actual type
85  //
86  // scalar_type = is the type of abs, normf, absmin, absmax, real, imag.
87  // Not all of these functions are defined for all types.
88  // Unfortunately, in the current version, some misuses will only be
89  // detected at run time.
90 
91 
92 #define TYPEINFO(num, T, iscmplx, mcpyok, realT,floatrealT) \
93 template<> class TensorTypeData<T> {\
94 public: \
95  enum {id = num}; \
96  enum {supported = true}; \
97  enum {iscomplex = iscmplx}; \
98  enum {memcopyok = mcpyok}; \
99  typedef T type; \
100  typedef realT scalar_type; \
101  typedef floatrealT float_scalar_type; \
102 }; \
103 template<> class TensorTypeFromId<num> {\
104 public: \
105  typedef T type; \
106 }
107 
108  TYPEINFO(0,int,false,true,int,double);
109  TYPEINFO(1,long,false,true,long,double);
110  TYPEINFO(2,float,false,true,float,float);
111  TYPEINFO(3,double,false,true,double,double);
112  TYPEINFO(4,float_complex,true,true,float,float);
113  TYPEINFO(5,double_complex,true,true,double,double);
114 
115 #ifdef HAVE_LONG_LONG
116  TYPEINFO(6,long long,false,true,long long,double);
117 #define TENSOR_MAX_TYPE_ID 6
118 #else
119 #define TENSOR_MAX_TYPE_ID 5
120 #endif // HAVE_LONG_LONG
121 
122 #undef TYPEINFO
123 
124 #ifdef TENSOR_CC
125  const char *tensor_type_names[TENSOR_MAX_TYPE_ID+1] = {
126  "int","long","float","double","float_complex","double_complex"
127 #ifdef HAVE_LONG_LONG
128  ,"long long"
129 #endif // HAVE_LONG_LONG
130  };
131 #else
132  extern const char *tensor_type_names[];
133 #endif
134 
148 
149  template <typename TypeData, typename, bool = TypeData::supported>
150  struct IsSupported;
151 
152  template <typename TypeData, typename ReturnType>
153  struct IsSupported <TypeData, ReturnType, true> {
154  typedef ReturnType type;
155  };
156 
157  // This macro embodies the above for a single parameter template.
158  // Look in tensor.h for example of how to use in multi-parameter
159  // templates.
160  //
161  // *** !!! *** Unfortunately, this macro was confusing Doxygen
162  // so we have removed all usages.
163  //#define ISSUPPORTED(T,RETURNTYPE)
164  //template <typename T> typename IsSupported < TensorTypeData<T>, RETURNTYPE >::type
165 
167  template <typename leftT, typename rightT>
168  struct TensorResultType {};
169 
170 #define SPEC(L,R,T) \
171  template <> struct TensorResultType<L,R> {typedef T type;}; \
172  template <> struct TensorResultType<R,L> {typedef T type;}
173 #define DPEC(L,R,T) \
174  template <> struct TensorResultType<L,L> {typedef T type;}
175 
176  DPEC(int,int,int);
177  SPEC(int,long,long);
178  SPEC(int,float,float);
179  SPEC(int,double,double);
182  DPEC(long,long,long);
183  SPEC(long,float,float);
184  SPEC(long,double,double);
187  DPEC(float,float,float);
188  SPEC(float,double,double);
191  DPEC(double,double,double);
197 
198 #ifdef HAVE_LONG_LONG
199  SPEC(int,long long,long long);
200  SPEC(long,long long,long long);
201  DPEC(long long,long long,long long);
202  SPEC(long long,float,float);
203  SPEC(long long,double,double);
204  SPEC(long long,float_complex,float_complex);
206 #endif // HAVE_LONG_LONG
207 
209 #define TENSOR_RESULT_TYPE(L,R) typename TensorResultType<L,R>::type
210 
211 
212 #undef DPEC
213 #undef SPEC
214 }
215 #endif // MADNESS_TENSOR_TYPE_DATA_H__INCLUDED
Definition: type_data.h:61
std::complex< double > double_complex
Definition: lineplot.cc:16
This provides the reverse mapping from integer id to type name.
Definition: type_data.h:68
SPEC(int, long, long)
Definition: type_data.h:150
long type
Definition: type_data.h:70
DPEC(int, int, int)
ReturnType type
Definition: type_data.h:154
Definition: type_data.h:59
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
T type
Definition: type_data.h:62
TYPEINFO(0, int, false, true, int, double)
Definition: type_data.h:60
const char * tensor_type_names[]
std::complex< float > float_complex
Definition: ran.h:40
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
TensorResultType::type is the type of (L op R) where op is nominally multiplication.
Definition: type_data.h:168
Traits class to specify support of numeric types.
Definition: type_data.h:56
#define TENSOR_MAX_TYPE_ID
Definition: type_data.h:119