Changeset 0a8b32 in git


Ignore:
Timestamp:
Feb 27, 2017, 2:46:18 PM (7 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
5c773a32c223f8f216df09eef7badedc4d0754a6
Parents:
e059d4cdef9e5f024a0949809f58353d2dee7a11
Message:
dyn_mod: python: syntax
Location:
Singular/dyn_modules/python
Files:
1 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • Singular/dyn_modules/python/IIntvec.h

    re059d4 r0a8b32  
    33#include <vector>
    44#include <misc/intvec.h>
    5 class Intvec: public std::vector<int>{
     5class Intvec: public std::vector<int>
     6{
    67public:
    7   Intvec(iterator first,
    8         iterator last,
    9         const allocator_type& __a = allocator_type()):
    10     std::vector<int>(first,last,__a){
    11   }
     8  Intvec(iterator first,
     9        iterator last,
     10        const allocator_type& __a = allocator_type()):
     11    std::vector<int>(first,last,__a){}
    1212  Intvec(int n=0):std::vector<int>(n){}
    13   Intvec(intvec& iv):std::vector<int>(iv.length()){
     13  Intvec(intvec& iv):std::vector<int>(iv.length())
     14  {
    1415    int n=iv.length();
    15     for(int i=0;i<n;i++){
     16    for(int i=0;i<n;i++)
     17    {
    1618      (*this)[i]=iv[i];
    1719    }
    1820  }
    19   intvec* allocate_legacy_intvec_copy() const{
     21  intvec* allocate_legacy_intvec_copy() const
     22  {
    2023    int s=size();
    2124    intvec* iv=new intvec(s);
    22    
    23     for(int i=0;i<s;i++){
     25
     26    for(int i=0;i<s;i++)
     27    {
    2428      (*iv)[i]=(*this)[i];
    2529    }
  • Singular/dyn_modules/python/Ideal.h

    re059d4 r0a8b32  
    66//base for ideals as well for modules
    77//doesn't need a destructor, as Polys will destroy itself
    8 template <class poly_type> class IdealBase {
     8template <class poly_type> class IdealBase
     9{
    910 protected:
    1011  std::vector<poly_type> storage;
     
    1516  typedef typename std::vector<poly_type>::difference_type difference_type;
    1617  typedef typename std::vector<poly_type>::allocator_type allocator_type;
    17  IdealBase(){
    18  }
    19  
    20  IdealBase(iterator first,
    21              iterator last,
    22              const typename
    23              std::vector<poly_type>::allocator_type& __a = allocator_type()):
     18 IdealBase(){}
     19
     20 IdealBase(iterator first,
     21             iterator last,
     22             const typename
     23             std::vector<poly_type>::allocator_type& __a = allocator_type()):
    2424   storage(first,last,__a)
    25    {
    26    
    27  }
    28  ring getRing() const{
     25   {}
     26 ring getRing() const
     27 {
    2928  //FIXME: is a hack
    30   if (size()>0){
     29  if (size()>0)
     30  {
    3131    return storage[0].getRing();
    3232  }
    3333  else
    34   return (ring) NULL;
     34    return (ring) NULL;
    3535 }
    36  poly_type& operator[] (int n){
     36 poly_type& operator[] (int n)
     37 {
    3738   return storage[n];
    3839 }
    39  const poly_type& operator[](int n) const{
     40 const poly_type& operator[](int n) const
     41 {
    4042   return storage[n];
    4143 }
    42  void push_back(const poly_type& p){
     44 void push_back(const poly_type& p)
     45 {
    4346   storage.push_back(p);
    4447 }
    45  void push_front(const poly_type& p){
     48 void push_front(const poly_type& p)
     49 {
    4650   storage.push_front(p);
    4751 }
    4852
    49  iterator begin(){
     53 iterator begin()
     54 {
    5055   return storage.begin();
    5156 }
    52  iterator end(){
     57 iterator end()
     58 {
    5359   return storage.end();
    5460 }
    55  size_type size() const{
     61 size_type size() const
     62 {
    5663   return storage.size();
    5764 }
    5865 iterator
    59    insert(iterator __position, const value_type& __x){
    60    return storage.insert(__position,__x);
    61  }
     66   insert(iterator __position, const value_type& __x)
     67   {
     68     return storage.insert(__position,__x);
     69   }
    6270 iterator
    63    erase(iterator __position){
    64    return storage.erase(__position);
    65  }
     71   erase(iterator __position)
     72   {
     73     return storage.erase(__position);
     74   }
    6675 iterator
    67    erase(iterator __first, iterator __last){
    68    return storage.erase(__first,__last);
    69  }
    70  void insert(iterator __pos, iterator __first, iterator __last){
     76   erase(iterator __first, iterator __last)
     77   {
     78     return storage.erase(__first,__last);
     79   }
     80 void insert(iterator __pos, iterator __first, iterator __last)
     81 {
    7182   return insert(__pos,__first,__last);
    7283 }
    73 
    7484};
    7585
    7686class Ideal:
    77 public IdealBase<Poly>{
     87public IdealBase<Poly>
     88{
    7889 public:
    79   Ideal(){
    80   }
    81   Ideal(ideal i, ring r){
    82     for(int j=0;j<IDELEMS(i);j++){
     90  Ideal(){}
     91  Ideal(ideal i, ring r)
     92  {
     93    for(int j=0;j<IDELEMS(i);j++)
     94    {
    8395      storage.push_back(Poly(i->m[j],r));
    8496    }
    8597  }
    86   Ideal(iterator first, 
    87         iterator last,
    88         const allocator_type& __a = allocator_type()):
    89     IdealBase<Poly>(first,last,__a){
    90   }
    91  ideal as_ideal() const{
     98  Ideal(iterator first,
     99        iterator last,
     100        const allocator_type& __a = allocator_type()):
     101    IdealBase<Poly>(first,last,__a){}
     102 ideal as_ideal() const
     103 {
    92104   //no checks for rings
    93105   int s=size();
    94    
    95    if (s==0)
    96     s=1;
    97    
     106
     107   if (s==0) s=1;
     108
    98109   ideal result=idInit(s,1);
    99110   result->m[0]=NULL;
    100111   s=size();
    101    for(int i=0;i<s;i++){
     112   for(int i=0;i<s;i++)
     113   {
    102114     result->m[i]=storage[i].as_poly();
    103115   }
     
    106118};
    107119class Module:
    108 public IdealBase<Vector>{
     120public IdealBase<Vector>
     121{
    109122public:
    110  Module(ideal i, ring r){
    111     for(int j=0;j<IDELEMS(i);j++){
     123 Module(ideal i, ring r)
     124 {
     125    for(int j=0;j<IDELEMS(i);j++)
     126    {
    112127      storage.push_back(Vector(i->m[j],r));
    113128    }
    114129  }
    115   ideal as_module() const{
    116    
     130  ideal as_module() const
     131  {
    117132   //no checks for rings
    118133        int s=size();
    119    
     134
    120135        if (s==0)
    121136        s=1;
    122    
     137
    123138        ideal result=idInit(s,1);
    124139        result->m[0]=NULL;
    125140        s=size();
    126         for(int i=0;i<s;i++){
     141        for(int i=0;i<s;i++)
     142        {
    127143            result->m[i]=storage[i].as_poly();
    128 
    129144        }
    130145    if (size()==0)
     
    133148            result->rank=id_RankFreeModule(result,storage[0].getRing());
    134149   return result;
    135    
    136150  }
    137   Module(iterator first, 
    138         iterator last,
    139         const allocator_type& __a = allocator_type()):
     151  Module(iterator first,
     152        iterator last,
     153        const allocator_type& __a = allocator_type()):
    140154    IdealBase<Vector>(first,last,__a)
    141   { }
     155  {}
    142156  Module()
    143   { }
     157  {}
    144158};
    145159#endif
  • Singular/dyn_modules/python/Makefile

    re059d4 r0a8b32  
    33PYTHON_VERSION=2.7
    44SINGULAR_BASE=../../..
    5 CFLAGS  = -DSING_NDEBUG -DSING_OMNDEBUG -I. -I${SINGULAR_BASE} -I${SINGULAR_BASE}/kernel -I${SINGULAR_BASE}/Singular  -I/usr/include/python${PYTHON_VERSION} -I/tmp2/wawa -I${SINGULAR_BASE}/libpolys -I/tmp2/wawa/libpolys -I${SINGULAR_BASE}/factory/include
    6 LDFLAGS= -lboost_python -lpython${PYTHON_VERSION}
     5CFLAGS  = -DSING_NDEBUG -DSING_OMNDEBUG -DDYNAMIC_VERSION \
     6-I. -I${SINGULAR_BASE} -I${SINGULAR_BASE}/Singular -I${SINGULAR_BASE}/libpolys -I/tmp2/wawa/libpolys -I/usr/include/python${PYTHON_VERSION} -I/tmp2/wawa -I${SINGULAR_BASE}/factory/include
     7LDFLAGS= -lboost_python-${PYTHON_VERSION} -lpython${PYTHON_VERSION}
    78#LD     =
    89MKINSTALLDIRS=mkdir -p
     
    1213INSTALL_DATA    = ${INSTALL} -m 644
    1314SRCS    = python.cc poly_wrap.cc vector_wrap.cc CF_wrap.cc\
    14              Å†umber_wrap.cc
     15             Å†umber_wrap.cc ring_wrap.cc ideal_wrap.cc intvec_wrap.cc \
     16             interpreter_support.cc
    1517OBJS    = python.o poly_wrap.o vector_wrap.o CF_wrap.o\
    16              number_wrap.o
     18             number_wrap.o ring_wrap.o ideal_wrap.o intvec_wrap.o \
     19             interpreter_support.o
    1720
    1821all:    python_module.so
    1922
    20 %.o: %.cc Makefile
     23%.o: %.cc
    2124        ${CXX} ${CFLAGS} -c -fPIC -DPIC $< -o $*.o
    2225
  • Singular/dyn_modules/python/Poly.h

    re059d4 r0a8b32  
    2121
    2222};
    23 class ExceptionBasedErrorHandler{
     23class ExceptionBasedErrorHandler
     24{
    2425    public:
    2526        static const bool handleErrors=true;
    26         static void handleDifferentRing(ring r, ring s){
    27         PrintS("throwing");
    28         throw DifferentDomainException();
    29     }
     27        static void handleDifferentRing(ring r, ring s)
     28        {
     29          PrintS("throwing");
     30          throw DifferentDomainException();
     31        }
    3032};
    3133
    3234//PolyImpl is a 08/15 poly wrapper
    3335//Poly wraps around PolyImpl with reference counting using boost
    34 class TrivialErrorHandler{
     36class TrivialErrorHandler
     37{
    3538    public:
    3639    static const bool handleErrors=false;
    37     static void handleDifferentRing(ring r, ring s){
    38     }
     40    static void handleDifferentRing(ring r, ring s)
     41    {}
    3942};
    4043typedef TrivialErrorHandler MyErrorHandler;
  • Singular/dyn_modules/python/PowerSeries.h

    re059d4 r0a8b32  
    88  std::input_iterator_tag,
    99  typename traits::expansion_type,
    10   int, 
     10  int,
    1111  shared_ptr<const typename traits::expansion_type>,
    12   const typename traits::expansion_type
    13   > {
     12  const typename traits::expansion_type
     13  >
     14{
    1415 private:
    1516  typedef typename traits::denominator_type denominator_type;
     
    2324  denominator_type lastPot;
    2425 public:
    25   PowerSeriesInputIterator(numerator_type num_arg, 
    26                            denominator_type den_arg):
    27     data(den_arg.getRing()), 
     26  PowerSeriesInputIterator(numerator_type num_arg,
     27                           denominator_type den_arg):
     28    data(den_arg.getRing()),
    2829    lastPot(den_arg.getRing()),
    2930    numerator(num_arg),
    30     denominator(den_arg){
    31 
    32     ring r=denominator.getRing();
    33 
    34     //not the lead coef    Number c=denominator.leadCoef();
    35     Number c(1,r);
    36     typename traits::denominator_type::iterator it=denominator.begin();
    37     typename traits::denominator_type::iterator end=denominator.end();
    38     while(it!=end){
    39      
    40       if ((*it).isConstant()){
    41         //change this type
    42         c=denominator_type(*it).leadCoef();
    43        
    44         break;
     31    denominator(den_arg)
     32    {
     33      ring r=denominator.getRing();
     34      //not the lead coef    Number c=denominator.leadCoef();
     35      Number c(1,r);
     36      typename traits::denominator_type::iterator it=denominator.begin();
     37      typename traits::denominator_type::iterator end=denominator.end();
     38      while(it!=end)
     39      {
     40        if ((*it).isConstant())
     41        {
     42          //change this type
     43          c=denominator_type(*it).leadCoef();
     44          break;
     45        }
     46        ++it;
    4547      }
    46      
    47       ++it;
    48      
    49      
    50  
     48      c=Number(1,r)/c;
     49      numerator*=c;
     50      denominator*=c;
     51      toPot=denominator+denominator_type(-1,r);
     52      toPot*=Number(-1,r);
     53      //change this type
     54      lastPot=denominator_type(1,r);
     55      data=numerator;
     56      state=0;
    5157    }
    52     c=Number(1,r)/c;
    53     numerator*=c;
    54     denominator*=c;
    55     toPot=denominator+denominator_type(-1,r);
    56    
    57     toPot*=Number(-1,r);
    58     //change this type
    59     lastPot=denominator_type(1,r);
    60     data=numerator;
    61     state=0;
    62    
    63   }
    64   PowerSeriesInputIterator(){
     58  PowerSeriesInputIterator()
     59  {
    6560    state=-1;
    6661  }
    67   void shorten(){
     62  void shorten()
     63  {
    6864    typename expansion_type::iterator it=data.begin();
    6965    typename expansion_type::iterator end=data.end();
    7066    ring r=data.getRing();
    7167    expansion_type remove(r);
    72     while(it!=end){
    73       if(it->lmTotalDegree()<state){
    74         remove+=expansion_type(*it);
     68    while(it!=end)
     69    {
     70      if(it->lmTotalDegree()<state)
     71      {
     72        remove+=expansion_type(*it);
    7573      }
    7674      it++;
     
    7977    data+=remove;
    8078  }
    81   expansion_type getValue(){
     79  expansion_type getValue()
     80  {
    8281    typename expansion_type::iterator it=data.begin();
    8382    typename expansion_type::iterator end=data.end();
    8483    ring r=data.getRing();
    8584    expansion_type res(r);
    86     while(it!=end){
     85    while(it!=end)
     86    {
    8787      if(it->lmTotalDegree()==state)
    88         {
    89           res+=expansion_type(*it);
    90         }
     88        {
     89          res+=expansion_type(*it);
     90        }
    9191      it++;
    9292    }
    9393    return res;
    9494  }
    95   PowerSeriesInputIterator& operator++(){
     95  PowerSeriesInputIterator& operator++()
     96  {
    9697    state++;
    9798    shorten();
    9899    lastPot*=toPot;
    99    
    100100    data+=lastPot*numerator;
    101    
    102  
    103101    return *this;
    104    
    105102  }
    106103  //bad if this are iterators for different PowerSeries
    107   bool operator==(const PowerSeriesInputIterator& t2){
     104  bool operator==(const PowerSeriesInputIterator& t2)
     105  {
    108106    return state==t2.state;
    109107  }
    110   bool operator!=(const PowerSeriesInputIterator& t2){
     108  bool operator!=(const PowerSeriesInputIterator& t2)
     109  {
    111110    return state!=t2.state;
    112111  }
    113 
    114 
    115 
    116   PowerSeriesInputIterator operator++(int){
     112  PowerSeriesInputIterator operator++(int)
     113  {
    117114    PowerSeriesInputIterator it(*this);
    118115    ++(*this);
    119116    return it;
    120117  }
    121   const expansion_type operator*(){
     118  const expansion_type operator*()
     119  {
    122120    return expansion_type(getValue());
    123121  }
    124   shared_ptr<const expansion_type> operator->(){
     122  shared_ptr<const expansion_type> operator->()
     123  {
    125124    return shared_ptr<const expansion_type>(new expansion_type(getValue()));
    126125  }
    127   };
     126};
    128127
    129128
    130 template<class traits> class PowerSeriesBase{
     129template<class traits> class PowerSeriesBase
     130{
    131131 public:
    132132  typedef typename traits::denominator_type denominator_type;
     
    136136  numerator_type numerator;
    137137 public:
    138  
    139   PowerSeriesBase(){
    140   }
    141   PowerSeriesBase(const numerator_type &a, const denominator_type & b):numerator(a),denominator(b){
     138  PowerSeriesBase(){}
     139  PowerSeriesBase(const numerator_type &a, const denominator_type & b):numerator(a),denominator(b)
     140  {
    142141    assume(a.getRing()==b.getRing());
    143142    //asume b!=NULL
    144143  }
    145144  typedef PowerSeriesInputIterator<traits> iterator;
    146   iterator begin(){
     145  iterator begin()
     146  {
    147147    return iterator(numerator,denominator);
    148148  }
    149   iterator end(){
     149  iterator end()
     150  {
    150151    return iterator();
    151152  }
    152  
    153 
    154153};
    155154class PowerSeriesPolyTraits;
     
    157156typedef PowerSeriesBase<PowerSeriesPolyTraits> PowerSeries;
    158157typedef PowerSeriesBase<PowerSeriesVectorTraits> VectorPowerSeries;
    159 class PowerSeriesPolyTraits{
     158class PowerSeriesPolyTraits
     159{
    160160 public:
    161161  typedef Poly numerator_type;
     
    164164  typedef Poly expansion_type;
    165165};
    166 class PowerSeriesVectorTraits{
     166class PowerSeriesVectorTraits
     167{
    167168 public:
    168169  typedef Vector numerator_type;
     
    172173};
    173174
    174 
    175175#endif
  • Singular/dyn_modules/python/interpreter_support.cc

    re059d4 r0a8b32  
    1 
    21#include <sstream>
    32#include <boost/python.hpp>
     
    76#include "Poly.h"
    87#include "Ideal.h"
    9 #include "lists.h"
    10 #include "structs.h"
    11 #include "ipshell.h"
    12 #include "numbers.h"
    13 
    14 #include "febase.h"
    15 #include "ipid.h"
    16 #include "ipshell.h"
    17 #include "matpol.h"
     8#include "kernel/structs.h"
     9#include "Singular/lists.h"
     10#include "Singular/ipid.h"
     11#include "Singular/ipshell.h"
     12#include "coeffs/numbers.h"
     13
     14#include "Singular/ipid.h"
     15#include "Singular/ipshell.h"
     16#include "polys/matpol.h"
    1817#include "ring_wrap.h"
    1918#include "intvec_wrap.h"
    2019#include "poly_wrap.h"
    21 extern BOOLEAN errorreported;
    2220extern int inerror;
    2321using namespace boost::python;
    2422using boost::python::numeric::array;
    2523using boost::python::extract;
    26 static void free_leftv(leftv args){
     24static void free_leftv(leftv args)
     25{
    2726    args->CleanUp();
    2827    omFreeBin(args, sleftv_bin);
    2928}
    3029
    31 matrix matrixFromArray(const array& f){
     30matrix matrixFromArray(const boost::python::numeric::array& f)
     31{
    3232  object o=f.attr("shape");
    33 
    3433  object o1=o[0];
    35 
    3634  object o2=o[1];
    3735  int l1=extract<int>(o1);
    38 
    39 
    4036  int l2=extract<int>(o2);
    4137  matrix m=mpNew(l1,l2);
    42   for(int i=0;i<l1;i++){
    43     for(int j=0;j<l2;j++){
     38  for(int i=0;i<l1;i++)
     39  {
     40    for(int j=0;j<l2;j++)
     41    {
    4442      Poly& x = boost::python::extract<Poly&>(f[boost::python::make_tuple(i,j)]);
    4543      poly p=x.as_poly();
     
    4947  return m;
    5048}
    51 bool is_builtin(const char* name){
     49bool is_builtin(const char* name)
     50{
    5251  int cmd_n=-1;
    5352  IsCmd(name,cmd_n);
    5453  return (cmd_n!=-1);
    5554}
    56 class arg_list{
     55class arg_list
     56{
    5757 public:
    5858  leftv args;
    59   arg_list(){
     59  arg_list()
     60  {
    6061    args=(leftv) NULL;
    6162  }
    62   ~arg_list(){
    63     if (args!=NULL){
     63  ~arg_list()
     64  {
     65    if (args!=NULL)
     66    {
    6467      args->CleanUp();
    6568      omFreeBin(args, sleftv_bin);
    6669    }
    67 
    68   }
    69   leftv pop_front(){
     70  }
     71  leftv pop_front()
     72  {
    7073    assume(args!=NULL);
    7174    leftv res=args;
     
    7477    return res;
    7578  }
    76   int length(){
     79  int length()
     80  {
    7781    leftv v=args;
    7882    int l=0;
    79     while(v!=NULL){
     83    while(v!=NULL)
     84    {
    8085      l++;
    8186      v=v->next;
     
    8388    return l;
    8489  }
    85   void appendPoly(const Poly& p){
     90  void appendPoly(const Poly& p)
     91  {
    8692    leftv v=initArg();
    8793    v->data=p.as_poly();
     
    8995    internal_append(v);
    9096  }
    91   void appendIdeal(const Ideal& p){
     97  void appendIdeal(const Ideal& p)
     98  {
    9299    leftv v=initArg();
    93100    v->data=p.as_ideal();
     
    95102    internal_append(v);
    96103  }
    97   void appendModule(const Module& p){
     104  void appendModule(const Module& p)
     105  {
    98106    leftv v=initArg();
    99107    v->data=p.as_module();
     
    101109    internal_append(v);
    102110  }
    103   void appendint(int p){
    104       leftv v=initArg();
     111  void appendint(int p)
     112  {
     113    leftv v=initArg();
    105114    v->data=(void*)((long)p);
    106115    v->rtyp=INT_CMD;
    107116    internal_append(v);
    108117  }
    109   void appendNumber(const Number& p){
    110       leftv v=initArg();
     118  void appendNumber(const Number& p)
     119  {
     120    leftv v=initArg();
    111121    v->data=(void*) p.as_number();
    112122    v->rtyp=NUMBER_CMD;
    113123    internal_append(v);
    114124  }
    115   void appendVector(const Vector& p){
     125  void appendVector(const Vector& p)
     126  {
    116127    leftv v=initArg();
    117128    v->data=p.as_poly();
     
    119130    internal_append(v);
    120131  }
    121   void appendArray(const array& f){
     132  void appendArray(const boost::python::numeric::array& f)
     133  {
    122134    leftv v=initArg();
    123135    matrix m=matrixFromArray(f);
     
    125137    v->rtyp=MATRIX_CMD;
    126138    internal_append(v);
    127 
    128   }
    129   void appendString(const char* s){
     139  }
     140  void appendString(const char* s)
     141  {
    130142    leftv v=initArg();
    131143    v->data=omStrDup(s);
     
    133145    internal_append(v);
    134146  }
    135   void appendRing(const Ring& r){
     147  void appendRing(const Ring& r)
     148  {
    136149    leftv v=initArg();
    137150    v->data=r.pimpl.get();
     
    140153    internal_append(v);
    141154  }
    142 
    143   lists dumpToLists(){
     155  lists dumpToLists()
     156  {
    144157    int n=length();
    145 
    146158    lists res=(lists)omAlloc0Bin(slists_bin);
    147159    res->Init(n);
    148     for(int i=0;i<n;i++){
    149         leftv iv=pop_front();
    150         //swap the content
    151         memcpy(&res->m[i],iv,sizeof(sleftv));
    152         //iv->Init();
    153         omFreeBin(iv, sleftv_bin);
     160    for(int i=0;i<n;i++)
     161    {
     162      leftv iv=pop_front();
     163      //swap the content
     164      memcpy(&res->m[i],iv,sizeof(sleftv));
     165      //iv->Init();
     166      omFreeBin(iv, sleftv_bin);
    154167    }
    155168    return res;
    156 
    157   }
    158   void appendPrelist(arg_list& l){
     169  }
     170  void appendPrelist(arg_list& l)
     171  {
    159172    leftv v=initArg();
    160173    v->data=l.dumpToLists();
    161 
    162174    v->rtyp=LIST_CMD;
    163175    internal_append(v);
    164176  }
    165   void appendIntvec(Intvec& iv){
     177  void appendIntvec(Intvec& iv)
     178  {
    166179    leftv v=initArg();
    167180    v->data=iv.allocate_legacy_intvec_copy();
    168 
    169181    v->rtyp=INTVEC_CMD;
    170182    internal_append(v);
    171183  }
    172 
    173    protected:
    174   leftv initArg(){
     184protected:
     185  leftv initArg()
     186  {
    175187    leftv res=(leftv)omAllocBin(sleftv_bin);
    176188    res->Init();
    177189    return res;
    178190  }
    179   void internal_append(leftv v){
    180     if (args!=NULL){
     191  void internal_append(leftv v)
     192  {
     193    if (args!=NULL)
     194    {
    181195      leftv last=args;
    182       while(last->next!=NULL){
     196      while(last->next!=NULL)
     197      {
    183198        last=last->next;
    184199      }
    185200      last->next=v;
    186     } else
     201    }
     202    else
    187203      args=v;
    188204  }
    189 
    190205};
    191206
    192 class idhdl_wrap{
     207class idhdl_wrap
     208{
    193209 public:
    194210  idhdl id;
    195   idhdl_wrap(idhdl id){
     211  idhdl_wrap(idhdl id)
     212  {
    196213    this->id=id;
    197214  }
    198   idhdl_wrap(){
     215  idhdl_wrap()
     216  {
    199217    id=(idhdl) NULL;
    200218  }
    201   bool is_zero(){
     219  bool is_zero()
     220  {
    202221    return id==NULL;
    203222  }
    204   bool id_is_proc(){
     223  bool id_is_proc()
     224  {
    205225    return (id->typ==PROC_CMD);
    206226  }
    207   bool print_type(){
     227  bool print_type()
     228  {
    208229    Print("type:%d\n",id->typ);
    209230  }
    210   void writePoly(const Poly& p){
    211 
    212     if (id->typ==POLY_CMD){
     231  void writePoly(const Poly& p)
     232  {
     233    if (id->typ==POLY_CMD)
     234    {
    213235      p_Delete(&id->data.p, currRing);
    214236      id->data.p=p.as_poly();
    215237    }
    216 
    217   }
    218   void writeIdeal(const Ideal& p){
    219     if (id->typ==IDEAL_CMD){
     238  }
     239  void writeIdeal(const Ideal& p)
     240  {
     241    if (id->typ==IDEAL_CMD)
     242    {
    220243      id_Delete(&id->data.uideal, currRing);
    221 
    222244      id->data.uideal=p.as_ideal();
    223245    }
    224246  }
    225   void writeModule(const Module& p){
    226     if (id->typ==MODUL_CMD){
     247  void writeModule(const Module& p)
     248  {
     249    if (id->typ==MODUL_CMD)
     250    {
    227251      id_Delete(&id->data.uideal, currRing);
    228 
    229252      id->data.uideal=p.as_module();
    230253    }
    231254  }
    232   void writeint(int p){
    233     if (id->typ==INT_CMD){
     255  void writeint(int p)
     256  {
     257    if (id->typ==INT_CMD)
     258    {
    234259      id->data.i=p;
    235260    }
    236261  }
    237   void writeNumber(const Number& p){
    238 
    239  if (id->typ==NUMBER_CMD){
     262  void writeNumber(const Number& p)
     263  {
     264    if (id->typ==NUMBER_CMD)
     265    {
    240266      n_Delete(&id->data.n, currRing);
    241267      id->data.n=p.as_number();
    242268    }
    243269  }
    244   void writeVector(const Vector& p){
    245 
    246     if (id->typ==VECTOR_CMD){
     270  void writeVector(const Vector& p)
     271  {
     272    if (id->typ==VECTOR_CMD)
     273    {
    247274      p_Delete(&id->data.p, currRing);
    248275      id->data.p=p.as_poly();
    249276    }
    250277  }
    251   void writeArray(const array& f){
    252     if(id->typ=MATRIX_CMD){
     278  void writeArray(const boost::python::numeric::array& f)
     279  {
     280    if(id->typ=MATRIX_CMD)
     281    {
    253282      matrix m=matrixFromArray(f);
    254283      id_Delete((ideal*) &id->data.umatrix,currRing);
     
    256285    }
    257286  }
    258    void writeRing(const Ring& r){
    259     if(id->typ=RING_CMD){
     287  void writeRing(const Ring& r)
     288  {
     289    if(id->typ=RING_CMD)
     290    {
    260291      r.pimpl->ref++;
    261 
    262292      ((ring) id->data.uring)->ref--;//FIXME: destruct it
    263293      ring r2=r.pimpl.get();
     
    265295    }
    266296  }
    267   void writeString(const char* s){
    268     if(id->typ=STRING_CMD){
     297  void writeString(const char* s)
     298  {
     299    if(id->typ=STRING_CMD)
     300    {
    269301        omFree((ADDRESS) id->data.ustring);
    270302        id->data.ustring=omStrDup(s);
    271303    }
    272304  }
    273   void writeIntvec(const Intvec& iv){
    274     if(id->typ=INTVEC_CMD){
     305  void writeIntvec(const Intvec& iv)
     306  {
     307    if(id->typ=INTVEC_CMD)
     308    {
    275309        delete id->data.iv;
    276310        id->data.iv=iv.allocate_legacy_intvec_copy();;
    277311    }
    278312  }
    279   void writeList(arg_list& f){
     313  void writeList(arg_list& f)
     314  {
    280315    //warning f gets empty
    281     if(id->typ=LIST_CMD){
     316    if(id->typ=LIST_CMD)
     317    {
    282318        id->data.l->Clean(currRing);
    283319        id->data.l=f.dumpToLists();
    284320    }
    285 }
     321  }
    286322};
    287323
    288324
    289 static array buildPythonMatrix(matrix m, ring r){
     325static boost::python::numeric::array buildPythonMatrix(matrix m, ring r)
     326{
    290327  using boost::python::numeric::array;
    291328  using boost::python::self;
     
    296333
    297334  list l;
    298 
    299 
    300   for(int i=1;i<=MATROWS(m);i++){
     335  for(int i=1;i<=MATROWS(m);i++)
     336  {
    301337    list row;
    302     for(int j=1;j<=MATCOLS(m);j++){
     338    for(int j=1;j<=MATCOLS(m);j++)
     339    {
    303340      Poly ip(MATELEM(m,i,j),r);//copy it
    304341      row.append(ip);
     
    309346  }
    310347  //FIXME: should call this only once
    311   array::set_module_and_type("Numeric",
     348  boost::python::numeric::array::set_module_and_type("Numeric",
    312349                             "ArrayType"
    313350                             );
    314 
    315   return array(l);
     351  return boost::python::numeric::array(l);
    316352}
    317353boost::python::object buildPyObjectFromLeftv(leftv v);
    318 boost::python::list buildPythonList(lists l, ring r){
     354boost::python::list buildPythonList(lists l, ring r)
     355{
    319356    using boost::python::list;
    320357    list res;
    321358
    322     for(int i=0;i<=l->nr;i++){
     359    for(int i=0;i<=l->nr;i++)
     360    {
    323361        leftv lv=&l->m[i];
    324362        object o=buildPyObjectFromLeftv(lv);
     
    328366}
    329367
    330 boost::python::object buildPyObjectFromLeftv(leftv v){
     368boost::python::object buildPyObjectFromLeftv(leftv v)
     369{
    331370  using boost::python::object;
    332   switch (v->rtyp){
     371  switch (v->rtyp)
     372  {
    333373  case INT_CMD:
    334374    return object((int)((long)v->data));
     
    362402  using boost::python::object;
    363403
    364   switch (id.id->typ){
     404  switch (id.id->typ)
     405  {
    365406  case STRING_CMD:
    366407    return str((const char*) id.id->data.ustring);
     
    402443}
    403444
    404 boost::python::object call_interpreter_method(const idhdl_wrap& proc, const arg_list& args){
     445boost::python::object call_interpreter_method(const idhdl_wrap& proc, const arg_list& args)
     446{
    405447  //idhdl oldPackHDL=currPackHdl;
    406448
     
    410452  //FIXME: will call procedure from different package, maybe use iiMakeProc
    411453
    412   return buildPyObjectFromLeftv(iiMake_proc(proc.id,NULL,args.args));
    413454  int err=iiPStart(proc.id, args.args);
    414455  //currPack=oldPack;
     
    417458  errorreported=inerror=0;
    418459
    419   return buildPyObjectFromLeftv(&iiRETURNEXPR[voice]);
     460  return buildPyObjectFromLeftv(&iiRETURNEXPR);
    420461
    421462  //return res;
    422463}
    423 boost::python::object call_builtin_method_general(const char* name, arg_list& l){
    424 
    425 
     464boost::python::object call_builtin_method_general(const char* name, arg_list& l)
     465{
    426466  int cmd_n=-1;
    427467  IsCmd(name,cmd_n);
     
    429469
    430470//   return Py_None;
    431   if (cmd_n<0){
    432 
    433 
    434   return object();
    435 
    436   } else {
    437 
    438 
     471  if (cmd_n<0)
     472  {
     473    return object();
     474  }
     475  else
     476  {
    439477    leftv res=(leftv)omAllocBin(sleftv_bin);
    440478    res->Init();
    441     switch(l.length()){
     479    switch(l.length())
     480    {
    442481    case 1:
    443482      iiExprArith1(res,l.args,cmd_n);
     
    457496        leftv arg2=l.pop_front();
    458497        leftv arg3=l.pop_front();
    459 
    460 
    461498        iiExprArith3(res,cmd_n,arg1,arg2,arg3);
    462499        free_leftv(arg1);
     
    476513  }
    477514}
    478 static boost::python::str idhdl_as_str(idhdl_wrap iw){
     515static boost::python::str idhdl_as_str(idhdl_wrap iw)
     516{
    479517  idhdl i=iw.id;
    480518  using boost::python::str;
    481519  //ring r=p.getRing();
    482520
    483 
    484521  std::basic_stringstream<char>  s;
    485522  s<<i;
    486523  return boost::python::str(s.str());
    487524}
    488 static idhdl_wrap get_idhdl(const char *n){
    489   //idhdl ggetid(const char *n, BOOLEAN local = FALSE);
    490   return idhdl_wrap(ggetid(n, FALSE));
     525static idhdl_wrap get_idhdl(const char *n)
     526{
     527  //idhdl ggetid(const char *n);
     528  return idhdl_wrap(ggetid(n));
    491529}
    492530void export_interpreter()
     
    525563  def("transfer_to_python",buildPyObjectFromIdhdl);
    526564  def("is_builtin", is_builtin);
    527 
    528 }
    529 
    530 
     565}
     566
  • Singular/dyn_modules/python/intvec_wrap.cc

    re059d4 r0a8b32  
    22#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
    33#include <kernel/mod2.h>
     4#include "IIntvec.h"
    45#include "intvec_wrap.h"
    56
  • Singular/dyn_modules/python/intvec_wrap.h

    re059d4 r0a8b32  
    11#ifndef INTVEC_WRAP_HEADER
    22#define INTVEC_WRAP_HEADER
    3 #include <vector>
    4 #include <kernel/mod2.h>
    5 #include "misc/intvec.h"
    6 #include "IIntvec.h"
     3
    74void export_intvec();
    85
    9 
    106#endif
  • Singular/dyn_modules/python/mywrapper.cc

    re059d4 r0a8b32  
    44#include "wrapper.h"
    55
    6 void initPySingular() {
     6void initPySingular()
     7{
    78  initSingular();
    89  init_Singular();
  • Singular/dyn_modules/python/playground.cc

    re059d4 r0a8b32  
    2525  }
    2626  boost::python::numeric::array::set_module_and_type("Numeric",
    27                              "ArrayType"
    28                              );
     27                             "ArrayType"
     28                             );
    2929  boost::python::numeric::array a(l);
    3030  return a;
  • Singular/dyn_modules/python/python.cc

    re059d4 r0a8b32  
    1010#include <kernel/mod2.h>
    1111#include <tok.h>
    12 #include <structs.h>
     12#include <kernel/structs.h>
     13#include <Singular/mod_lib.h>
    1314#include <ipid.h>
    1415
    1516#include <locals.h>
    1617#include <omalloc/omalloc.h>
    17 #include "python.h"
    1818
    1919#include <stdio.h>
     
    2424#include "wrapper.h"
    2525
    26 //int mod_init(
    27 //  int (*iiAddCproc)(char *libname, char *procname, BOOLEAN pstatic,
    28 //              BOOLEAN(*func)(leftv res, leftv v))
    29 //  )
    30 extern "C" int mod_init( SModulFunctions* psModulFunctions)
    31 {
    32   Py_Initialize();
    33   PyRun_SimpleString("from sys import path\n\
    34 path.insert(0,'.')\n");
    35   initSingular();
    36   init_Singular();
    37 
    38   psModulFunctions->iiAddCproc(currPack->libname,"python",FALSE, mod_python);
    39   return 0;
    40 }
    41 
    42 extern "C" BOOLEAN mod_python(leftv __res, leftv __h)
     26static BOOLEAN mod_python(leftv __res, leftv __h)
    4327{
    4428  leftv __v = __h, __v_save;
     
    6852    return TRUE;
    6953}
     54//int mod_init(
     55//  int (*iiAddCproc)(char *libname, char *procname, BOOLEAN pstatic,
     56//              BOOLEAN(*func)(leftv res, leftv v))
     57//  )
     58extern "C" int SI_MOD_INIT(python_module)(SModulFunctions* psModulFunctions)
     59{
     60  Py_Initialize();
     61  PyRun_SimpleString("from sys import path\n\
     62path.insert(0,'.')\n");
     63  initSingular();
     64  init_Singular();
     65
     66  psModulFunctions->iiAddCproc(currPack->libname,"python",FALSE, mod_python);
     67  return MAX_TOK;
     68}
     69
  • Singular/dyn_modules/python/ring_wrap.cc

    re059d4 r0a8b32  
    44#include "ring_wrap.h"
    55#include "poly_wrap.h"
    6 #include "febase.h"
    76static boost::python::object Ring_as_str(const Ring& r)
    87{
     
    109  StringSetS("");
    1110  rWrite(r.pimpl.get());
    12   char* out=StringAppendS("");
     11  char* out=StringEndS();
    1312  return boost::python::str(out,strlen(out));
    1413}
    15 void ring_set(Ring & r){
     14void ring_set(Ring & r)
     15{
    1616      //FIXME: only a hack, no solution
    1717      char name_buffer[100];
     
    2525      currRingHdl=shadow_hdl;
    2626
    27     }
    28 void export_ring(){
     27}
     28void export_ring()
     29{
    2930boost::python::class_<Ring>("Ring", "reference to a Singular ring")
    3031     .def("__str__", Ring_as_str)
    3132     .def("set", ring_set,"equivalent to the singular command setring, which is not mapped as it is a command")
    3233     .def(boost::python::init <>());
    33 
    3434}
  • Singular/dyn_modules/python/ring_wrap.h

    re059d4 r0a8b32  
    1818
    1919//typedef boosRing
    20 class Ring{
     20class Ring
     21{
    2122   public:
    2223     intrusive_ptr<ip_sring> pimpl;
    23      Ring(ring r=currRing): pimpl(r){
    24 
    25      }
    26      Ring(const Ring& r2):pimpl(r2.pimpl){
    27 
    28        }
    29      ~Ring(){
    30 
    31      }
    32 
     24     Ring(ring r=currRing): pimpl(r){}
     25     Ring(const Ring& r2):pimpl(r2.pimpl){}
     26     ~Ring(){}
    3327};
    3428void export_ring();
  • Singular/dyn_modules/python/wrapper.h

    re059d4 r0a8b32  
    77
    88
    9 #include "structs.h"
     9#include "kernel/structs.h"
    1010#include "coeffs/numbers.h"
    1111
    12 //#include "febase.h"
    13 #include "ipid.h"
    14 #include "ipshell.h"
    15 //#include "util.h"
     12#include "Singular/ipid.h"
     13#include "Singular/ipshell.h"
    1614#include "Number.h"
    1715#include "Poly.h"
     
    2422#include "CF_wrap.h"
    2523#include "number_wrap.h"
    26 //#include "playground.h"
    2724#include "interpreter_support.h"
    2825#include "ring_wrap.h"
     
    3330using namespace boost::python;
    3431
    35 Vector unitVector0(int i){
     32Vector unitVector0(int i)
     33{
    3634  return unitVector(i,currRing);
    3735}
    3836
    39 
    40 
    41 
    42 
    43 
    44 
    45 //typedef void * idhdl;
    46 void different_ring_translator(DifferentDomainException const& x) {
     37void different_ring_translator(DifferentDomainException const& x)
     38{
    4739    PrintS("hoho");
    4840    PyErr_SetString(PyExc_UserWarning, "Objects didn't have the same ring");
    4941}
    50 BOOST_PYTHON_MODULE(Singular){
     42BOOST_PYTHON_MODULE(Singular)
     43{
    5144  //Print("ref count after add: %d", currRing->ref);
    5245  register_exception_translator<
    5346          DifferentDomainException>(different_ring_translator);
    5447  export_poly();
    55 
    56 
    57 
    5848  export_number();
    5949  export_vector();
     
    7161    .def("__iter__", boost::python::iterator<VectorPowerSeries>());
    7262  def("gen",unitVector0);
    73 
    74 
    7563  //    .def(self+=self)
    76 
    7764  //   .def(self+self)
    7865  //.def(self*=Number())
    7966  //.def(Number() * self);
    80 
    8167}
    82 BOOST_PYTHON_MODULE(factory){
     68BOOST_PYTHON_MODULE(factory)
     69{
    8370  boost::python::class_<Variable>("variable")
    8471    .def(boost::python::init <const int, char>())
    8572    .def(boost::python::init <char>())
    86 
    8773    .def(boost::python::init <const int>());
    8874  export_CF();
    8975}
    90 BOOST_PYTHON_MODULE(_Singular){
     76BOOST_PYTHON_MODULE(_Singular)
     77{
    9178export_interpreter();
    92 
    9379}
    9480#endif
Note: See TracChangeset for help on using the changeset viewer.