Changeset 26f928 in git for modules/python


Ignore:
Timestamp:
Sep 9, 2005, 12:03:07 PM (19 years ago)
Author:
Michael Brickenstein <bricken@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38dfc5131670d387a89455159ed1e071997eec94')
Children:
a675fcb30922f056ecdcbd0e77cdd66c2c919faf
Parents:
4a8f253390029bf6c14db1e195cea6271e34a4d4
Message:
*bricken: writing global variables


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

Legend:

Unmodified
Added
Removed
  • modules/python/README

    r4a8f25 r26f928  
    7575
    7676
     77NEWS:
     78*global_functions has be renamed to singular_globals_proxy
     79the old name exists for short time for compat.
     80
     81*it is now possible to use the singular_globals_proxy for
     82    -reading global variables
     83    -writing global variables, if the var exists with the correct type in the interpreter
     84    -calling global interpreter functions (not builtins, for example groebner but not std
    7785
    7886
     
    8391
    8492
    85 
  • modules/python/interpreter.py

    r4a8f25 r26f928  
    2121                raise AttributeError("Global variable "+name+" has unknown type")
    2222            return res
    23 
     23    def __setattr__(self,name,value):
     24        id=get_idhdl(name)
     25        if id.is_zero():
     26            raise Expception
     27        else:
     28            id.write(value)
    2429#for compatibility the old name
    2530global_functions=singular_globals_proxy
  • modules/python/interpreter_support.cc

    r4a8f25 r26f928  
    1818using boost::python::numeric::array;
    1919using boost::python::extract;
     20matrix matrixFromArray(const array& f){
     21  object o=f.attr("shape");
     22 
     23  object o1=o[0];
     24 
     25  object o2=o[1];
     26  int l1=extract<int>(o1);
     27
     28 
     29  int l2=extract<int>(o2);
     30  matrix m=mpNew(l1,l2);
     31  for(int i=0;i<l1;i++){
     32    for(int j=0;j<l2;j++){
     33      Poly& x = boost::python::extract<Poly&>(f[boost::python::make_tuple(i,j)]);
     34      poly p=x.as_poly();
     35      MATELEM(m,i+1,j+1)=p;
     36    }
     37  }
     38  return m;
     39}
    2040class idhdl_wrap{
    2141 public:
     
    3656    Print("type:%d\n",id->typ);
    3757  }
     58  void writePoly(const Poly& p){
     59   
     60    if (id->typ==POLY_CMD){
     61      p_Delete(&id->data.p, currRing);
     62      id->data.p=p.as_poly();
     63    }
     64   
     65  }
     66  void writeIdeal(const Ideal& p){
     67    if (id->typ==IDEAL_CMD){
     68      id_Delete(&id->data.uideal, currRing);
     69     
     70      id->data.uideal=p.as_ideal();
     71    }
     72  }
     73  void writeint(int p){
     74    if (id->typ==INT_CMD){
     75      id->data.i=p;
     76    }
     77  }
     78  void writeNumber(const Number& p){
     79     
     80 if (id->typ==NUMBER_CMD){
     81      n_Delete(&id->data.n, currRing);
     82      id->data.n=p.as_number();
     83    }
     84  }
     85  void writeVector(const Vector& p){
     86       
     87    if (id->typ==VECTOR_CMD){
     88      p_Delete(&id->data.p, currRing);
     89      id->data.p=p.as_poly();
     90    }
     91  }
     92  void writeArray(const array& f){
     93    if(id->typ=MATRIX_CMD){
     94      matrix m=matrixFromArray(f);
     95      id_Delete((ideal*) &id->data.umatrix,currRing);
     96      id->data.umatrix;
     97    }
     98  }
    3899};
     100
     101
    39102class arg_list{
    40103 public:
     
    79142  }
    80143  void appendArray(const array& f){
    81    
    82    
    83     object o=f.attr("shape");
    84  
    85     object o1=o[0];
    86    
    87     object o2=o[1];
    88     int l1=extract<int>(o1);
    89    
    90 
    91     int l2=extract<int>(o2);
    92     matrix m=mpNew(l1,l2);
    93     for(int i=0;i<l1;i++){
    94       for(int j=0;j<l2;j++){
    95         Poly& x = boost::python::extract<Poly&>(f[boost::python::make_tuple(i,j)]);
    96         poly p=x.as_poly();
    97         MATELEM(m,i+1,j+1)=p;
    98       }
    99     }
    100     leftv v=initArg();
     144    leftv v=initArg();
     145    matrix m=matrixFromArray(f);
    101146    v->data=m;
    102147    v->rtyp=MATRIX_CMD;
     
    236281    .def("is_proc", &idhdl_wrap::id_is_proc)
    237282    .def("print_type", &idhdl_wrap::print_type)
     283    .def("write", &idhdl_wrap::writePoly)
     284    .def("write", &idhdl_wrap::writeArray)
     285    .def("write", &idhdl_wrap::writeNumber)
     286    .def("write", &idhdl_wrap::writeint)
     287    .def("write", &idhdl_wrap::writeIdeal)
     288    .def("write", &idhdl_wrap::writeVector)
    238289    .def("__str__", idhdl_as_str);
    239290  def("call_interpreter_method",call_interpreter_method);
  • modules/python/interpretertester

    r4a8f25 r26f928  
    11ring r=0,(x,y,z),lp;
    22int a=12345;
     3poly f=0;
    34timer=1;
    45proc myprintmat(matrix m){
     
    5354print functions.groebner(i);
    5455xy=x*y
    55 
     56functions.f=xy
    5657
    5758xye1=xy*gen(1)
     
    6768print functions.a
    6869");
     70print(f);
    6971$
Note: See TracChangeset for help on using the changeset viewer.