Loading...
Searching...
No Matches
interpreter_support.cc File Reference
`#include "kernel/mod2.h"`
`#include <sstream>`
`#include <boost/python.hpp>`
`#include <boost/python/suite/indexing/vector_indexing_suite.hpp>`
`#include "Singular/subexpr.h"`
`#include "Poly.h"`
`#include "Ideal.h"`
`#include "kernel/structs.h"`
`#include "Singular/lists.h"`
`#include "Singular/ipid.h"`
`#include "Singular/ipshell.h"`
`#include "coeffs/numbers.h"`
`#include "polys/matpol.h"`
`#include "ring_wrap.h"`
`#include "intvec_wrap.h"`
`#include "poly_wrap.h"`

Go to the source code of this file.

## Data Structures

class | arg_list
class | idhdl_wrap

## Typedefs

typedef boost::python::numeric::array | NumpyArrayType

## Functions

static void | free_leftv (leftv args)
matrix | matrixFromArray (const NumpyArrayType &f)
bool | is_builtin (const char *name)
static NumpyArrayType | buildPythonMatrix (matrix m, ring r)
boost::python::object | buildPyObjectFromLeftv (leftv v)
boost::python::list | buildPythonList (lists l, ring r)
boost::python::object | buildPyObjectFromIdhdl (const idhdl_wrap &id)
boost::python::object | call_interpreter_method (const idhdl_wrap &proc, const arg_list &args)
boost::python::object | call_builtin_method_general (const char *name, arg_list &l)
static boost::python::str | idhdl_as_str (idhdl_wrap iw)
static idhdl_wrap | get_idhdl (const char *n)
void | export_interpreter ()

## Variables

EXTERN_VAR int | inerror

## Typedef Documentation

## NumpyArrayType

typedef boost::python::numeric::array NumpyArrayType

Definition at line 31 of file interpreter_support.cc.

## Function Documentation

## buildPyObjectFromIdhdl()

boost::python::object buildPyObjectFromIdhdl | ( | const idhdl_wrap & | id | ) |

Definition at line 411 of file interpreter_support.cc.

{
using boost::python::object;
switch (id.id->typ)
{
case STRING_CMD:
return str((const char*) id.id->data.ustring);
case INT_CMD:
return object((int)id.id->data.i);
case POLY_CMD:
return object(Poly((poly) id.id->data.p, currRing));
case VECTOR_CMD:
return object( Vector((poly) id.id->data.p, currRing));
case IDEAL_CMD:
//object res;
return object(Ideal((ideal) id.id->data.uideal, currRing));
case MODUL_CMD:
//object res;
return object(Module((ideal) id.id->data.uideal, currRing));
case NUMBER_CMD:
return object(Number((number) id.id->data.n, currRing));
case MATRIX_CMD:
{
return buildPythonMatrix((matrix) id.id->data.umatrix,currRing);
}
case LIST_CMD:
return buildPythonList((lists) id.id->data.l, currRing);
case RING_CMD:
return object(Ring((ring) id.id->data.uring));
case INTVEC_CMD:
return object(Intvec(*(intvec*) id.id->data.iv));
default:
return object();
//Py_INCREF(Py_None);
//return Py_None;
}
}
Ideal
Definition Ideal.h:88
Intvec
Definition IIntvec.h:6
Module
Definition Ideal.h:121
Number
Definition Number.h:34
Ring
Definition ring_wrap.h:21
Vector
Definition Poly.h:509
intvec
Definition intvec.h:24
IDEAL_CMD
@ IDEAL_CMD
Definition grammar.cc:285
MATRIX_CMD
@ MATRIX_CMD
Definition grammar.cc:287
MODUL_CMD
@ MODUL_CMD
Definition grammar.cc:288
VECTOR_CMD
@ VECTOR_CMD
Definition grammar.cc:293
NUMBER_CMD
@ NUMBER_CMD
Definition grammar.cc:289
POLY_CMD
@ POLY_CMD
Definition grammar.cc:290
RING_CMD
@ RING_CMD
Definition grammar.cc:282
buildPythonMatrix
static NumpyArrayType buildPythonMatrix(matrix m, ring r)
Definition interpreter_support.cc:332
buildPythonList
boost::python::list buildPythonList(lists l, ring r)
Definition interpreter_support.cc:365
matrix
ip_smatrix * matrix
Definition matpol.h:43
lists
slists * lists
Definition mpr_numeric.h:146
LibThread::str
char * str(leftv arg)
Definition shared.cc:699
currRing
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
Poly
Definition janet.h:15
LIST_CMD
@ LIST_CMD
Definition tok.h:118
INTVEC_CMD
@ INTVEC_CMD
Definition tok.h:101
STRING_CMD
@ STRING_CMD
Definition tok.h:187
INT_CMD
@ INT_CMD
Definition tok.h:96

