SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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>
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
21 #endif
22 
23 namespace shogun
24 {
26  SGIO* sg_io=NULL;
28  CMath* sg_math=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 
83  {
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;
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 
117  {
118  SG_REF(sg_io);
119  return sg_io;
120  }
121 
123  {
124  SG_REF(parallel);
125  SG_UNREF(sg_parallel);
126  sg_parallel=parallel;
127  }
128 
130  {
131  SG_REF(sg_parallel);
132  return sg_parallel;
133  }
134 
136  {
137  SG_REF(version);
138  SG_UNREF(sg_version);
139  sg_version=version;
140  }
141 
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 
156  {
157  SG_REF(sg_math);
158  return sg_math;
159  }
160 
162  {
163  SG_REF(rand);
164  SG_UNREF(sg_rand);
165  sg_rand=rand;
166  }
167 
169  {
170  SG_REF(sg_rand);
171  return sg_rand;
172  }
173 }
void init_shogun(void(*print_message)(FILE *target, const char *str), void(*print_warning)(FILE *target, const char *str), void(*print_error)(FILE *target, const char *str), void(*cancel_computations)(bool &delayed, bool &immediately))
Definition: init.cpp:44
void set_global_version(Version *version)
Definition: init.cpp:135
void set_global_math(CMath *math)
Definition: init.cpp:148
void(* sg_print_warning)(FILE *target, const char *str)
function called to print warning messages
Definition: init.cpp:35
#define SG_UNREF(x)
Definition: SGRefObject.h:35
void exit_shogun()
Definition: init.cpp:88
void init_shogun_with_defaults()
Definition: init.cpp:82
CRandom * sg_rand
Definition: init.cpp:29
Version * sg_version
Definition: init.cpp:27
CMath * get_global_math()
Definition: init.cpp:155
Parallel * sg_parallel
Definition: init.cpp:25
void(* sg_print_error)(FILE *target, const char *str)
function called to print error messages
Definition: init.cpp:38
SGIO * sg_io
Definition: init.cpp:26
Parallel * get_global_parallel()
Definition: init.cpp:129
SGIO * get_global_io()
Definition: init.cpp:116
void(* sg_cancel_computations)(bool &delayed, bool &immediately)
function called to cancel things
Definition: init.cpp:41
#define SG_REF(x)
Definition: SGRefObject.h:34
Class Version provides version information.
Definition: Version.h:32
CMath * sg_math
Definition: init.cpp:28
void set_global_parallel(Parallel *parallel)
Definition: init.cpp:122
void(* sg_print_message)(FILE *target, const char *str)
function called to print normal messages
Definition: init.cpp:32
: Pseudo random number geneartor
Definition: Random.h:32
Class Parallel provides helper functions for multithreading.
Definition: Parallel.h:27
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
Version * get_global_version()
Definition: init.cpp:142
Class which collects generic mathematical functions.
Definition: Math.h:133
void set_global_rand(CRandom *rand)
Definition: init.cpp:161
void sg_global_print_default(FILE *target, const char *str)
Definition: init.cpp:77
void set_global_io(SGIO *io)
Definition: init.cpp:109
Class SGIO, used to do input output operations throughout shogun.
Definition: SGIO.h:245
CRandom * get_global_rand()
Definition: init.cpp:168
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
Definition: SGObject.h:40

SHOGUN Machine Learning Toolbox - Documentation