Loading...
Searching...
No Matches
machinelearning.cc
Go to the documentation of this file.
#include <stdio.h>
#include "kernel/mod2.h"
#if defined(HAVE_READLINE) && defined(HAVE_READLINE_READLINE_H)
#include <readline/history.h>
#include "Singular/ipid.h"
#include "Singular/mod_lib.h"
#include "kernel/oswrapper/feread.h"
#ifdef HAVE_PYTHON
#include "mlpredict.h"
static BOOLEAN predictHelp(leftv result, leftv arg)
{
char *buffer[5];
int lengths[5];
char *filename = getenv("SINGULARHIST");
if (filename==NULL) filename=SINGULARHIST_FILE;
int i;
lists L = (lists)omAllocBin(slists_bin);
buffer[0] = NULL;
buffer[1] = NULL;
buffer[2] = NULL;
buffer[3] = NULL;
buffer[4] = NULL;
if (write_history(filename))
{
printf("Failed to write history\n");
return TRUE;
}
if (!ml_initialise())
{
WerrorS("Initialise of ml failed.");
/* Notify singular that an error occured */
return TRUE;
}
#ifdef HAVE_OMALLOC
ml_make_prediction(filename, buffer, lengths, _omStrDup);
#else /*xalloc*/
ml_make_prediction(filename, buffer, lengths, strdup);
#endif
L->Init(5);
for (i = 0; i < 5; i++) {
//printf("prediction %d: %s\n", i, buffer[i]);
L->m[i].rtyp = STRING_CMD;
L->m[i].data = buffer[i];
}
// pass the resultant list to the res datastructure
result->rtyp=LIST_CMD;
result->data=(void *)L;
ml_finalise();
return FALSE;
//result->rtyp=NONE; // set the result type
}
// initialisation of the module
extern "C" int SI_MOD_INIT(machinelearning)(SModulFunctions* psModulFunctions)
{
char *filename = getenv("SINGULARHIST");
if (filename==NULL)
{
WarnS("SINGULARHIST is not set - no history available, using ~/.singularhist");
}
// this is the initialization routine of the module
// adding the routine predictHelp:
psModulFunctions->iiAddCproc(
(currPack->libname? currPack->libname: ""),
"predictHelp",// for the singular interpreter
FALSE, // should enter the global name space
predictHelp); // the C/C++ routine
return MAX_TOK;
}
#endif
#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
SModulFunctions
Definition ipid.h:69
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
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