]> www.ginac.de Git - ginac.git/commitdiff
some changes to allow GiNaC to cooperate with cint:
authorAlexander Frink <Alexander.Frink@uni-mainz.de>
Tue, 14 Dec 1999 20:41:18 +0000 (20:41 +0000)
committerAlexander Frink <Alexander.Frink@uni-mainz.de>
Tue, 14 Dec 1999 20:41:18 +0000 (20:41 +0000)
matrix.h/.cpp: vector<ex> replaced with exvector where
               typedef vector<ex,malloc_alloc> exvector

constant.h/.cpp: typedef for evalffunction

color.h/.cpp: replaced vector<exvector> with exvectorvector where
              typedef vector<exvector,malloc_alloc> exvectorvector

ex.h: OBSCURE_CINT_HACK defines around some weird code. Never define
      OBSCURE_CINT_HACK when compiling libginac

ginac/color.cpp
ginac/color.h
ginac/constant.cpp
ginac/constant.h
ginac/ex.h
ginac/matrix.cpp
ginac/matrix.h

index 468645ddadfaa5e87912c16eb13b9e71469e0de7..696d70f7946d0316b47f6cbc17f97a8726b21065 100644 (file)
@@ -440,9 +440,9 @@ ex color::simplify_ncmul(exvector const & v) const
     exvector delta8vec;
     exvector fvec;
     exvector dvec;
     exvector delta8vec;
     exvector fvec;
     exvector dvec;
-    vector<exvector> Tvecs;
+    exvectorvector Tvecs;
     Tvecs.resize(MAX_REPRESENTATION_LABELS);
     Tvecs.resize(MAX_REPRESENTATION_LABELS);
-    vector<exvector> ONEvecs;
+    exvectorvector ONEvecs;
     ONEvecs.resize(MAX_REPRESENTATION_LABELS);
     exvector unknownvec;
     
     ONEvecs.resize(MAX_REPRESENTATION_LABELS);
     exvector unknownvec;
     
