SHOGUN
v3.0.0
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
19
#ifdef TRACE_MEMORY_ALLOCS
20
shogun::CMap<void*, shogun::MemoryBlock>
* sg_mallocs=NULL;
21
#endif
22
23
namespace
shogun
24
{
25
Parallel
*
sg_parallel
=NULL;
26
SGIO
*
sg_io
=NULL;
27
Version
*
sg_version
=NULL;
28
CMath
*
sg_math
=NULL;
29
CRandom
*
sg_rand
=NULL;
30
32
void (*
sg_print_message
)(FILE* target,
const
char
* str) = NULL;
33
35
void (*
sg_print_warning
)(FILE* target,
const
char
* str) = NULL;
36
38
void (*
sg_print_error
)(FILE* target,
const
char
* str) = NULL;
39
41
void (*
sg_cancel_computations
)(
bool
&delayed,
bool
&immediately)=NULL;
42
43
44
void
init_shogun
(
void
(*print_message)(FILE* target,
const
char
* str),
45
void
(*print_warning)(FILE* target,
const
char
* str),
46
void
(*print_error)(FILE* target,
const
char
* str),
47
void
(*cancel_computations)(
bool
&delayed,
bool
&immediately))
48
{
49
if
(!
sg_io
)
50
sg_io
=
new
shogun::SGIO
();
51
if
(!
sg_parallel
)
52
sg_parallel
=
new
shogun::Parallel
();
53
if
(!
sg_version
)
54
sg_version
=
new
shogun::Version
();
55
if
(!
sg_math
)
56
sg_math
=
new
shogun::CMath
();
57
if
(!
sg_rand
)
58
sg_rand
=
new
shogun::CRandom
();
59
#ifdef TRACE_MEMORY_ALLOCS
60
if
(!sg_mallocs)
61
sg_mallocs =
new
shogun::CMap<void*, MemoryBlock>
(631, 1024,
false
);
62
63
SG_REF
(sg_mallocs);
64
#endif
65
SG_REF
(
sg_io
);
66
SG_REF
(
sg_parallel
);
67
SG_REF
(
sg_version
);
68
SG_REF
(
sg_math
);
69
SG_REF
(
sg_rand
);
70
71
sg_print_message
=print_message;
72
sg_print_warning
=print_warning;
73
sg_print_error
=print_error;
74
sg_cancel_computations
=cancel_computations;
75
}
76
77
void
sg_global_print_default
(FILE* target,
const
char
* str)
78
{
79
fprintf(target,
"%s"
, str);
80
}
81
82
void
init_shogun_with_defaults
()
83
{
84
init_shogun
(&
sg_global_print_default
, &
sg_global_print_default
,
85
&
sg_global_print_default
);
86
}
87
88
void
exit_shogun
()
89
{
90
#ifdef TRACE_MEMORY_ALLOCS
91
list_memory_allocs();
92
shogun::CMap<void*, shogun::MemoryBlock>
* mallocs=sg_mallocs;
93
sg_mallocs=NULL;
94
SG_UNREF
(mallocs);
95
#endif
96
sg_print_message
=NULL;
97
sg_print_warning
=NULL;
98
sg_print_error
=NULL;
99
sg_cancel_computations
=NULL;
100
101
SG_UNREF
(
sg_rand
);
102
SG_UNREF
(
sg_math
);
103
SG_UNREF
(
sg_version
);
104
SG_UNREF
(
sg_parallel
);
105
SG_UNREF
(
sg_io
);
106
107
}
108
109
void
set_global_io
(
SGIO
* io)
110
{
111
SG_REF
(io);
112
SG_UNREF
(
sg_io
);
113
sg_io
=io;
114
}
115
116
SGIO
*
get_global_io
()
117
{
118
SG_REF
(
sg_io
);
119
return
sg_io
;
120
}
121
122
void
set_global_parallel
(
Parallel
* parallel)
123
{
124
SG_REF
(parallel);
125
SG_UNREF
(
sg_parallel
);
126
sg_parallel
=parallel;
127
}
128
129
Parallel
*
get_global_parallel
()
130
{
131
SG_REF
(
sg_parallel
);
132
return
sg_parallel
;
133
}
134
135
void
set_global_version
(
Version
* version)
136
{
137
SG_REF
(version);
138
SG_UNREF
(
sg_version
);
139
sg_version
=version;
140
}
141
142
Version
*
get_global_version
()
143
{
144
SG_REF
(
sg_version
);
145
return
sg_version
;
146
}
147
148
void
set_global_math
(
CMath
* math)
149
{
150
SG_REF
(math);
151
SG_UNREF
(
sg_math
);
152
sg_math
=math;
153
}
154
155
CMath
*
get_global_math
()
156
{
157
SG_REF
(
sg_math
);
158
return
sg_math
;
159
}
160
161
void
set_global_rand
(
CRandom
* rand)
162
{
163
SG_REF
(rand);
164
SG_UNREF
(
sg_rand
);
165
sg_rand
=rand;
166
}
167
168
CRandom
*
get_global_rand
()
169
{
170
SG_REF
(
sg_rand
);
171
return
sg_rand
;
172
}
173
}
SHOGUN
Machine Learning Toolbox - Documentation