Shark.h
Go to the documentation of this file.
1 /**
2  * \mainpage Shark Machine Learning Library Ver. 3.0.0.
3  * Shark is a modular C++ library for the design and
4  * optimization of adaptive systems. It provides methods for linear
5  * and nonlinear optimization, in particular evolutionary and
6  * gradient-based algorithms, kernel-based learning algorithms and
7  * neural networks, and various other machine learning
8  * techniques. SHARK serves as a toolbox to support real world
9  * applications as well as research in different domains of
10  * computational intelligence and machine learning. The sources are
11  * compatible with the following platforms: Windows, Solaris, MacOS X,
12  * and Linux.
13  *
14  * \date 2011
15  *
16  * \par Copyright 1995-2017 Shark Development Team
17  *
18  * <BR><HR>
19  * This file is part of Shark.
20  * <http://shark-ml.org/>
21  *
22  * Shark is free software: you can redistribute it and/or modify
23  * it under the terms of the GNU Lesser General Public License as published
24  * by the Free Software Foundation, either version 3 of the License, or
25  * (at your option) any later version.
26  *
27  * Shark is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  *
32  * You should have received a copy of the GNU Lesser General Public License
33  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
34  *
35  */
36 #ifndef SHARK_CORE_SHARK_H
37 #define SHARK_CORE_SHARK_H
38 
39 #include <boost/version.hpp>
40 #include <boost/assign.hpp>
41 #include <boost/config.hpp>
42 #include <boost/property_tree/ptree.hpp>
43 #include <boost/property_tree/json_parser.hpp>
44 
45 #include <iostream>
46 #include <map>
47 #include <string>
48 
49 namespace shark {
50 
51 /**
52  * \namespace General namespace of the whole Shark machine learning library.
53  */
54 
55 /**
56  * \brief Models the build type.
57  */
58 enum BuildType {
59  RELEASE_BUILD_TYPE, ///< A release build.
60  DEBUG_BUILD_TYPE ///< A debug build.
61 };
62 
63 namespace tag {
64 
65 /**
66  * \namespace tag Tagging namespace for type-based dispatching.
67  */
68 
69 /**
70  * \brief Tags the build type.
71  */
72 struct BuildTypeTag {
73  /**
74  * \brief The build settings that the library has been compiled with.
75  */
76 #if defined( _DEBUG ) || defined( DEBUG )
77  static const BuildType VALUE = DEBUG_BUILD_TYPE;
78 #else
79  static const BuildType VALUE = RELEASE_BUILD_TYPE;
80 #endif
81 };
82 
83 /**
84  * \brief Tags whether this is a dynamic build
85  */
86 /* #undef SHARK_USE_DYNLIB */
87 struct DynamicLibraryTag{
88  /**
89  * \brief Whether this is a dynamic or static build of Shark
90  */
91 #ifdef SHARK_USE_DYNLIB
92  static const bool VALUE = true;
93 #else
94  static const bool VALUE = false;
95 #endif
96 };
97 
98 /**
99  * \brief Tags whether SIMD has been enabled.
100  */
101 /* #undef SHARK_USE_SIMD */
102 
103 #ifdef SHARK_USE_SIMD
104 #define REMORA_USE_SIMD
105 #endif
106 /**
107  * \brief Tags whether BLAS has been enabled.
108  */
109 #define SHARK_USE_CBLAS
110 #ifdef SHARK_USE_CBLAS
111 #define REMORA_USE_CBLAS
112 #endif
113 
114 /**
115  * \brief Tags whether CLBLAS has been enabled.
116  */
117 /* #undef SHARK_USE_CLBLAS */
118 #ifdef SHARK_USE_CLBLAS
119 #define REMORA_USE_GPU
120 #endif
121 
122  /**
123  * \brief Tags whether full LAPACK is available
124  */
125 /* #undef SHARK_USE_LAPACK */
126 
127  /**
128  * \brief Tags whether the LAPACK portion of ATLAS is used
129  */
130 /* #undef SHARK_USE_ATLAS_LAPACK */
131 
132 /**
133  * \brief Tags whether OpenMP has been enabled.
134  */
135 /* #undef SHARK_USE_OPENMP */
136 struct OpenMpTag {
137 #ifdef _OPENMP
138  static const bool VALUE = true;
139 #else
140  static const bool VALUE = false;
141 #endif
142 };
143 
144 /**
145  * \brief Tags official releases of the shark library.
146  */
147 struct OfficialReleaseTag {
148 #ifdef SHARK_OFFICIAL_RELEASE
149  static const bool VALUE = true;
150 #else
151  static const bool VALUE = false;
152 #endif
153 };
154 
155 }
156 
157 /**
158  * \brief Allows for querying compile settings at runtime. Provides the
159  * current command line arguments to the rest of the library.
160  */
161 class Shark {
162  protected:
163  // Not implemented
164  Shark();
165  Shark( const Shark & shark );
166  Shark & operator=( const Shark & rhs );
167  public:
168 
169  /**
170  * \brief Models a version according to the major.minor.patch versioning scheme.
171  */
172  template<unsigned int major, unsigned int minor, unsigned int patch>
173  struct Version {
174 
175  /** \brief Default printf-format for formatting version numbers. */
176  static const char * DEFAULT_FORMAT() {
177  return( "%d.%d.%d" );
178  }
179 
180  /** @brief Returns the major revision number. */
181  static unsigned int MAJOR() {
182  return( major );
183  }
184 
185  /** @brief Returns the minor revision number. */
186  static unsigned int MINOR() {
187  return( minor );
188  }
189 
190  /** @brief Returns the patch revision number. */
191  static unsigned int PATCH() {
192  return( patch );
193  }
194 
195  };
196 
197  /**
198  * \brief Marks the current version of the Shark Machine Learning Library.
199  */
200  typedef Version<
201  3,
202  1,
203  0
204  > version_type;
205 
206  /**
207  * \brief Marks the boost version Shark has been built against.
208  */
209  typedef Version<
210  BOOST_VERSION / 100000,
211  ((BOOST_VERSION / 100) % 1000),
212  (BOOST_VERSION % 100)
214 
215  /**
216  * \brief Accesses the build type of the library.
217  */
218  static BuildType buildType() {
219  return( tag::BuildTypeTag::VALUE );
220  }
221 
222  /**
223  * \brief Queries whether Shark has been compiled with OpenMP enabled.
224  */
225  static bool hasOpenMp() {
226  return( tag::OpenMpTag::VALUE );
227  }
228 
229  /**
230  * \brief Queries whether Shark has been compiled as dynamic library
231  */
232  static bool isDynamicLibrary() {
233  return( tag::DynamicLibraryTag::VALUE );
234  }
235 
236  /**
237  * \brief Checks whether this is an official Shark release.
238  */
239  static bool isOfficialRelease() {
240  return( tag::OfficialReleaseTag::VALUE );
241  }
242 
243  /**
244  * \brief Prints information about the Shark Machine Learning Library to the supplied stream.
245  */
246  template<typename Stream>
247  static void info( Stream & s ) {
248  std::map< BuildType, std::string > buildTypeMap = boost::assign::map_list_of( RELEASE_BUILD_TYPE, "Release" )( DEBUG_BUILD_TYPE, "Debug" );
249 
250  boost::property_tree::ptree pt, version;
251  version.add("major", version_type::MAJOR());
252  version.add("minor", version_type::MINOR());
253  version.add("patch", version_type::PATCH());
254 
255  pt.add_child("version", version);
256  pt.add("isOfficialRelease", isOfficialRelease());
257  pt.add("platform", BOOST_PLATFORM);
258  pt.add("compiler", BOOST_COMPILER);
259  pt.add("stdLib", BOOST_STDLIB);
260  version.put("major", boost_version_type::MAJOR());
261  version.put("minor", boost_version_type::MINOR());
262  version.put("patch", boost_version_type::PATCH());
263  pt.add_child("boostVersion", version);
264  pt.add("buildType", buildTypeMap[buildType()]);
265  pt.add("dynamicBuild", isDynamicLibrary());
266  pt.add("hasOpenMp", hasOpenMp());
267 
268  boost::property_tree::write_json(s, pt);
269  }
270 
271 };
272 
273 }
274 
275 #endif