X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fmatrix.cpp;h=deeba2806e97d81cbb1c5de9803ed7ce90e15bc7;hb=fe065a48f215ef391284f3448ba2e7f81e6c0596;hp=bacacad8889a4199c7a07576470903f6586277e7;hpb=24fe247f9ed16114a765a01c593fec5c4a2f591c;p=ginac.git diff --git a/ginac/matrix.cpp b/ginac/matrix.cpp index bacacad8..deeba280 100644 --- a/ginac/matrix.cpp +++ b/ginac/matrix.cpp @@ -25,8 +25,11 @@ #include "matrix.h" #include "debugmsg.h" +#include "utils.h" +#ifndef NO_GINAC_NAMESPACE namespace GiNaC { +#endif // ndef NO_GINAC_NAMESPACE ////////// // default constructor, destructor, copy constructor, assignment operator @@ -40,7 +43,7 @@ matrix::matrix() : basic(TINFO_matrix), row(1), col(1) { debugmsg("matrix default constructor",LOGLEVEL_CONSTRUCT); - m.push_back(exZERO()); + m.push_back(_ex0()); } matrix::~matrix() @@ -89,20 +92,20 @@ void matrix::destroy(bool call_parent) * * @param r number of rows * @param c number of cols */ -matrix::matrix(int r, int c) +matrix::matrix(unsigned r, unsigned c) : basic(TINFO_matrix), row(r), col(c) { - debugmsg("matrix constructor from int,int",LOGLEVEL_CONSTRUCT); - m.resize(r*c, exZERO()); + debugmsg("matrix constructor from unsigned,unsigned",LOGLEVEL_CONSTRUCT); + m.resize(r*c, _ex0()); } // protected /** Ctor from representation, for internal use only. */ -matrix::matrix(int r, int c, vector const & m2) +matrix::matrix(unsigned r, unsigned c, exvector const & m2) : basic(TINFO_matrix), row(r), col(c), m(m2) { - debugmsg("matrix constructor from int,int,vector",LOGLEVEL_CONSTRUCT); + debugmsg("matrix constructor from unsigned,unsigned,exvector",LOGLEVEL_CONSTRUCT); } ////////// @@ -117,6 +120,42 @@ basic * matrix::duplicate() const return new matrix(*this); } +void matrix::print(ostream & os, unsigned upper_precedence) const +{ + debugmsg("matrix print",LOGLEVEL_PRINT); + os << "[[ "; + for (unsigned r=0; r tmp(row*col); - for (int i=0; i::const_iterator r=m.begin(); r!=m.end(); ++r) { + for (exvector::const_iterator r=m.begin(); r!=m.end(); ++r) { if ((*r).has(other)) return true; } return false; @@ -171,10 +210,10 @@ ex matrix::eval(int level) const } // eval() entry by entry - vector m2(row*col); + exvector m2(row*col); --level; - for (int r=0; r m2(row*col); + exvector m2(row*col); --level; - for (int r=0; r sum(this->m); - vector::iterator i; - vector::const_iterator ci; + exvector sum(this->m); + exvector::iterator i; + exvector::const_iterator ci; for (i=sum.begin(), ci=other.m.begin(); i!=sum.end(); ++i, ++ci) { @@ -273,9 +312,9 @@ matrix matrix::sub(matrix const & other) const throw (std::logic_error("matrix::sub(): incompatible matrices")); } - vector dif(this->m); - vector::iterator i; - vector::const_iterator ci; + exvector dif(this->m); + exvector::iterator i; + exvector::const_iterator ci; for (i=dif.begin(), ci=other.m.begin(); i!=dif.end(); ++i, ++ci) { @@ -293,10 +332,10 @@ matrix matrix::mul(matrix const & other) const throw (std::logic_error("matrix::mul(): incompatible matrices")); } - vector prod(row*other.col); - for (int i=0; i=row || co<0 || co>=col) { throw (std::range_error("matrix::operator(): index out of range")); @@ -321,7 +360,7 @@ ex const & matrix::operator() (int ro, int co) const /** Set individual elements manually. * * @exception range_error (index out of range) */ -matrix & matrix::set(int ro, int co, ex value) +matrix & matrix::set(unsigned ro, unsigned co, ex value) { if (ro<0 || ro>=row || co<0 || co>=col) { throw (std::range_error("matrix::set(): index out of range")); @@ -336,10 +375,10 @@ matrix & matrix::set(int ro, int co, ex value) * represents the transposed. */ matrix matrix::transpose(void) const { - vector trans(col*row); + exvector trans(col*row); - for (int r=0; r sigma(M.cols()); - for (int i=0; i sigma(M.cols()); + for (unsigned i=0; i::const_iterator r=m.begin(); r!=m.end(); ++r) { + for (exvector::const_iterator r=m.begin(); r!=m.end(); ++r) { if (!(*r).info(info_flags::numeric)) { if (normalized) { return determinant_symbolic_minor(*this).normal(); @@ -530,7 +569,7 @@ ex matrix::trace(void) const } ex tr; - for (int r=0; r0; --r) { - int first_non_zero=1; + unsigned last_assigned_sol=n+1; + for (unsigned r=m; r>0; --r) { + unsigned first_non_zero=1; while ((first_non_zero<=n)&&(a.ffe_get(r,first_non_zero).is_zero())) { first_non_zero++; } @@ -723,11 +762,11 @@ matrix matrix::fraction_free_elim(matrix const & vars, } else { // assign solutions for vars between first_non_zero+1 and // last_assigned_sol-1: free parameters - for (int c=first_non_zero+1; c<=last_assigned_sol-1; ++c) { + for (unsigned c=first_non_zero+1; c<=last_assigned_sol-1; ++c) { sol.ffe_set(c,1,vars.ffe_get(c,1)); } ex e=b.ffe_get(r,1); - for (int c=first_non_zero+1; c<=n; ++c) { + for (unsigned c=first_non_zero+1; c<=n; ++c) { e=e-a.ffe_get(r,c)*sol.ffe_get(c,1); } sol.ffe_set(first_non_zero,1, @@ -737,21 +776,21 @@ matrix matrix::fraction_free_elim(matrix const & vars, } // assign solutions for vars between 1 and // last_assigned_sol-1: free parameters - for (int c=1; c<=last_assigned_sol-1; ++c) { + for (unsigned c=1; c<=last_assigned_sol-1; ++c) { sol.ffe_set(c,1,vars.ffe_get(c,1)); } /* - for (int c=1; c<=n; ++c) { + for (unsigned c=1; c<=n; ++c) { cout << vars.ffe_get(c,1) << "->" << sol.ffe_get(c,1) << endl; } */ #ifdef DO_GINAC_ASSERT // test solution with echelon matrix - for (int r=1; r<=m; ++r) { + for (unsigned r=1; r<=m; ++r) { ex e=0; - for (int c=1; c<=n; ++c) { + for (unsigned c=1; c<=n; ++c) { e=e+a.ffe_get(r,c)*sol.ffe_get(c,1); } if (!(e-b.ffe_get(r,1)).normal().is_zero()) { @@ -763,9 +802,9 @@ matrix matrix::fraction_free_elim(matrix const & vars, } // test solution with original matrix - for (int r=1; r<=m; ++r) { + for (unsigned r=1; r<=m; ++r) { ex e=0; - for (int c=1; c<=n; ++c) { + for (unsigned c=1; c<=n; ++c) { e=e+ffe_get(r,c)*sol.ffe_get(c,1); } try { @@ -798,24 +837,24 @@ matrix matrix::solve(matrix const & v) const // build the extended matrix of *this with v attached to the right matrix tmp(row,col+v.col); - for (int r=0; r sol(v.row*v.col); - for (int c=0; c=0; --r) { + exvector sol(v.row*v.col); + for (unsigned c=0; c=0; --r) { sol[r*v.col+c] = tmp[r*tmp.col+c]; - for (int i=r+1; i