[PyGiNaC-users] latex output [patch] and indexed [patch]
Status: Alpha
Brought to you by:
jbrandmeyer
From: Ondrej C. <ond...@gm...> - 2005-04-26 10:28:43
|
Hi, I am sending a few patches to implement latex output and a class indexed in order to create indexed objects. Ondrej Certik --- pyginac-orig/src/basic.cpp 2005-03-30 22:55:17.000000000 +0200 +++ pyginac/src/basic.cpp 2005-04-26 10:38:57.978028296 +0200 @@ -397,6 +397,17 @@ return converter.returned_hash; } +//template< typename GinacPrintable> +//print_to_string_latex(const GinacPrintable & This) +std::string +print_to_string_latex(const GiNaC::basic& This) +{ + std::ostringstream output; + output << GiNaC::latex; + output << This; + return output.str(); +} + } // !namespace anonymous void @@ -524,6 +535,7 @@ // Overrides for special Python object behavior .def( "__str__", &print_to_string<basic>) + .def( "print_latex", print_to_string_latex) .def( "__hash__", wrap_hash, "Compute a hash of an expression.") ; --- pyginac-orig/src/idx.cpp 2004-11-13 14:58:38.000000000 +0100 +++ pyginac/src/idx.cpp 2005-04-26 11:48:45.977355624 +0200 @@ -17,7 +17,9 @@ #include <boost/python/class.hpp> #include <boost/python/implicit.hpp> +#include <boost/python.hpp> #include <ginac/idx.h> +#include <ginac/indexed.h> namespace pyginac { @@ -30,6 +32,17 @@ using GiNaC::varidx; using GiNaC::spinidx; using GiNaC::ex; + using GiNaC::indexed; + + class_<indexed, bases<basic> >("indexed", + "This class holds an indexed expression.\n" + "It consists of a 'base' expression (the expression being indexed) " + "which can be accessed as op(0), and n (n >=3D 0)" + "indices (all of class idx), accessible as op(1)..op(n).", + init<const ex&>()) + .def( init<const ex&, const ex&>()) + .def( init<const ex&, const ex&, const ex&>()) + ; class_<idx, bases<basic> >("idx", "This class holds one index of an indexed object.\n" @@ -82,6 +95,7 @@ implicitly_convertible<idx, ex>(); implicitly_convertible<varidx, ex>(); implicitly_convertible<spinidx, ex>(); + implicitly_convertible<indexed, ex>(); } } // !namespace pyginac --- pyginac-orig/src/symbol.cpp 2004-11-14 04:03:14.000000000 +0100 +++ pyginac/src/symbol.cpp 2005-04-26 10:43:29.009825200 +0200 @@ -52,6 +52,7 @@ class_<symbol, bases<basic> >("symbol", "An algebraic symbol.", init<std::string>()) .def( init<std::string, domain>()) + .def( init<std::string, std::string>()) .def( init<const symbol&>()) .def( "assign", &symbol::assign, "Temporarily assign an expression to this symbol.") |