]> www.ginac.de Git - ginac.git/blobdiff - ginac/matrix.cpp
* Added output-support for Python bindings and LaTeX printing for
[ginac.git] / ginac / matrix.cpp
index df262238677aeb3d2cc8a207cb1cc1a96942cfab..0bedb6bb1a1e506fc0017ea3243d66c64ed3797a 100644 (file)
@@ -20,6 +20,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <iostream>
 #include <algorithm>
 #include <map>
 #include <stdexcept>
@@ -35,7 +36,6 @@
 #include "print.h"
 #include "archive.h"
 #include "utils.h"
-#include "debugmsg.h"
 
 namespace GiNaC {
 
@@ -48,7 +48,6 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(matrix, basic)
 /** Default ctor.  Initializes to 1 x 1-dimensional zero-matrix. */
 matrix::matrix() : inherited(TINFO_matrix), row(1), col(1)
 {
-       debugmsg("matrix default ctor",LOGLEVEL_CONSTRUCT);
        m.push_back(_ex0);
 }
 
@@ -75,7 +74,6 @@ DEFAULT_DESTROY(matrix)
 matrix::matrix(unsigned r, unsigned c)
   : inherited(TINFO_matrix), row(r), col(c)
 {
-       debugmsg("matrix ctor from unsigned,unsigned",LOGLEVEL_CONSTRUCT);
        m.resize(r*c, _ex0);
 }
 
@@ -83,10 +81,7 @@ matrix::matrix(unsigned r, unsigned c)
 
 /** Ctor from representation, for internal use only. */
 matrix::matrix(unsigned r, unsigned c, const exvector & m2)
-  : inherited(TINFO_matrix), row(r), col(c), m(m2)
-{
-       debugmsg("matrix ctor from unsigned,unsigned,exvector",LOGLEVEL_CONSTRUCT);
-}
+  : inherited(TINFO_matrix), row(r), col(c), m(m2) {}
 
 /** Construct matrix from (flat) list of elements. If the list has fewer
  *  elements than the matrix, the remaining matrix elements are set to zero.
@@ -95,7 +90,6 @@ matrix::matrix(unsigned r, unsigned c, const exvector & m2)
 matrix::matrix(unsigned r, unsigned c, const lst & l)
   : inherited(TINFO_matrix), row(r), col(c)
 {
-       debugmsg("matrix ctor from unsigned,unsigned,lst",LOGLEVEL_CONSTRUCT);
        m.resize(r*c, _ex0);
 
        for (unsigned i=0; i<l.nops(); i++) {
@@ -113,7 +107,6 @@ matrix::matrix(unsigned r, unsigned c, const lst & l)
 
 matrix::matrix(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
 {
-       debugmsg("matrix ctor from archive_node", LOGLEVEL_CONSTRUCT);
        if (!(n.find_unsigned("row", row)) || !(n.find_unsigned("col", col)))
                throw (std::runtime_error("unknown matrix dimensions in archive"));
        m.reserve(row * col);
@@ -148,14 +141,15 @@ DEFAULT_UNARCHIVE(matrix)
 
 void matrix::print(const print_context & c, unsigned level) const
 {
-       debugmsg("matrix print", LOGLEVEL_PRINT);
-
        if (is_a<print_tree>(c)) {
 
                inherited::print(c, level);
 
        } else {
 
+               if (is_a<print_python_repr>(c))
+                       c.s << class_name() << '(';
+
                c.s << "[";
                for (unsigned y=0; y<row-1; ++y) {
                        c.s << "[";
@@ -174,6 +168,9 @@ void matrix::print(const print_context & c, unsigned level) const
                m[row*col-1].print(c);
                c.s << "]]";
 
+               if (is_a<print_python_repr>(c))
+                       c.s << ')';
+
        }
 }
 
@@ -201,8 +198,6 @@ ex & matrix::let_op(int i)
 /** Evaluate matrix entry by entry. */
 ex matrix::eval(int level) const
 {
-       debugmsg("matrix eval",LOGLEVEL_MEMBER_FUNCTION);
-       
        // check if we have to do anything at all
        if ((level==1)&&(flags & status_flags::evaluated))
                return *this;
@@ -788,7 +783,7 @@ ex matrix::determinant(unsigned algo) const
                                                ++acc;
                                c_zeros.push_back(uintpair(acc,c));
                        }
-                       sort(c_zeros.begin(),c_zeros.end());
+                       std::sort(c_zeros.begin(),c_zeros.end());
                        std::vector<unsigned> pre_sort;
                        for (std::vector<uintpair>::const_iterator i=c_zeros.begin(); i!=c_zeros.end(); ++i)
                                pre_sort.push_back(i->second);