## buildPyObjectFromLeftv()

boost::python::object buildPyObjectFromLeftv | ( | leftv | v | ) |

Definition at line 379 of file interpreter_support.cc.

{
using boost::python::object;
switch (v->rtyp)
{
case INT_CMD:
return object((int)((long)v->data));
case POLY_CMD:
return object(Poly((poly) v->data, currRing));
case STRING_CMD:
return str((const char*) v->data);
case VECTOR_CMD:
return object( Vector((poly) v->data, currRing));
case IDEAL_CMD:
return object(Ideal((ideal) v->data, currRing));
case MODUL_CMD:
return object(Module((ideal) v->data, currRing));
case NUMBER_CMD:
return object(Number((number) v->data, currRing));
case MATRIX_CMD:
return buildPythonMatrix((matrix) v->data,currRing);
case LIST_CMD:
return buildPythonList((lists) v->data, currRing);
case RING_CMD:
return object(Ring((ring) v->data));
case INTVEC_CMD:
return object(Intvec(*(intvec*) v->data));
default:
return object();
}
}
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39

## buildPythonList()

boost::python::list buildPythonList | ( | lists | l,
|  | ring | r )

Definition at line 365 of file interpreter_support.cc.

{
using boost::python::list;
list res;
for(int i=0;i<=l->nr;i++)
{
leftv lv=&l->m[i];
object o=buildPyObjectFromLeftv(lv);
res.append(o);
}
return res;
}
l
int l
Definition cfEzgcd.cc:100
i
int i
Definition cfEzgcd.cc:132
res
CanonicalForm res
Definition facAbsFact.cc:60
buildPyObjectFromLeftv
boost::python::object buildPyObjectFromLeftv(leftv v)
Definition interpreter_support.cc:379
leftv
sleftv * leftv
Definition structs.h:53

## buildPythonMatrix()

NumpyArrayType buildPythonMatrix | ( | matrix | m,
|  | ring | r )

static

Definition at line 332 of file interpreter_support.cc.

{
//using boost::python::numeric::array;
using boost::python::self;
using boost::python::make_tuple;
using boost::python::tuple;
using boost::python::object;
using boost::python::list;
list l;
for(int i=1;i<=MATROWS(m);i++)
{
list row;
for(int j=1;j<=MATCOLS(m);j++)
{
Poly ip(MATELEM(m,i,j),r);//copy it
row.append(ip);
//a[boost::python::make_tuple(i%2,i%5)]=ip;
//a[boost::python::make_tuple(i%2,i%5)]=ip;
}
l.append(row);
}
#if BOOST_VERSION <106500
//FIXME: should call this only once
NumpyArrayType::set_module_and_type("Numeric",
"ArrayType"
);
return NumpyArrayType(l);
#else
return boost::python::numpy::array(l);
#endif
}
m
int m
Definition cfEzgcd.cc:128
j
int j
Definition facHensel.cc:110
NumpyArrayType
boost::python::numeric::array NumpyArrayType
Definition interpreter_support.cc:31
MATELEM
#define MATELEM(mat, i, j)
1-based access to matrix
Definition matpol.h:29
MATROWS
#define MATROWS(i)
Definition matpol.h:26
MATCOLS
#define MATCOLS(i)
Definition matpol.h:27

## call_builtin_method_general()

boost::python::object call_builtin_method_general | ( | const char * | name,
|  | arg_list & | l )

Definition at line 463 of file interpreter_support.cc.

{
int cmd_n=-1;
IsCmd(name,cmd_n);
// Py_INCREF(Py_None);
// return Py_None;
if (cmd_n<0)
{
return object();
}
else
{
leftv res=(leftv)omAllocBin(sleftv_bin);
res->Init();
switch(l.length())
{
case 1:
iiExprArith1(res,l.args,cmd_n);
break;
case 2:
{
leftv arg1=l.pop_front();
leftv arg2=l.pop_front();
iiExprArith2(res,arg1,cmd_n,arg2,TRUE);
free_leftv(arg1);
free_leftv(arg2);
break;
}
case 3:
{
leftv arg1=l.pop_front();
leftv arg2=l.pop_front();
leftv arg3=l.pop_front();
iiExprArith3(res,cmd_n,arg1,arg2,arg3);
free_leftv(arg1);
free_leftv(arg2);
free_leftv(arg3);
break;
}
default:
iiExprArithM(res, l.args, cmd_n);
}
boost::python::object real_res=buildPyObjectFromLeftv(res);
res->CleanUp();
omFreeBin(res, sleftv_bin);
errorreported=inerror=0;
return real_res;
//cleanup not to forget
}
}
TRUE
#define TRUE
Definition auxiliary.h:101
name
char name(const Variable &v)
Definition factory.h:189
errorreported
VAR short errorreported
Definition feFopen.cc:23
free_leftv
static void free_leftv(leftv args)
Definition interpreter_support.cc:24
inerror
EXTERN_VAR int inerror
Definition interpreter_support.cc:21
iiExprArith2
BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
Definition iparith.cc:9176
IsCmd
int IsCmd(const char *n, int &tok)
Definition iparith.cc:9773
iiExprArith1
BOOLEAN iiExprArith1(leftv res, leftv a, int op)
Definition iparith.cc:9365
iiExprArithM
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
Definition iparith.cc:9666
iiExprArith3
BOOLEAN iiExprArith3(leftv res, int op, leftv a, leftv b, leftv c)
Definition iparith.cc:9575
sleftv_bin
EXTERN_VAR omBin sleftv_bin
Definition ipid.h:145
omAllocBin
#define omAllocBin(bin)
Definition omAllocDecl.h:205
omFreeBin
#define omFreeBin(addr, bin)
Definition omAllocDecl.h:259

## call_interpreter_method()

boost::python::object call_interpreter_method | ( | const idhdl_wrap & | proc,
|  | const arg_list & | args )

Definition at line 456 of file interpreter_support.cc.

{
int err=iiMake_proc(proc.id, NULL, args.args);
errorreported=inerror=0;
return buildPyObjectFromLeftv(&iiRETURNEXPR);
}
proc
unsigned char * proc[NUM_PROC]
Definition checklibs.c:16
arg_list::args
leftv args
Definition interpreter_support.cc:65
iiMake_proc
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv args)
Definition iplib.cc:513
iiRETURNEXPR
INST_VAR sleftv iiRETURNEXPR
Definition iplib.cc:483
NULL
#define NULL
Definition omList.c:12

## export_interpreter()

void export_interpreter | ( |  | ) |

Definition at line 529 of file interpreter_support.cc.

{
def("get_idhdl", get_idhdl);
boost::python::class_<arg_list>("i_arg_list")
.def("append", &arg_list::appendPoly)
.def("append", &arg_list::appendArray)
.def("append", &arg_list::appendNumber)
.def("append", &arg_list::appendint)
.def("append", &arg_list::appendIdeal)
.def("append", &arg_list::appendModule)
.def("append", &arg_list::appendPrelist)
.def("append", &arg_list::appendVector)
.def("append", &arg_list::appendRing)
.def("append", &arg_list::appendIntvec)
.def("append", &arg_list::appendString);
boost::python::class_<idhdl_wrap>("interpreter_id")
.def("is_zero", &idhdl_wrap::is_zero)
.def("is_proc", &idhdl_wrap::id_is_proc)
.def("print_type", &idhdl_wrap::print_type)
.def("write", &idhdl_wrap::writePoly)
.def("write", &idhdl_wrap::writeArray)
.def("write", &idhdl_wrap::writeNumber)
.def("write", &idhdl_wrap::writeint)
.def("write", &idhdl_wrap::writeIdeal)
.def("write", &idhdl_wrap::writeModule)
.def("write", &idhdl_wrap::writeVector)
.def("write", &idhdl_wrap::writeList)
.def("write", &idhdl_wrap::writeString)
.def("write", &idhdl_wrap::writeIntvec)
.def("write", &idhdl_wrap::writeRing)
.def("__str__", idhdl_as_str);
def("call_interpreter_method",call_interpreter_method);
def("cbm",call_builtin_method_general);
def("transfer_to_python",buildPyObjectFromIdhdl);
def("is_builtin", is_builtin);
}
arg_list::appendint
void appendint(int p)
Definition interpreter_support.cc:118
arg_list::appendArray
void appendArray(const NumpyArrayType &f)
Definition interpreter_support.cc:139
arg_list::appendPrelist
void appendPrelist(arg_list &l)
Definition interpreter_support.cc:177
arg_list::appendNumber
void appendNumber(const Number &p)
Definition interpreter_support.cc:125
arg_list::appendVector
void appendVector(const Vector &p)
Definition interpreter_support.cc:132
arg_list::appendString
void appendString(const char *s)
Definition interpreter_support.cc:147
arg_list::appendIntvec
void appendIntvec(Intvec &iv)
Definition interpreter_support.cc:184
arg_list::appendModule
void appendModule(const Module &p)
Definition interpreter_support.cc:111
arg_list::appendPoly
void appendPoly(const Poly &p)
Definition interpreter_support.cc:97
arg_list::appendIdeal
void appendIdeal(const Ideal &p)
Definition interpreter_support.cc:104
arg_list::appendRing
void appendRing(const Ring &r)
Definition interpreter_support.cc:154
idhdl_wrap::writeIdeal
void writeIdeal(const Ideal &p)
Definition interpreter_support.cc:246
idhdl_wrap::writeList
void writeList(arg_list &f)
Definition interpreter_support.cc:320
idhdl_wrap::writePoly
void writePoly(const Poly &p)
Definition interpreter_support.cc:238
idhdl_wrap::writeString
void writeString(const char *s)
Definition interpreter_support.cc:304
idhdl_wrap::writeNumber
void writeNumber(const Number &p)
Definition interpreter_support.cc:269
idhdl_wrap::writeIntvec
void writeIntvec(const Intvec &iv)
Definition interpreter_support.cc:312
idhdl_wrap::writeVector
void writeVector(const Vector &p)
Definition interpreter_support.cc:277
idhdl_wrap::print_type
bool print_type()
Definition interpreter_support.cc:234
idhdl_wrap::writeArray
void writeArray(const NumpyArrayType &f)
Definition interpreter_support.cc:285
idhdl_wrap::writeRing
void writeRing(const Ring &r)
Definition interpreter_support.cc:294
idhdl_wrap::writeModule
void writeModule(const Module &p)
Definition interpreter_support.cc:254
idhdl_wrap::writeint
void writeint(int p)
Definition interpreter_support.cc:262
idhdl_wrap::id_is_proc
bool id_is_proc()
Definition interpreter_support.cc:230
idhdl_wrap::is_zero
bool is_zero()
Definition interpreter_support.cc:226
is_builtin
bool is_builtin(const char *name)
Definition interpreter_support.cc:56
call_builtin_method_general
boost::python::object call_builtin_method_general(const char *name, arg_list &l)
Definition interpreter_support.cc:463
idhdl_as_str
static boost::python::str idhdl_as_str(idhdl_wrap iw)
Definition interpreter_support.cc:514
get_idhdl
static idhdl_wrap get_idhdl(const char *n)
Definition interpreter_support.cc:524
call_interpreter_method
boost::python::object call_interpreter_method(const idhdl_wrap &proc, const arg_list &args)
Definition interpreter_support.cc:456
buildPyObjectFromIdhdl
boost::python::object buildPyObjectFromIdhdl(const idhdl_wrap &id)
Definition interpreter_support.cc:411

