4 #include <boost/python.hpp>
5 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
22 using namespace boost::python;
23 using boost::python::extract;
24 static void free_leftv(
leftv args)
30 #if BOOST_VERSION < 106500
31 typedef typename boost::python::numeric::array NumpyArrayType;
33 #include <boost/python/numpy.hpp>
34 typedef typename boost::python::numpy::ndarray NumpyArrayType;
37 matrix matrixFromArray(
const NumpyArrayType&
f)
39 object o=
f.attr(
"shape");
42 int l1=extract<int>(o1);
43 int l2=extract<int>(o2);
49 Poly&
x = boost::python::extract<Poly&>(
f[boost::python::make_tuple(
i,
j)]);
56 bool is_builtin(
const char*
name)
97 void appendPoly(
const Poly&
p)
104 void appendIdeal(
const Ideal&
p)
107 v->data=
p.as_ideal();
111 void appendModule(
const Module&
p)
114 v->data=
p.as_module();
118 void appendint(
int p)
121 v->data=(
void*)((
long)
p);
125 void appendNumber(
const Number&
p)
128 v->data=(
void*)
p.as_number();
132 void appendVector(
const Vector&
p)
139 void appendArray(
const NumpyArrayType&
f)
147 void appendString(
const char*
s)
154 void appendRing(
const Ring& r)
169 leftv iv=pop_front();
177 void appendPrelist(arg_list&
l)
180 v->data=
l.dumpToLists();
184 void appendIntvec(
Intvec& iv)
198 void internal_append(
leftv v)
238 void writePoly(
const Poly&
p)
243 id->data.p=
p.as_poly();
246 void writeIdeal(
const Ideal&
p)
251 id->data.uideal=
p.as_ideal();
254 void writeModule(
const Module&
p)
259 id->data.uideal=
p.as_module();
269 void writeNumber(
const Number&
p)
274 id->data.n=
p.as_number();
277 void writeVector(
const Vector&
p)
282 id->data.p=
p.as_poly();
285 void writeArray(
const NumpyArrayType&
f)
294 void writeRing(
const Ring& r)
299 ((ring) id->
data.uring)->ref--;
300 ring r2=r.
pimpl.get();
304 void writeString(
const char*
s)
312 void writeIntvec(
const Intvec& iv)
320 void writeList(arg_list&
f)
326 id->data.l=
f.dumpToLists();
332 static NumpyArrayType buildPythonMatrix(
matrix m, ring r)
335 using boost::python::self;
336 using boost::python::make_tuple;
337 using boost::python::tuple;
338 using boost::python::object;
339 using boost::python::list;
354 #if BOOST_VERSION <106500
356 NumpyArrayType::set_module_and_type(
"Numeric",
359 return NumpyArrayType(
l);
361 return boost::python::numpy::array(
l);
364 boost::python::object buildPyObjectFromLeftv(
leftv v);
365 boost::python::list buildPythonList(
lists l, ring r)
367 using boost::python::list;
370 for(
int i=0;
i<=
l->nr;
i++)
373 object o=buildPyObjectFromLeftv(lv);
379 boost::python::object buildPyObjectFromLeftv(
leftv v)
381 using boost::python::object;
385 return object((
int)((
long)
v->data));
389 return str((
const char*)
v->data);
403 return object(
Ring((ring)
v->data));
411 boost::python::object buildPyObjectFromIdhdl(
const idhdl_wrap&
id)
413 using boost::python::object;
418 return str((
const char*)
id.id->data.ustring);
421 return object((
int)
id.id->data.i);
446 return object(
Ring((ring)
id.id->data.uring));
456 boost::python::object call_interpreter_method(
const idhdl_wrap&
proc,
const arg_list& args)
463 boost::python::object call_builtin_method_general(
const char*
name, arg_list&
l)
506 boost::python::object real_res=buildPyObjectFromLeftv(
res);
514 static boost::python::str idhdl_as_str(idhdl_wrap iw)
517 using boost::python::str;
520 std::basic_stringstream<char>
s;
522 return boost::python::str(
s.str());
524 static idhdl_wrap get_idhdl(
const char *n)
527 return idhdl_wrap(
ggetid(n));
531 def(
"get_idhdl", get_idhdl);
532 boost::python::class_<arg_list>(
"i_arg_list")
533 .def(
"append", &arg_list::appendPoly)
534 .def(
"append", &arg_list::appendArray)
535 .def(
"append", &arg_list::appendNumber)
536 .def(
"append", &arg_list::appendint)
537 .def(
"append", &arg_list::appendIdeal)
538 .def(
"append", &arg_list::appendModule)
539 .def(
"append", &arg_list::appendPrelist)
540 .def(
"append", &arg_list::appendVector)
541 .def(
"append", &arg_list::appendRing)
542 .def(
"append", &arg_list::appendIntvec)
543 .def(
"append", &arg_list::appendString);
544 boost::python::class_<idhdl_wrap>(
"interpreter_id")
545 .def(
"is_zero", &idhdl_wrap::is_zero)
546 .def(
"is_proc", &idhdl_wrap::id_is_proc)
547 .def(
"print_type", &idhdl_wrap::print_type)
548 .def(
"write", &idhdl_wrap::writePoly)
549 .def(
"write", &idhdl_wrap::writeArray)
550 .def(
"write", &idhdl_wrap::writeNumber)
551 .def(
"write", &idhdl_wrap::writeint)
552 .def(
"write", &idhdl_wrap::writeIdeal)
553 .def(
"write", &idhdl_wrap::writeModule)
554 .def(
"write", &idhdl_wrap::writeVector)
555 .def(
"write", &idhdl_wrap::writeList)
556 .def(
"write", &idhdl_wrap::writeString)
557 .def(
"write", &idhdl_wrap::writeIntvec)
558 .def(
"write", &idhdl_wrap::writeRing)
559 .def(
"__str__", idhdl_as_str);
560 def(
"call_interpreter_method",call_interpreter_method);
561 def(
"cbm",call_builtin_method_general);
562 def(
"transfer_to_python",buildPyObjectFromIdhdl);
563 def(
"is_builtin", is_builtin);
unsigned char * proc[NUM_PROC]
intvec * allocate_legacy_intvec_copy() const
intrusive_ptr< ip_sring > pimpl
Class used for (list of) interpreter objects.
void CleanUp(ring r=currRing)
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
const CanonicalForm int s
const Variable & v
< [in] a sqrfree bivariate poly
char name(const Variable &v)
void export_interpreter()
static BOOLEAN length(leftv result, leftv arg)
BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
int IsCmd(const char *n, int &tok)
BOOLEAN iiExprArith1(leftv res, leftv a, int op)
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
BOOLEAN iiExprArith3(leftv res, int op, leftv a, leftv b, leftv c)
idhdl ggetid(const char *n)
EXTERN_VAR omBin sleftv_bin
INST_VAR sleftv iiRETURNEXPR
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv sl)
matrix mpNew(int r, int c)
create a r x c zero-matrix
#define MATELEM(mat, i, j)
1-based access to matrix
#define omFreeBin(addr, bin)
static void p_Delete(poly *p, const ring r)
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix