4 #include <boost/python.hpp> 5 #include <boost/python/numpy.hpp> 6 #include <boost/python/suite/indexing/vector_indexing_suite.hpp> 24 using boost::python::numpy::ndarray;
25 using boost::python::extract;
26 static void free_leftv(
leftv args)
32 matrix matrixFromArray(
const boost::python::numpy::ndarray&
f)
34 object o=
f.attr(
"shape");
37 int l1=extract<int>(o1);
38 int l2=extract<int>(o2);
44 Poly&
x = boost::python::extract<Poly&>(
f[boost::python::make_tuple(
i,
j)]);
51 bool is_builtin(
const char*
name)
92 void appendPoly(
const Poly&
p)
99 void appendIdeal(
const Ideal&
p)
102 v->data=
p.as_ideal();
106 void appendModule(
const Module&
p)
109 v->data=
p.as_module();
113 void appendint(
int p)
116 v->data=(
void*)((
long)
p);
120 void appendNumber(
const Number&
p)
123 v->data=(
void*)
p.as_number();
127 void appendVector(
const Vector&
p)
134 void appendArray(
const boost::python::numpy::ndarray&
f)
142 void appendString(
const char*
s)
149 void appendRing(
const Ring&
r)
152 v->data=
r.pimpl.get();
164 leftv iv=pop_front();
172 void appendPrelist(arg_list&
l)
175 v->data=
l.dumpToLists();
179 void appendIntvec(
Intvec& iv)
193 void internal_append(
leftv v)
233 void writePoly(
const Poly&
p)
238 id->data.p=
p.as_poly();
241 void writeIdeal(
const Ideal&
p)
246 id->data.uideal=
p.as_ideal();
249 void writeModule(
const Module&
p)
254 id->data.uideal=
p.as_module();
264 void writeNumber(
const Number&
p)
269 id->data.n=
p.as_number();
272 void writeVector(
const Vector&
p)
277 id->data.p=
p.as_poly();
280 void writeArray(
const boost::python::numpy::ndarray&
f)
289 void writeRing(
const Ring&
r)
294 ((ring) id->
data.uring)->ref--;
295 ring r2=
r.pimpl.get();
299 void writeString(
const char*
s)
307 void writeIntvec(
const Intvec& iv)
315 void writeList(arg_list&
f)
321 id->data.l=
f.dumpToLists();
327 static boost::python::numpy::ndarray buildPythonMatrix(
matrix m, ring
r)
329 using boost::python::numpy::ndarray;
330 using boost::python::self;
331 using boost::python::make_tuple;
332 using boost::python::tuple;
333 using boost::python::object;
334 using boost::python::list;
349 return boost::python::numpy::array(
l);
351 boost::python::object buildPyObjectFromLeftv(
leftv v);
352 boost::python::list buildPythonList(
lists l, ring
r)
354 using boost::python::list;
357 for(
int i=0;
i<=
l->nr;
i++)
360 object o=buildPyObjectFromLeftv(lv);
366 boost::python::object buildPyObjectFromLeftv(
leftv v)
368 using boost::python::object;
372 return object((
int)((
long)
v->data));
376 return str((
const char*)
v->data);
390 return object(
Ring((ring)
v->data));
398 boost::python::object buildPyObjectFromIdhdl(
const idhdl_wrap&
id)
400 using boost::python::object;
405 return str((
const char*)
id.id->data.ustring);
408 return object((
int)
id.id->data.i);
433 return object(
Ring((ring)
id.id->data.uring));
443 boost::python::object call_interpreter_method(
const idhdl_wrap&
proc,
const arg_list& args)
450 boost::python::object call_builtin_method_general(
const char*
name, arg_list&
l)
493 boost::python::object real_res=buildPyObjectFromLeftv(
res);
501 static boost::python::str idhdl_as_str(idhdl_wrap iw)
504 using boost::python::str;
507 std::basic_stringstream<char>
s;
509 return boost::python::str(
s.str());
511 static idhdl_wrap get_idhdl(
const char *n)
514 return idhdl_wrap(
ggetid(n));
518 def(
"get_idhdl", get_idhdl);
519 boost::python::class_<arg_list>(
"i_arg_list")
520 .def(
"append", &arg_list::appendPoly)
521 .def(
"append", &arg_list::appendArray)
522 .def(
"append", &arg_list::appendNumber)
523 .def(
"append", &arg_list::appendint)
524 .def(
"append", &arg_list::appendIdeal)
525 .def(
"append", &arg_list::appendModule)
526 .def(
"append", &arg_list::appendPrelist)
527 .def(
"append", &arg_list::appendVector)
528 .def(
"append", &arg_list::appendRing)
529 .def(
"append", &arg_list::appendIntvec)
530 .def(
"append", &arg_list::appendString);
531 boost::python::class_<idhdl_wrap>(
"interpreter_id")
532 .def(
"is_zero", &idhdl_wrap::is_zero)
533 .def(
"is_proc", &idhdl_wrap::id_is_proc)
534 .def(
"print_type", &idhdl_wrap::print_type)
535 .def(
"write", &idhdl_wrap::writePoly)
536 .def(
"write", &idhdl_wrap::writeArray)
537 .def(
"write", &idhdl_wrap::writeNumber)
538 .def(
"write", &idhdl_wrap::writeint)
539 .def(
"write", &idhdl_wrap::writeIdeal)
540 .def(
"write", &idhdl_wrap::writeModule)
541 .def(
"write", &idhdl_wrap::writeVector)
542 .def(
"write", &idhdl_wrap::writeList)
543 .def(
"write", &idhdl_wrap::writeString)
544 .def(
"write", &idhdl_wrap::writeIntvec)
545 .def(
"write", &idhdl_wrap::writeRing)
546 .def(
"__str__", idhdl_as_str);
547 def(
"call_interpreter_method",call_interpreter_method);
548 def(
"cbm",call_builtin_method_general);
549 def(
"transfer_to_python",buildPyObjectFromIdhdl);
550 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)
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
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)