Changeset 4a8f25 in git for modules/python


Ignore:
Timestamp:
Sep 9, 2005, 11:29:09 AM (19 years ago)
Author:
Michael Brickenstein <bricken@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38dfc5131670d387a89455159ed1e071997eec94')
Children:
26f92837efc1ad04c4c0b9a2be093e843a281a61
Parents:
51092d076fe254dc637ef1f5f80e5c2a1c01d4f6
Message:
*bricken: reading global singular variables


git-svn-id: file:///usr/local/Singular/svn/trunk@8605 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
modules/python
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • modules/python/interpreter.py

    r51092d r4a8f25  
    11from Singular import *
    2 class global_functions(object):
     2class singular_globals_proxy(object):
    33    def __getattr__(self,name):
    44        proc=get_idhdl(name)
    55        if proc.is_zero():
    6             raise AttributeError("Global variable " + name + " not present in the Singular interpreter")
    7         def fun_wrapper(*args):
    8             l=i_arg_list()
    9             for a in args:
    10                 l.append(a)
    11             proc=get_idhdl(name)
    12             return call_interpreter_method(proc, l)
    13         return fun_wrapper
     6            raise AttributeError("Global variable " + name + " not present in the Singular interpreter")
     7        if proc.is_proc():
     8            def fun_wrapper(*args):
     9                l=i_arg_list()
     10                for a in args:
     11                    l.append(a)
     12                proc=get_idhdl(name)
     13                if not proc.is_proc():
     14                    proc.print_type()
     15                    raise Exception
     16                return call_interpreter_method(proc, l)
     17            return fun_wrapper
     18        else:
     19            res=transfer_to_python(proc)
     20            if res is None:
     21                raise AttributeError("Global variable "+name+" has unknown type")
     22            return res
     23
     24#for compatibility the old name
     25global_functions=singular_globals_proxy
  • modules/python/interpreter_support.cc

    r51092d r4a8f25  
    3030    return id==NULL;
    3131  }
     32  bool id_is_proc(){
     33    return (id->typ==PROC_CMD);
     34  }
     35  bool print_type(){
     36    Print("type:%d\n",id->typ);
     37  }
    3238};
    3339class arg_list{
     
    116122 
    117123};
     124static PyObject* buildPythonMatrix(matrix m, ring r){
     125  using boost::python::numeric::array;
     126  using boost::python::self;
     127  using boost::python::make_tuple;
     128  using boost::python::tuple;
     129  using boost::python::object;
     130  using boost::python::list;
     131 
     132  list l;
     133 
     134 
     135  for(int i=1;i<=MATROWS(m);i++){
     136    list row;
     137    for(int j=1;j<=MATCOLS(m);j++){
     138      Poly ip(MATELEM(m,i,j),r);//copy it
     139      row.append(ip);
     140      //a[boost::python::make_tuple(i%2,i%5)]=ip;
     141      //a[boost::python::make_tuple(i%2,i%5)]=ip;
     142    }
     143    l.append(row);
     144  }
     145  //FIXME: should call this only once
     146  array::set_module_and_type("Numeric",
     147                             "ArrayType"
     148                             );
     149 
     150  return to_python_value<array>()(array(l));
     151}
    118152PyObject* buildPyObjectFromLeftv(leftv v){
    119153 
     
    134168  case MATRIX_CMD:
    135169    {
    136       using boost::python::numeric::array;
    137       using boost::python::self;
    138       using boost::python::make_tuple;
    139       using boost::python::tuple;
    140       using boost::python::object;
    141       using boost::python::list;
    142       matrix m=(matrix) v->data;
    143       list l;
    144 
    145 
    146       for(int i=1;i<=MATROWS(m);i++){
    147         list row;
    148         for(int j=1;j<=MATCOLS(m);j++){
    149           Poly ip(MATELEM(m,i,j),currRing);//copy it
    150           row.append(ip);
    151           //a[boost::python::make_tuple(i%2,i%5)]=ip;
    152           //a[boost::python::make_tuple(i%2,i%5)]=ip;
    153         }
    154         l.append(row);
    155       }
    156       //FIXME: should call this only once
    157       array::set_module_and_type("Numeric",
    158                              "ArrayType"
    159                              );
    160 
    161       return to_python_value<array>()(array(l));
     170      return buildPythonMatrix((matrix) v->data,currRing);
     171    }
     172  default:
     173    Py_INCREF(Py_None);
     174    return Py_None;
     175  }
     176}
     177PyObject* buildPyObjectFromIdhdl(const idhdl_wrap&  id){
     178 
     179 
     180  switch (id.id->typ){
     181  case INT_CMD:
     182    return PyInt_FromLong((int)id.id->data.i);
     183  case POLY_CMD:
     184   
     185    return to_python_value<Poly>()(Poly((poly) id.id->data.p, currRing));
     186  case  VECTOR_CMD:
     187   
     188    return to_python_value<Vector>()( Vector((poly) id.id->data.p, currRing));
     189  case IDEAL_CMD:
     190    return to_python_value<Ideal>()(Ideal((ideal) id.id->data.uideal, currRing));
     191  case  NUMBER_CMD:
     192 
     193    return to_python_value<Number>()(Number((number) id.id->data.n, currRing));
     194  case MATRIX_CMD:
     195    {
     196      return buildPythonMatrix((matrix) id.id->data.umatrix,currRing);
    162197    }
    163198  default:
     
    199234  boost::python::class_<idhdl_wrap>("interpreter_id")
    200235    .def("is_zero", &idhdl_wrap::is_zero)
     236    .def("is_proc", &idhdl_wrap::id_is_proc)
     237    .def("print_type", &idhdl_wrap::print_type)
    201238    .def("__str__", idhdl_as_str);
    202239  def("call_interpreter_method",call_interpreter_method);
    203 }
    204 
    205 
     240  def("transfer_to_python",buildPyObjectFromIdhdl);
     241}
     242
     243
  • modules/python/interpretertester

    r51092d r4a8f25  
    11ring r=0,(x,y,z),lp;
     2int a=12345;
    23timer=1;
    34proc myprintmat(matrix m){
     
    6465m=functions.testproc6(x,y)
    6566functions.myprintmat(m)
    66 
     67print functions.a
    6768");
    6869$
Note: See TracChangeset for help on using the changeset viewer.