4 #include <boost/python.hpp> 5 #include <boost/python/suite/indexing/vector_indexing_suite.hpp> 23 using boost::python::numeric::array;
24 using boost::python::extract;
25 static void free_leftv(
leftv args)
31 matrix matrixFromArray(
const boost::python::numeric::array&
f)
33 object o=f.attr(
"shape");
36 int l1=extract<int>(o1);
37 int l2=extract<int>(o2);
43 Poly&
x = boost::python::extract<Poly&>(f[boost::python::make_tuple(
i,
j)]);
50 bool is_builtin(
const char*
name)
91 void appendPoly(
const Poly&
p)
98 void appendIdeal(
const Ideal& p)
105 void appendModule(
const Module& p)
112 void appendint(
int p)
115 v->
data=(
void*)((
long)
p);
119 void appendNumber(
const Number& p)
126 void appendVector(
const Vector& p)
133 void appendArray(
const boost::python::numeric::array& f)
136 matrix m=matrixFromArray(f);
141 void appendString(
const char*
s)
148 void appendRing(
const Ring&
r)
163 leftv iv=pop_front();
165 memcpy(&res->
m[
i],iv,
sizeof(
sleftv));
171 void appendPrelist(arg_list& l)
174 v->
data=l.dumpToLists();
178 void appendIntvec(
Intvec& iv)
192 void internal_append(
leftv v)
232 void writePoly(
const Poly& p)
240 void writeIdeal(
const Ideal& p)
248 void writeModule(
const Module& p)
263 void writeNumber(
const Number& p)
271 void writeVector(
const Vector& p)
279 void writeArray(
const boost::python::numeric::array& f)
283 matrix m=matrixFromArray(f);
288 void writeRing(
const Ring& r)
293 ((ring) id->
data.uring)->ref--;
294 ring r2=r.
pimpl.get();
298 void writeString(
const char*
s)
306 void writeIntvec(
const Intvec& iv)
314 void writeList(arg_list& f)
320 id->data.l=f.dumpToLists();
326 static boost::python::numeric::array buildPythonMatrix(
matrix m, ring r)
328 using boost::python::numeric::array;
329 using boost::python::self;
330 using boost::python::make_tuple;
331 using boost::python::tuple;
332 using boost::python::object;
333 using boost::python::list;
349 boost::python::numeric::array::set_module_and_type(
"Numeric",
352 return boost::python::numeric::array(l);
354 boost::python::object buildPyObjectFromLeftv(
leftv v);
355 boost::python::list buildPythonList(
lists l, ring r)
357 using boost::python::list;
360 for(
int i=0;
i<=l->
nr;
i++)
363 object o=buildPyObjectFromLeftv(lv);
369 boost::python::object buildPyObjectFromLeftv(
leftv v)
371 using boost::python::object;
375 return object((
int)((
long)v->
data));
379 return str((
const char*) v->
data);
393 return object(
Ring((ring) v->
data));
401 boost::python::object buildPyObjectFromIdhdl(
const idhdl_wrap&
id)
403 using boost::python::object;
408 return str((
const char*)
id.id->data.ustring);
411 return object((
int)
id.id->data.i);
436 return object(
Ring((ring)
id.id->data.uring));
446 boost::python::object call_interpreter_method(
const idhdl_wrap&
proc,
const arg_list& args)
453 boost::python::object call_builtin_method_general(
const char* name, arg_list& l)
475 leftv arg1=l.pop_front();
476 leftv arg2=l.pop_front();
484 leftv arg1=l.pop_front();
485 leftv arg2=l.pop_front();
486 leftv arg3=l.pop_front();
496 boost::python::object real_res=buildPyObjectFromLeftv(res);
504 static boost::python::str idhdl_as_str(idhdl_wrap iw)
507 using boost::python::str;
510 std::basic_stringstream<char>
s;
512 return boost::python::str(s.str());
514 static idhdl_wrap get_idhdl(
const char *n)
517 return idhdl_wrap(
ggetid(n));
521 def(
"get_idhdl", get_idhdl);
522 boost::python::class_<arg_list>(
"i_arg_list")
523 .def(
"append", &arg_list::appendPoly)
524 .def(
"append", &arg_list::appendArray)
525 .def(
"append", &arg_list::appendNumber)
526 .def(
"append", &arg_list::appendint)
527 .def(
"append", &arg_list::appendIdeal)
528 .def(
"append", &arg_list::appendModule)
529 .def(
"append", &arg_list::appendPrelist)
530 .def(
"append", &arg_list::appendVector)
531 .def(
"append", &arg_list::appendRing)
532 .def(
"append", &arg_list::appendIntvec)
533 .def(
"append", &arg_list::appendString);
534 boost::python::class_<idhdl_wrap>(
"interpreter_id")
535 .def(
"is_zero", &idhdl_wrap::is_zero)
536 .def(
"is_proc", &idhdl_wrap::id_is_proc)
537 .def(
"print_type", &idhdl_wrap::print_type)
538 .def(
"write", &idhdl_wrap::writePoly)
539 .def(
"write", &idhdl_wrap::writeArray)
540 .def(
"write", &idhdl_wrap::writeNumber)
541 .def(
"write", &idhdl_wrap::writeint)
542 .def(
"write", &idhdl_wrap::writeIdeal)
543 .def(
"write", &idhdl_wrap::writeModule)
544 .def(
"write", &idhdl_wrap::writeVector)
545 .def(
"write", &idhdl_wrap::writeList)
546 .def(
"write", &idhdl_wrap::writeString)
547 .def(
"write", &idhdl_wrap::writeIntvec)
548 .def(
"write", &idhdl_wrap::writeRing)
549 .def(
"__str__", idhdl_as_str);
550 def(
"call_interpreter_method",call_interpreter_method);
551 def(
"cbm",call_builtin_method_general);
552 def(
"transfer_to_python",buildPyObjectFromIdhdl);
553 def(
"is_builtin", is_builtin);
const CanonicalForm int s
idhdl ggetid(const char *n)
unsigned char * proc[NUM_PROC]
Class used for (list of) interpreter objects.
BOOLEAN iiExprArith1(leftv res, leftv a, int op)
BOOLEAN iiExprArith3(leftv res, int op, leftv a, leftv b, leftv c)
intrusive_ptr< ip_sring > pimpl
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
void export_interpreter()
char name(const Variable &v)
intvec * allocate_legacy_intvec_copy() const
INLINE_THIS void Init(int l=0)
matrix mpNew(int r, int c)
create a r x c zero-matrix
static void p_Delete(poly *p, const ring r)
const Variable & v
< [in] a sqrfree bivariate poly
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv sl)
void CleanUp(ring r=currRing)
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
#define omFreeBin(addr, bin)
BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
#define MATELEM(mat, i, j)
int IsCmd(const char *n, int &tok)