SHOGUN
3.2.1
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
base
init.cpp
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 3 of the License, or
5
* (at your option) any later version.
6
*
7
* Written (W) 2009 Soeren Sonnenburg
8
* Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#include <
shogun/base/init.h
>
12
#include <
shogun/mathematics/Math.h
>
13
#include <
shogun/mathematics/Random.h
>
14
#include <
shogun/lib/common.h
>
15
#include <
shogun/lib/Map.h
>
16
#include <
shogun/base/Parallel.h
>
17
#include <
shogun/base/Version.h
>
18
#include <stdlib.h>
19
#include <string.h>
20
21
#ifdef TRACE_MEMORY_ALLOCS
22
shogun::CMap<void*, shogun::MemoryBlock>
* sg_mallocs=NULL;
23
#endif
24
25
namespace
shogun
26
{
27
Parallel
*
sg_parallel
=NULL;
28
SGIO
*
sg_io
=NULL;
29
Version
*
sg_version
=NULL;
30
CMath
*
sg_math
=NULL;
31
CRandom
*
sg_rand
=NULL;
32
34
void (*
sg_print_message
)(FILE* target,
const
char
* str) = NULL;
35
37
void (*
sg_print_warning
)(FILE* target,
const
char
* str) = NULL;
38
40
void (*
sg_print_error
)(FILE* target,
const
char
* str) = NULL;
41
43
void (*
sg_cancel_computations
)(
bool
&delayed,
bool
&immediately)=NULL;
44
45
46
void
init_shogun
(
void
(*print_message)(FILE* target,
const
char
* str),
47
void
(*print_warning)(FILE* target,
const
char
* str),
48
void
(*print_error)(FILE* target,
const
char
* str),
49
void
(*cancel_computations)(
bool
&delayed,
bool
&immediately))
50
{
51
if
(!
sg_io
)
52
sg_io
=
new
shogun::SGIO
();
53
if
(!
sg_parallel
)
54
sg_parallel
=
new
shogun::Parallel
();
55
if
(!
sg_version
)
56
sg_version
=
new
shogun::Version
();
57
if
(!
sg_math
)
58
sg_math
=
new
shogun::CMath
();
59
if
(!
sg_rand
)
60
sg_rand
=
new
shogun::CRandom
();
61
#ifdef TRACE_MEMORY_ALLOCS
62
if
(!sg_mallocs)
63
sg_mallocs =
new
shogun::CMap<void*, MemoryBlock>
(631, 1024,
false
);
64
65
SG_REF
(sg_mallocs);
66
#endif
67
SG_REF
(
sg_io
);
68
SG_REF
(
sg_parallel
);
69
SG_REF
(
sg_version
);
70
SG_REF
(
sg_math
);
71
SG_REF
(
sg_rand
);
72
73
sg_print_message
=print_message;
74
sg_print_warning
=print_warning;
75
sg_print_error
=print_error;
76
sg_cancel_computations
=cancel_computations;
77
78
init_from_env
();
79
}
80
81
void
sg_global_print_default
(FILE* target,
const
char
* str)
82
{
83
fprintf(target,
"%s"
, str);
84
}
85
86
void
init_shogun_with_defaults
()
87
{
88
init_shogun
(&
sg_global_print_default
, &
sg_global_print_default
,
89
&
sg_global_print_default
);
90
}
91
92
void
exit_shogun
()
93
{
94
#ifdef TRACE_MEMORY_ALLOCS
95
list_memory_allocs();
96
shogun::CMap<void*, shogun::MemoryBlock>
* mallocs=sg_mallocs;
97
sg_mallocs=NULL;
98
SG_UNREF
(mallocs);
99
#endif
100
sg_print_message
=NULL;
101
sg_print_warning
=NULL;
102
sg_print_error
=NULL;
103
sg_cancel_computations
=NULL;
104
105
SG_UNREF
(
sg_rand
);
106
SG_UNREF
(
sg_math
);
107
SG_UNREF
(
sg_version
);
108
SG_UNREF
(
sg_parallel
);
109
SG_UNREF
(
sg_io
);
110
111
}
112
113
void
set_global_io
(
SGIO
* io)
114
{
115
SG_REF
(io);
116
SG_UNREF
(
sg_io
);
117
sg_io
=io;
118
}
119
120
SGIO
*
get_global_io
()
121
{
122
SG_REF
(
sg_io
);
123
return
sg_io
;
124
}
125
126
void
set_global_parallel
(
Parallel
* parallel)
127
{
128
SG_REF
(parallel);
129
SG_UNREF
(
sg_parallel
);
130
sg_parallel
=parallel;
131
}
132
133
Parallel
*
get_global_parallel
()
134
{
135
SG_REF
(
sg_parallel
);
136
return
sg_parallel
;
137
}
138
139
void
set_global_version
(
Version
* version)
140
{
141
SG_REF
(version);
142
SG_UNREF
(
sg_version
);
143
sg_version
=version;
144
}
145
146
Version
*
get_global_version
()
147
{
148
SG_REF
(
sg_version
);
149
return
sg_version
;
150
}
151
152
void
set_global_math
(
CMath
* math)
153
{
154
SG_REF
(math);
155
SG_UNREF
(
sg_math
);
156
sg_math
=math;
157
}
158
159
CMath
*
get_global_math
()
160
{
161
SG_REF
(
sg_math
);
162
return
sg_math
;
163
}
164
165
void
set_global_rand
(
CRandom
* rand)
166
{
167
SG_REF
(rand);
168
SG_UNREF
(
sg_rand
);
169
sg_rand
=rand;
170
}
171
172
CRandom
*
get_global_rand
()
173
{
174
SG_REF
(
sg_rand
);
175
return
sg_rand
;
176
}
177
178
void
init_from_env
()
179
{
180
char
* env_log_val = NULL;
181
SGIO
* io =
get_global_io
();
182
env_log_val = getenv(
"SHOGUN_LOG_LEVEL"
);
183
if
(env_log_val)
184
{
185
if
(strncmp(env_log_val,
"DEBUG"
, 5) == 0)
186
io->
set_loglevel
(
MSG_DEBUG
);
187
else
if
(strncmp(env_log_val,
"WARN"
, 4) == 0)
188
io->
set_loglevel
(
MSG_WARN
);
189
else
if
(strncmp(env_log_val,
"ERROR"
, 5) == 0)
190
io->
set_loglevel
(
MSG_ERROR
);
191
}
192
SG_UNREF
(io);
193
}
194
}
SHOGUN
Machine Learning Toolbox - Documentation