Shark.h
Go to the documentation of this file.
1/**
2 * \mainpage Shark Machine Learning Library Ver. 4.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
49namespace shark {
50
51/**
52 * \namespace General namespace of the whole Shark machine learning library.
53 */
54
55/**
56 * \brief Models the build type.
57 */
59 RELEASE_BUILD_TYPE, ///< A release build.
60 DEBUG_BUILD_TYPE ///< A debug build.
61};
62
63namespace tag {
64
65/**
66 * \namespace tag Tagging namespace for type-based dispatching.
67 */
68
69/**
70 * \brief Tags the build type.
71 */
72struct 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 #define SHARK_USE_DYNLIB
87struct 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 GPU support through OpenCL has been enabled.
116 */
117/* #undef SHARK_USE_OPENCL */
118#ifdef SHARK_USE_OPENCL
119 #define REMORA_USE_GPU
120#endif
121
122/**
123 * \brief Tags whether OpenCL backend should use CLBLAST
124 */
125/* #undef SHARK_USE_CLBLAST */
126#ifdef SHARK_USE_CLBLAST
127#define REMORA_USE_CLBLAST
128#endif
129
130 /**
131 * \brief Tags whether full LAPACK is available
132 */
133/* #undef SHARK_USE_LAPACK */
134
135 /**
136 * \brief Tags whether the LAPACK portion of ATLAS is used
137 */
138/* #undef SHARK_USE_ATLAS_LAPACK */
139
140/**
141 * \brief Tags whether OpenMP has been enabled.
142 */
143/* #undef SHARK_USE_OPENMP */
144struct OpenMpTag {
145#ifdef _OPENMP
146 static const bool VALUE = true;
147#else
148 static const bool VALUE = false;
149#endif
150};
151
152/**
153 * \brief Tags official releases of the shark library.
154 */
155struct OfficialReleaseTag {
156#ifdef SHARK_OFFICIAL_RELEASE
157 static const bool VALUE = true;
158#else
159 static const bool VALUE = false;
160#endif
161};
162
163}
164
165/**
166 * \brief Allows for querying compile settings at runtime. Provides the
167 * current command line arguments to the rest of the library.
168 */
169class Shark {
170 protected:
171 // Not implemented
173 Shark( const Shark & shark );
174 Shark & operator=( const Shark & rhs );
175 public:
176
177 /**
178 * \brief Models a version according to the major.minor.patch versioning scheme.
179 */
180 template<unsigned int major, unsigned int minor, unsigned int patch>
181 struct Version {
182
183 /** \brief Default printf-format for formatting version numbers. */
184 static const char * DEFAULT_FORMAT() {
185 return( "%d.%d.%d" );
186 }
187
188 /** @brief Returns the major revision number. */
189 static unsigned int MAJOR() {
190 return( major );
191 }
192
193 /** @brief Returns the minor revision number. */
194 static unsigned int MINOR() {
195 return( minor );
196 }
197
198 /** @brief Returns the patch revision number. */
199 static unsigned int PATCH() {
200 return( patch );
201 }
202
203 };
204
205 /**
206 * \brief Marks the current version of the Shark Machine Learning Library.
207 */
208 typedef Version<
209 4,
210 0,
211 0
212 > version_type;
213
214 /**
215 * \brief Marks the boost version Shark has been built against.
216 */
217 typedef Version<
218 BOOST_VERSION / 100000,
219 ((BOOST_VERSION / 100) % 1000),
220 (BOOST_VERSION % 100)
221 > boost_version_type;
222
223 /**
224 * \brief Accesses the build type of the library.
225 */
227 return( tag::BuildTypeTag::VALUE );
228 }
229
230 /**
231 * \brief Queries whether Shark has been compiled with OpenMP enabled.
232 */
233 static bool hasOpenMp() {
234 return( tag::OpenMpTag::VALUE );
235 }
236
237 /**
238 * \brief Queries whether Shark has been compiled as dynamic library
239 */
240 static bool isDynamicLibrary() {
241 return( tag::DynamicLibraryTag::VALUE );
242 }
243
244 /**
245 * \brief Checks whether this is an official Shark release.
246 */
247 static bool isOfficialRelease() {
248 return( tag::OfficialReleaseTag::VALUE );
249 }
250
251 /**
252 * \brief Prints information about the Shark Machine Learning Library to the supplied stream.
253 */
254 template<typename Stream>
255 static void info( Stream & s ) {
256 std::map< BuildType, std::string > buildTypeMap = boost::assign::map_list_of( RELEASE_BUILD_TYPE, "Release" )( DEBUG_BUILD_TYPE, "Debug" );
257
258 boost::property_tree::ptree pt, version;
259 version.add("major", version_type::MAJOR());
260 version.add("minor", version_type::MINOR());
261 version.add("patch", version_type::PATCH());
262
263 pt.add_child("version", version);
264 pt.add("isOfficialRelease", isOfficialRelease());
265 pt.add("platform", BOOST_PLATFORM);
266 pt.add("compiler", BOOST_COMPILER);
267 pt.add("stdLib", BOOST_STDLIB);
268 version.put("major", boost_version_type::MAJOR());
269 version.put("minor", boost_version_type::MINOR());
270 version.put("patch", boost_version_type::PATCH());
271 pt.add_child("boostVersion", version);
272 pt.add("buildType", buildTypeMap[buildType()]);
273 pt.add("dynamicBuild", isDynamicLibrary());
274 pt.add("hasOpenMp", hasOpenMp());
275
276 boost::property_tree::write_json(s, pt);
277 }
278
279};
280
281}
282
283#endif