SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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)
53  if (!sg_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);
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);
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);
126  sg_parallel=parallel;
127  }
128 
130  {
132  return sg_parallel;
133  }
134 
136  {
137  SG_REF(version);
139  sg_version=version;
140  }
141 
143  {
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 }

SHOGUN Machine Learning Toolbox - Documentation