File:  [CENS] / python / pyGiNaC / wrappers3 / add_py.cpp
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Thu Apr 26 19:44:48 2001 UTC (16 years, 7 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Impl. pseries,ncmul. Preparing for a release.

/*
# This file is part of the PyGiNaC package.
# http://cens.ioc.ee/projects/pyginac/
#
# $Revision: 1.4 $
# $Id: add_py.cpp,v 1.4 2001-04-26 19:44:48 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.
#
*/
/*DT
  Add
  ---

  >>> from ginac import add,symbol,numeric,ex,is_add,is_numeric
  >>> c = add(symbol('a'),numeric(3,4))
  >>> c
  add([symbol('a'), numeric('3/4')])
  >>> c.is_add(), ex().is_add()
  (1, 0)
  >>> d = add(3,4)
  >>> d
  numeric('7')
  >>> is_numeric(d), is_add(d), is_add({})
  (1, 0, 0)
  >>> add([])
  numeric('0')
  >>> add(3)
  numeric('3')
  >>> add([symbol('a'), numeric('3/4')])
  add([symbol('a'), numeric('3/4')])
  >>> add()
  numeric('0')
  >>> add({})
  Traceback (most recent call last):
  ...
  TypeError: ex_from_ref() argument must be number|string|ex|sequence (got <type 'dictionary'>)

*/


#ifdef PYGINAC_DEFS
this_module.def(&add_0, "add");
this_module.def(&add_1, "add");
this_module.def(&add_2ex, "add");
this_module.def(&add_2, "add");
ex_class.def(&ex::is_add, "is_add");
this_module.def(&ex::is_add, "is_add");
this_module.def(&return_false, "is_add");
//ex_class.def(&ex::mth, "mth");
#else

#ifdef PYGINAC_EX_PROTOS
#define PYGINAC_PROTOS
#endif

#ifdef PYGINAC_PROTOS

#ifdef PYGINAC_EX_PROTOS
bool is_add(void) const;
#else // PYGINAC_EX_PROTOS
GiNaC::ex add_0(void);
GiNaC::ex add_1(const GiNaC::add & e);
GiNaC::ex add_2ex(const GiNaC::ex & l, const GiNaC::ex & r);
GiNaC::ex add_2(py::ref l, py::ref r);
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
GiNaC::add from_python (PyObject* o, py::type<const GiNaC::add &>);
BOOST_PYTHON_END_CONVERSION_NAMESPACE
#endif // !PYGINAC_EX_PROTOS

#else  // PYGINAC_PROTOS
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
GiNaC::add from_python (PyObject* o, py::type<const GiNaC::add &>) {
  return GiNaC::add(from_python(o, py::type<const GiNaC::exvector &>()));
}
BOOST_PYTHON_END_CONVERSION_NAMESPACE
/*F_DT is_add(obj)
  Check if `obj' is add.
*/
/*M_DT is_add(self)
  Check if object is add.
*/
bool ex::is_add(void) const { return is_ex_exactly_of_type(*this, add); }

/*F_DT add(*args)
  add() - return numeric('0').
  add(l,r) - add two expressions.
    If `l' and/or `r' are Python objects, an attempt is made to convert
    them to ex objects.
  add(seq) - sum of expressions in a sequence `seq'.
  add(add(...)) -> add(...)
*/
GiNaC::ex add_0(void) {
  return GiNaC::numeric();
}
GiNaC::ex add_1(const GiNaC::add & e) {
  return e;
}
GiNaC::ex add_2ex(const GiNaC::ex & l, const GiNaC::ex & r) {
  return GiNaC::add(l,r);
}
GiNaC::ex add_2(py::ref l, py::ref r) {
  return GiNaC::add(ex_from_ref(l), ex_from_ref(r));
}

#endif // !PYGINAC_PROTOS
#endif // !PYGINAC_DEFS




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