My Project
Toggle main menu visibility
Loading...
Searching...
No Matches
Singular
dyn_modules
machinelearning
machinelearning.cc
Go to the documentation of this file.
1
#include <stdio.h>
2
3
#include "
kernel/mod2.h
"
4
#if defined(HAVE_READLINE) && defined(HAVE_READLINE_READLINE_H)
5
#include <readline/history.h>
6
#include "
Singular/ipid.h
"
7
#include "
Singular/mod_lib.h
"
8
#include "
kernel/oswrapper/feread.h
"
9
10
#ifdef HAVE_PYTHON
11
12
#include "
mlpredict.h
"
13
14
static
BOOLEAN
predictHelp(
leftv
result
,
leftv
arg)
15
{
16
char
*buffer[5];
17
int
lengths[5];
18
char
*filename =
getenv
(
"SINGULARHIST"
);
19
if
(filename==
NULL
) filename=
SINGULARHIST_FILE
;
20
int
i
;
21
lists
L = (
lists
)
omAllocBin
(
slists_bin
);
22
23
buffer[0] =
NULL
;
24
buffer[1] =
NULL
;
25
buffer[2] =
NULL
;
26
buffer[3] =
NULL
;
27
buffer[4] =
NULL
;
28
29
if
(
write_history
(filename))
30
{
31
printf(
"Failed to write history\n"
);
32
return
TRUE
;
33
}
34
35
if
(!ml_initialise())
36
{
37
WerrorS
(
"Initialise of ml failed."
);
38
/* Notify singular that an error occured */
39
return
TRUE
;
40
}
41
#ifdef HAVE_OMALLOC
42
ml_make_prediction(filename, buffer, lengths,
_omStrDup
);
43
#else
/*xalloc*/
44
ml_make_prediction(filename, buffer, lengths,
strdup
);
45
#endif
46
47
L->
Init
(5);
48
49
for
(
i
= 0;
i
< 5;
i
++) {
50
//printf("prediction %d: %s\n", i, buffer[i]);
51
L->
m
[
i
].
rtyp
=
STRING_CMD
;
52
L->
m
[
i
].
data
= buffer[
i
];
53
}
54
55
// pass the resultant list to the res datastructure
56
result
->rtyp=
LIST_CMD
;
57
result
->data=(
void
*)L;
58
59
ml_finalise();
60
return
FALSE
;
61
62
//result->rtyp=NONE; // set the result type
63
}
64
65
// initialisation of the module
66
extern
"C"
int
SI_MOD_INIT(machinelearning)(
SModulFunctions
* psModulFunctions)
67
{
68
char
*filename =
getenv
(
"SINGULARHIST"
);
69
if
(filename==
NULL
)
70
{
71
WarnS
(
"SINGULARHIST is not set - no history available, using ~/.singularhist"
);
72
}
73
// this is the initialization routine of the module
74
// adding the routine predictHelp:
75
psModulFunctions->iiAddCproc(
76
(
currPack
->libname?
currPack
->libname:
""
),
77
"predictHelp"
,
// for the singular interpreter
78
FALSE
,
// should enter the global name space
79
predictHelp);
// the C/C++ routine
80
return
MAX_TOK
;
81
}
82
#endif
83
#endif
BOOLEAN
int BOOLEAN
Definition
auxiliary.h:88
TRUE
#define TRUE
Definition
auxiliary.h:101
FALSE
#define FALSE
Definition
auxiliary.h:97
i
int i
Definition
cfEzgcd.cc:132
sleftv::rtyp
int rtyp
Definition
subexpr.h:91
sleftv::data
void * data
Definition
subexpr.h:88
slists::m
sleftv * m
Definition
lists.h:46
slists::Init
INLINE_THIS void Init(int l=0)
WarnS
#define WarnS
Definition
emacs.cc:78
result
return result
Definition
facAbsBiFact.cc:76
WerrorS
void WerrorS(const char *s)
Definition
feFopen.cc:24
getenv
char * getenv()
write_history
int write_history()
feread.h
SINGULARHIST_FILE
#define SINGULARHIST_FILE
Definition
feread.h:20
currPack
VAR package currPack
Definition
ipid.cc:55
ipid.h
slists_bin
VAR omBin slists_bin
Definition
lists.cc:23
mlpredict.h
Function definitions for using python to do machine learning in Singular.
mod2.h
mod_lib.h
lists
slists * lists
Definition
mpr_numeric.h:146
omAllocBin
#define omAllocBin(bin)
Definition
omAllocDecl.h:205
strdup
#define strdup
Definition
omAllocFunc.c:18
_omStrDup
OM_INLINE_DECL char * _omStrDup(const char *s)
NULL
#define NULL
Definition
omList.c:12
SModulFunctions
Definition
ipid.h:69
leftv
sleftv * leftv
Definition
structs.h:53
LIST_CMD
@ LIST_CMD
Definition
tok.h:118
STRING_CMD
@ STRING_CMD
Definition
tok.h:187
MAX_TOK
@ MAX_TOK
Definition
tok.h:220
Generated on
for My Project by
doxygen 1.17.0
for
Singular