File:  [CENS] / python / pyGiNaC / wrappers / ncmul.py
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Tue Apr 17 22:39:25 2001 UTC (16 years, 7 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Fixed bugs. Exposed/checked functions. Started testing framework.

# This file is part of the PyGiNaC package.
# http://cens.ioc.ee/projects/pyginac/
#
# $Revision: 1.4 $
# $Id: ncmul.py,v 1.4 2001-04-17 22:39:25 pearu Exp $
#
# Copyright 2001 Pearu Peterson all rights reserved,
# Pearu Peterson <pearu@cens.ioc.ee>
# Permission to use, modify, and distribute this software is given under the
# terms of the LGPL.  See http://www.fsf.org
#
# NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
#
# TODO:
# Expose functions nonsimplified_ncmul,simplified_ncmul if needed.

depends = ['basic']

uses = ['ex','exvector']

#STARTPROTO

class ncmul(exprseq):
    """Non-commutative product of expressions."""
    def __init__(self,*args):
        """ncmul() - construct empty product (equivalent to 0)
    ncmul(e1,e2) - construct a product e1*e2
    ncmul(seq)   - construct a product seq[0]*seq[1]*...*seq[-1]
    ncmul(ex(ncmul(...))) - returns ncmul(...)
    """
    def get_factors(self):
        """Returns factors as an exvector."""

#ENDPROTO

wrapperclass = '''
class ncmul_w : public GiNaC::ncmul {
  PyObject * self;
public:
  ncmul_w(python::ref v)
  : GiNaC::ncmul(exvector_w(v)) {
    DEBUG_C("ncmul_w(raw:ref)");
  }

  ncmul_w(PyObject * self_)
  : GiNaC::ncmul(), self(self_) {
    DEBUG_C("ncmul_w()");
  }
  ncmul_w(PyObject * self_, const GiNaC::ncmul & m)
  : GiNaC::ncmul(m), self(self_) {
    DEBUG_C("ncmul_w(ncmul)");
  }
  ncmul_w(PyObject * self_, const GiNaC::ex & m)
  : GiNaC::ncmul(ex_to_ncmul_w(m)), self(self_) {
    DEBUG_C("ncmul_w(ex)");
  }
  ncmul_w(PyObject * self_, const GiNaC::exvector & v)
  : GiNaC::ncmul(v), self(self_) {
    DEBUG_C("ncmul_w(exvector)");
  }
  ncmul_w(PyObject * self_, python::ref lh, python::ref rh)
  : GiNaC::ncmul(ex_w(lh),ex_w(rh)), self(self_) {
    DEBUG_C("ncmul_w(ref,ref)");
  }'''
for i in range(3,nof_ncmul_params+1):
    wrapperclass += '''
  ncmul_w(PyObject * self_, %s)
  : GiNaC::ncmul(%s), self(self_) {
    DEBUG_C("ncmul_w(%s*ref)");
  }
'''%(', '.join(['python::ref f%s'%(j) for j in range(1,i+1)]),
     ', '.join(['ex_w(f%s)'%(j) for j in range(1,i+1)]),i)
wrapperclass += '''
  ncmul_w(PyObject * self_, python::ref v)
  : GiNaC::ncmul(exvector_w(v)), self(self_) {
    DEBUG_C("ncmul_w(ref)");
  }
  ~ncmul_w() {
    DEBUG_C("ncmul_w::~ncmul_w()");
  }
};

'''

builder = '''
python::class_builder<ncmul_w> ncmul_w_class(this_module, "_ncmul_w");
python::class_builder<GiNaC::ncmul, ncmul_w> ncmul_class(this_module, "ncmul");
ncmul_py_class = python::as_object(ncmul_class.get_extension_class());
ncmul_class.declare_base(ncmul_w_class);
ncmul_class.declare_base(basic_class);
'''

constructors = '''
ncmul_class.def(python::constructor<>());
ncmul_class.def(python::constructor<const GiNaC::ncmul &>());
ncmul_class.def(python::constructor<const GiNaC::ex &>());
//ncmul_class.def(python::constructor<const GiNaC::ex &, const GiNaC::ex>());
ncmul_class.def(python::constructor<python::ref, python::ref>());
'''+\
'\n'.join(['''ncmul_class.def(python::constructor<%s>());
'''%(', '.join(['python::ref']*i)) for i in range(3,nof_ncmul_params+1)])+\
'''
ncmul_class.def(python::constructor<const GiNaC::exvector &>());
ncmul_class.def(python::constructor<python::ref>());
'''

defs = '''
ncmul_class.def(&basic_w::python_str, "__str__");
ncmul_class.def(&basic_w::python_repr, "__repr__");
ncmul_class.def(&basic_w::coerce, "__coerce__");
BASIC_OPS(ncmul)

ncmul_class.def(&ncmul_w::get_factors, "get_factors");
'''

implementation = '''
EX_TO_BASIC(ncmul)
'''

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>