Common.hxx
1 // Copyright (C) 2001-2012 Vivien Mallet
2 //
3 // This file is part of the linear-algebra library Seldon,
4 // http://seldon.sourceforge.net/.
5 //
6 // Seldon is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your option)
9 // any later version.
10 //
11 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 // more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with Seldon. If not, see http://www.gnu.org/licenses/.
18 
19 
20 #ifndef SELDON_FILE_COMMON_HXX
21 
22 #include <complex>
23 #include <iostream>
24 #include <typeinfo>
25 
26 #ifdef SELDON_WITH_HDF5
27 #include <hdf5.h>
28 #endif
29 
30 namespace std
31 {
32  template<class T>
33  T conjugate(const T& x);
34 
35  template<class T>
36  complex<T> conjugate(const complex<T>& x);
37 
38  template<class T>
39  T realpart(const T& x);
40 
41  template<class T>
42  T realpart(const complex<T>& x);
43 }
44 
45 namespace Seldon
46 {
47  using namespace std;
48 
49  template <class T>
50  void PrintArray(T* v, int lgth);
51 
53 
57  class Str
58  {
59  private:
61  std::ostringstream output_;
62 
63  public:
64  Str();
65  Str(const Str& s);
66  operator std::string() const;
67  template <class T>
68  Str& operator << (const T& input);
69  };
70 
71  template <class T>
72  Str operator + (const Str&, const T& input);
73 
74 #ifndef SWIG
75  ostream& operator << (ostream& out, Str& in);
76  ostream& operator << (ostream& out, Str in);
77 #endif
78 
79 
80  template<typename T>
81  std::string to_str(const T& input);
82 
83  template <class T>
84  void to_num(std::string s, T& num);
85 
86  template <class T>
87  T to_num(std::string s);
88 
90 
98  template<class T>
100  {
101  public :
102  typedef T Treal;
103  typedef std::complex<T> Tcplx;
104  };
105 
107  template<class T>
108  class ClassComplexType< complex<T> >
109  {
110  public :
111  typedef T Treal;
112  typedef std::complex<T> Tcplx;
113  };
114 
115  template <class T>
116  void SetComplexZero(T& number);
117 
118  template <class T>
119  void SetComplexZero(std::complex<T>& number);
120 
121  template <class T>
122  void SetComplexOne(T& number);
123 
124  template <class T>
125  void SetComplexOne(std::complex<T>& number);
126 
127  template <class T>
128  void SetComplexReal(int n, std::complex<T>& number);
129 
130  template <class T>
131  void SetComplexReal(int n, T& number);
132 
133  template <class T>
134  void SetComplexReal(bool n, std::complex<T>& number);
135 
136  void SetComplexReal(int x, std::complex<int>& number);
137 
138  template <class T>
139  void SetComplexReal(const T& x, std::complex<T>& number);
140 
141  template <class T>
142  void SetComplexReal(const std::complex<T>& x, T& number);
143 
144  template <class T0, class T1>
145  void SetComplexReal(const T0& x, T1& number);
146 
147  template<class T>
148  T ComplexAbs(const T& val);
149 
150  template<class T>
151  T ComplexAbs(const std::complex<T>& val);
152 
153  template<class T>
154  T absSquare(const T& x);
155 
156  template<class T>
157  T absSquare(const std::complex<T>& x);
158 
159  string GetExtension(const string& nom);
160  string GetBaseString(const string& nom);
161 
162 #ifdef SELDON_WITH_HDF5
163  template <class T>
164  hid_t GetH5Type(T& input);
165 #endif
166 
167  void InitSeldon(int, char**);
168  int FinalizeSeldon();
169 
170 } // namespace Seldon.
171 
172 #include "CommonInline.cxx"
173 #define SELDON_FILE_COMMON_HXX
174 #endif
Seldon::ClassComplexType
workaround class to retrieve double type from complex<double>
Definition: Common.hxx:99
Seldon::GetBaseString
string GetBaseString(const string &nom)
returns base of a string
Definition: Common.cxx:43
Seldon::operator+
const TinyMatrixSum< T, m, n, E1, E2 > operator+(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns u+v
Definition: TinyMatrixExpressionInline.cxx:197
Seldon::to_str
std::string to_str(const T &input)
Converts most types to string.
Definition: CommonInline.cxx:137
Seldon::Str
This class helps formatting C++ strings on the fly.
Definition: Common.hxx:57
Seldon::absSquare
T absSquare(const T &x)
returns the square modulus of z
Definition: CommonInline.cxx:340
Seldon::InitSeldon
void InitSeldon(int argc, char **argv)
Function to call in parallel to initialize MPI.
Definition: Common.cxx:105
Seldon::GetExtension
string GetExtension(const string &nom)
returns extension of a string
Definition: Common.cxx:31
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::operator<<
ostream & operator<<(ostream &out, const Array< T, N, Allocator > &A)
operator<< overloaded for a 3D array.
Definition: Array.cxx:1617
Seldon::SetComplexReal
void SetComplexReal(int n, std::complex< T > &number)
Sets a complex number to (n, 0).
Definition: CommonInline.cxx:234
Seldon::ComplexAbs
T ComplexAbs(const T &val)
returns absolute value of val
Definition: CommonInline.cxx:309