My Project
Loading...
Searching...
No Matches
test_init_ml.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include "kernel/mod2.h"
4#if defined(HAVE_READLINE) && defined(HAVE_READLINE_READLINE_H)
5#ifdef HAVE_PYTHON
6#include <Python.h>
7#include "mlpredict.h"
8
9
10/* this is found as an internal function in mlpredict.c, for use in testing */
11ml_internal *_get_internals();
12
13int test_ml_is_initialised();
14void remove_dictionary();
15void remove_vectors();
16void remove_file_list();
17
18void remove_dictionary()
19{
20 ml_internal *internal_obs = NULL;
21 /* get internal datastructures */
22 internal_obs = _get_internals();
23
24 printf("Removing pDictionary\n");
25 Py_DECREF(internal_obs->pDictionary);
26 internal_obs->pDictionary = NULL;
27
28 return;
29}
30
31void remove_vectors()
32{
33 ml_internal *internal_obs = NULL;
34 /* get internal datastructures */
35 internal_obs = _get_internals();
36
37 printf("Removing pVectors\n");
38 Py_DECREF(internal_obs->pVectors);
39 internal_obs->pVectors = NULL;
40}
41
42void remove_file_list()
43{
44 ml_internal *internal_obs = NULL;
45 /* get internal datastructures */
46 internal_obs = _get_internals();
47
48 printf("Removing pFile_list\n");
49 Py_DECREF(internal_obs->pFile_list);
50 internal_obs->pFile_list = NULL;
51}
52
53int test_ml_is_initialised()
54{
55 int i;
56
57 ml_initialise();
58
59 i = ml_is_initialised();
60 printf("Returnvalue for ml_is_initialised: \t%d\n", i);
61 if (i != 1)
62 {
63 printf("Cannot test - initialization failed\n");
64 return 0;
65 }
66
67 remove_dictionary();
68
69 i = ml_is_initialised();
70 printf("Returnvalue for ml_is_initialised: \t%d\n", i);
71 if (i != 0) return 1;
72
73 i = ml_initialise();
74 printf("Returnvalue for ml_initialise: \t\t%d\n", i);
75 if (i != 1) return 1;
76
77 i = ml_is_initialised();
78 printf("Returnvalue for ml_is_initialised: \t%d\n", i);
79 if (i != 1) return 1;
80
81 remove_vectors();
82
83 i = ml_is_initialised();
84 printf("Returnvalue for ml_is_initialised: \t%d\n", i);
85 if (i != 0) return 1;
86
87 i = ml_initialise();
88 printf("Returnvalue for ml_initialise: \t\t%d\n", i);
89 if (i != 1) return 1;
90
91 i = ml_is_initialised();
92 printf("Returnvalue for ml_is_initialised: \t%d\n", i);
93 if (i != 1) return 1;
94
95 remove_file_list();
96
97 i = ml_is_initialised();
98 printf("Returnvalue for ml_is_initialised: \t%d\n", i);
99 if (i != 0) return 1;
100
101 i = ml_initialise();
102 printf("Returnvalue for ml_initialise: \t\t%d\n", i);
103 if (i != 1) return 1;
104
105 i = ml_is_initialised();
106 printf("Returnvalue for ml_is_initialised: \t%d\n", i);
107 if (i != 1) return 1;
108
109 return 0;
110}
111
112
113int main(int argc, char *argv[])
114{
115 int i = 0;
116
117 if (argc != 1) {
118 printf("Usage: %s\n", argv[0]);
119 return 1;
120 }
121
122 /* initially should not be initialised */
123 i = ml_is_initialised();
124 printf("Returnvalue for ml_is_initialised: \t%d\n", i);
125 if (i != 1)
126 {
127 printf("Cannot test - initialization failed\n");
128 return 0;
129 }
130
131 /* check that python script says it's not initialised */
132 Py_Initialize();
133 i = ml_is_initialised();
134 printf("Returnvalue for ml_is_initialised: \t%d\n", i);
135 if (i != 0) return 1;
136
137 i = ml_initialise();
138 printf("Returnvalue for ml_initialise: \t\t%d\n", i);
139 if (i != 1) return 1;
140
141 /* Should now be initialised */
142 i = ml_is_initialised();
143 printf("Returnvalue for ml_is_initialised: \t%d\n", i);
144 if (i != 1) return 1;
145
146 if (test_ml_is_initialised()) return 1;
147
148 i = ml_finalise();
149 printf("Returnvalue for ml_finalise: \t\t%d\n", i);
150 if (i != 1) return 1;
151
152 i = ml_is_initialised();
153 printf("Returnvalue for ml_is_initialised: \t%d\n", i);
154 if (i != 0) return 1;
155
156 return 0;
157}
158#else /*!HAVE_PYTHON*/
159int main(int argc, char *argv[])
160{
161 return 0;
162}
163#endif
164#else /*!HAVE_READLINE*/
165int main(int argc, char *argv[])
166{
167 return 0;
168}
169#endif
int i
Definition: cfEzgcd.cc:132
Function definitions for using python to do machine learning in Singular.
#define NULL
Definition: omList.c:12
int main()