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