SHOGUN  v2.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>
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
20 #endif
21 
22 namespace shogun
23 {
25  SGIO* sg_io=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)
51  if (!sg_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);
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 
78  {
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;
95 
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 
111  {
112  SG_REF(sg_io);
113  return sg_io;
114  }
115 
117  {
119  sg_parallel=parallel;
121  }
122 
124  {
126  return sg_parallel;
127  }
128 
130  {
132  sg_version=version;
134  }
135 
137  {
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 
150  {
151  SG_REF(sg_math);
152  return sg_math;
153  }
154 }

SHOGUN Machine Learning Toolbox - Documentation