1 /**
2  * @file bindings/go/mlpack/capi/io_util.hpp
3  * @author Yasmine Dumouchel
4  * @author Yashwant Singh
5  *
6  * Utility function for Go to set and get parameters to and from the IO.
7  *
8  * mlpack is free software; you may redistribute it and/or modify it under the
9  * terms of the 3-clause BSD license.  You should have received a copy of the
10  * 3-clause BSD license along with mlpack.  If not, see
11  * http://www.opensource.org/licenses/BSD-3-Clause for more information.
12  */
13 #ifndef MLPACK_BINDINGS_GO_IO_UTIL_HPP
14 #define MLPACK_BINDINGS_GO_IO_UTIL_HPP
15 
16 #include <mlpack/core/util/io.hpp>
17 #include <mlpack/core/data/dataset_mapper.hpp>
18 
19 namespace mlpack {
20 namespace util {
21 
22 /**
23  * Set the parameter to the given value.
24  *
25  * @param identifier Name of parameter.
26  * @param value Value to set parameter to.
27  */
28 template<typename T>
SetParam(const std::string & identifier,T & value)29 inline void SetParam(const std::string& identifier, T& value)
30 {
31   IO::GetParam<T>(identifier) = std::move(value);
32 }
33 
34 /**
35  * Set the parameter to the given value, given that the type is a pointer.
36  *
37  * @param identifier Name of parameter.
38  * @param value Value to set parameter to.
39  */
40 template<typename T>
SetParamPtr(const std::string & identifier,T * value)41 inline void SetParamPtr(const std::string& identifier,
42                         T* value)
43 {
44   IO::GetParam<T*>(identifier) = value;
45 }
46 
47 /**
48  * Return a pointer.  This function exists to work around Cython's seeming lack
49  * of support for template pointer types.
50  */
51 template<typename T>
GetParamPtr(const std::string & paramName)52 T* GetParamPtr(const std::string& paramName)
53 {
54   return IO::GetParam<T*>(paramName);
55 }
56 
57 /**
58  * Turn verbose output on.
59  */
EnableVerbose()60 inline void EnableVerbose()
61 {
62   Log::Info.ignoreInput = false;
63 }
64 
65 /**
66  * Turn verbose output off.
67  */
DisableVerbose()68 inline void DisableVerbose()
69 {
70   Log::Info.ignoreInput = true;
71 }
72 
73 /**
74  * Disable backtraces.
75  */
DisableBacktrace()76 inline void DisableBacktrace()
77 {
78   Log::Fatal.backtrace = false;
79 }
80 
81 /**
82  * Reset the status of all timers.
83  */
ResetTimers()84 inline void ResetTimers()
85 {
86   // Just get a new object---removes all old timers.
87   IO::GetSingleton().timer.Reset();
88 }
89 
90 /**
91  * Enable timing.
92  */
EnableTimers()93 inline void EnableTimers()
94 {
95   Timer::EnableTiming();
96 }
97 
98 } // namespace util
99 } // namespace mlpack
100 
101 #endif
102