## free_leftv()

void free_leftv | ( | leftv | args | ) |

static

Definition at line 24 of file interpreter_support.cc.

{
args->CleanUp();
omFreeBin(args, sleftv_bin);
}
sleftv::CleanUp
void CleanUp(ring r=currRing)
Definition subexpr.cc:351

## get_idhdl()

idhdl_wrap get_idhdl | ( | const char * | n | ) |

static

Definition at line 524 of file interpreter_support.cc.

{
//idhdl ggetid(const char *n);
return idhdl_wrap(ggetid(n));
}
idhdl_wrap
Definition interpreter_support.cc:215
ggetid
idhdl ggetid(const char *n)
Definition ipid.cc:581

## idhdl_as_str()

boost::python::str idhdl_as_str | ( | idhdl_wrap | iw | ) |

static

Definition at line 514 of file interpreter_support.cc.

{
idhdl i=iw.id;
using boost::python::str;
//ring r=p.getRing();
std::basic_stringstream<char> s;
s<<i;
return boost::python::str(s.str());
}
idhdl_wrap::id
idhdl id
Definition interpreter_support.cc:217
s
const CanonicalForm int s
Definition facAbsFact.cc:51
idhdl
idrec * idhdl
Definition ring.h:22

## is_builtin()

bool is_builtin | ( | const char * | name | ) |

Definition at line 56 of file interpreter_support.cc.

{
int cmd_n=-1;
IsCmd(name,cmd_n);
return (cmd_n!=-1);
}

## matrixFromArray()

matrix matrixFromArray | ( | const NumpyArrayType & | f | ) |

Definition at line 37 of file interpreter_support.cc.

{
object o=f.attr("shape");
object o1=o[0];
object o2=o[1];
int l1=extract<int>(o1);
int l2=extract<int>(o2);
matrix m=mpNew(l1,l2);
for(int i=0;i<l1;i++)
{
for(int j=0;j<l2;j++)
{
Poly& x = boost::python::extract<Poly&>(f[boost::python::make_tuple(i,j)]);
poly p=x.as_poly();
MATELEM(m,i+1,j+1)=p;
}
}
return m;
}
x
Variable x
Definition cfModGcd.cc:4090
p
int p
Definition cfModGcd.cc:4086
f
FILE * f
Definition checklibs.c:9
mpNew
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition matpol.cc:37

## Variable Documentation

## inerror

EXTERN_VAR int inerror

Definition at line 21 of file interpreter_support.cc.