Changeset 451a9a in git


Ignore:
Timestamp:
Jun 21, 2006, 8:27:12 AM (18 years ago)
Author:
Michael Brickenstein <bricken@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38dfc5131670d387a89455159ed1e071997eec94')
Children:
20d72f0729f1c6d0a9a7ed847785c4fb0271b3b7
Parents:
e6cbed94a014891c3db90b82149bb853254bb0d9
Message:
*bricken: + module type


git-svn-id: file:///usr/local/Singular/svn/trunk@9247 2c84dea3-7e68-4137-9b89-c4e89433aadc
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • kernel/Ideal.h

    re6cbed r451a9a  
    11#ifndef IDEAL_CPP_HEADER
    22#define IDEAL_CPP_HEADER
    3 //$Id: Ideal.h,v 1.7 2005-09-21 09:51:10 bricken Exp $
     3//$Id: Ideal.h,v 1.8 2006-06-21 06:26:58 bricken Exp $
    44#include <vector>
    55#include "Poly.h"
     
    106106 }
    107107};
    108 class Modul:
     108class Module:
    109109public IdealBase<Vector>{
     110public:
     111 Module(ideal i, ring r){
     112    for(int j=0;j<IDELEMS(i);j++){
     113      storage.push_back(Vector(i->m[j],r));
     114    }
     115  }
     116  ideal as_module() const{
     117   
     118   //no checks for rings
     119        int s=size();
     120   
     121        if (s==0)
     122        s=1;
     123   
     124        ideal result=idInit(s,1);
     125        result->m[0]=NULL;
     126        s=size();
     127        for(int i=0;i<s;i++){
     128            result->m[i]=storage[i].as_poly();
     129
     130        }
     131    if (size()==0)
     132            result->rank=0;
     133        else
     134            result->rank=idRankFreeModule(result,storage[0].getRing());
     135   return result;
     136   
     137  }
     138  Module(iterator first,
     139        iterator last,
     140        const allocator_type& __a = allocator_type()):
     141    IdealBase<Vector>(first,last,__a){
     142  }
     143  Module(){
     144  }
    110145};
    111146#endif
  • kernel/Poly.h

    re6cbed r451a9a  
    1 //$Id: Poly.h,v 1.33 2006-03-22 14:14:29 bricken Exp $
     1//$Id: Poly.h,v 1.34 2006-06-21 06:26:58 bricken Exp $
    22
    33
     
    6060  }
    6161  friend inline bool operator==(const Poly& p1, const Poly& p2);
     62  friend inline bool operator==(const Vector& p1, const Vector& p2);
    6263  friend PolyImpl operator+(const PolyImpl& p1, const PolyImpl& n2);
    6364  friend PolyImpl operator-(const PolyImpl& p1, const PolyImpl& n2);
     
    525526    return *this;
    526527  }
    527 
     528  friend inline bool operator==(const Vector& p1, const Vector& p2);
    528529};
    529530
     
    583584  return p_EqualPolys(p1.ptr->p,p2.ptr->p,r1);
    584585}
     586inline bool operator==(const Vector& p1, const Vector& p2){
     587  ring r1=p1.getRing();
     588  ring r2=p2.getRing();
     589  if (r1!=r2) return false;
     590  return p_EqualPolys(p1.ptr->p,p2.ptr->p,r1);
     591}
    585592template <poly_variant variant, class create_type,class error_traits>
    586593  inline typename PolyBase<variant,create_type,error_traits>::create_type
  • modules/python/ideal_wrap.cc

    re6cbed r451a9a  
    1 //$Id: ideal_wrap.cc,v 1.9 2006-03-15 10:40:43 bricken Exp $
     1//$Id: ideal_wrap.cc,v 1.10 2006-06-21 06:27:11 bricken Exp $
    22#include <boost/python.hpp>
    33#include "mod2.h"
     
    2929  return res;
    3030}
     31static boost::python::object Module_as_str(const Module& p)
     32{
     33  using boost::python::str;
     34  //ring r=p.getRing();
     35  str helper;
     36  list tojoin;
     37  int i;
     38  int s=p.size();
     39  //tojoin.append("[");
     40  for(i=0;i<s;i++){
     41    tojoin.append(Vector_as_str(p[i]));
     42    if (i<s-1)
     43      tojoin.append(", ");
     44  }
     45  //tojoin.append("]");
     46  str res=helper.join(tojoin);
     47  return res;
     48}
     49
    3150static Ring Ideal_get_Ring(const Ideal & p){
    3251  return p.getRing();
     
    3958    python list supports with the expception, that elements must\
    4059    be Polynomials")
     60     .def(init<>())
     61     .def(init<const Ideal&>())
    4162     .def("__str__", Ideal_as_str)
    4263     .def("ring",Ideal_get_Ring)
     
    4566   
    4667}
     68void export_module()
     69{
     70   boost::python::class_<Module>("Module", "supports most operation a\
     71    python list supports with the expception, that elements must\
     72    be Polynomials")
     73     .def(init<>())
     74     .def(init<const Module&>())
     75     .def("__str__", Module_as_str)
     76     .def("ring",Ideal_get_Ring)
     77     .def(boost::python::init <>())
     78     .def(vector_indexing_suite<Module>());
     79   
     80}
    4781
    4882
  • modules/python/ideal_wrap.h

    re6cbed r451a9a  
    22#define IDEAL_WRAP_HEADER
    33void export_ideal();
     4void export_module();
    45#endif
  • modules/python/idealtester

    re6cbed r451a9a  
    11ring r=0,(x,y,z),lp;
    22timer=1;
    3 python_module::python("from Singular import number,  polynomial, ideal
    4 i=ideal()
    5 zero=number(0)
    6 one=number(1)
    7 zerop=polynomial(0)
     3LIB("python_module.so");
     4Python_module::python("from Singular import Number,  Polynomial, Ideal, gen, Module
     5i=Ideal()
     6zero=Number(0)
     7one=Number(1)
     8zerop=Polynomial(0)
    89i.append(zerop)
    910print len(i)
    10 onep=polynomial(1)
     11onep=Polynomial(1)
    1112i.append(onep)
    1213print len(i)
     
    1415  print p
    1516print i
    16 xy=polynomial('xy')
     17xy=Polynomial('xy')
    1718print xy
    18 comp=polynomial('xy+1')
     19comp=Polynomial('xy+1')
    1920print comp
    2021#the same as only monomials are build
    2122
    22 z=polynomial(xy);
    23 z*=number(3);
     23z=Polynomial(xy);
     24z*=Number(3);
    2425print z,xy
    25 print xy+number(1)
     26print xy+Number(1)
    2627print z+xy
    2728print z,xy
    2829print xy*xy
    2930print xy
    30 for t in ((xy+number(1))*(xy+number(-1))):
     31for t in ((xy+Number(1))*(xy+Number(-1))):
    3132  print t,-t,t
     33import util
     34r=util.create_ring(char=0,nvars=3, varNames=['t','u','v','w'], ordering='lp', register=locals())
     35r.set()
     36m=Module()
     37m.append(t*u*gen(1)+v*gen(2))
     38m.append(w*gen(4))
     39m.append(v*u*gen(3))
     40print m
     41print m[1:]
     42del m[1]
     43print m
    3244");
    3345$
  • modules/python/interpreter_support.cc

    re6cbed r451a9a  
    1 //$Id: interpreter_support.cc,v 1.20 2006-06-17 13:47:17 bricken Exp $
     1//$Id: interpreter_support.cc,v 1.21 2006-06-21 06:27:11 bricken Exp $
    22
    33#include <sstream>
     
    9696    internal_append(v);
    9797  }
     98  void appendModule(const Module& p){
     99    leftv v=initArg();
     100    v->data=p.as_module();
     101    v->rtyp=MODUL_CMD;
     102    internal_append(v);
     103  }
    98104  void appendint(int p){
    99105      leftv v=initArg();
     
    218224    }
    219225  }
     226  void writeModule(const Module& p){
     227    if (id->typ==MODUL_CMD){
     228      id_Delete(&id->data.uideal, currRing);
     229     
     230      id->data.uideal=p.as_module();
     231    }
     232  }
    220233  void writeint(int p){
    221234    if (id->typ==INT_CMD){
     
    331344  case IDEAL_CMD:
    332345    return object(Ideal((ideal) v->data, currRing));
     346  case MODUL_CMD:
     347    return object(Module((ideal) v->data, currRing));
    333348  case  NUMBER_CMD:
    334349 
     
    368383
    369384    return object(Ideal((ideal) id.id->data.uideal, currRing));
     385  case MODUL_CMD:
     386    //object res;
     387
     388    return object(Module((ideal) id.id->data.uideal, currRing));
    370389  case  NUMBER_CMD:
    371390 
     
    485504    .def("append", &arg_list::appendint)
    486505    .def("append", &arg_list::appendIdeal)
     506    .def("append", &arg_list::appendModule)
    487507    .def("append", &arg_list::appendPrelist)
    488508    .def("append", &arg_list::appendVector)
     
    499519    .def("write", &idhdl_wrap::writeint)
    500520    .def("write", &idhdl_wrap::writeIdeal)
     521    .def("write", &idhdl_wrap::writeModule)
    501522    .def("write", &idhdl_wrap::writeVector)
    502523    .def("write", &idhdl_wrap::writeList)
  • modules/python/interpretertester

    re6cbed r451a9a  
    33poly f=10;
    44ideal i=x,y;
     5module m=x*gen(1),y*gen(2);
    56list l=f,i;
    67intvec iv=1,2,3,45,5,6,7,8;
     
    3738return(p);
    3839}
     40
    3941proc testproc5(int p){
    4042print("Hallo Welt ihr ints");
     
    5456  return(m);
    5557}
     58
     59proc testproc7(module p){
     60print("Hallo Welt ihr Modules");
     61print(p);
     62return(p);
     63}
     64
    5665list mylist=1,2,3;
    5766LIB("python_module.so");
     
    95104print functions.testproc5(325)
    96105print functions.testproc6(x,y)
     106print functions.testproc7(functions.m)
    97107from Singular import foo2;
    98108m=functions.testproc6(x,y)
    99109functions.myprintmat(m)
    100110print functions.a
     111print 'Read module:', functions.m
    101112
    102113print i
  • modules/python/poly_wrap.cc

    re6cbed r451a9a  
    88using boost::python::self;
    99boost::python::str Poly_as_str(const Poly& p)
     10{
     11  using boost::python::str;
     12  //ring r=p.getRing();
     13 
     14  char* out=p.c_string();
     15  return boost::python::str(out,strlen(out));
     16}
     17boost::python::str Vector_as_str(const Vector& p)
    1018{
    1119  using boost::python::str;
     
    3442    .def("leadCoef",&Poly::leadCoef)
    3543    .def("leadExp", &Poly::leadExp)
     44   
    3645    .def(-self)
    3746    .def(self*=self)
     
    4655    .def(self+=Number())
    4756    .def(self*=Number())
     57   
    4858    .def(self*self);
     59 
    4960}
    5061
  • modules/python/poly_wrap.h

    re6cbed r451a9a  
    66void export_poly();
    77boost::python::str Poly_as_str(const Poly& p);
     8boost::python::str Vector_as_str(const Vector& p);
    89#endif
  • modules/python/wrapper.h

    re6cbed r451a9a  
    1 //$Id: wrapper.h,v 1.33 2006-03-24 17:36:58 bricken Exp $
     1//$Id: wrapper.h,v 1.34 2006-06-21 06:27:12 bricken Exp $
    22#ifndef PYTHON_SINGULAR_WRAPPER_HEADER
    33#define PYTHON_SINGULAR_WRAPPER_HEADER
     
    6161  export_playground();
    6262  export_ideal();
     63  export_module();
    6364  //export_interpreter();
    6465  export_ring();
Note: See TracChangeset for help on using the changeset viewer.