@@ -656,8 +656,8 @@ color color_delta8(ex const & a, ex const & b)
 
 void split_color_string_in_parts(exvector const & v, exvector & delta8vec,
                                  exvector & fvec, exvector & dvec,
 
 void split_color_string_in_parts(exvector const & v, exvector & delta8vec,
                                  exvector & fvec, exvector & dvec,
-                                 vector<exvector> & Tvecs,
-                                 vector<exvector> & ONEvecs,
+                                 exvectorvector & Tvecs,
+                                 exvectorvector & ONEvecs,
                                  exvector & unknownvec)
 {
     // if not all elements are of type color, put all Ts in unknownvec to
                                  exvector & unknownvec)
 {
     // if not all elements are of type color, put all Ts in unknownvec to
@@ -704,8 +704,8 @@ void split_color_string_in_parts(exvector const & v, exvector & delta8vec,
 }    
 
 exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
 }    
 
 exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
-                                exvector & dvec, vector<exvector> & Tvecs,
-                                vector<exvector> & ONEvecs, exvector & unknownvec)
+                                exvector & dvec, exvectorvector & Tvecs,
+                                exvectorvector & ONEvecs, exvector & unknownvec)
 {
     unsigned sz=delta8vec.size()+fvec.size()+dvec.size()+unknownvec.size();
     for (unsigned rl=0; rl<MAX_REPRESENTATION_LABELS; ++rl) {
 {
     unsigned sz=delta8vec.size()+fvec.size()+dvec.size()+unknownvec.size();
     for (unsigned rl=0; rl<MAX_REPRESENTATION_LABELS; ++rl) {
@@ -777,9 +777,9 @@ ex color_trace(exvector const & v, unsigned const rl)
     exvector delta8vec;
     exvector fvec;
     exvector dvec;
     exvector delta8vec;
     exvector fvec;
     exvector dvec;
-    vector<exvector> Tvecs;
+    exvectorvector Tvecs;
     Tvecs.resize(MAX_REPRESENTATION_LABELS);
     Tvecs.resize(MAX_REPRESENTATION_LABELS);
-    vector<exvector> ONEvecs;
+    exvectorvector ONEvecs;
     ONEvecs.resize(MAX_REPRESENTATION_LABELS);
     exvector unknownvec;
 
     ONEvecs.resize(MAX_REPRESENTATION_LABELS);
     exvector unknownvec;
 
@@ -817,9 +817,9 @@ ex simplify_pure_color_string(ex const & e)
     exvector delta8vec;
     exvector fvec;
     exvector dvec;
     exvector delta8vec;
     exvector fvec;
     exvector dvec;
-    vector<exvector> Tvecs;
+    exvectorvector Tvecs;
     Tvecs.resize(MAX_REPRESENTATION_LABELS);
     Tvecs.resize(MAX_REPRESENTATION_LABELS);
-    vector<exvector> ONEvecs;
+    exvectorvector ONEvecs;
     ONEvecs.resize(MAX_REPRESENTATION_LABELS);
     exvector unknownvec;
 
     ONEvecs.resize(MAX_REPRESENTATION_LABELS);
     exvector unknownvec;
 
index f72034d8a3a8382546c6f82349b5c5d7b7938af5..ecc0ddfd2f7ba0430e4f8338b9fff74cad2433b7 100644 (file)
@@ -36,6 +36,8 @@ const unsigned MAX_REPRESENTATION_LABELS = 4;
 const unsigned COLOR_EIGHT = 8; // N*N-1
 const unsigned COLOR_THREE = 3; // N
 
 const unsigned COLOR_EIGHT = 8; // N*N-1
 const unsigned COLOR_THREE = 3; // N
 
+typedef vector<exvector,malloc_alloc> exvectorvector;
+
 /** Base class for color object */
 class color : public indexed
 {
 /** Base class for color object */
 class color : public indexed
 {
@@ -50,12 +52,12 @@ class color : public indexed
     friend unsigned subs_index_in_exvector(exvector & v, ex const & is, ex const & ir);
     friend void split_color_string_in_parts(exvector const & v, exvector & delta8vec,
                                             exvector & fvec, exvector & dvec,
     friend unsigned subs_index_in_exvector(exvector & v, ex const & is, ex const & ir);
     friend void split_color_string_in_parts(exvector const & v, exvector & delta8vec,
                                             exvector & fvec, exvector & dvec,
-                                            vector<exvector> & Tvecs,
-                                            vector<exvector> & ONEvecs,
+                                            exvectorvector & Tvecs,
+                                            exvectorvector & ONEvecs,
                                             exvector & unknownvec);
     friend exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
                                             exvector & unknownvec);
     friend exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
-                                           exvector & dvec, vector<exvector> & Tvecs,
-                                           vector<exvector> & ONEvecs, exvector & unknownvec);
+                                           exvector & dvec, exvectorvector & Tvecs,
+                                           exvectorvector & ONEvecs, exvector & unknownvec);
     friend ex color_trace_of_one_representation_label(exvector const & v);
     friend ex color_trace(exvector const & v, unsigned const rl);
     friend ex simplify_pure_color_string(ex const & e);
     friend ex color_trace_of_one_representation_label(exvector const & v);
     friend ex color_trace(exvector const & v, unsigned const rl);
     friend ex simplify_pure_color_string(ex const & e);
@@ -149,12 +151,12 @@ ex color_h(ex const & a, ex const & b, ex const & c);
 color color_delta8(ex const & a, ex const & b);
 void split_color_string_in_parts(exvector const & v, exvector & delta8vec,
                                  exvector & fvec, exvector & dvec,
 color color_delta8(ex const & a, ex const & b);
 void split_color_string_in_parts(exvector const & v, exvector & delta8vec,
                                  exvector & fvec, exvector & dvec,
-                                 vector<exvector> & Tvecs,
-                                 vector<exvector> & ONEvecs,
+                                 exvectorvector & Tvecs,
+                                 exvectorvector & ONEvecs,
                                  exvector & unknownvec);
 exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
                                  exvector & unknownvec);
 exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
-                                exvector & dvec, vector<exvector> & Tvecs,
-                                vector<exvector> & ONEvecs, exvector & unknownvec);
+                                exvector & dvec, exvectorvector & Tvecs,
+                                exvectorvector & ONEvecs, exvector & unknownvec);
 ex color_trace_of_one_representation_label(exvector const & v);
 ex color_trace(exvector const & v, unsigned const rl=0);
 ex simplify_pure_color_string(ex const & e);
 ex color_trace_of_one_representation_label(exvector const & v);
 ex color_trace(exvector const & v, unsigned const rl=0);
 ex simplify_pure_color_string(ex const & e);
index f16a00f7f0c431626b8cb08aea0a33ee003626b5..166b53e94a7b5861f2af87e3a49bed6f9350a143 100644 (file)
@@ -86,7 +86,7 @@ void constant::destroy(bool call_parent)
 
 // public
 
 
 // public
 
-constant::constant(string const & initname, ex (*efun)()) :
+constant::constant(string const & initname, evalffunctype efun) :
     basic(TINFO_constant), name(initname), ef(efun),
     // number(0), fct_assigned(true), serial(next_serial++)
     number(0), serial(next_serial++)
     basic(TINFO_constant), name(initname), ef(efun),
     // number(0), fct_assigned(true), serial(next_serial++)
     number(0), serial(next_serial++)
index f6adc64910ff5d985dac45e34801d9113993f835..9d0151e3d17dbc816fbc5f17ba8d340dc8741649 100644 (file)
@@ -30,6 +30,8 @@
 namespace GiNaC {
 #endif // ndef NO_GINAC_NAMESPACE
 
 namespace GiNaC {
 #endif // ndef NO_GINAC_NAMESPACE
 
+typedef ex (*evalffunctype)(void);
+    
 /** This class holds constants, symbols with specific numerical value. Each
  *  object of this class must either provide their own function to evaluate it
  *  to class numeric or provide the constant as a numeric (if it's an exact
 /** This class holds constants, symbols with specific numerical value. Each
  *  object of this class must either provide their own function to evaluate it
  *  to class numeric or provide the constant as a numeric (if it's an exact
@@ -51,7 +53,7 @@ protected:
 
     // other constructors
 public:
 
     // other constructors
 public:
-    constant(string const & initname, ex (*efun)()=0);
+    constant(string const & initname, evalffunctype efun=0);
     constant(string const & initname, numeric const & initnumber);
 
     // functions overriding virtual functions from bases classes
     constant(string const & initname, numeric const & initnumber);
 
     // functions overriding virtual functions from bases classes
@@ -77,7 +79,7 @@ protected:
 
 private:
     string name;
 
 private:
     string name;
-    ex (*ef)();
+    evalffunctype ef;
     numeric * number;
     // bool fct_assigned;
     unsigned serial;  //!< unique serial number for comparision
     numeric * number;
     // bool fct_assigned;
     unsigned serial;  //!< unique serial number for comparision
index 29b9b077f0f82a45c0b1fe6c470e5c2b85ea8f30..f2c0a03e5133cec2457e67630e73f53968bbe9c9 100644 (file)
@@ -71,6 +71,9 @@ public:
             GINAC_ASSERT(exZERO().bp->flags & status_flags::dynallocated);
             GINAC_ASSERT(bp!=0);
             ++bp->refcount;
             GINAC_ASSERT(exZERO().bp->flags & status_flags::dynallocated);
             GINAC_ASSERT(bp!=0);
             ++bp->refcount;
+#ifdef OBSCURE_CINT_HACK
+            update_last_created_or_assigned_bp();
+#endif // def OBSCURE_CINT_HACK
         }
 #else
 ;
         }
 #else
 ;
@@ -96,6 +99,9 @@ public:
             GINAC_ASSERT(bp!=0);
             GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
             ++bp->refcount;
             GINAC_ASSERT(bp!=0);
             GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
             ++bp->refcount;
+#ifdef OBSCURE_CINT_HACK
+            update_last_created_or_assigned_bp();
+#endif // def OBSCURE_CINT_HACK
         }
 #else
 ;
         }
 #else
 ;
@@ -114,6 +120,9 @@ public:
                 delete bp;
             }
             bp=tmpbp;
                 delete bp;
             }
             bp=tmpbp;
+#ifdef OBSCURE_CINT_HACK
+            update_last_created_or_assigned_bp();
+#endif // def OBSCURE_CINT_HACK
             return *this;
         }
 #else
             return *this;
         }
 #else
@@ -124,9 +133,12 @@ public:
 public:
     ex(basic const & other)
 #ifdef INLINE_EX_CONSTRUCTORS
 public:
     ex(basic const & other)
 #ifdef INLINE_EX_CONSTRUCTORS
-    {
-        construct_from_basic(other);
-    }
+        {
+            construct_from_basic(other);
+#ifdef OBSCURE_CINT_HACK
+            update_last_created_or_assigned_bp();
+#endif // def OBSCURE_CINT_HACK
+        }
 #else
 ;
 #endif // def INLINE_EX_CONSTRUCTORS
 #else
 ;
 #endif // def INLINE_EX_CONSTRUCTORS
@@ -225,10 +237,39 @@ private:
     void construct_from_basic(basic const & other);
     void makewriteable();
 
     void construct_from_basic(basic const & other);
     void makewriteable();
 
+#ifdef OBSCURE_CINT_HACK
+public:
+    static bool last_created_or_assigned_bp_can_be_converted_to_ex(void)
+        {
+            if (last_created_or_assigned_bp==0) return false;
+            if ((last_created_or_assigned_bp->flags &
+                 status_flags::dynallocated)==0) return false;
+            if ((last_created_or_assigned_bp->flags &
+                 status_flags::evaluated)==0) return false;
+            return true;
+        }
+protected:
+    void update_last_created_or_assigned_bp(void)
+        {
+            if (last_created_or_assigned_bp!=0) {
+                if (--last_created_or_assigned_bp->refcount == 0) {
+                    delete last_created_or_assigned_bp;
+                }
+            }
+            last_created_or_assigned_bp=bp;
+            ++last_created_or_assigned_bp->refcount;
+            last_created_or_assigned_bp_modified=true;
+        }
+#endif // def OBSCURE_CINT_HACK
+
 // member variables
 
 public:
     basic *bp;
 // member variables
 
 public:
     basic *bp;
+#ifdef OBSCURE_CINT_HACK
+    static basic *last_created_or_assigned_bp;
+    static bool last_created_or_assigned_bp_modified;
+#endif // def OBSCURE_CINT_HACK
 };
 
 // utility functions
 };
 
 // utility functions
index a4db03dd9746ee80164769ac970590354e4cb0e2..dd0caa55edbf177b204c2e55c4fc70abcf74b5c0 100644 (file)
@@ -101,10 +101,10 @@ matrix::matrix(int r, int c)
 // protected
 
 /** Ctor from representation, for internal use only. */
 // protected
 
 /** Ctor from representation, for internal use only. */
-matrix::matrix(int r, int c, vector<ex> const & m2)
+matrix::matrix(int r, int c, exvector const & m2)
     : basic(TINFO_matrix), row(r), col(c), m(m2)
 {
     : basic(TINFO_matrix), row(r), col(c), m(m2)
 {
-    debugmsg("matrix constructor from int,int,vector<ex>",LOGLEVEL_CONSTRUCT);
+    debugmsg("matrix constructor from int,int,exvector",LOGLEVEL_CONSTRUCT);
 }
 
 //////////
 }
 
 //////////
@@ -170,7 +170,7 @@ ex & matrix::let_op(int const i)
 /** expands the elements of a matrix entry by entry. */
 ex matrix::expand(unsigned options) const
 {
 /** expands the elements of a matrix entry by entry. */
 ex matrix::expand(unsigned options) const
 {
-    vector<ex> tmp(row*col);
+    exvector tmp(row*col);
     for (int i=0; i<row*col; ++i) {
         tmp[i]=m[i].expand(options);
     }
     for (int i=0; i<row*col; ++i) {
         tmp[i]=m[i].expand(options);
     }
@@ -187,7 +187,7 @@ bool matrix::has(ex const & other) const
     if (is_equal(*other.bp)) return true;
     
     // search all the elements
     if (is_equal(*other.bp)) return true;
     
     // search all the elements
-    for (vector<ex>::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;
         if ((*r).has(other)) return true;
     }
     return false;
@@ -209,7 +209,7 @@ ex matrix::eval(int level) const
     }
     
     // eval() entry by entry
     }
     
     // eval() entry by entry
-    vector<ex> m2(row*col);
+    exvector m2(row*col);
     --level;    
     for (int r=0; r<row; ++r) {
         for (int c=0; c<col; ++c) {
     --level;    
     for (int r=0; r<row; ++r) {
         for (int c=0; c<col; ++c) {
@@ -237,7 +237,7 @@ ex matrix::evalf(int level) const
     }
     
     // evalf() entry by entry
     }
     
     // evalf() entry by entry
-    vector<ex> m2(row*col);
+    exvector m2(row*col);
     --level;
     for (int r=0; r<row; ++r) {
         for (int c=0; c<col; ++c) {
     --level;
     for (int r=0; r<row; ++r) {
         for (int c=0; c<col; ++c) {
@@ -291,9 +291,9 @@ matrix matrix::add(matrix const & other) const
         throw (std::logic_error("matrix::add(): incompatible matrices"));
     }
     
         throw (std::logic_error("matrix::add(): incompatible matrices"));
     }
     
-    vector<ex> sum(this->m);
-    vector<ex>::iterator i;
-    vector<ex>::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) {
     for (i=sum.begin(), ci=other.m.begin();
          i!=sum.end();
          ++i, ++ci) {
@@ -311,9 +311,9 @@ matrix matrix::sub(matrix const & other) const
         throw (std::logic_error("matrix::sub(): incompatible matrices"));
     }
     
         throw (std::logic_error("matrix::sub(): incompatible matrices"));
     }
     
-    vector<ex> dif(this->m);
-    vector<ex>::iterator i;
-    vector<ex>::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) {
     for (i=dif.begin(), ci=other.m.begin();
          i!=dif.end();
          ++i, ++ci) {
@@ -331,7 +331,7 @@ matrix matrix::mul(matrix const & other) const
         throw (std::logic_error("matrix::mul(): incompatible matrices"));
     }
     
         throw (std::logic_error("matrix::mul(): incompatible matrices"));
     }
     
-    vector<ex> prod(row*other.col);
+    exvector prod(row*other.col);
     for (int i=0; i<row; ++i) {
         for (int j=0; j<other.col; ++j) {
             for (int l=0; l<col; ++l) {
     for (int i=0; i<row; ++i) {
         for (int j=0; j<other.col; ++j) {
             for (int l=0; l<col; ++l) {
@@ -374,7 +374,7 @@ matrix & matrix::set(int ro, int co, ex value)
  *  represents the transposed. */
 matrix matrix::transpose(void) const
 {
  *  represents the transposed. */
 matrix matrix::transpose(void) const
 {
-    vector<ex> trans(col*row);
+    exvector trans(col*row);
     
     for (int r=0; r<col; ++r) {
         for (int c=0; c<row; ++c) {
     
     for (int r=0; r<col; ++r) {
         for (int c=0; c<row; ++c) {
@@ -544,7 +544,7 @@ ex matrix::determinant(bool normalized) const
     }
 
     // check, if there are non-numeric entries in the matrix:
     }
 
     // check, if there are non-numeric entries in the matrix:
-    for (vector<ex>::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();
         if (!(*r).info(info_flags::numeric)) {
             if (normalized) {
                 return determinant_symbolic_minor(*this).normal();
@@ -861,7 +861,7 @@ matrix matrix::solve(matrix const & v) const
     }
     
     // assemble the solution matrix
     }
     
     // assemble the solution matrix
-    vector<ex> sol(v.row*v.col);
+    exvector sol(v.row*v.col);
     for (int c=0; c<v.col; ++c) {
         for (int r=col-1; r>=0; --r) {
             sol[r*v.col+c] = tmp[r*tmp.col+c];
     for (int c=0; c<v.col; ++c) {
         for (int r=col-1; r>=0; --r) {
             sol[r*v.col+c] = tmp[r*tmp.col+c];
index cf6b1699fa3de57bc31894c1a0513e6ea70da3eb..8e7ab39e7cc92d57a1d4651da58e7f9cdaf2afab 100644 (file)
@@ -54,7 +54,7 @@ protected:
     // other constructors
 public:
     matrix(int r, int c);
     // other constructors
 public:
     matrix(int r, int c);
-    matrix(int r, int c, vector<ex> const & m2);
+    matrix(int r, int c, exvector const & m2);
    
     // functions overriding virtual functions from bases classes
 public:
    
     // functions overriding virtual functions from bases classes
 public:
@@ -102,7 +102,7 @@ protected:
 protected:
     int row;                    /**< number of rows      */
     int col;                    /**< number of columns   */
 protected:
     int row;                    /**< number of rows      */
     int col;                    /**< number of columns   */
-    vector<ex> m;               /**< representation (cols indexed first) */
+    exvector m;               /**< representation (cols indexed first) */
     static unsigned precedence;
 };
 
     static unsigned precedence;
 };