refactoring polynom. 47/14847/22
Cedric Delamarre [Thu, 10 Jul 2014 17:11:56 +0000 (19:11 +0200)]
// bug_12679 doesn't work because of round in multiplication
// two last commit in dependencies are mandatory
test_run("polynomials",[],["no_check_error_output"]);

Change-Id: I62c056d117e9fbdb0fed9d1ff6446f3725684ac3

62 files changed:
scilab/modules/api_scilab/src/cpp/api_poly.cpp
scilab/modules/ast/includes/ast/runvisitor.hxx
scilab/modules/ast/includes/exps/matrixexp.hxx
scilab/modules/ast/includes/operations/types_power.hxx
scilab/modules/ast/includes/types/arrayof.hxx
scilab/modules/ast/includes/types/dollar.hxx
scilab/modules/ast/includes/types/double.hxx
scilab/modules/ast/includes/types/polynom.hxx
scilab/modules/ast/includes/types/singlepoly.hxx
scilab/modules/ast/src/cpp/ast/visitor_common.cpp
scilab/modules/ast/src/cpp/operations/types_addition.cpp
scilab/modules/ast/src/cpp/operations/types_comparison_eq.cpp
scilab/modules/ast/src/cpp/operations/types_divide.cpp
scilab/modules/ast/src/cpp/operations/types_multiplication.cpp
scilab/modules/ast/src/cpp/operations/types_power.cpp
scilab/modules/ast/src/cpp/operations/types_substraction.cpp
scilab/modules/ast/src/cpp/types/double.cpp
scilab/modules/ast/src/cpp/types/implicitlist.cpp
scilab/modules/ast/src/cpp/types/polynom.cpp
scilab/modules/ast/src/cpp/types/singlepoly.cpp
scilab/modules/cacsd/sci_gateway/cpp/sci_arl2_ius.cpp
scilab/modules/cacsd/sci_gateway/cpp/sci_freq.cpp
scilab/modules/cacsd/sci_gateway/cpp/sci_ldiv.cpp
scilab/modules/cacsd/sci_gateway/cpp/sci_residu.cpp
scilab/modules/cacsd/sci_gateway/cpp/sci_rtitr.cpp
scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/differential_equations/sci_gateway/cpp/sci_ode.cpp
scilab/modules/elementary_functions/Makefile.am
scilab/modules/elementary_functions/Makefile.in
scilab/modules/elementary_functions/sci_gateway/cpp/sci_abs.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_ceil.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_clean.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_conj.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_cumsum.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_floor.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_imag.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_imult.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_int.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_isreal.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_real.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_round.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_tril.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_triu.cpp
scilab/modules/elementary_functions/src/c/elementary_functions.vcxproj
scilab/modules/elementary_functions/src/c/elementary_functions.vcxproj.filters
scilab/modules/elementary_functions/src/cpp/clean.cpp [new file with mode: 0644]
scilab/modules/elementary_functions/src/cpp/clean.hxx [new file with mode: 0644]
scilab/modules/elementary_functions/src/cpp/cumprod.cpp
scilab/modules/elementary_functions/src/cpp/cumsum.cpp
scilab/modules/elementary_functions/src/cpp/diag.cpp
scilab/modules/elementary_functions/src/cpp/prod.cpp
scilab/modules/elementary_functions/src/cpp/sum.cpp
scilab/modules/polynomials/sci_gateway/cpp/sci_bezout.cpp
scilab/modules/polynomials/sci_gateway/cpp/sci_coeff.cpp
scilab/modules/polynomials/sci_gateway/cpp/sci_degree.cpp
scilab/modules/polynomials/sci_gateway/cpp/sci_poly.cpp
scilab/modules/polynomials/sci_gateway/cpp/sci_pppdiv.cpp
scilab/modules/polynomials/sci_gateway/cpp/sci_roots.cpp
scilab/modules/polynomials/sci_gateway/cpp/sci_sfact.cpp
scilab/modules/polynomials/sci_gateway/cpp/sci_simp.cpp
scilab/modules/polynomials/tests/unit_tests/polelm.dia.ref
scilab/modules/polynomials/tests/unit_tests/polelm.tst

index 0424f77..f699165 100644 (file)
@@ -137,18 +137,23 @@ SciErr getCommonMatrixOfPoly(void* _pvCtx, int* _piAddress, int _iComplex, int*
         return sciErr;
     }
 
-    for (int i = 0 ; i < iSize ; i++)
+    SinglePoly** pSP = pMP->get();
+    if (_iComplex == 1)
     {
-        memcpy(_pdblReal[i], pMP->get(i)->getCoefReal(), sizeof(double) * pMP->get(i)->getRank());
+        for (int i = 0 ; i < iSize ; i++)
+        {
+            memcpy(_pdblReal[i], pSP[i]->get(),    sizeof(double) * pSP[i]->getSize());
+            memcpy(_pdblImg[i],  pSP[i]->getImg(), sizeof(double) * (_piNbCoef[i] + 1));
+        }
     }
-
-    if (_iComplex == 1)
+    else
     {
         for (int i = 0 ; i < iSize ; i++)
         {
-            memcpy(_pdblImg[i], pMP->get(i)->getCoefImg(), sizeof(double) * _piNbCoef[i]);
+            memcpy(_pdblReal[i], pSP[i]->get(), sizeof(double) * pSP[i]->getSize());
         }
     }
+
     return sciErr;
 }
 
index 75a6988..c34d902 100644 (file)
@@ -71,9 +71,9 @@ public:
         {
             if (_result != NULL)
             {
-                //                                     std::cout << "before single delete : " << _result << std::endl;
+                //                    std::cout << "before single delete : " << _result << std::endl;
                 _result->killMe();
-                //                                     std::cout << "after single delete" << std::endl;
+                //                    std::cout << "after single delete" << std::endl;
             }
         }
         else
@@ -299,8 +299,8 @@ public:
     | Attributes.  |
     `-------------*/
 protected:
-    vector<types::InternalType*>       _resultVect;
-    types::InternalType*       _result;
+    vector<types::InternalType*>    _resultVect;
+    types::InternalType*    _result;
     bool m_bSingleResult;
     int _excepted_result;
     symbol::Variable* m_pAns;
index 6c7c254..4ef1ae8 100644 (file)
@@ -82,12 +82,12 @@ public:
     /** \name Accessors.
     ** \{ */
 public:
-    const std::list<MatrixLineExp *>&  lines_get() const
+    const std::list<MatrixLineExp *>&    lines_get() const
     {
         return *_lines;
     }
 
-    std::list<MatrixLineExp *>&        lines_get()
+    std::list<MatrixLineExp *>&    lines_get()
     {
         return *_lines;
     }
index c387e7f..87b96b9 100644 (file)
@@ -27,6 +27,7 @@ int PowerPolyByDouble(Polynom* _pPoly, Double* _pDouble, InternalType** _pOut);
 
 //dot power operations
 int DotPowerDoubleByDouble(Double* _pDouble1, Double* _pDouble2, Double** _pDoubleOut);
+int DotPowerPolyByDouble(Polynom* _pPoly, Double* _pDouble, InternalType** _pOut);
 
 extern "C"
 {
index 510a473..9cee186 100644 (file)
@@ -53,12 +53,11 @@ public:
     typedef T type;
 
 protected :
-    bool                    m_bComplex;
     T*                      m_pRealData;
     T*                      m_pImgData;
 
 
-    ArrayOf() : GenericType(), m_bComplex(false), m_pRealData(NULL), m_pImgData(NULL) {}
+    ArrayOf() : GenericType(), m_pRealData(NULL), m_pImgData(NULL) {}
 
     virtual                 ~ArrayOf()
     {
@@ -143,7 +142,6 @@ protected :
         {
             m_pImgData = allocData(m_iSize);
             *_pImgData = m_pImgData;
-            m_bComplex = true;
         }
         else
         {
@@ -200,7 +198,7 @@ public :
 
     virtual bool isComplex()
     {
-        return m_bComplex;
+        return m_pImgData != NULL;
     }
 
     inline virtual bool isScalar() //2 dims and each dim == 1
@@ -216,19 +214,17 @@ public :
     {
         if (_bComplex == false)
         {
-            if (isComplex() == true)
+            if (m_pImgData != NULL)
             {
                 deleteImg();
-                m_bComplex = false;
             }
         }
         else // _bComplex == true
         {
-            if (isComplex() == false)
+            if (m_pImgData == NULL)
             {
                 m_pImgData = allocData(m_iSize);
                 memset(m_pImgData, 0x00, sizeof(T) * m_iSize);
-                m_bComplex = true;
             }
         }
     }
@@ -303,7 +299,7 @@ public :
     /*internal function to manage img part*/
     bool setImg(int _iPos, T _data)
     {
-        if (isComplex() == false || m_pImgData == NULL || _iPos >= m_iSize)
+        if (m_pImgData == NULL || _iPos >= m_iSize)
         {
             return false;
         }
@@ -508,7 +504,7 @@ public :
         }
 
         //update complexity
-        if (pSource->isComplex() && isComplex() == false)
+        if (pSource->isComplex() && m_pImgData == NULL)
         {
             setComplex(true);
         }
@@ -549,25 +545,22 @@ public :
             {
                 //element-wise insertion
                 set(iPos, pRealData[0]);
-                if (bComplex)
+                if (pImgData != NULL && bComplex)
                 {
-                    if (pImgData != NULL)
-                    {
-                        setImg(iPos, pImgData[0]);
-                    }
+                    setImg(iPos, pImgData[0]);
                 }
             }
             else
             {
                 set(iPos, pRealData[i]);
-                if (bComplex)
+                if (pImgData != NULL && bComplex)
                 {
                     setImg(iPos, pImgData[i]);
                 }
             }
 
             // reset imaginary part
-            if (isComplex() && bComplex == false)
+            if (m_pImgData != NULL && bComplex == false)
             {
                 setImg(iPos, 0);
             }
@@ -753,24 +746,32 @@ public :
         {
             setComplex(true);
         }
-
-        if (isComplex())
+        else if (isComplex())
         {
             pGT->setComplex(true);
         }
 
-
-        for (int i = 0 ; i < iRows ; i++)
+        if (pGT->isComplex())
         {
-            for (int j = 0 ; j < iCols ; j++)
+            for (int i = 0 ; i < iRows ; i++)
             {
-                set(_iRows + i, _iCols + j, pGT->get(i, j));
-                if (pGT->isComplex())
+                for (int j = 0 ; j < iCols ; j++)
                 {
+                    set(_iRows + i, _iCols + j, pGT->get(i, j));
                     setImg(_iRows + i, _iCols + j, pGT->getImg(i, j));
                 }
             }
         }
+        else
+        {
+            for (int i = 0 ; i < iRows ; i++)
+            {
+                for (int j = 0 ; j < iCols ; j++)
+                {
+                    set(_iRows + i, _iCols + j, pGT->get(i, j));
+                }
+            }
+        }
 
         return true;
     }
@@ -922,20 +923,20 @@ public :
                 {
                     //special case for row vector
                     int piRealDim[2] = {1, iNewDimSize};
-                    pOut = createEmpty(2, piRealDim, isComplex());
+                    pOut = createEmpty(2, piRealDim, m_pImgData != NULL);
                     //in this case we have to care of 2nd dimension
                     //iNotEntire = 1;
                 }
                 else
                 {
                     int piRealDim[2] = {iNewDimSize, 1};
-                    pOut = createEmpty(2, piRealDim, isComplex());
+                    pOut = createEmpty(2, piRealDim, m_pImgData != NULL);
                 }
             }
         }
         else
         {
-            pOut = createEmpty(iDims, piNewDims, isComplex());
+            pOut = createEmpty(iDims, piNewDims, m_pImgData != NULL);
         }
 
         delete[] piNewDims;
@@ -968,7 +969,7 @@ public :
             {
                 //compute new index
                 pOut->set(iNewPos, get(i));
-                if (isComplex())
+                if (m_pImgData != NULL)
                 {
                     pOut->setImg(iNewPos, getImg(i));
                 }
@@ -1119,19 +1120,19 @@ public :
                 {
                     //special case for row vector
                     int piRealDim[2] = {1, piCountDim[0]};
-                    pOut = createEmpty(2, piRealDim, isComplex());
+                    pOut = createEmpty(2, piRealDim, m_pImgData != NULL);
                 }
                 else
                 {
                     if (getSize() == 1)
                     {
                         //for extraction on scalar
-                        pOut = createEmpty(pArg[0]->getAs<GenericType>()->getDims(), pArg[0]->getAs<GenericType>()->getDimsArray(), isComplex());
+                        pOut = createEmpty(pArg[0]->getAs<GenericType>()->getDims(), pArg[0]->getAs<GenericType>()->getDimsArray(), m_pImgData != NULL);
                     }
                     else
                     {
                         int piRealDim[2] = {piCountDim[0], 1};
-                        pOut = createEmpty(2, piRealDim, isComplex());
+                        pOut = createEmpty(2, piRealDim, m_pImgData != NULL);
                     }
                 }
             }
@@ -1139,7 +1140,7 @@ public :
         else
         {
             //matrix
-            pOut = createEmpty(iDims, piCountDim, isComplex());
+            pOut = createEmpty(iDims, piCountDim, m_pImgData != NULL);
         }
 
         int* piIndex    = new int[_pArgs->size()];
@@ -1203,7 +1204,7 @@ public :
             }
 
             pOut->set(i, get(iPos));
-            if (isComplex())
+            if (m_pImgData != NULL)
             {
                 pOut->setImg(i, getImg(iPos));
             }
@@ -1295,7 +1296,7 @@ public :
         T* pImgData = NULL;
 
         int iNewSize = 0;
-        if (isComplex())
+        if (m_pImgData != NULL)
         {
             iNewSize = get_max_size(_piDims, _iDims);
             if (m_iSizeMax < iNewSize)
@@ -1327,8 +1328,8 @@ public :
                 //delete all array
                 deleteAll();
                 //replace old array by new one
-                m_pRealData    = pRealData;
-                m_pImgData     = pImgData;
+                m_pRealData    = pRealData;
+                m_pImgData    = pImgData;
             }
             else
             {
@@ -1399,7 +1400,7 @@ public :
                 //delete all array
                 deleteAll();
                 //replace old array by new one
-                m_pRealData    = pRealData;
+                m_pRealData    = pRealData;
             }
             else
             {
@@ -1454,7 +1455,7 @@ public :
             }
         }
         m_iRows = m_piDims[0];
-        m_iCols        = m_piDims[1];
+        m_iCols    = m_piDims[1];
         m_iSize = iNewSize;
         return true;
     }
@@ -1483,7 +1484,7 @@ public :
         if (_iPos < m_iCols)
         {
             int piDims[2] = {m_iRows, 1};
-            pOut = createEmpty(2, piDims, isComplex());
+            pOut = createEmpty(2, piDims, m_pImgData != NULL);
             T* pReal    = pOut->get();
             T* pImg     = pOut->getImg();
             for (int i = 0 ; i < m_iRows ; i++)
@@ -1491,7 +1492,7 @@ public :
                 pReal[i] = copyValue(get(i, _iPos));
             }
 
-            if (isComplex())
+            if (m_pImgData != NULL)
             {
                 for (int i = 0 ; i < m_iRows ; i++)
                 {
index 0d5ca41..252347b 100644 (file)
@@ -23,16 +23,17 @@ public :
 
     Dollar()
     {
-        int piDims[2]   = {1, 1};
-        m_szVarName        = L"$";
-        m_bComplex         = false;
-        SinglePoly** pPoly    = NULL;
+        int piDims[2] = {1, 1};
+        m_szVarName   = L"$";
+        SinglePoly** pPoly = NULL;
         create(piDims, 2, &pPoly, NULL);
 
-        Double dblCoef(1, 2);
-        dblCoef.set(0, 0, 0);
-        dblCoef.set(0, 1, 1.0);
-        setCoef(0, &dblCoef);
+        double* pdblCoef = NULL;
+        SinglePoly* SPCoef = new SinglePoly(&pdblCoef, 1);
+        pdblCoef[0] = 0;
+        pdblCoef[1] = 1.0;
+
+        m_pRealData[0] = SPCoef;
     }
 
     Dollar* clone()
index 10f0093..1b887cd 100644 (file)
@@ -73,6 +73,10 @@ public :
         return true;
     }
 
+    bool isComplex()
+    {
+        return (m_pImgData != NULL) || isViewAsZComplex();
+    }
 
     bool isTrue()
     {
@@ -199,7 +203,7 @@ public :
 
         if (isScalar())
         {
-            if (m_bComplex)
+            if (isComplex())
             {
                 out = new Double(m_pRealData[0], -m_pImgData[0]);
             }
@@ -213,9 +217,9 @@ public :
 
         if (m_iDims == 2)
         {
-            Double * pReturn = new Double(getCols(), getRows(), m_bComplex);
+            Double * pReturn = new Double(getCols(), getRows(), isComplex());
             out = pReturn;
-            if (m_bComplex)
+            if (isComplex())
             {
                 Transposition::adjoint(getRows(), getCols(), m_pRealData, pReturn->m_pRealData, m_pImgData, pReturn->m_pImgData);
             }
@@ -246,9 +250,9 @@ public :
 
         if (m_iDims == 2)
         {
-            Double * pReturn = new Double(getCols(), getRows(), m_bComplex);
+            Double * pReturn = new Double(getCols(), getRows(), isComplex());
             out = pReturn;
-            if (m_bComplex)
+            if (isComplex())
             {
                 Transposition::transpose(getRows(), getCols(), m_pRealData, pReturn->m_pRealData, m_pImgData, pReturn->m_pImgData);
             }
index dd22576..e66a4f6 100644 (file)
@@ -65,6 +65,8 @@ public :
                : IdPolynom;
     }
 
+    bool isComplex(void);
+
     inline bool             isPoly()
     {
         return true;
@@ -74,15 +76,15 @@ public :
     std::wstring            getVariableName();
     void                    setVariableName(std::wstring);
     bool                    getRank(int *_piRank);
-    bool                    getRealRank(int *_piRank);
     int                     getMaxRank(void);
-    int                     getRealMaxRank(void);
     Double*                 evaluate(Double* _pdblValue);
     void                    updateRank(void);
     Double*                 getCoef(void);
     void                    setCoef(Double *_pCoef);
     Double*                 extractCoef(int _iRank);
     bool                    insertCoef(int _iRank, Double* _pCoef);
+    void                    setZeros();
+
     bool                    set(int _iPos, SinglePoly* _pS);
     bool                    set(int _iRows, int _iCols, SinglePoly* _pS);
     bool                    set(SinglePoly** _pS);
index 1aa25e0..6baebcc 100644 (file)
 
 namespace types
 {
-class EXTERN_AST SinglePoly : public GenericType
+class EXTERN_AST SinglePoly : public ArrayOf<double>
 {
 public :
     SinglePoly();
     SinglePoly(double** _pdblCoefR, int _iRank);
     SinglePoly(double** _pdblCoefR, double** _pdblcoefI, int _iRank);
-    SinglePoly(Double** _poCoefR, int _iRank);
+
     virtual                 ~SinglePoly();
+    virtual void            deleteAll();
+    virtual void            deleteImg();
 
     // FIXME : Should not return NULL;
     SinglePoly*             clone();
@@ -38,22 +40,21 @@ public :
     }
     /*Config management*/
     void                    whoAmI();
-    bool                    isComplex();
-    void                    setComplex(bool _bComplex);
 
+    virtual double          getNullValue();
+    virtual SinglePoly*     createEmpty(int _iDims, int* _piDims, bool _bComplex);
+    virtual double*         allocData(int _iSize);
+    virtual double          copyValue(double _dblData);
+    virtual bool            subMatrixToString(std::wostringstream& ostr, int* _piDims, int _iDims);
+
+    bool                    setZeros();
     int                     getRank();
-    int                     getRealRank();
     bool                    setRank(int _iRank, bool bSave = false);
-    Double*                 getCoef();
-    double*                 getCoefReal();
-    double*                 getCoefImg();
     bool                    setCoef(Double *_poPow);
     bool                    setCoef(double *_pdblCoefR, double *_pdblCoefI);
     bool                    evaluate(double _dblInR, double _dblInI, double *_pdblOutR, double *_pdblOutI);
     void                    updateRank(void);
 
-    GenericType*            getColumnValues(int _iPos);
-    void                    createPoly(double**_pdblCoefR, double**_pdblCoefI, int _iRank);
     void                    toStringReal(std::wstring _szVar, std::list<std::wstring>* _pListExp , std::list<std::wstring>* _pListCoef);
     void                    toStringImg(std::wstring _szVar, std::list<std::wstring>* _pListExp , std::list<std::wstring>* _pListCoef);
 
@@ -85,11 +86,6 @@ protected :
 private :
     void                    toStringInternal(double *_pdblVal, std::wstring _szVar, std::list<std::wstring>* _pListExp , std::list<std::wstring>* _pListCoef);
 
-
-private :
-    bool                    m_bComplex;
-    Double*                 m_pdblCoef;
-    int                     m_iRank;
 };
 }
 
index 172a7d9..477c7cd 100644 (file)
@@ -72,11 +72,9 @@ types::InternalType* allocDest(types::InternalType* _poSource, int _iRows, int _
         case types::GenericType::ScilabPolynom :
         {
             int* piRank = new int[_iRows * _iCols];
-            for (int i = 0 ; i < _iRows * _iCols ; i++)
-            {
-                piRank[i] = 1;
-            }
+            memset(piRank, 0x00, _iRows * _iCols * sizeof(int));
             poResult = new types::Polynom(_poSource->getAs<types::Polynom>()->getVariableName(), _iRows, _iCols, piRank);
+            delete[] piRank;
             break;
         }
         case types::InternalType::ScilabImplicitList :
@@ -91,9 +89,9 @@ types::InternalType* allocDest(types::InternalType* _poSource, int _iRows, int _
 
 types::InternalType* AddElementToVariableFromCol(types::InternalType* _poDest, types::InternalType* _poSource, int _iRows, int _iCols, int *_piCols)
 {
-    types::InternalType *poResult                  = NULL;
-    types::InternalType::ScilabType TypeSource = _poSource->getType();
-    types::InternalType::ScilabType TypeDest           = types::InternalType::ScilabInternal;
+    types::InternalType *poResult                = NULL;
+    types::InternalType::ScilabType TypeSource    = _poSource->getType();
+    types::InternalType::ScilabType TypeDest        = types::InternalType::ScilabInternal;
     int iCurRow                                 = _iRows;
     int iCurCol                                 = _iCols;
 
@@ -102,9 +100,9 @@ types::InternalType* AddElementToVariableFromCol(types::InternalType* _poDest, t
     {
         //First call, alloc _poSource
         poResult    = allocDest(_poSource, _iRows, _iCols);
-        TypeDest       = TypeSource;
-        iCurCol            = 0;
-        iCurRow                = 0;
+        TypeDest    = TypeSource;
+        iCurCol        = 0;
+        iCurRow        = 0;
     }
     else
     {
@@ -140,9 +138,9 @@ types::InternalType* AddElementToVariableFromCol(types::InternalType* _poDest, t
 
 types::InternalType* AddElementToVariableFromRow(types::InternalType* _poDest, types::InternalType* _poSource, int _iRows, int _iCols, int *_piRows)
 {
-    types::InternalType *poResult                  = NULL;
-    types::InternalType::ScilabType TypeSource = _poSource->getType();
-    types::InternalType::ScilabType TypeDest           = types::InternalType::ScilabInternal;
+    types::InternalType *poResult                = NULL;
+    types::InternalType::ScilabType TypeSource    = _poSource->getType();
+    types::InternalType::ScilabType TypeDest        = types::InternalType::ScilabInternal;
     int iCurRow                                 = _iRows;
     int iCurCol                                 = _iCols;
 
@@ -150,13 +148,13 @@ types::InternalType* AddElementToVariableFromRow(types::InternalType* _poDest, t
     {
         //First call, alloc _poSource
         poResult    = allocDest(_poSource, _iRows, _iCols);
-        iCurCol            = 0;
-        iCurRow                = 0;
-        TypeDest       = TypeSource;
+        iCurCol        = 0;
+        iCurRow        = 0;
+        TypeDest    = TypeSource;
     }
     else
     {
-        TypeDest       = _poDest->getType();
+        TypeDest    = _poDest->getType();
         poResult    = _poDest;
     }
 
@@ -194,9 +192,9 @@ _iCols : Position if _poDest allready initialized else size of the matrix
 */
 types::InternalType* AddElementToVariable(types::InternalType* _poDest, types::InternalType* _poSource, int _iRows, int _iCols)
 {
-    types::InternalType *poResult      = NULL;
-    types::InternalType::ScilabType TypeSource = _poSource->getType();
-    types::InternalType::ScilabType TypeDest           =       types::InternalType::ScilabInternal;
+    types::InternalType *poResult = NULL;
+    types::InternalType::ScilabType TypeSource = _poSource->getType();
+    types::InternalType::ScilabType TypeDest = types::InternalType::ScilabInternal;
     int iCurRow = _iRows;
     int iCurCol = _iCols;
 
@@ -246,11 +244,9 @@ types::InternalType* AddElementToVariable(types::InternalType* _poDest, types::I
             case types::GenericType::ScilabPolynom :
             {
                 int* piRank = new int[_iRows * _iCols];
-                for (int i = 0 ; i < _iRows * _iCols ; i++)
-                {
-                    piRank[i] = 1;
-                }
+                memset(piRank, 0x00, _iRows * _iCols * sizeof(int));
                 poResult = new types::Polynom(_poSource->getAs<types::Polynom>()->getVariableName(), _iRows, _iCols, piRank);
+                delete[] piRank;
                 break;
             }
             case types::InternalType::ScilabImplicitList :
@@ -265,7 +261,7 @@ types::InternalType* AddElementToVariable(types::InternalType* _poDest, types::I
         }
         iCurCol = 0;
         iCurRow = 0;
-        TypeDest =     TypeSource;
+        TypeDest =    TypeSource;
     }
     else
     {
@@ -283,40 +279,43 @@ types::InternalType* AddElementToVariable(types::InternalType* _poDest, types::I
                 if (TypeSource == types::GenericType::ScilabPolynom)
                 {
                     types::Double *poDest = _poDest->getAs<types::Double>();
+                    Polynom* pPSource = _poSource->getAs<types::Polynom>();
+
                     //Convert Dest to ScilabPolynom
-                    int *piRank = new int[poDest->getSize()];
-                    for (int i = 0 ; i < poDest->getSize() ; i++)
-                    {
-                        piRank[i] = 1;
-                    }
+                    int iSize = poDest->getSize();
+                    int *piRank = new int[iSize];
+                    memset(piRank, 0x00, iSize * sizeof(int));
+                    poResult = new types::Polynom(pPSource->getVariableName(), poDest->getRows(), poDest->getCols(), piRank);
+                    delete[] piRank;
 
-                    poResult = new types::Polynom(_poSource->getAs<types::Polynom>()->getVariableName(), poDest->getRows(), poDest->getCols(),  piRank);
+                    Polynom* pPResult = poResult->getAs<types::Polynom>();
+                    pPResult->setComplex(poDest->isComplex());
 
                     double *pR = poDest->getReal();
-                    double *pI = poDest->getImg();
-                    for (int i = 0 ; i < poDest->getSize() ; i++)
+                    SinglePoly** pSP = pPResult->get();
+
+                    if (poDest->isComplex())
                     {
-                        types::Double *pdbl = NULL;
-                        if (poDest->isComplex())
+                        double *pI = poDest->getImg();
+                        for (int i = 0 ; i < iSize; i++)
                         {
-                            pdbl = new types::Double(pR[i], pI[i]);
+                            pSP[i]->set(0, pR[i]);
+                            pSP[i]->setImg(0, pI[i]);
                         }
-                        else
+                    }
+                    else
+                    {
+                        for (int i = 0 ; i < iSize; i++)
                         {
-                            pdbl = new types::Double(pR[i]);
+                            pSP[i]->set(0, pR[i]);
                         }
-
-                        poResult->getAs<types::Polynom>()->setCoef(i, pdbl);
-                        delete pdbl;
                     }
 
-                    Polynom* pP = _poSource->getAs<types::Polynom>();
-
-                    for (int i = 0 ; i < pP->getRows() ; i++)
+                    for (int i = 0 ; i < pPSource->getRows() ; i++)
                     {
-                        for (int j = 0 ; j < pP->getCols() ; j++)
+                        for (int j = 0 ; j < pPSource->getCols() ; j++)
                         {
-                            poResult->getAs<types::Polynom>()->setCoef(iCurRow + i, iCurCol + j, _poSource->getAs<types::Polynom>()->get(i, j)->getCoef());
+                            pPResult->set(iCurRow + i, iCurCol + j, pPSource->get(i, j));
                         }
                     }
 
@@ -339,7 +338,7 @@ types::InternalType* AddElementToVariable(types::InternalType* _poDest, types::I
                             {
                                 types::SinglePoly* pSPOut = pPolyOut->get(iCurRow + i, iCurCol + j);
 
-                                pSPOut->setRank(1);
+                                pSPOut->setRank(0);
                                 double pDblR = pD->get(i, j);
                                 double pDblI = pD->getImg(i, j);
                                 pSPOut->setCoef(&pDblR, &pDblI);
@@ -354,7 +353,7 @@ types::InternalType* AddElementToVariable(types::InternalType* _poDest, types::I
                             {
                                 types::SinglePoly* pSPOut = pPolyOut->get(iCurRow + i, iCurCol + j);
 
-                                pSPOut->setRank(1);
+                                pSPOut->setRank(0);
                                 double pDbl = pD->get(i, j);
                                 pSPOut->setCoef(&pDbl, NULL);
                             }
@@ -1677,29 +1676,28 @@ InternalType* insertionCall(const ast::Exp& e, typed_list* _pArgs, InternalType*
         {
             Double* pDest = _pVar->getAs<Double>();
             Polynom* pIns = _pInsert->getAs<Polynom>();
-            Polynom* pP = new Polynom(pIns->getVariableName(), pDest->getDims(), pDest->getDimsArray());
+            int iSize = pDest->getSize();
+            int* piRanks = new int[iSize];
+            memset(piRanks, 0x00, iSize * sizeof(int));
+            Polynom* pP = new Polynom(pIns->getVariableName(), pDest->getDims(), pDest->getDimsArray(), piRanks);
+            delete[] piRanks;
             pP->setComplex(pDest->isComplex());
 
-            for (int idx = 0 ; idx < pP->getSize() ; idx++)
+            if (pP->isComplex())
             {
-                double* pR = NULL;
-                double* pI = NULL;
-                if (pP->isComplex())
+                for (int idx = 0 ; idx < pP->getSize() ; idx++)
                 {
-                    SinglePoly* pS = new SinglePoly(&pR, &pI, 1);
                     double dblR = pDest->get(idx);
                     double dblI = pDest->getImg(idx);
-                    pS->setCoef(&dblR, &dblI);
-                    pP->set(idx, pS);
-                    delete pS;
+                    pP->get(idx)->setCoef(&dblR, &dblI);
                 }
-                else
+            }
+            else
+            {
+                for (int idx = 0 ; idx < pP->getSize() ; idx++)
                 {
-                    SinglePoly* pS = new SinglePoly(&pR, 1);
                     double dblR = pDest->get(idx);
-                    pS->setCoef(&dblR, NULL);
-                    pP->set(idx, pS);
-                    delete pS;
+                    pP->get(idx)->setCoef(&dblR, NULL);
                 }
             }
 
@@ -1710,31 +1708,31 @@ InternalType* insertionCall(const ast::Exp& e, typed_list* _pArgs, InternalType*
         {
             Polynom* pDest = _pVar->getAs<Polynom>();
             Double* pIns = _pInsert->getAs<Double>();
-            Polynom* pP = new Polynom(pDest->getVariableName(), pIns->getDims(), pIns->getDimsArray());
+            int iSize = pIns->getSize();
+            int* piRanks = new int[iSize];
+            memset(piRanks, 0x00, iSize * sizeof(int));
+            Polynom* pP = new Polynom(pDest->getVariableName(), pIns->getDims(), pIns->getDimsArray(), piRanks);
+            delete[] piRanks;
             pP->setComplex(pIns->isComplex());
 
-            for (int idx = 0 ; idx < pP->getSize() ; idx++)
+            if (pP->isComplex())
             {
-                double* pR = NULL;
-                double* pI = NULL;
-                if (pP->isComplex())
+                for (int idx = 0 ; idx < pP->getSize() ; idx++)
                 {
-                    SinglePoly* pS = new SinglePoly(&pR, &pI, 1);
                     double dblR = pIns->get(idx);
                     double dblI = pIns->getImg(idx);
-                    pS->setCoef(&dblR, &dblI);
-                    pP->set(idx, pS);
-                    delete pS;
+                    pP->get(idx)->setCoef(&dblR, &dblI);
                 }
-                else
+            }
+            else
+            {
+                for (int idx = 0 ; idx < pP->getSize() ; idx++)
                 {
-                    SinglePoly* pS = new SinglePoly(&pR, 1);
                     double dblR = pIns->get(idx);
-                    pS->setCoef(&dblR, NULL);
-                    pP->set(idx, pS);
-                    delete pS;
+                    pP->get(idx)->setCoef(&dblR, NULL);
                 }
             }
+
             pRet = pDest->insert(_pArgs, pP);
             delete pP;
         }
index 71c7e0a..e993b37 100644 (file)
@@ -1723,39 +1723,39 @@ template<> InternalType* add_M_M<Polynom, Polynom, Polynom>(Polynom* _pL, Polyno
         }
 
         //Result P1(0) + P2(i)
-        Double *pCoef1 = _pL->get(0)->getCoef();
-        double *p1R   = pCoef1->getReal();
-        double *p1I   = pCoef1->getImg();
+        SinglePoly *pCoef1 = _pL->get(0);
+        double *p1R = pCoef1->get();
+        double *p1I = pCoef1->getImg();
         for (int i = 0 ; i < _pR->getSize() ; i++)
         {
-            Double *pCoef2 = _pR->get(i)->getCoef();
-            double *p2R   = pCoef2->getReal();
-            double *p2I   = pCoef2->getImg();
+            SinglePoly *pCoef2 = _pR->get(i);
+            double *p2R = pCoef2->get();
+            double *p2I = pCoef2->getImg();
 
-            Double *pCoefR = pOut->get(i)->getCoef();
-            double *pRR   = pCoefR->getReal();
-            double *pRI   = pCoefR->getImg();
+            SinglePoly *pCoefR = pOut->get(i);
+            double *pRR = pCoefR->get();
+            double *pRI = pCoefR->getImg();
 
-            for (int j = 0 ; j < std::min(pRank1[0], pRank2[i]) ; j++)
+            for (int j = 0 ; j < std::min(pRank1[0], pRank2[i]) + 1; j++)
             {
                 pRR[j] = p1R[j] + p2R[j];
             }
 
             double *pTemp = (pRank1[0] > pRank2[i] ? p1R : p2R);
-            for (int j = std::min(pRank1[0], pRank2[i]) ; j < std::max(pRank1[0], pRank2[i]) ; j++)
+            for (int j = std::min(pRank1[0], pRank2[i]) + 1; j < std::max(pRank1[0], pRank2[i]) + 1; j++)
             {
                 pRR[j] = pTemp[j];
             }
 
             if (pOut->isComplex())
             {
-                for (int j = 0 ; j < std::min(pRank1[0], pRank2[i]) ; j++)
+                for (int j = 0 ; j < std::min(pRank1[0], pRank2[i]) + 1; j++)
                 {
                     pRI[j] = (p1I == NULL ? 0 : p1I[j]) + (p2I == NULL ? 0 : p2I[j]);
                 }
 
                 double *pTemp = (pRank1[0] > pRank2[i] ? p1I : p2I);
-                for (int j = std::min(pRank1[0], pRank2[i]) ; j < std::max(pRank1[0], pRank2[i]); j++)
+                for (int j = std::min(pRank1[0], pRank2[i]) + 1; j < std::max(pRank1[0], pRank2[i]) + 1; j++)
                 {
                     pRI[j] = pTemp == NULL ? 0 : pTemp[j];
                 }
@@ -1792,40 +1792,40 @@ template<> InternalType* add_M_M<Polynom, Polynom, Polynom>(Polynom* _pL, Polyno
         }
 
         //Result P1(i) + P2(0)
-        Double *pCoef2 = _pR->get(0)->getCoef();
-        double *p2R   = pCoef2->getReal();
-        double *p2I   = pCoef2->getImg();
+        SinglePoly *pCoef2 = _pR->get(0);
+        double *p2R = pCoef2->get();
+        double *p2I = pCoef2->getImg();
 
         for (int i = 0 ; i < _pL->getSize() ; i++)
         {
-            Double *pCoef1 = _pL->get(i)->getCoef();
-            double *p1R   = pCoef1->getReal();
-            double *p1I   = pCoef1->getImg();
+            SinglePoly *pCoef1 = _pL->get(i);
+            double *p1R = pCoef1->get();
+            double *p1I = pCoef1->getImg();
 
-            Double *pCoefR = pOut->get(i)->getCoef();
-            double *pRR   = pCoefR->getReal();
-            double *pRI   = pCoefR->getImg();
+            SinglePoly *pCoefR = pOut->get(i);
+            double *pRR = pCoefR->get();
+            double *pRI = pCoefR->getImg();
 
-            for (int j = 0 ; j < std::min(pRank1[i], pRank2[0]) ; j++)
+            for (int j = 0 ; j < std::min(pRank1[i], pRank2[0]) + 1 ; j++)
             {
                 pRR[j] = p1R[j] + p2R[j];
             }
 
             double *pTemp = (pRank1[i] > pRank2[0] ? p1R : p2R);
-            for (int j = std::min(pRank1[i], pRank2[0]) ; j < std::max(pRank1[i], pRank2[0]) ; j++)
+            for (int j = std::min(pRank1[i], pRank2[0]) + 1; j < std::max(pRank1[i], pRank2[0]) + 1; j++)
             {
                 pRR[j] = pTemp[j];
             }
 
             if (pOut->isComplex())
             {
-                for (int j = 0 ; j < std::min(pRank1[i], pRank2[0]) ; j++)
+                for (int j = 0 ; j < std::min(pRank1[i], pRank2[0]) + 1; j++)
                 {
                     pRI[j] = (p1I == NULL ? 0 : p1I[j]) + (p2I == NULL ? 0 : p2I[j]);
                 }
 
                 double *pTemp = (pRank1[i] > pRank2[0] ? p1I : p2I);
-                for (int j = std::min(pRank1[i], pRank2[0]) ; j < std::max(pRank1[i], pRank2[0]); j++)
+                for (int j = std::min(pRank1[i], pRank2[0]) + 1; j < std::max(pRank1[i], pRank2[0]) + 1; j++)
                 {
                     pRI[j] = pTemp == NULL ? 0 : pTemp[j];
                 }
@@ -1885,9 +1885,9 @@ template<> InternalType* add_M_M<Polynom, Polynom, Polynom>(Polynom* _pL, Polyno
         for (int i = 0 ; i < _pL->getSize() ; i++)
         {
             iAddScilabPolynomToScilabPolynom(
-                _pL->get(i)->getCoef()->getReal(), pRank1[i],
-                _pR->get(i)->getCoef()->getReal(), pRank2[i],
-                pOut->get(i)->getCoef()->getReal(), pRank[i]);
+                _pL->get(i)->get(), pRank1[i] + 1,
+                _pR->get(i)->get(), pRank2[i] + 1,
+                pOut->get(i)->get(), pRank[i] + 1);
         }
     }
     else if (bComplex1 == false && bComplex2 == true)
@@ -1895,9 +1895,9 @@ template<> InternalType* add_M_M<Polynom, Polynom, Polynom>(Polynom* _pL, Polyno
         for (int i = 0 ; i < _pL->getSize() ; i++)
         {
             iAddScilabPolynomToComplexPoly(
-                _pL->get(i)->getCoef()->getReal(), pRank1[i],
-                _pR->get(i)->getCoef()->getReal(), _pR->get(i)->getCoef()->getImg(), pRank2[i],
-                pOut->get(i)->getCoef()->getReal(), pOut->get(i)->getCoef()->getImg(), pRank[i]);
+                _pL->get(i)->get(), pRank1[i] + 1,
+                _pR->get(i)->get(), _pR->get(i)->getImg(), pRank2[i] + 1,
+                pOut->get(i)->get(), pOut->get(i)->getImg(), pRank[i] + 1);
         }
     }
     else if (bComplex1 == true && bComplex2 == false)
@@ -1905,9 +1905,9 @@ template<> InternalType* add_M_M<Polynom, Polynom, Polynom>(Polynom* _pL, Polyno
         for (int i = 0 ; i < _pL->getSize() ; i++)
         {
             iAddScilabPolynomToComplexPoly(
-                _pR->get(i)->getCoef()->getReal(), pRank2[i],
-                _pL->get(i)->getCoef()->getReal(), _pL->get(i)->getCoef()->getImg(), pRank1[i],
-                pOut->get(i)->getCoef()->getReal(), pOut->get(i)->getCoef()->getImg(), pRank[i]);
+                _pR->get(i)->get(), pRank2[i] + 1,
+                _pL->get(i)->get(), _pL->get(i)->getImg(), pRank1[i] + 1,
+                pOut->get(i)->get(), pOut->get(i)->getImg(), pRank[i] + 1);
         }
     }
     else if (bComplex1 == true && bComplex2 == true)
@@ -1915,9 +1915,9 @@ template<> InternalType* add_M_M<Polynom, Polynom, Polynom>(Polynom* _pL, Polyno
         for (int i = 0 ; i < _pL->getSize() ; i++)
         {
             iAddComplexPolyToComplexPoly(
-                _pL->get(i)->getCoef()->getReal(), _pL->get(i)->getCoef()->getImg(), pRank1[i],
-                _pR->get(i)->getCoef()->getReal(), _pR->get(i)->getCoef()->getImg(), pRank2[i],
-                pOut->get(i)->getCoef()->getReal(), pOut->get(i)->getCoef()->getImg(), pRank[i]);
+                _pL->get(i)->get(), _pL->get(i)->getImg(), pRank1[i] + 1,
+                _pR->get(i)->get(), _pR->get(i)->getImg(), pRank2[i] + 1,
+                pOut->get(i)->get(), pOut->get(i)->getImg(), pRank[i] + 1);
         }
     }
 
@@ -1970,12 +1970,12 @@ template<> InternalType* add_M_M<Double, Polynom, Polynom>(Double* _pL, Polynom*
         {
             SinglePoly *pInPoly  = _pR->get(0);
             SinglePoly *pOutPoly = pOut->get(i);
-            double *pInPolyR     = pInPoly->getCoef()->getReal();
-            double *pOutPolyR    = pOutPoly->getCoef()->getReal();
+            double *pInPolyR     = pInPoly->get();
+            double *pOutPolyR    = pOutPoly->get();
 
             pOutPolyR[0] = pInDblR[i] + pInPolyR[0];
 
-            for (int j = 1 ; j < pInPoly->getRank() ; j++)
+            for (int j = 1 ; j < pInPoly->getSize() ; j++)
             {
                 pOutPolyR[j] = pInPolyR[j];
             }
@@ -1987,12 +1987,12 @@ template<> InternalType* add_M_M<Double, Polynom, Polynom>(Double* _pL, Polynom*
             {
                 SinglePoly *pInPoly  = _pR->get(0);
                 SinglePoly *pOutPoly = pOut->get(i);
-                double *pInPolyI     = pInPoly->getCoef()->getImg();
-                double *pOutPolyI    = pOutPoly->getCoef()->getImg();
+                double *pInPolyI     = pInPoly->getImg();
+                double *pOutPolyI    = pOutPoly->getImg();
 
                 pOutPolyI[0] = (pInDblI != NULL ? pInDblI[i] : 0) + (pInPolyI != NULL ? pInPolyI[0] : 0);
 
-                for (int j = 1 ; j < pInPoly->getRank() ; j++)
+                for (int j = 1 ; j < pInPoly->getSize() ; j++)
                 {
                     pOutPolyI[j] = (pInPolyI != NULL ? pInPolyI[j] : 0);
                 }
@@ -2011,8 +2011,8 @@ template<> InternalType* add_M_M<Double, Polynom, Polynom>(Double* _pL, Polynom*
             for (int i = 0 ; i < pOut->getSize() ; i++)
             {
                 SinglePoly *pSPOut   = pOut->get(i);
-                double *pOutPolyR    = pSPOut->getCoef()->getReal();
-                double *pOutPolyI    = pSPOut->getCoef()->getImg();
+                double *pOutPolyR    = pSPOut->get();
+                double *pOutPolyI    = pSPOut->getImg();
 
                 pOutPolyR[0] += pInDblR[0];
                 pOutPolyI[0] += pInDblI[0];
@@ -2024,8 +2024,8 @@ template<> InternalType* add_M_M<Double, Polynom, Polynom>(Double* _pL, Polynom*
             for (int i = 0 ; i < pOut->getSize() ; i++)
             {
                 SinglePoly *pSPOut   = pOut->get(i);
-                double *pOutPolyR    = pSPOut->getCoef()->getReal();
-                double *pOutPolyI    = pSPOut->getCoef()->getImg();
+                double *pOutPolyR    = pSPOut->get();
+                double *pOutPolyI    = pSPOut->getImg();
 
                 pOutPolyR[0] += pInDblR[0];
                 pOutPolyI[0] = pInDblI[0];
@@ -2036,7 +2036,7 @@ template<> InternalType* add_M_M<Double, Polynom, Polynom>(Double* _pL, Polynom*
             for (int i = 0 ; i < pOut->getSize() ; i++)
             {
                 SinglePoly *pSPOut = pOut->get(i);
-                double *pOutPolyR  = pSPOut->getCoef()->getReal();
+                double *pOutPolyR  = pSPOut->get();
 
                 pOutPolyR[0] += pInDblR[0];
             }
@@ -2074,8 +2074,8 @@ template<> InternalType* add_M_M<Double, Polynom, Polynom>(Double* _pL, Polynom*
         for (int i = 0 ; i < pOut->getSize() ; i++)
         {
             SinglePoly *pSPOut   = pOut->get(i);
-            double *pOutPolyR    = pSPOut->getCoef()->getReal();
-            double *pOutPolyI    = pSPOut->getCoef()->getImg();
+            double *pOutPolyR    = pSPOut->get();
+            double *pOutPolyI    = pSPOut->getImg();
 
             pOutPolyR[0] += pInDblR[i];
             pOutPolyI[0] += pInDblI[i];
@@ -2087,8 +2087,8 @@ template<> InternalType* add_M_M<Double, Polynom, Polynom>(Double* _pL, Polynom*
         for (int i = 0 ; i < pOut->getSize() ; i++)
         {
             SinglePoly *pSPOut   = pOut->get(i);
-            double *pOutPolyR    = pSPOut->getCoef()->getReal();
-            double *pOutPolyI    = pSPOut->getCoef()->getImg();
+            double *pOutPolyR    = pSPOut->get();
+            double *pOutPolyI    = pSPOut->getImg();
 
             pOutPolyR[0] += pInDblR[i];
             pOutPolyI[0] = pInDblI[i];
@@ -2099,7 +2099,7 @@ template<> InternalType* add_M_M<Double, Polynom, Polynom>(Double* _pL, Polynom*
         for (int i = 0 ; i < pOut->getSize() ; i++)
         {
             SinglePoly *pSPOut = pOut->get(i);
-            double *pOutPolyR  = pSPOut->getCoef()->getReal();
+            double *pOutPolyR  = pSPOut->get();
 
             pOutPolyR[0] += pInDblR[i];
         }
index 7716ec1..62aac68 100644 (file)
@@ -339,7 +339,7 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
             int iSize       = pL->getSize();
             int iRank       = 0;
 
-            pR->getRealRank(&iRank);
+            pR->getRank(&iRank);
             if (iRank != 0) // check rank
             {
                 memset(piResult, 0x00, iSize * sizeof(int));
@@ -347,11 +347,11 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
             else
             {
                 // check values
-                double dR       = pR->get(0)->getCoef()->get(0);
+                double dR       = pR->get(0)->get(0);
                 double* pdblL   = pL->get();
                 if (pL->isComplex() && pR->isComplex())
                 {
-                    double dRImg    = pR->get(0)->getCoef()->getImg(0);
+                    double dRImg    = pR->get(0)->getImg(0);
                     double* pdblLImg = pL->getImg();
                     for (int i = 0 ; i < iSize; i++)
                     {
@@ -368,7 +368,7 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
                 }
                 else if (pR->isComplex())
                 {
-                    double dRImg    = pR->get(0)->getCoef()->getImg(0);
+                    double dRImg    = pR->get(0)->getImg(0);
                     for (int i = 0 ; i < iSize; i++)
                     {
                         piResult[i] = (int)((dR == pdblL[i]) && (dRImg == 0));
@@ -395,7 +395,7 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
             int* piRank     = new int[iSize];
             double dL       = pL->get(0);
 
-            pR->getRealRank(piRank);
+            pR->getRank(piRank);
 
             if (pL->isComplex() && pR->isComplex())
             {
@@ -404,8 +404,8 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
                 {
                     if (piRank[i] == 0)
                     {
-                        piResult[i] = (int)(dL == pR->get(i)->getCoef()->get(0) &&
-                                            dLImg == pR->get(i)->getCoef()->getImg(0));
+                        piResult[i] = (int)(dL == pR->get(i)->get(0) &&
+                                            dLImg == pR->get(i)->getImg(0));
                     }
                     else
                     {
@@ -420,7 +420,7 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
                 {
                     if (piRank[i] == 0)
                     {
-                        piResult[i] = (int)(dL == pR->get(i)->getCoef()->get(0) &&
+                        piResult[i] = (int)(dL == pR->get(i)->get(0) &&
                                             dLImg == 0);
                     }
                     else
@@ -435,8 +435,8 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
                 {
                     if (piRank[i] == 0)
                     {
-                        piResult[i] = (int)(dL == pR->get(i)->getCoef()->get(0) &&
-                                            pR->get(i)->getCoef()->getImg(0) == 0);
+                        piResult[i] = (int)(dL == pR->get(i)->get(0) &&
+                                            pR->get(i)->getImg(0) == 0);
                     }
                     else
                     {
@@ -448,7 +448,7 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
             {
                 for (int i = 0 ; i < iSize; i++)
                 {
-                    piResult[i] = piRank[i] ? 0 : (int)(dL == pR->get(i)->getCoef()->get(0));
+                    piResult[i] = piRank[i] ? 0 : (int)(dL == pR->get(i)->get(0));
                 }
             }
 
@@ -481,7 +481,7 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
         int* piRank     = new int[iSize];
         double* pdblL   = pL->get();
 
-        pR->getRealRank(piRank);
+        pR->getRank(piRank);
 
         if (pL->isComplex() && pR->isComplex())
         {
@@ -490,8 +490,8 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
             {
                 if (piRank[i] == 0)
                 {
-                    piResult[i] = (int)(pdblL[i] == pR->get(i)->getCoef()->get(0) &&
-                                        pdblLImg[i] == pR->get(i)->getCoef()->getImg(0));
+                    piResult[i] = (int)(pdblL[i] == pR->get(i)->get(0) &&
+                                        pdblLImg[i] == pR->get(i)->getImg(0));
                 }
                 else
                 {
@@ -506,7 +506,7 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
             {
                 if (piRank[i] == 0)
                 {
-                    piResult[i] = (int)(pdblL[i] == pR->get(i)->getCoef()->get(0) &&
+                    piResult[i] = (int)(pdblL[i] == pR->get(i)->get(0) &&
                                         pdblLImg[i] == 0);
                 }
                 else
@@ -521,8 +521,8 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
             {
                 if (piRank[i] == 0)
                 {
-                    piResult[i] = (int)(pdblL[i] == pR->get(i)->getCoef()->get(0) &&
-                                        pR->get(i)->getCoef()->getImg(0) == 0);
+                    piResult[i] = (int)(pdblL[i] == pR->get(i)->get(0) &&
+                                        pR->get(i)->getImg(0) == 0);
                 }
                 else
                 {
@@ -534,7 +534,7 @@ InternalType *GenericComparisonEqual(InternalType *_pLeftOperand, InternalType *
         {
             for (int i = 0 ; i < iSize; i++)
             {
-                piResult[i] = piRank[i] ? 0 : (int)(pdblL[i] == pR->get(i)->getCoef()->get(0));
+                piResult[i] = piRank[i] ? 0 : (int)(pdblL[i] == pR->get(i)->get(0));
             }
         }
 
index 9ecbeb3..5a51bfe 100644 (file)
@@ -365,7 +365,7 @@ int RDividePolyByDouble(Polynom* _pPoly, Double* _pDouble, Polynom** _pPolyOut)
             bool bComplex1 = _pPoly->isComplex();
             bool bComplex2 = _pDouble->isComplex();
 
-            Double* pC = (*_pPolyOut)->get(i)->getCoef();
+            SinglePoly* pC = (*_pPolyOut)->get(i);
 
             if (bComplex1 == false && bComplex2 == false)
             {
@@ -395,9 +395,10 @@ int RDividePolyByDouble(Polynom* _pPoly, Double* _pDouble, Polynom** _pPolyOut)
         iColResult = _pDouble->getRows();
 
         piRank = new int[iRowResult * iRowResult];
+        int iMaxRank = _pPoly->getMaxRank();
         for (int i = 0 ; i < iRowResult * iRowResult ; i++)
         {
-            piRank[i] = _pPoly->getMaxRank();
+            piRank[i] = iMaxRank;
         }
 
         pTemp = new Polynom(_pPoly->getVariableName(), iRowResult, iRowResult, piRank);
@@ -406,10 +407,10 @@ int RDividePolyByDouble(Polynom* _pPoly, Double* _pDouble, Polynom** _pPolyOut)
             pTemp->setComplex(true);
         }
 
-        Double *pdblData = _pPoly->get(0)->getCoef();
+        SinglePoly *pdblData = _pPoly->get(0);
         for (int i = 0 ; i < iRowResult ; i++)
         {
-            pTemp->setCoef(i, i, pdblData);
+            pTemp->set(i, i, pdblData);
         }
     }
 
@@ -426,40 +427,40 @@ int RDividePolyByDouble(Polynom* _pPoly, Double* _pDouble, Polynom** _pPolyOut)
         for (int i = 0 ; i < _pPoly->getSize() ; i++)
         {
             SinglePoly *pPolyIn   = _pPoly->get(i);
-            double* pRealIn  = pPolyIn->getCoef()->getReal();
-            double* pImgIn  = pPolyIn->getCoef()->getImg();
+            double* pRealIn  = pPolyIn->get();
+            double* pImgIn  = pPolyIn->getImg();
 
             SinglePoly *pPolyOut  = (*_pPolyOut)->get(i);
-            double* pRealOut = pPolyOut->getCoef()->getReal();
-            double* pImgOut  = pPolyOut->getCoef()->getImg();
+            double* pRealOut = pPolyOut->get();
+            double* pImgOut  = pPolyOut->getImg();
 
             if (bComplex1 == false && bComplex2 == false)
             {
                 iRightDivisionRealMatrixByRealMatrix(
                     pRealIn, 1,
                     _pDouble->getReal(), 0,
-                    pRealOut, 1, pPolyOut->getRank());
+                    pRealOut, 1, pPolyOut->getSize());
             }
             else if (bComplex1 == false && bComplex2 == true)
             {
                 iRightDivisionRealMatrixByComplexMatrix(
                     pRealIn, 1,
                     _pDouble->getReal(), _pDouble->getImg(), 0,
-                    pRealOut, pImgOut, 1, pPolyOut->getRank());
+                    pRealOut, pImgOut, 1, pPolyOut->getSize());
             }
             else if (bComplex1 == true && bComplex2 == false)
             {
                 iRightDivisionComplexMatrixByRealMatrix(
                     pRealIn, pImgIn, 1,
                     _pDouble->getReal(), 0,
-                    pRealOut, pImgOut, 1, pPolyOut->getRank());
+                    pRealOut, pImgOut, 1, pPolyOut->getSize());
             }
             else if (bComplex1 == true && bComplex2 == true)
             {
                 iRightDivisionComplexMatrixByComplexMatrix(
                     pRealIn, pImgIn, 1,
                     _pDouble->getReal(), _pDouble->getImg(), 0,
-                    pRealOut, pImgOut, 1, pPolyOut->getRank());
+                    pRealOut, pImgOut, 1, pPolyOut->getSize());
             }
         }
     }
@@ -469,7 +470,7 @@ int RDividePolyByDouble(Polynom* _pPoly, Double* _pDouble, Polynom** _pPolyOut)
         double *pReal    = pResultCoef->getReal();
         double *pImg    = pResultCoef->getImg();
 
-        for (int i = 0 ; i < pTemp->get(0)->getRank() ; i++)
+        for (int i = 0 ; i < pTemp->get(0)->getSize() ; i++)
         {
             Double *pCoef    = pTemp->extractCoef(i);
             Double *pResultCoef = new Double(iRowResult, iColResult, pCoef->isComplex());
@@ -676,7 +677,7 @@ int DotRDividePolyByDouble(Polynom* _pPoly1, Double* _pDouble2, Polynom** _pPoly
     //check dimension compatibilities ( same number of dimension and same size for each dimension
     int iDims1      = _pPoly1->getDims();
     int* piDims1    = _pPoly1->getDimsArray();
-    int iMaxRank    = _pPoly1->getMaxRank();
+    int iMaxSize    = _pPoly1->getMaxRank() + 1;
     int iSizePoly   = _pPoly1->getSize();
     int iDims2      = _pDouble2->getDims();
     int* piDims2    = _pDouble2->getDimsArray();
@@ -698,21 +699,21 @@ int DotRDividePolyByDouble(Polynom* _pPoly1, Double* _pDouble2, Polynom** _pPoly
     int* piRanks = new int[iSizePoly];
     for (int i = 0; i < iSizePoly; i++)
     {
-        piRanks[i] = iMaxRank;
+        piRanks[i] = iMaxSize - 1;
     }
 
     // create output and working table
     (*_pPolyOut) = new Polynom(_pPoly1->getVariableName(), iDims2, piDims2, piRanks);
     delete[] piRanks;
-    Double* pDblCoefOut = new Double(_pPoly1->getRows(), _pPoly1->getCols() * iMaxRank, bComplex1 || bComplex2);
-    double* pdblCoef2   = new double[_pPoly1->getRows() * _pPoly1->getCols() * iMaxRank];
+    Double* pDblCoefOut = new Double(_pPoly1->getRows(), _pPoly1->getCols() * iMaxSize, bComplex1 || bComplex2);
+    double* pdblCoef2   = new double[_pPoly1->getRows() * _pPoly1->getCols() * iMaxSize];
     Double* pDblCoef1   = _pPoly1->getCoef();
 
     int iZero = 0;
     double* pdbl = _pDouble2->get();
     for (int i = 0; i < iSizePoly; i++)
     {
-        C2F(dcopy)(&iMaxRank, pdbl + i, &iZero, pdblCoef2 + i, &iSizePoly);
+        C2F(dcopy)(&iMaxSize, pdbl + i, &iZero, pdblCoef2 + i, &iSizePoly);
     }
 
     int iInc1       = 1;
index 34c81d9..c104359 100644 (file)
@@ -528,28 +528,28 @@ int MultiplyDoubleByPoly(Double* _pDouble, Polynom* _pPoly, Polynom** _pPolyOut)
         for (int i = 0 ; i < _pPoly->getSize() ; i++)
         {
             SinglePoly *pPolyIn     = _pPoly->get(i);
-            double* pRealIn         = pPolyIn->getCoef()->get();
-            double* pImgIn          = pPolyIn->getCoef()->getImg();
+            double* pRealIn         = pPolyIn->get();
+            double* pImgIn          = pPolyIn->getImg();
 
             SinglePoly *pPolyOut    = (*_pPolyOut)->get(i);
-            double* pRealOut        = pPolyOut->getCoef()->get();
-            double* pImgOut         = pPolyOut->getCoef()->getImg();
+            double* pRealOut        = pPolyOut->get();
+            double* pImgOut         = pPolyOut->getImg();
 
             if (bComplex1 == false && bComplex2 == false)
             {
-                iMultiRealScalarByRealMatrix(_pDouble->get(0), pRealIn, 1, pPolyIn->getRank(), pRealOut);
+                iMultiRealScalarByRealMatrix(_pDouble->get(0), pRealIn, 1, pPolyIn->getSize(), pRealOut);
             }
             else if (bComplex1 == false && bComplex2 == true)
             {
-                iMultiRealScalarByComplexMatrix(_pDouble->get(0), pRealIn, pImgIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiRealScalarByComplexMatrix(_pDouble->get(0), pRealIn, pImgIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
             else if (bComplex1 == true && bComplex2 == false)
             {
-                iMultiComplexScalarByRealMatrix(_pDouble->get(0), _pDouble->getImg(0), pRealIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiComplexScalarByRealMatrix(_pDouble->get(0), _pDouble->getImg(0), pRealIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
             else if (bComplex1 == true && bComplex2 == true)
             {
-                iMultiComplexScalarByComplexMatrix(_pDouble->get(0), _pDouble->getImg(0), pRealIn, pImgIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiComplexScalarByComplexMatrix(_pDouble->get(0), _pDouble->getImg(0), pRealIn, pImgIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
         }
         (*_pPolyOut)->updateRank();
@@ -575,30 +575,30 @@ int MultiplyDoubleByPoly(Double* _pDouble, Polynom* _pPoly, Polynom** _pPolyOut)
         double *pDoubleI    = _pDouble->getImg();
 
         SinglePoly *pPolyIn = _pPoly->get(0);
-        double* pRealIn     = pPolyIn->getCoef()->get();
-        double* pImgIn      = pPolyIn->getCoef()->getImg();
+        double* pRealIn     = pPolyIn->get();
+        double* pImgIn      = pPolyIn->getImg();
 
         for (int i = 0 ; i < _pDouble->getSize() ; i++)
         {
             SinglePoly *pPolyOut    = (*_pPolyOut)->get(i);
-            double* pRealOut        = pPolyOut->getCoef()->get();
-            double* pImgOut         = pPolyOut->getCoef()->getImg();
+            double* pRealOut        = pPolyOut->get();
+            double* pImgOut         = pPolyOut->getImg();
 
             if (bComplex1 == false && bComplex2 == false)
             {
-                iMultiRealScalarByRealMatrix(pDoubleR[i], pRealIn, 1, pPolyIn->getRank(), pRealOut);
+                iMultiRealScalarByRealMatrix(pDoubleR[i], pRealIn, 1, pPolyIn->getSize(), pRealOut);
             }
             else if (bComplex1 == false && bComplex2 == true)
             {
-                iMultiRealScalarByComplexMatrix(pDoubleR[i], pRealIn, pImgIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiRealScalarByComplexMatrix(pDoubleR[i], pRealIn, pImgIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
             else if (bComplex1 == true && bComplex2 == false)
             {
-                iMultiComplexScalarByRealMatrix(pDoubleR[i], pDoubleI[i], pRealIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiComplexScalarByRealMatrix(pDoubleR[i], pDoubleI[i], pRealIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
             else if (bComplex1 == true && bComplex2 == true)
             {
-                iMultiComplexScalarByComplexMatrix(pDoubleR[i], pDoubleI[i], pRealIn, pImgIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiComplexScalarByComplexMatrix(pDoubleR[i], pDoubleI[i], pRealIn, pImgIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
         }
 
@@ -612,9 +612,10 @@ int MultiplyDoubleByPoly(Double* _pDouble, Polynom* _pPoly, Polynom** _pPolyOut)
     }
 
     int* piRank = new int[_pDouble->getRows() * _pPoly->getCols()];
+    int iMaxRank = _pPoly->getMaxRank();
     for (int i = 0 ; i < _pDouble->getRows() * _pPoly->getCols() ; i++)
     {
-        piRank[i] = _pPoly->getMaxRank();
+        piRank[i] = iMaxRank;
     }
 
     (*_pPolyOut) = new Polynom(_pPoly->getVariableName(), _pDouble->getRows(), _pPoly->getCols(), piRank);
@@ -685,30 +686,30 @@ int MultiplyPolyByDouble(Polynom* _pPoly, Double* _pDouble, Polynom **_pPolyOut)
         double *pDoubleI    = _pDouble->getImg();
 
         SinglePoly *pPolyIn = _pPoly->get(0);
-        double* pRealIn     = pPolyIn->getCoef()->get();
-        double* pImgIn      = pPolyIn->getCoef()->getImg();
+        double* pRealIn     = pPolyIn->get();
+        double* pImgIn      = pPolyIn->getImg();
 
         for (int i = 0 ; i < _pDouble->getSize() ; i++)
         {
             SinglePoly *pPolyOut    = (*_pPolyOut)->get(i);
-            double* pRealOut        = pPolyOut->getCoef()->get();
-            double* pImgOut         = pPolyOut->getCoef()->getImg();
+            double* pRealOut        = pPolyOut->get();
+            double* pImgOut         = pPolyOut->getImg();
 
             if (bComplex1 == false && bComplex2 == false)
             {
-                iMultiRealScalarByRealMatrix(pDoubleR[i], pRealIn, 1, pPolyIn->getRank(), pRealOut);
+                iMultiRealScalarByRealMatrix(pDoubleR[i], pRealIn, 1, pPolyIn->getSize(), pRealOut);
             }
             else if (bComplex1 == false && bComplex2 == true)
             {
-                iMultiComplexScalarByRealMatrix(pDoubleR[i], pDoubleI[i], pRealIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiComplexScalarByRealMatrix(pDoubleR[i], pDoubleI[i], pRealIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
             else if (bComplex1 == true && bComplex2 == false)
             {
-                iMultiRealScalarByComplexMatrix(pDoubleR[i], pRealIn, pImgIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiRealScalarByComplexMatrix(pDoubleR[i], pRealIn, pImgIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
             else if (bComplex1 == true && bComplex2 == true)
             {
-                iMultiComplexScalarByComplexMatrix(pDoubleR[i], pDoubleI[i], pRealIn, pImgIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiComplexScalarByComplexMatrix(pDoubleR[i], pDoubleI[i], pRealIn, pImgIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
         }
 
@@ -733,28 +734,28 @@ int MultiplyPolyByDouble(Polynom* _pPoly, Double* _pDouble, Polynom **_pPolyOut)
         for (int i = 0 ; i < _pPoly->getSize() ; i++)
         {
             SinglePoly *pPolyIn = _pPoly->get(i);
-            double* pRealIn     = pPolyIn->getCoef()->get();
-            double* pImgIn      = pPolyIn->getCoef()->getImg();
+            double* pRealIn     = pPolyIn->get();
+            double* pImgIn      = pPolyIn->getImg();
 
             SinglePoly *pPolyOut    = (*_pPolyOut)->get(i);
-            double* pRealOut        = pPolyOut->getCoef()->get();
-            double* pImgOut         = pPolyOut->getCoef()->getImg();
+            double* pRealOut        = pPolyOut->get();
+            double* pImgOut         = pPolyOut->getImg();
 
             if (bComplex1 == false && bComplex2 == false)
             {
-                iMultiRealScalarByRealMatrix(_pDouble->get(0), pRealIn, 1, pPolyIn->getRank(), pRealOut);
+                iMultiRealScalarByRealMatrix(_pDouble->get(0), pRealIn, 1, pPolyIn->getSize(), pRealOut);
             }
             else if (bComplex1 == false && bComplex2 == true)
             {
-                iMultiComplexScalarByRealMatrix(_pDouble->get(0), _pDouble->getImg(0), pRealIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiComplexScalarByRealMatrix(_pDouble->get(0), _pDouble->getImg(0), pRealIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
             else if (bComplex1 == true && bComplex2 == false)
             {
-                iMultiRealScalarByComplexMatrix(_pDouble->get(0), pRealIn, pImgIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiRealScalarByComplexMatrix(_pDouble->get(0), pRealIn, pImgIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
             else if (bComplex1 == true && bComplex2 == true)
             {
-                iMultiComplexScalarByComplexMatrix(_pDouble->get(0), _pDouble->getImg(0), pRealIn, pImgIn, 1, pPolyIn->getRank(), pRealOut, pImgOut);
+                iMultiComplexScalarByComplexMatrix(_pDouble->get(0), _pDouble->getImg(0), pRealIn, pImgIn, 1, pPolyIn->getSize(), pRealOut, pImgOut);
             }
         }
 
@@ -768,9 +769,10 @@ int MultiplyPolyByDouble(Polynom* _pPoly, Double* _pDouble, Polynom **_pPolyOut)
     }
 
     int* piRank = new int[_pPoly->getRows() * _pDouble->getCols()];
+    int iMaxRank = _pPoly->getMaxRank();
     for (int i = 0 ; i < _pPoly->getRows() * _pDouble->getCols() ; i++)
     {
-        piRank[i] = _pPoly->getMaxRank();
+        piRank[i] = iMaxRank;
     }
 
     (*_pPolyOut) = new Polynom(_pPoly->getVariableName(), _pPoly->getRows(), _pDouble->getCols(), piRank);
@@ -780,7 +782,6 @@ int MultiplyPolyByDouble(Polynom* _pPoly, Double* _pDouble, Polynom **_pPolyOut)
         (*_pPolyOut)->setComplex(true);
     }
 
-
     //Distribution a la mano par appels a des sous-fonctions ( iMulti...ScalarBy...Scalar ) plus iAdd...To... )
 
     //for each line of _pPoly
@@ -789,51 +790,47 @@ int MultiplyPolyByDouble(Polynom* _pPoly, Double* _pDouble, Polynom **_pPolyOut)
         //for each col of _pDouble
         for (int iCol2 = 0 ; iCol2 < _pDouble->getCols() ; iCol2++)
         {
+            SinglePoly* pSPOut = (*_pPolyOut)->get(iRow1, iCol2);
+            pSPOut->setZeros();
+
             //for each rows of _pDouble / cols of _pPoly
             for (int iRow2 = 0 ; iRow2 < _pDouble->getRows() ; iRow2++)
             {
-                Double *pPolyCoef = _pPoly->get(iRow1, iRow2)->getCoef();
+                // SinglePoly(iRow1, iRow2) * Double(iRow2, iCol2)
+                SinglePoly* pSPIn = _pPoly->get(iRow1, iRow2);
+                int iSize = pSPIn->getSize();
+                double* pdblMult = new double[iSize];
 
-                Double *pDouble = NULL;
-                if (bComplex2 == false)
+                if (bComplex1 == false && bComplex2 == false)
                 {
-                    pDouble = new Double(_pDouble->get(iRow2, iCol2));
+                    //Real Matrix by Real Scalar
+                    iMultiRealScalarByRealMatrix(_pDouble->get(iRow2, iCol2), pSPIn->get(), iSize, 1, pdblMult);
+                    add(pSPOut->get(), (long long)iSize, pdblMult, pSPOut->get());
                 }
-                else
+                else if (bComplex1 == false && bComplex2 == true)
                 {
-                    pDouble = new Double(_pDouble->get(iRow2, iCol2), _pDouble->getImg(iRow2, iCol2));
+                    //Real Matrix by Scalar Complex
+                    double* pdblMultImg = new double[iSize];
+                    iMultiComplexScalarByRealMatrix(_pDouble->get(iRow2, iCol2), _pDouble->getImg(iRow2, iCol2), pSPIn->get(), pSPIn->getSize(), 1, pdblMult, pdblMultImg);
+                    add(pSPOut->get(), pSPOut->getImg(), (long long)iSize, pdblMult, pdblMultImg, pSPOut->get(), pSPOut->getImg());
+                    delete[] pdblMultImg;
                 }
-
-                Double *TimeDouble = NULL; //(pPolyCoef->getRows(), pPolyCoef->getCols(), bComplexOut);
-                MultiplyDoubleByDouble(pPolyCoef, pDouble, &TimeDouble);
-
-                //Adjust size to allow vector multiplication
-                Double* pCoef = (*_pPolyOut)->get(iRow1, iCol2)->getCoef();
-
-                if (TimeDouble->getRows() > pCoef->getRows())
+                else if (bComplex1 == true && bComplex2 == false)
                 {
-                    pCoef->resize(TimeDouble->getRows(), pCoef->getCols());
+                    double* pdblMultImg = new double[iSize];
+                    iMultiRealScalarByComplexMatrix(_pDouble->get(iRow2, iCol2), pSPIn->get(), pSPIn->getImg(), pSPIn->getSize(), 1, pdblMult, pdblMultImg);
+                    add(pSPOut->get(), pSPOut->getImg(), (long long)iSize, pdblMult, pdblMultImg, pSPOut->get(), pSPOut->getImg());
+                    delete[] pdblMultImg;
                 }
-                else if (TimeDouble->getRows() < pCoef->getRows())
+                else //if(bComplex1 == true && bComplex2 == true)
                 {
-                    TimeDouble->resize(pCoef->getRows(), TimeDouble->getCols());
+                    double* pdblMultImg = new double[iSize];
+                    iMultiComplexScalarByComplexMatrix(_pDouble->get(iRow2, iCol2), _pDouble->getImg(iRow2, iCol2), pSPIn->get(), pSPIn->getImg(), pSPIn->getSize(), 1, pdblMult, pdblMultImg);
+                    add(pSPOut->get(), pSPOut->getImg(), (long long)iSize, pdblMult, pdblMultImg, pSPOut->get(), pSPOut->getImg());
+                    delete[] pdblMultImg;
                 }
 
-                if (TimeDouble->getCols() > pCoef->getCols())
-                {
-                    pCoef->resize(pCoef->getRows(), TimeDouble->getCols());
-                }
-                else if (TimeDouble->getCols() < pCoef->getCols())
-                {
-                    TimeDouble->resize(TimeDouble->getRows(), pCoef->getCols());
-                }
-
-                add_function pAdd = getAddFunction(TimeDouble->getId(), pCoef->getId());
-                Double *pAddDouble = (Double*)pAdd(TimeDouble, pCoef);
-                (*_pPolyOut)->setCoef(iRow1, iCol2, pAddDouble);
-
-                delete pAddDouble;
-                delete pDouble;
+                delete[] pdblMult;
             }//for(int iRow2 = 0 ; iRow2 < _pDouble->getRows() ; iRow2++)
         }//for(int iCol2 = 0 ; iCol2 < _pDouble->getCols() ; iCol2++)
     }//for(int iRow1 = 0 ; iRow1 < _pPoly->getRows() ; iRow1++)
@@ -850,15 +847,12 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
     if (_pPoly1->isScalar() && _pPoly2->isScalar())
     {
         //poly1(0) * poly2(0)
-        int* piRank = new int[1];
-        piRank[0] = _pPoly1->get(0)->getRealRank() + _pPoly2->get(0)->getRealRank() + 1;
-
-        (*_pPolyOut) = new Polynom(_pPoly1->getVariableName(), 1, 1, piRank);
+        int iRank = _pPoly1->get(0)->getRank() + _pPoly2->get(0)->getRank();
+        (*_pPolyOut) = new Polynom(_pPoly1->getVariableName(), 1, 1, &iRank);
         if (bComplex1 || bComplex2)
         {
             (*_pPolyOut)->setComplex(true);
         }
-        delete[] piRank;
 
         if (bComplex1 == false && bComplex2 == false)
         {
@@ -866,12 +860,12 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
             SinglePoly *pPoly2  = _pPoly2->get(0);
             SinglePoly *pPolyOut = (*_pPolyOut)->get(0);
 
-            pPolyOut->getCoef()->setZeros();
+            pPolyOut->setZeros();
 
             iMultiScilabPolynomByScilabPolynom(
-                pPoly1->getCoef()->get(), pPoly1->getRank(),
-                pPoly2->getCoef()->get(), pPoly2->getRank(),
-                pPolyOut->getCoef()->get(), pPolyOut->getRank());
+                pPoly1->get(), pPoly1->getSize(),
+                pPoly2->get(), pPoly2->getSize(),
+                pPolyOut->get(), pPolyOut->getSize());
         }
         else if (bComplex1 == false && bComplex2 == true)
         {
@@ -879,12 +873,12 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
             SinglePoly *pPoly2  = _pPoly2->get(0);
             SinglePoly *pPolyOut = (*_pPolyOut)->get(0);
 
-            pPolyOut->getCoef()->setZeros();
+            pPolyOut->setZeros();
 
             iMultiScilabPolynomByComplexPoly(
-                pPoly1->getCoef()->get(), pPoly1->getRank(),
-                pPoly2->getCoef()->get(), pPoly2->getCoef()->getImg(), pPoly2->getRank(),
-                pPolyOut->getCoef()->get(), pPolyOut->getCoef()->getImg(), pPolyOut->getRank());
+                pPoly1->get(), pPoly1->getSize(),
+                pPoly2->get(), pPoly2->getImg(), pPoly2->getSize(),
+                pPolyOut->get(), pPolyOut->getImg(), pPolyOut->getSize());
         }
         else if (bComplex1 == true && bComplex2 == false)
         {
@@ -892,28 +886,25 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
             SinglePoly *pPoly2  = _pPoly2->get(0);
             SinglePoly *pPolyOut = (*_pPolyOut)->get(0);
 
-            pPolyOut->getCoef()->setZeros();
+            pPolyOut->setZeros();
 
             iMultiComplexPolyByScilabPolynom(
-                pPoly1->getCoef()->get(), pPoly1->getCoef()->getImg(), pPoly1->getRank(),
-                pPoly2->getCoef()->get(), pPoly2->getRank(),
-                pPolyOut->getCoef()->get(), pPolyOut->getCoef()->getImg(), pPolyOut->getRank());
+                pPoly1->get(), pPoly1->getImg(), pPoly1->getSize(),
+                pPoly2->get(), pPoly2->getSize(),
+                pPolyOut->get(), pPolyOut->getImg(), pPolyOut->getSize());
         }
         else if (bComplex1 == true && bComplex2 == true)
         {
             SinglePoly *pPoly1   = _pPoly1->get(0);
             SinglePoly *pPoly2   = _pPoly2->get(0);
             SinglePoly *pPolyOut  = (*_pPolyOut)->get(0);
-            Double *pCoef1  = pPoly1->getCoef();
-            Double *pCoef2  = pPoly2->getCoef();
-            Double *pCoefOut = pPolyOut->getCoef();
 
-            pCoefOut->setZeros();
+            pPolyOut->setZeros();
 
             iMultiComplexPolyByComplexPoly(
-                pCoef1->get(), pCoef1->getImg(), pPoly1->getRank(),
-                pCoef2->get(), pCoef2->getImg(), pPoly2->getRank(),
-                pCoefOut->get(), pCoefOut->getImg(), pPolyOut->getRank());
+                pPoly1->get(), pPoly1->getImg(), pPoly1->getSize(),
+                pPoly2->get(), pPoly2->getImg(), pPoly2->getSize(),
+                pPolyOut->get(), pPolyOut->getImg(), pPolyOut->getSize());
         }
 
         (*_pPolyOut)->updateRank();
@@ -926,7 +917,7 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
         int* piRank = new int[_pPoly2->getSize()];
         for (int i = 0 ; i < _pPoly2->getSize() ; i++)
         {
-            piRank[i] = _pPoly1->get(0)->getRealRank() + _pPoly2->get(i)->getRealRank() + 1;
+            piRank[i] = _pPoly1->get(0)->getRank() + _pPoly2->get(i)->getRank();
         }
 
         (*_pPolyOut) = new Polynom(_pPoly1->getVariableName(), _pPoly2->getDims(), _pPoly2->getDimsArray(), piRank);
@@ -945,12 +936,12 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
                 SinglePoly *pPoly2  = _pPoly2->get(iPoly);
                 SinglePoly *pPolyOut = (*_pPolyOut)->get(iPoly);
 
-                pPolyOut->getCoef()->setZeros();
+                pPolyOut->setZeros();
 
                 iMultiScilabPolynomByScilabPolynom(
-                    pPoly1->getCoef()->get(), pPoly1->getRank(),
-                    pPoly2->getCoef()->get(), pPoly2->getRank(),
-                    pPolyOut->getCoef()->get(), pPolyOut->getRank());
+                    pPoly1->get(), pPoly1->getSize(),
+                    pPoly2->get(), pPoly2->getSize(),
+                    pPolyOut->get(), pPolyOut->getSize());
             }
         }
         else if (bComplex1 == false && bComplex2 == true)
@@ -960,12 +951,12 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
                 SinglePoly *pPoly2  = _pPoly2->get(iPoly);
                 SinglePoly *pPolyOut = (*_pPolyOut)->get(iPoly);
 
-                pPolyOut->getCoef()->setZeros();
+                pPolyOut->setZeros();
 
                 iMultiScilabPolynomByComplexPoly(
-                    pPoly1->getCoef()->get(), pPoly1->getRank(),
-                    pPoly2->getCoef()->get(), pPoly2->getCoef()->getImg(), pPoly2->getRank(),
-                    pPolyOut->getCoef()->get(), pPolyOut->getCoef()->getImg(), pPolyOut->getRank());
+                    pPoly1->get(), pPoly1->getSize(),
+                    pPoly2->get(), pPoly2->getImg(), pPoly2->getSize(),
+                    pPolyOut->get(), pPolyOut->getImg(), pPolyOut->getSize());
             }
         }
         else if (bComplex1 == true && bComplex2 == false)
@@ -975,30 +966,27 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
                 SinglePoly *pPoly2  = _pPoly2->get(iPoly);
                 SinglePoly *pPolyOut = (*_pPolyOut)->get(iPoly);
 
-                pPolyOut->getCoef()->setZeros();
+                pPolyOut->setZeros();
 
                 iMultiComplexPolyByScilabPolynom(
-                    pPoly1->getCoef()->get(), pPoly1->getCoef()->getImg(), pPoly1->getRank(),
-                    pPoly2->getCoef()->get(), pPoly2->getRank(),
-                    pPolyOut->getCoef()->get(), pPolyOut->getCoef()->getImg(), pPolyOut->getRank());
+                    pPoly1->get(), pPoly1->getImg(), pPoly1->getSize(),
+                    pPoly2->get(), pPoly2->getSize(),
+                    pPolyOut->get(), pPolyOut->getImg(), pPolyOut->getSize());
             }
         }
         else if (bComplex1 == true && bComplex2 == true)
         {
-            Double *pCoef1  = pPoly1->getCoef();
             for (int iPoly = 0 ; iPoly < _pPoly2->getSize() ; iPoly++)
             {
                 SinglePoly *pPoly2   = _pPoly2->get(iPoly);
                 SinglePoly *pPolyOut  = (*_pPolyOut)->get(iPoly);
-                Double *pCoef2  = pPoly2->getCoef();
-                Double *pCoefOut = pPolyOut->getCoef();
 
-                pCoefOut->setZeros();
+                pPolyOut->setZeros();
 
                 iMultiComplexPolyByComplexPoly(
-                    pCoef1->get(), pCoef1->getImg(), pPoly1->getRank(),
-                    pCoef2->get(), pCoef2->getImg(), pPoly2->getRank(),
-                    pCoefOut->get(), pCoefOut->getImg(), pPolyOut->getRank());
+                    pPoly1->get(), pPoly1->getImg(), pPoly1->getSize(),
+                    pPoly2->get(), pPoly2->getImg(), pPoly2->getSize(),
+                    pPolyOut->get(), pPolyOut->getImg(), pPolyOut->getSize());
             }
         }
 
@@ -1012,7 +1000,7 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
         int* piRank = new int[_pPoly1->getSize()];
         for (int i = 0 ; i < _pPoly1->getSize() ; i++)
         {
-            piRank[i] = _pPoly2->get(0)->getRealRank() + _pPoly1->get(i)->getRealRank() + 1;
+            piRank[i] = _pPoly2->get(0)->getRank() + _pPoly1->get(i)->getRank();
         }
 
         (*_pPolyOut) = new Polynom(_pPoly1->getVariableName(), _pPoly1->getDims(), _pPoly1->getDimsArray(), piRank);
@@ -1030,12 +1018,12 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
                 SinglePoly *pPoly1  = _pPoly1->get(iPoly);
                 SinglePoly *pPolyOut = (*_pPolyOut)->get(iPoly);
 
-                pPolyOut->getCoef()->setZeros();
+                pPolyOut->setZeros();
 
                 iMultiScilabPolynomByScilabPolynom(
-                    pPoly1->getCoef()->get(), pPoly1->getRank(),
-                    pPoly2->getCoef()->get(), pPoly2->getRank(),
-                    pPolyOut->getCoef()->get(), pPolyOut->getRank());
+                    pPoly1->get(), pPoly1->getSize(),
+                    pPoly2->get(), pPoly2->getSize(),
+                    pPolyOut->get(), pPolyOut->getSize());
             }
         }
         else if (bComplex1 == false && bComplex2 == true)
@@ -1045,12 +1033,12 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
                 SinglePoly *pPoly1  = _pPoly1->get(iPoly);
                 SinglePoly *pPolyOut = (*_pPolyOut)->get(iPoly);
 
-                pPolyOut->getCoef()->setZeros();
+                pPolyOut->setZeros();
 
                 iMultiScilabPolynomByComplexPoly(
-                    pPoly1->getCoef()->get(), pPoly1->getRank(),
-                    pPoly2->getCoef()->get(), pPoly2->getCoef()->getImg(), pPoly2->getRank(),
-                    pPolyOut->getCoef()->get(), pPolyOut->getCoef()->getImg(), pPolyOut->getRank());
+                    pPoly1->get(), pPoly1->getSize(),
+                    pPoly2->get(), pPoly2->getImg(), pPoly2->getSize(),
+                    pPolyOut->get(), pPolyOut->getImg(), pPolyOut->getSize());
             }
         }
         else if (bComplex1 == true && bComplex2 == false)
@@ -1060,30 +1048,27 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
                 SinglePoly *pPoly1  = _pPoly1->get(iPoly);
                 SinglePoly *pPolyOut = (*_pPolyOut)->get(iPoly);
 
-                pPolyOut->getCoef()->setZeros();
+                pPolyOut->setZeros();
 
                 iMultiComplexPolyByScilabPolynom(
-                    pPoly1->getCoef()->get(), pPoly1->getCoef()->getImg(), pPoly1->getRank(),
-                    pPoly2->getCoef()->get(), pPoly2->getRank(),
-                    pPolyOut->getCoef()->get(), pPolyOut->getCoef()->getImg(), pPolyOut->getRank());
+                    pPoly1->get(), pPoly1->getImg(), pPoly1->getSize(),
+                    pPoly2->get(), pPoly2->getSize(),
+                    pPolyOut->get(), pPolyOut->getImg(), pPolyOut->getSize());
             }
         }
         else if (bComplex1 == true && bComplex2 == true)
         {
-            Double *pCoef2  = pPoly2->getCoef();
             for (int iPoly = 0 ; iPoly < _pPoly1->getSize() ; iPoly++)
             {
                 SinglePoly *pPoly1   = _pPoly1->get(iPoly);
                 SinglePoly *pPolyOut  = (*_pPolyOut)->get(iPoly);
-                Double *pCoef1  = pPoly1->getCoef();
-                Double *pCoefOut = pPolyOut->getCoef();
 
-                pCoefOut->setZeros();
+                pPolyOut->setZeros();
 
                 iMultiComplexPolyByComplexPoly(
-                    pCoef1->get(), pCoef1->getImg(), pPoly1->getRank(),
-                    pCoef2->get(), pCoef2->getImg(), pPoly2->getRank(),
-                    pCoefOut->get(), pCoefOut->getImg(), pPolyOut->getRank());
+                    pPoly1->get(), pPoly1->getImg(), pPoly1->getSize(),
+                    pPoly2->get(), pPoly2->getImg(), pPoly2->getSize(),
+                    pPolyOut->get(), pPolyOut->getImg(), pPolyOut->getSize());
             }
         }
 
@@ -1098,9 +1083,10 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
 
     // matrix by matrix
     int* piRank = new int[_pPoly1->getRows() * _pPoly2->getCols()];
+    int iMaxRank = _pPoly1->getMaxRank() + _pPoly2->getMaxRank();
     for (int i = 0 ; i < _pPoly1->getRows() * _pPoly2->getCols() ; i++)
     {
-        piRank[i] = _pPoly1->getMaxRank() + _pPoly2->getMaxRank() - 1;
+        piRank[i] = iMaxRank;
     }
 
     (*_pPolyOut) = new Polynom(_pPoly1->getVariableName(), _pPoly1->getRows(), _pPoly2->getCols(), piRank);
@@ -1122,24 +1108,24 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
             for (int iCol = 0 ; iCol < _pPoly2->getCols() ; iCol++)
             {
                 SinglePoly *pResult = (*_pPolyOut)->get(iRow, iCol);
-                pResult->getCoef()->setZeros();
+                pResult->setZeros();
 
                 for (int iCommon = 0 ; iCommon < _pPoly1->getCols() ; iCommon++)
                 {
                     SinglePoly *pL   = _pPoly1->get(iRow, iCommon);
                     SinglePoly *pR   = _pPoly2->get(iCommon, iCol);
 
-                    pTemp->getCoef()->setZeros();
+                    pTemp->setZeros();
 
                     iMultiScilabPolynomByScilabPolynom(
-                        pL->getCoef()->get(), pL->getRank(),
-                        pR->getCoef()->get(), pR->getRank(),
-                        pTemp->getCoef()->get(), pL->getRank() + pR->getRank() - 1);
+                        pL->get(), pL->getSize(),
+                        pR->get(), pR->getSize(),
+                        pTemp->get(), pL->getRank() + pR->getRank() + 1);
 
                     iAddScilabPolynomToScilabPolynom(
-                        pResult->getCoef()->get(), pResult->getRank(),
-                        pTemp->getCoef()->get(), pResult->getRank(),
-                        pResult->getCoef()->get(), pResult->getRank());
+                        pResult->get(), pResult->getSize(),
+                        pTemp->get(), pResult->getSize(),
+                        pResult->get(), pResult->getSize());
                 }
             }
         }
@@ -1155,24 +1141,24 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
             for (int iCol = 0 ; iCol < _pPoly2->getCols() ; iCol++)
             {
                 SinglePoly *pResult = (*_pPolyOut)->get(iRow, iCol);
-                pResult->getCoef()->setZeros();
+                pResult->setZeros();
 
                 for (int iCommon = 0 ; iCommon < _pPoly1->getCols() ; iCommon++)
                 {
                     SinglePoly *pL   = _pPoly1->get(iRow, iCommon);
                     SinglePoly *pR   = _pPoly2->get(iCommon, iCol);
 
-                    pTemp->getCoef()->setZeros();
+                    pTemp->setZeros();
 
                     iMultiScilabPolynomByComplexPoly(
-                        pL->getCoef()->get(), pL->getRank(),
-                        pR->getCoef()->get(), pR->getCoef()->getImg(), pR->getRank(),
-                        pTemp->getCoef()->get(), pTemp->getCoef()->getImg(), pL->getRank() + pR->getRank() - 1);
+                        pL->get(), pL->getSize(),
+                        pR->get(), pR->getImg(), pR->getSize(),
+                        pTemp->get(), pTemp->getImg(), pL->getRank() + pR->getRank() + 1);
 
                     iAddComplexPolyToComplexPoly(
-                        pResult->getCoef()->get(), pResult->getCoef()->getImg(), pResult->getRank(),
-                        pTemp->getCoef()->get(), pTemp->getCoef()->getImg(), pResult->getRank(),
-                        pResult->getCoef()->get(), pResult->getCoef()->getImg(), pResult->getRank());
+                        pResult->get(), pResult->getImg(), pResult->getSize(),
+                        pTemp->get(), pTemp->getImg(), pResult->getSize(),
+                        pResult->get(), pResult->getImg(), pResult->getSize());
                 }
             }
         }
@@ -1188,24 +1174,24 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
             for (int iCol = 0 ; iCol < _pPoly2->getCols() ; iCol++)
             {
                 SinglePoly *pResult = (*_pPolyOut)->get(iRow, iCol);
-                pResult->getCoef()->setZeros();
+                pResult->setZeros();
 
                 for (int iCommon = 0 ; iCommon < _pPoly1->getCols() ; iCommon++)
                 {
                     SinglePoly *pL   = _pPoly1->get(iRow, iCommon);
                     SinglePoly *pR   = _pPoly2->get(iCommon, iCol);
 
-                    pTemp->getCoef()->setZeros();
+                    pTemp->setZeros();
 
                     iMultiScilabPolynomByComplexPoly(
-                        pR->getCoef()->get(), pR->getRank(),
-                        pL->getCoef()->get(), pL->getCoef()->getImg(), pL->getRank(),
-                        pTemp->getCoef()->get(), pTemp->getCoef()->getImg(), pL->getRank() + pR->getRank() - 1);
+                        pR->get(), pR->getSize(),
+                        pL->get(), pL->getImg(), pL->getSize(),
+                        pTemp->get(), pTemp->getImg(), pL->getRank() + pR->getRank() + 1);
 
                     iAddComplexPolyToComplexPoly(
-                        pResult->getCoef()->get(), pResult->getCoef()->getImg(), pResult->getRank(),
-                        pTemp->getCoef()->get(), pTemp->getCoef()->getImg(), pResult->getRank(),
-                        pResult->getCoef()->get(), pResult->getCoef()->getImg(), pResult->getRank());
+                        pResult->get(), pResult->getImg(), pResult->getSize(),
+                        pTemp->get(), pTemp->getImg(), pResult->getSize(),
+                        pResult->get(), pResult->getImg(), pResult->getSize());
                 }
             }
         }
@@ -1221,24 +1207,24 @@ int MultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOut)
             for (int iCol = 0 ; iCol < _pPoly2->getCols() ; iCol++)
             {
                 SinglePoly *pResult = (*_pPolyOut)->get(iRow, iCol);
-                pResult->getCoef()->setZeros();
+                pResult->setZeros();
 
                 for (int iCommon = 0 ; iCommon < _pPoly1->getCols() ; iCommon++)
                 {
                     SinglePoly *pL   = _pPoly1->get(iRow, iCommon);
                     SinglePoly *pR   = _pPoly2->get(iCommon, iCol);
 
-                    pTemp->getCoef()->setZeros();
+                    pTemp->setZeros();
 
                     iMultiComplexPolyByComplexPoly(
-                        pL->getCoef()->get(), pL->getCoef()->getImg(), pL->getRank(),
-                        pR->getCoef()->get(), pR->getCoef()->getImg(), pR->getRank(),
-                        pTemp->getCoef()->get(), pTemp->getCoef()->getImg(), pL->getRank() + pR->getRank() - 1);
+                        pL->get(), pL->getImg(), pL->getSize(),
+                        pR->get(), pR->getImg(), pR->getSize(),
+                        pTemp->get(), pTemp->getImg(), pL->getRank() + pR->getRank() + 1);
 
                     iAddComplexPolyToComplexPoly(
-                        pResult->getCoef()->get(), pResult->getCoef()->getImg(), pResult->getRank(),
-                        pTemp->getCoef()->get(), pTemp->getCoef()->getImg(), pResult->getRank(),
-                        pResult->getCoef()->get(), pResult->getCoef()->getImg(), pResult->getRank());
+                        pResult->get(), pResult->getImg(), pResult->getSize(),
+                        pTemp->get(), pTemp->getImg(), pResult->getSize(),
+                        pResult->get(), pResult->getImg(), pResult->getSize());
                 }
             }
         }
@@ -1680,14 +1666,18 @@ int DotMultiplyPolyByDouble(Polynom* _pPoly, Double* _pDouble, Polynom** _pPolyO
 
 int DotMultiplyDoubleByPoly(Double* _pDouble, Polynom* _pPoly, Polynom** _pPolyOut)
 {
+    int iSize = _pDouble->getSize();
     if (_pDouble->isScalar() == false &&
             _pPoly->isScalar() == false &&
-            _pDouble->getSize() != _pPoly->getSize())
+            iSize != _pPoly->getSize())
     {
         return 1;
     }
 
-    Polynom* pPolyTemp = new Polynom(_pPoly->getVariableName(), _pDouble->getDims(), _pDouble->getDimsArray());
+    int* piRanks = new int[iSize];
+    memset(piRanks, 0x00, iSize * sizeof(int));
+    Polynom* pPolyTemp = new Polynom(_pPoly->getVariableName(), _pDouble->getDims(), _pDouble->getDimsArray(), piRanks);
+    delete[] piRanks;
     pPolyTemp->setCoef(_pDouble);
     int iErr = DotMultiplyPolyByPoly(pPolyTemp, _pPoly, _pPolyOut);
     delete pPolyTemp;
@@ -1710,7 +1700,7 @@ int DotMultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOu
         int* piRank = new int[_pPoly1->getSize()];
         for (int i = 0 ; i < _pPoly1->getSize() ; i++)
         {
-            piRank[i] = _pPoly1->get(i)->getRank() + _pPoly2->get(i)->getRank() - 1;
+            piRank[i] = _pPoly1->get(i)->getRank() + _pPoly2->get(i)->getRank();
         }
 
         (*_pPolyOut) = new Polynom(_pPoly1->getVariableName(), _pPoly1->getDims(), _pPoly1->getDimsArray(), piRank);
@@ -1723,16 +1713,13 @@ int DotMultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOu
                 SinglePoly *pSP1    = _pPoly1->get(i);
                 SinglePoly *pSP2    = _pPoly2->get(i);
                 SinglePoly *pSPOut  = (*_pPolyOut)->get(i);
-                Double *pCoef1      = pSP1->getCoef();
-                Double *pCoef2      = pSP2->getCoef();
-                Double *pCoefOut    = pSPOut->getCoef();
 
-                pCoefOut->setZeros();
+                pSPOut->setZeros();
 
                 iMultiComplexPolyByComplexPoly(
-                    pCoef1->get(), pCoef1->getImg(), pSP1->getRank(),
-                    pCoef2->get(), pCoef2->getImg(), pSP2->getRank(),
-                    pCoefOut->get(), pCoefOut->getImg(), pSPOut->getRank());
+                    pSP1->get(), pSP1->getImg(), pSP1->getSize(),
+                    pSP2->get(), pSP2->getImg(), pSP2->getSize(),
+                    pSPOut->get(), pSPOut->getImg(), pSPOut->getSize());
 
             }
         }
@@ -1745,12 +1732,12 @@ int DotMultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOu
                 SinglePoly *pSP2   = _pPoly2->get(i);
                 SinglePoly *pSPOut = (*_pPolyOut)->get(i);
 
-                pSPOut->getCoef()->setZeros();
+                pSPOut->setZeros();
 
                 iMultiComplexPolyByScilabPolynom(
-                    pSP1->getCoef()->get(), pSP1->getCoef()->getImg(), pSP1->getRank(),
-                    pSP2->getCoef()->get(), pSP2->getRank(),
-                    pSPOut->getCoef()->get(), pSPOut->getCoef()->getImg(), pSPOut->getRank());
+                    pSP1->get(), pSP1->getImg(), pSP1->getSize(),
+                    pSP2->get(), pSP2->getSize(),
+                    pSPOut->get(), pSPOut->getImg(), pSPOut->getSize());
             }
         }
         else if (_pPoly2->isComplex())
@@ -1762,12 +1749,12 @@ int DotMultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOu
                 SinglePoly *pSP2   = _pPoly2->get(i);
                 SinglePoly *pSPOut = (*_pPolyOut)->get(i);
 
-                pSPOut->getCoef()->setZeros();
+                pSPOut->setZeros();
 
                 iMultiScilabPolynomByComplexPoly(
-                    pSP1->getCoef()->get(), pSP1->getRank(),
-                    pSP2->getCoef()->get(), pSP2->getCoef()->getImg(), pSP2->getRank(),
-                    pSPOut->getCoef()->get(), pSPOut->getCoef()->getImg(), pSPOut->getRank());
+                    pSP1->get(), pSP1->getSize(),
+                    pSP2->get(), pSP2->getImg(), pSP2->getSize(),
+                    pSPOut->get(), pSPOut->getImg(), pSPOut->getSize());
             }
         }
         else
@@ -1778,12 +1765,12 @@ int DotMultiplyPolyByPoly(Polynom* _pPoly1, Polynom* _pPoly2, Polynom** _pPolyOu
                 SinglePoly *pSP2   = _pPoly2->get(i);
                 SinglePoly *pSPOut = (*_pPolyOut)->get(i);
 
-                pSPOut->getCoef()->setZeros();
+                pSPOut->setZeros();
 
                 iMultiScilabPolynomByScilabPolynom(
-                    pSP1->getCoef()->get(), pSP1->getRank(),
-                    pSP2->getCoef()->get(), pSP2->getRank(),
-                    pSPOut->getCoef()->get(), pSPOut->getRank());
+                    pSP1->get(), pSP1->getSize(),
+                    pSP2->get(), pSP2->getSize(),
+                    pSPOut->get(), pSPOut->getSize());
             }
         }
     }
index 5f68961..5c5c74a 100644 (file)
@@ -110,7 +110,7 @@ InternalType *GenericDotPower(InternalType *_pLeftOperand, InternalType *_pRight
         Polynom *pL   = _pLeftOperand->getAs<Polynom>();
         Double *pR   = _pRightOperand->getAs<Double>();
 
-        int iResult = PowerPolyByDouble(pL, pR, &pResult);
+        int iResult = DotPowerPolyByDouble(pL, pR, &pResult);
         switch (iResult)
         {
             case 1 :
@@ -347,7 +347,7 @@ int PowerPolyByDouble(Polynom* _pPoly, Double* _pDouble, InternalType** _pOut)
                 return 0;
             }
 
-            piRank[i] = ((iRank - 1) * iInputRank) + 1;
+            piRank[i] = iRank * iInputRank;
         }
 
         Polynom* pOut = new Polynom(_pPoly->getVariableName(), _pDouble->getRows(), _pDouble->getCols(), piRank);
@@ -355,7 +355,7 @@ int PowerPolyByDouble(Polynom* _pPoly, Double* _pDouble, InternalType** _pOut)
 
         for (int i = 0 ; i < _pDouble->getSize() ; i++)
         {
-            Double* pCoeffOut = pOut->get(i)->getCoef();
+            SinglePoly* pCoeffOut = pOut->get(i);
 
             int iCurrentRank    = 0;
             int iLoop           = (int)_pDouble->get(i);
@@ -370,7 +370,7 @@ int PowerPolyByDouble(Polynom* _pPoly, Double* _pDouble, InternalType** _pOut)
             {
                 if (iLoop % 2)
                 {
-                    int iRank = pP->getMaxRank() - 1;
+                    int iRank = pP->getMaxRank();
                     if (bComplex1)
                     {
                         C2F(wpmul1)(pCoeffOut->get(), pCoeffOut->getImg(), &iCurrentRank, pP->getCoef()->get(), pP->getCoef()->getImg(), &iRank, pCoeffOut->get(), pCoeffOut->getImg());
@@ -398,6 +398,114 @@ int PowerPolyByDouble(Polynom* _pPoly, Double* _pDouble, InternalType** _pOut)
     return 0;
 }
 
+int DotPowerPolyByDouble(Polynom* _pPoly, Double* _pDouble, InternalType** _pOut)
+{
+    if (_pDouble->isEmpty())
+    {
+        //p .^ []
+        *_pOut = Double::Empty();
+        return 0;
+    }
+
+    int iSize = _pPoly->getSize();
+    Double** pDblPower  = new Double*[iSize];
+    double* pdblPower   = _pDouble->get();
+
+    if (_pDouble->isScalar())
+    {
+        if (pdblPower[0] < 0)
+        {
+            //call overload
+            _pOut = NULL;
+            delete[] pDblPower;
+            return 0;
+        }
+
+        for (int i = 0; i < iSize; i++)
+        {
+            pDblPower[i] = new Double(pdblPower[0]);
+        }
+    }
+    else if (_pDouble->getSize() == iSize)
+    {
+        for (int i = 0; i < iSize; i++)
+        {
+            if (pdblPower[i] < 0)
+            {
+                //call overload
+                _pOut = NULL;
+                delete[] pDblPower;
+                return 0;
+            }
+
+            pDblPower[i] = new Double(pdblPower[i]);
+        }
+    }
+    else
+    {
+        delete[] pDblPower;
+        throw ast::ScilabError(_W("Invalid exponent.\n"));
+    }
+
+    InternalType* pITTempOut    = NULL;
+    Polynom* pPolyTemp          = new Polynom(_pPoly->getVariableName(), 1, 1);
+    Polynom* pPolyOut           = new Polynom(_pPoly->getVariableName(), _pPoly->getDims(), _pPoly->getDimsArray());
+    SinglePoly** pSPOut         = pPolyOut->get();
+    SinglePoly** pSPTemp        = pPolyTemp->get();
+    SinglePoly** pSP            = _pPoly->get();
+
+    int iResult = 0;
+    for (int i = 0; i < iSize; i++)
+    {
+        // set singlePoly of _pPoly in pPolyTemp without copy
+        pSPTemp[0] = pSP[i];
+        iResult = PowerPolyByDouble(pPolyTemp, pDblPower[i], &pITTempOut);
+        if (iResult)
+        {
+            break;
+        }
+
+        // get singlePoly of pITTempOut and set it in pPolyOut without copy
+        SinglePoly** pSPTempOut = pITTempOut->getAs<Polynom>()->get();
+        pSPOut[i] = pSPTempOut[0];
+        pSPTempOut[0] = NULL;
+        delete pITTempOut;
+    }
+
+    // delete exp
+    for (int i = 0; i < iSize; i++)
+    {
+        delete pDblPower[i];
+    }
+
+    delete pDblPower;
+
+    // delete temporary polynom
+    // do not delete the last SinglePoly of _pPoly setted without copy in pPolyTemp
+    pSPTemp[0] = NULL;
+    delete pPolyTemp;
+
+    switch (iResult)
+    {
+        case 1 :
+        {
+            delete pPolyOut;
+            throw ast::ScilabError(_W("Inconsistent row/column dimensions.\n"));
+        }
+        case 2 :
+        {
+            delete pPolyOut;
+            throw ast::ScilabError(_W("Invalid exponent.\n"));
+        }
+        default:
+            //OK
+            break;
+    }
+
+    *_pOut = pPolyOut;
+    return 0;
+}
+
 int DotPowerDoubleByDouble(Double* _pDouble1, Double* _pDouble2, Double** _pDoubleOut)
 {
     int iResultComplex = 0;
index d3ba531..0fbc1d5 100644 (file)
 #include <stdio.h>
 
 #include "types_substraction.hxx"
-//#include "scilabexception.hxx"
-//#include "core_math.h"
 #include "double.hxx"
 #include "polynom.hxx"
 #include "int.hxx"
 #include "sparse.hxx"
 #include "generic_operations.hxx"
 
-//
 extern "C"
 {
 #include "matrix_substraction.h"
-    //#include "localization.h"
-    //#include "charEncoding.h"
-    //#include "os_swprintf.h"
 #include "elem_common.h" //dset
 }
 
@@ -69,7 +63,7 @@ InternalType* GenericUnaryMinus(InternalType* _pRightOperand)
         double* pReal = NULL;
         double* pImg  = NULL;
 
-        Double* pDblCoef = NULL;
+        SinglePoly* pSPCoef = NULL;
 
         Polynom *pR = dynamic_cast<Polynom*>(_pRightOperand->clone());
         bool bComplex = pR->isComplex();
@@ -78,11 +72,11 @@ InternalType* GenericUnaryMinus(InternalType* _pRightOperand)
         {
             for (int i = 0; i < pR->getSize(); i++)
             {
-                pDblCoef = pR->get(i)->getCoef();
-                pReal = pDblCoef->getReal();
-                pImg = pDblCoef->getImg();
+                pSPCoef = pR->get(i);
+                pReal = pSPCoef->get();
+                pImg = pSPCoef->getImg();
 
-                for (int j = 0; j < pDblCoef->getSize(); j++)
+                for (int j = 0; j < pSPCoef->getSize(); j++)
                 {
                     pReal[j] *= -1;
                     pImg[j] *= -1;
@@ -93,10 +87,10 @@ InternalType* GenericUnaryMinus(InternalType* _pRightOperand)
         {
             for (int i = 0; i < pR->getSize(); i++)
             {
-                pDblCoef = pR->get(i)->getCoef();
-                pReal = pDblCoef->getReal();
+                pSPCoef = pR->get(i);
+                pReal = pSPCoef->get();
 
-                for (int j = 0; j < pDblCoef->getSize(); j++)
+                for (int j = 0; j < pSPCoef->getSize(); j++)
                 {
                     pReal[j] *= -1;
                 }
@@ -615,11 +609,11 @@ int SubstractPolyToDouble(Double *_pDouble, Polynom *_pPoly, Polynom** _pPolyOut
         for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
         {
             SinglePoly *pOutPoly    = (*_pPolyOut)->get(i);
-            double *pOutPolyR       = pOutPoly->getCoef()->get();
+            double *pOutPolyR       = pOutPoly->get();
 
             pOutPolyR[0] = pInDblR[0] - pOutPolyR[0];
 
-            for (int j = 1 ; j < pOutPoly->getRank() ; j++)
+            for (int j = 1 ; j < pOutPoly->getSize() ; j++)
             {
                 pOutPolyR[j] = - pOutPolyR[j];
             }
@@ -630,11 +624,11 @@ int SubstractPolyToDouble(Double *_pDouble, Polynom *_pPoly, Polynom** _pPolyOut
             for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
             {
                 SinglePoly *pOutPoly    = (*_pPolyOut)->get(i);
-                double *pOutPolyI       = pOutPoly->getCoef()->getImg();
+                double *pOutPolyI       = pOutPoly->getImg();
 
                 pOutPolyI[0]            = (pInDblI == NULL ? 0 : pInDblI[0]) - (pOutPolyI == NULL ? 0 : pOutPolyI[0]);
 
-                for (int j = 1 ; j < pOutPoly->getRank() ; j++)
+                for (int j = 1 ; j < pOutPoly->getSize() ; j++)
                 {
                     pOutPolyI[j] = - pOutPolyI[j];
                 }
@@ -660,12 +654,12 @@ int SubstractPolyToDouble(Double *_pDouble, Polynom *_pPoly, Polynom** _pPolyOut
             SinglePoly *pInPoly   = _pPoly->get(0);
             SinglePoly *pOutPoly  = (*_pPolyOut)->get(i);
 
-            double *pInPolyR = pInPoly->getCoef()->get();
-            double *pOutPolyR = pOutPoly->getCoef()->get();
+            double *pInPolyR = pInPoly->get();
+            double *pOutPolyR = pOutPoly->get();
 
             pOutPolyR[0] = pInDblR[i] - pInPolyR[0];
 
-            for (int j = 1 ; j < pOutPoly->getRank() ; j++)
+            for (int j = 1 ; j < pOutPoly->getSize() ; j++)
             {
                 pOutPolyR[j] = - pInPolyR[j];
             }
@@ -679,12 +673,12 @@ int SubstractPolyToDouble(Double *_pDouble, Polynom *_pPoly, Polynom** _pPolyOut
                 SinglePoly *pInPoly   = _pPoly->get(0);
                 SinglePoly *pOutPoly  = (*_pPolyOut)->get(i);
 
-                double *pInPolyI = pInPoly->getCoef()->getImg();
-                double *pOutPolyI = pOutPoly->getCoef()->getImg();
+                double *pInPolyI = pInPoly->getImg();
+                double *pOutPolyI = pOutPoly->getImg();
 
                 pOutPolyI[0] = (pInDblI != NULL ? pInDblI[i] : 0) - (pInPolyI != NULL ? pInPolyI[0] : 0);
 
-                for (int j = 1 ; j < pOutPoly->getRank() ; j++)
+                for (int j = 1 ; j < pOutPoly->getSize() ; j++)
                 {
                     pOutPolyI[j] = -pInPolyI[j];
                 }
@@ -721,11 +715,11 @@ int SubstractPolyToDouble(Double *_pDouble, Polynom *_pPoly, Polynom** _pPolyOut
     for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
     {
         SinglePoly *pOutPoly    = (*_pPolyOut)->get(i);
-        double *pOutPolyR       = pOutPoly->getCoef()->get();
+        double *pOutPolyR       = pOutPoly->get();
 
         pOutPolyR[0] = pInDblR[i] - pOutPolyR[0];
 
-        for (int j = 1 ; j < pOutPoly->getRank() ; j++)
+        for (int j = 1 ; j < pOutPoly->getSize() ; j++)
         {
             pOutPolyR[j] = - pOutPolyR[j];
         }
@@ -737,11 +731,11 @@ int SubstractPolyToDouble(Double *_pDouble, Polynom *_pPoly, Polynom** _pPolyOut
         for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
         {
             SinglePoly *pOutPoly  = (*_pPolyOut)->get(i);
-            double *pOutPolyI = pOutPoly->getCoef()->getImg();
+            double *pOutPolyI = pOutPoly->getImg();
 
             pOutPolyI[0] = (pInDblI != NULL ? pInDblI[i] : 0) - (pOutPolyI != NULL ? pOutPolyI[0] : 0);
 
-            for (int j = 1 ; j < pOutPoly->getRank() ; j++)
+            for (int j = 1 ; j < pOutPoly->getSize() ; j++)
             {
                 pOutPolyI[j] = - pOutPolyI[j];
             }
@@ -764,7 +758,7 @@ int SubstractDoubleToPoly(Polynom *_pPoly, Double *_pDouble, Polynom **_pPolyOut
         for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
         {
             SinglePoly *pOutPoly    = (*_pPolyOut)->get(i);
-            double *pOutPolyR       = pOutPoly->getCoef()->get();
+            double *pOutPolyR       = pOutPoly->get();
             pOutPolyR[0]   -= pInDblR[0];
         }
 
@@ -774,7 +768,7 @@ int SubstractDoubleToPoly(Polynom *_pPoly, Double *_pDouble, Polynom **_pPolyOut
             for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
             {
                 SinglePoly *pOutPoly    = (*_pPolyOut)->get(i);
-                double *pOutPolyI       = pOutPoly->getCoef()->getImg();
+                double *pOutPolyI       = pOutPoly->getImg();
 
                 pOutPolyI[0]            -=  (pInDblI == NULL ? 0 : pInDblI[0]);
             }
@@ -789,40 +783,65 @@ int SubstractDoubleToPoly(Polynom *_pPoly, Double *_pDouble, Polynom **_pPolyOut
         }
 
         (*_pPolyOut) = new Polynom(_pPoly->getVariableName(), _pDouble->getDims(), _pDouble->getDimsArray(), piRank);
+        (*_pPolyOut)->setComplex(_pPoly->isComplex() || _pDouble->isComplex());
 
-        for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
+        if (_pPoly->isComplex())
         {
-            SinglePoly *pInPoly     = _pPoly->get(0);
-            SinglePoly *pOutPoly    = (*_pPolyOut)->get(i);
-            double *pInPolyR        = pInPoly->getCoef()->get();
-            double *pOutPolyR       = pOutPoly->getCoef()->get();
-
-            pOutPolyR[0]            = pInPolyR[0] - pInDblR[i];
-
-            for (int j = 1 ; j < pOutPoly->getRank() ; j++)
+            SinglePoly *pInPoly = _pPoly->get(0);
+            double *pInPolyR    = pInPoly->get();
+            double *pInPolyI    = pInPoly->getImg();
+            for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
             {
-                pOutPolyR[j]        = pInPolyR[j];
+                SinglePoly *pOutPoly    = (*_pPolyOut)->get(i);
+                double *pOutPolyR       = pOutPoly->get();
+                double *pOutPolyI       = pOutPoly->getImg();
+
+                pOutPolyR[0]            = pInPolyR[0] - pInDblR[i];
+                pOutPolyI[0]            = pInPolyI[0];
+                for (int j = 1 ; j < pOutPoly->getSize() ; j++)
+                {
+                    pOutPolyR[j]        = pInPolyR[j];
+                    pOutPolyI[j]        = pInPolyI[j];
+                }
             }
         }
-
-        if (_pPoly->isComplex() || _pDouble->isComplex())
+        else if (_pDouble->isComplex())
         {
-            (*_pPolyOut)->setComplex(true);
+            SinglePoly *pInPoly = _pPoly->get(0);
+            double *pInPolyR    = pInPoly->get();
             for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
             {
-                SinglePoly *pInPoly     = _pPoly->get(0);
                 SinglePoly *pOutPoly    = (*_pPolyOut)->get(i);
-                double *pInPolyI        = pInPoly->getCoef()->getImg();
-                double *pOutPolyI       = pOutPoly->getCoef()->getImg();
+                double *pOutPolyR       = pOutPoly->get();
+                double *pOutPolyI       = pOutPoly->getImg();
 
-                pOutPolyI[0] = (pInPolyI != NULL ? pInPolyI[0] : 0) - (pInDblI != NULL ? pInDblI[i] : 0);
+                pOutPolyR[0]            = pInPolyR[0] - pInDblR[i];
+                pOutPolyI[0]            = - pInDblI[i];
+                for (int j = 1 ; j < pOutPoly->getSize() ; j++)
+                {
+                    pOutPolyR[j]        = pInPolyR[j];
+                    pOutPolyI[j]        = 0;
+                }
+            }
+        }
+        else
+        {
+            SinglePoly *pInPoly = _pPoly->get(0);
+            double *pInPolyR    = pInPoly->get();
+            for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
+            {
+                SinglePoly *pOutPoly    = (*_pPolyOut)->get(i);
+                double *pOutPolyR       = pOutPoly->get();
 
-                for (int j = 1 ; j < pOutPoly->getRank() ; j++)
+                pOutPolyR[0]            = pInPolyR[0] - pInDblR[i];
+                for (int j = 1 ; j < pOutPoly->getSize() ; j++)
                 {
-                    pOutPolyI[j] = pInPolyI[j];
+                    pOutPolyR[j]        = pInPolyR[j];
                 }
             }
         }
+
+        delete[] piRank;
     }
     else
     {
@@ -851,7 +870,7 @@ int SubstractDoubleToPoly(Polynom *_pPoly, Double *_pDouble, Polynom **_pPolyOut
         for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
         {
             SinglePoly *pOutPoly    = (*_pPolyOut)->get(i);
-            double *pOutPolyR       = pOutPoly->getCoef()->get();
+            double *pOutPolyR       = pOutPoly->get();
             pOutPolyR[0]            -= pInDblR[i];
         }
 
@@ -861,7 +880,7 @@ int SubstractDoubleToPoly(Polynom *_pPoly, Double *_pDouble, Polynom **_pPolyOut
             for (int i = 0 ; i < (*_pPolyOut)->getSize() ; i++)
             {
                 SinglePoly *pOutPoly    = (*_pPolyOut)->get(i);
-                double *pOutPolyI       = pOutPoly->getCoef()->getImg();
+                double *pOutPolyI       = pOutPoly->getImg();
 
                 pOutPolyI[0]            -= (pInDblI != NULL ? pInDblI[i] : 0);
             }
@@ -874,135 +893,173 @@ int SubstractPolyToPoly(Polynom *_pPoly1, Polynom *_pPoly2, Polynom **_pPolyOut)
 {
     if (_pPoly1->isScalar())
     {
-        int* pRankOut   = new int[_pPoly2->getSize()];
-        int* pRank1     = new int[_pPoly1->getSize()];
-        int* pRank2     = new int[_pPoly2->getSize()];
-        memset(pRank1, 0x00, _pPoly2->getSize() * sizeof(int));
+        SinglePoly* p1Coef  = _pPoly1->get(0);
+        int iRank1          = p1Coef->getRank();
+        int* pRank2         = new int[_pPoly2->getSize()];
+        int* pRankOut       = new int[_pPoly2->getSize()];
 
-        _pPoly1->getRank(pRank1);
         _pPoly2->getRank(pRank2);
         for (int i = 0 ; i < _pPoly2->getSize() ; i++)
         {
-            pRankOut[i] = std::max(pRank1[0], pRank2[i]);
+            pRankOut[i] = std::max(iRank1, pRank2[i]);
         }
 
         (*_pPolyOut) = new Polynom(_pPoly2->getVariableName(), _pPoly2->getDims(), _pPoly2->getDimsArray(), pRankOut);
-        if (_pPoly1->isComplex() || _pPoly2->isComplex())
-        {
-            (*_pPolyOut)->setComplex(true);
-        }
+        (*_pPolyOut)->setComplex(_pPoly1->isComplex() || _pPoly2->isComplex());
 
         //Result P1(0) + P2(i)
-        Double* p1Coef          = _pPoly1->get(0)->getCoef();
-        double* p1R             = p1Coef->get();
-
-        for (int i = 0 ; i < _pPoly2->getSize() ; i++)
+        double* p1R = p1Coef->get();
+        if ((*_pPolyOut)->isComplex())
         {
-            Double* p2Coef      = _pPoly2->get(i)->getCoef();
-            double* p2R         = p2Coef->get();
+            double* p1I = p1Coef->getImg();
+            for (int i = 0 ; i < _pPoly2->getSize() ; i++)
+            {
+                SinglePoly* p2Coef   = _pPoly2->get(i);
+                double* p2R          = p2Coef->get();
+                double* p2I          = p2Coef->getImg();
 
-            Double* pOutCoef    = (*_pPolyOut)->get(i)->getCoef();
-            double* pOutR       = pOutCoef->get();
+                SinglePoly* pOutCoef = (*_pPolyOut)->get(i);
+                double* pOutR        = pOutCoef->get();
+                double* pOutI        = pOutCoef->getImg();
 
-            for (int j = 0 ; j < pRankOut[i] ; j++)
-            {
-                if (j >= pRank1[0])
+                for (int j = 0 ; j < pRankOut[i] + 1 ; j++)
                 {
-                    pOutR[j] = - p2R[j];
-                }
-                else if (j >= pRank2[i])
-                {
-                    pOutR[j] = p1R[j];
-                }
-                else
-                {
-                    pOutR[j] = p1R[j] - p2R[j];
+                    if (j > iRank1)
+                    {
+                        pOutR[j] = - p2R[j];
+                        pOutI[j] = - (p2I ? p2I[j] : 0);
+                    }
+                    else if (j > pRank2[i])
+                    {
+                        pOutR[j] = p1R[j];
+                        pOutI[j] = (p1I ? p1I[j] : 0);
+                    }
+                    else
+                    {
+                        pOutR[j] = p1R[j] - p2R[j];
+                        pOutI[j] = (p1I ? p1I[j] : 0) - (p2I ? p2I[j] : 0);
+                    }
                 }
             }
-
-            if ((*_pPolyOut)->isComplex())
+        }
+        else
+        {
+            for (int i = 0 ; i < _pPoly2->getSize() ; i++)
             {
-                double *p1I     = p1Coef->getImg();
-                double *p2I     = p2Coef->getImg();
-                double *pOutI   = pOutCoef->getImg();
+                SinglePoly* p2Coef   = _pPoly2->get(i);
+                double* p2R          = p2Coef->get();
 
-                for (int j = 0 ; j < pRankOut[i] ; j++)
+                SinglePoly* pOutCoef = (*_pPolyOut)->get(i);
+                double* pOutR        = pOutCoef->get();
+
+                for (int j = 0 ; j < pRankOut[i] + 1 ; j++)
                 {
-                    pOutI[j]    = (p1I == NULL ? 0 : p1I[j]) - (p2I == NULL ? 0 : p2I[j]);
+                    if (j > iRank1)
+                    {
+                        pOutR[j] = - p2R[j];
+                    }
+                    else if (j > pRank2[i])
+                    {
+                        pOutR[j] = p1R[j];
+                    }
+                    else
+                    {
+                        pOutR[j] = p1R[j] - p2R[j];
+                    }
                 }
             }
         }
 
         delete[] pRankOut;
-        delete[] pRank1;
         delete[] pRank2;
+        (*_pPolyOut)->updateRank();
         return 0;
     }
 
     if (_pPoly2->isScalar())
     {
         //size(p2) == 1
-        int *pRankOut   = new int[_pPoly1->getSize()];
         int *pRank1     = new int[_pPoly1->getSize()];
-        int *pRank2     = new int[_pPoly2->getSize()];
-        memset(pRank2, 0x00, _pPoly1->getSize() * sizeof(int));
+        int iRank2      = _pPoly2->get(0)->getRank();
+        int *pRankOut   = new int[_pPoly1->getSize()];
 
         _pPoly1->getRank(pRank1);
-        _pPoly2->getRank(pRank2);
         for (int i = 0 ; i < _pPoly1->getSize() ; i++)
         {
-            pRankOut[i] = std::max(pRank1[i], pRank2[0]);
+            pRankOut[i] = std::max(pRank1[i], iRank2);
         }
 
         (*_pPolyOut) = new Polynom(_pPoly1->getVariableName(), _pPoly1->getDims(), _pPoly1->getDimsArray(), pRankOut);
-        if (_pPoly1->isComplex() || _pPoly2->isComplex())
-        {
-            (*_pPolyOut)->setComplex(true);
-        }
+        (*_pPolyOut)->setComplex(_pPoly1->isComplex() || _pPoly2->isComplex());
 
         //Result P1(i) + P2(0)
-        Double *p2Coef          = _pPoly2->get(0)->getCoef();
-        double *p2R             = p2Coef->get();
+        SinglePoly *p2Coef          = _pPoly2->get(0);
+        double *p2R                 = p2Coef->get();
 
-        for (int i = 0 ; i < _pPoly1->getSize() ; i++)
+        if ((*_pPolyOut)->isComplex())
         {
-            Double *p1Coef      = _pPoly1->get(i)->getCoef();
-            double *p1R   = p1Coef->get();
+            double *p2I                 = p2Coef->getImg();
+            for (int i = 0 ; i < _pPoly1->getSize() ; i++)
+            {
+                SinglePoly *p1Coef      = _pPoly1->get(i);
+                double *p1R             = p1Coef->get();
+                double *p1I             = p1Coef->getImg();
 
-            Double *pOutCoef    = (*_pPolyOut)->get(i)->getCoef();
-            double *pOutR       = pOutCoef->get();
+                SinglePoly *pOutCoef    = (*_pPolyOut)->get(i);
+                double *pOutR           = pOutCoef->get();
+                double *pOutI           = pOutCoef->getImg();
 
-            for (int j = 0 ; j < pRankOut[i] ; j++)
-            {
-                if (j >= pRank1[j])
-                {
-                    pOutR[j] = - p2R[j];
-                }
-                else if (j >= pRank2[0])
+                for (int j = 0 ; j < pRankOut[i] + 1 ; j++)
                 {
-                    pOutR[j] = p1R[j];
-                }
-                else
-                {
-                    pOutR[j] = p1R[j] - p2R[j];
+                    if (j > pRank1[j])
+                    {
+                        pOutR[j] = - p2R[j];
+                        pOutI[j] = - (p2I ? p2I[j] : 0);
+                    }
+                    else if (j > iRank2)
+                    {
+                        pOutR[j] = p1R[j];
+                        pOutI[j] = (p1I ? p1I[j] : 0);
+                    }
+                    else
+                    {
+                        pOutR[j] = p1R[j] - p2R[j];
+                        pOutI[j] = (p1I ? p1I[j] : 0) - (p2I ? p2I[j] : 0);
+                    }
                 }
             }
-
-            if ((*_pPolyOut)->isComplex())
+        }
+        else
+        {
+            for (int i = 0 ; i < _pPoly1->getSize() ; i++)
             {
-                double *p2I  = p2Coef->getImg();
-                double *p1I     = p1Coef->getImg();
-                double *pOutI   = pOutCoef->getImg();
-                for (int j = 0 ; j < pRankOut[i] ; j++)
+                SinglePoly *p1Coef      = _pPoly1->get(i);
+                double *p1R             = p1Coef->get();
+
+                SinglePoly *pOutCoef    = (*_pPolyOut)->get(i);
+                double *pOutR           = pOutCoef->get();
+
+                for (int j = 0 ; j < pRankOut[i] + 1 ; j++)
                 {
-                    pOutI[j]    = (p1I == NULL ? 0 : p1I[j]) - (p2I == NULL ? 0 : p2I[j]);
+                    if (j > pRank1[j])
+                    {
+                        pOutR[j] = - p2R[j];
+                    }
+                    else if (j > iRank2)
+                    {
+                        pOutR[j] = p1R[j];
+                    }
+                    else
+                    {
+                        pOutR[j] = p1R[j] - p2R[j];
+                    }
                 }
             }
         }
 
         delete[] pRankOut;
         delete[] pRank1;
-        delete[] pRank2;
+        (*_pPolyOut)->updateRank();
         return 0;
     }
 
@@ -1038,19 +1095,18 @@ int SubstractPolyToPoly(Polynom *_pPoly1, Polynom *_pPoly2, Polynom **_pPolyOut)
     }
 
     (*_pPolyOut) = new Polynom(_pPoly2->getVariableName(), iDims1, piDims1, pRankOut);
-    if (_pPoly1->isComplex() || _pPoly2->isComplex())
-    {
-        (*_pPolyOut)->setComplex(true);
-    }
+    (*_pPolyOut)->setComplex(_pPoly1->isComplex() || _pPoly2->isComplex());
 
     //Result P1(i) + P2(i)
     for (int i = 0 ; i < _pPoly1->getSize() ; i++)
     {
-        double *p1R     = _pPoly1->get(i)->getCoef()->get();
-        double *p2R     = _pPoly2->get(i)->getCoef()->get();
-        double *pOutR   = (*_pPolyOut)->get(i)->getCoef()->get();
+        double *p1R     = _pPoly1->get(i)->get();
+        double *p2R     = _pPoly2->get(i)->get();
+        double *pOutR   = (*_pPolyOut)->get(i)->get();
+        int iMin        = std::min(pRank1[i], pRank2[i]);
+        int iMax        = std::max(pRank1[i], pRank2[i]);
 
-        for (int j = 0 ; j < std::min(pRank1[i], pRank2[i]) ; j++)
+        for (int j = 0 ; j < iMin + 1 ; j++)
         {
             pOutR[j]    = p1R[j] - p2R[j];
         }
@@ -1068,23 +1124,23 @@ int SubstractPolyToPoly(Polynom *_pPoly1, Polynom *_pPoly2, Polynom **_pPolyOut)
             iCoef       = -1;
         }
 
-        for (int j = std::min(pRank1[i], pRank2[i]) ; j < std::max(pRank1[i], pRank2[i]) ; j++)
+        for (int j = iMin + 1 ; j < iMax + 1 ; j++)
         {
             pOutR[j]    = pTemp[j] * iCoef;
         }
 
         if ((*_pPolyOut)->isComplex())
         {
-            double *p1I     = _pPoly1->get(i)->getCoef()->getImg();
-            double *p2I     = _pPoly2->get(i)->getCoef()->getImg();
-            double *pOutI   = (*_pPolyOut)->get(i)->getCoef()->getImg();
+            double *p1I     = _pPoly1->get(i)->getImg();
+            double *p2I     = _pPoly2->get(i)->getImg();
+            double *pOutI   = (*_pPolyOut)->get(i)->getImg();
 
-            for (int j = 0 ; j < std::min(pRank1[i], pRank2[i]) ; j++)
+            for (int j = 0 ; j < iMin + 1 ; j++)
             {
                 pOutI[j]    = (p1I == NULL ? 0 : p1I[j]) - (p2I == NULL ? 0 : p2I[j]);
             }
 
-            for (int j = std::min(pRank1[i], pRank2[i]) ; j < std::max(pRank1[i], pRank2[i]) ; j++)
+            for (int j = iMin + 1 ; j < iMax + 1 ; j++)
             {
                 pOutI[j]  = pTemp[j] * iCoef;
             }
@@ -1095,11 +1151,7 @@ int SubstractPolyToPoly(Polynom *_pPoly1, Polynom *_pPoly2, Polynom **_pPolyOut)
     delete[] pRank1;
     delete[] pRank2;
 
-    if ((*_pPolyOut) != NULL)
-    {
-        (*_pPolyOut)->updateRank();
-    }
-
+    (*_pPolyOut)->updateRank();
     return 0;
 }
 
index 2491407..151b63f 100644 (file)
@@ -114,8 +114,6 @@ Double::Double(int _iRows, int _iCols, bool _bComplex, bool _bZComplex)
         create(piDims, 2, &pReal, &pImg);
     }
 
-    m_bComplex = _bComplex || _bZComplex;
-
     setViewAsInteger(false);
 #ifndef NDEBUG
     //Inspector::addItem(this);
@@ -134,7 +132,6 @@ Double::Double(double _dblReal)
     m_pRealData = new double[1];
     setViewAsInteger(false);
     setViewAsZComplex(false);
-
     m_pRealData[0] = _dblReal;
 
     //      int piDims[2] = {1, 1};
@@ -189,7 +186,7 @@ Double::Double(int _iRows, int _iCols, double **_pdblReal, double **_pdblImg)
 Double::Double(int _iDims, int* _piDims, bool _bComplex, bool _bZComplex)
 {
     double *pReal   = NULL;
-    double *pImg       = NULL;
+    double *pImg    = NULL;
     setViewAsZComplex(_bZComplex);
     setViewAsInteger(false);
 
@@ -202,14 +199,12 @@ Double::Double(int _iDims, int* _piDims, bool _bComplex, bool _bZComplex)
         create(_piDims, _iDims, &pReal, &pImg);
     }
 
-    m_bComplex = _bComplex || _bZComplex;
-
 #ifndef NDEBUG
     //Inspector::addItem(this);
 #endif
 }
 
-double*        Double::getReal() const
+double*    Double::getReal() const
 {
     return get();
 }
@@ -249,7 +244,7 @@ bool Double::setZeros()
         return false;
     }
 
-    if (m_bComplex == true)
+    if (isComplex() == true)
     {
         if (m_pImgData != NULL)
         {
@@ -270,7 +265,7 @@ bool Double::setOnes()
         std::fill(m_pRealData, m_pRealData + m_iSize, 1);
         //for(int iIndex = 0 ; iIndex < m_iSize ; iIndex++)
         //{
-        //     m_pRealData[iIndex] = 1;
+        //    m_pRealData[iIndex] = 1;
         //}
     }
     else
@@ -278,7 +273,7 @@ bool Double::setOnes()
         return false;
     }
 
-    if (m_bComplex == true)
+    if (isComplex() == true)
     {
         if (m_pImgData != NULL)
         {
@@ -470,16 +465,16 @@ bool Double::subMatrixToString(wostringstream& ostr, int* _piDims, int _iDims)
                     }
                     else
                     {
-                        iLen           += dfR.iWidth;
-                        dfI.iWidth     = 0;
+                        iLen        += dfR.iWidth;
+                        dfI.iWidth    = 0;
                     }
                 }
                 else
                 {
                     if (isRealZero(m_pRealData[iPos]))
                     {
-                        iLen           += dfI.iWidth;
-                        dfR.iWidth     = 0;
+                        iLen        += dfI.iWidth;
+                        dfR.iWidth    = 0;
                     }
                     else
                     {
@@ -542,7 +537,7 @@ bool Double::subMatrixToString(wostringstream& ostr, int* _piDims, int _iDims)
 
                     DoubleFormat df;
                     getDoubleFormat(ZeroIsZero(m_pRealData[iPos]), &df);
-                    iCurrentLen        = df.iWidth;
+                    iCurrentLen    = df.iWidth;
 
                     if (iCurrentLen > piSize[iCols1])
                     {
@@ -769,11 +764,11 @@ bool Double::subMatrixToString(wostringstream& ostr, int* _piDims, int _iDims)
 InternalType* Double::clone()
 {
     int iOne = 1;
-    Double *pReturn = new Double(m_iDims, m_piDims, m_bComplex);
+    Double *pReturn = new Double(m_iDims, m_piDims, isComplex());
     //memcpy(pReturn->getReal(), m_pRealData, m_iSize * sizeof(double));
     dcopy_(&m_iSize, m_pRealData, &iOne, pReturn->getReal(), &iOne);
 
-    if (m_bComplex)
+    if (isComplex())
     {
         pReturn->setComplex(true);
         //memcpy(pReturn->getImg(), m_pImgData, m_iSize * sizeof(double));
@@ -791,7 +786,7 @@ bool Double::fillFromCol(int _iCols, Double *_poSource)
     int iOne            = 1;
     dcopy_(&iSize, _poSource->getReal(), &iOne, pdblDest, &iOne);
 
-    if (m_bComplex)
+    if (isComplex())
     {
         pdblDest    = m_pImgData + iDestOffset;
         dcopy_(&iSize, _poSource->getImg(), &iOne, pdblDest, &iOne);
@@ -803,7 +798,7 @@ bool Double::fillFromRow(int _iRows, Double *_poSource)
 {
     int iCols = _poSource->getCols();
 
-    if (m_bComplex)
+    if (isComplex())
     {
     }
     else
@@ -1220,7 +1215,6 @@ void Double::convertToZComplex()
     else
     {
         pdblZ = oGetDoubleComplexFromPointer(getReal(), NULL, getSize());
-        m_bComplex = true;
     }
 
     delete[] m_pRealData;
index f66d582..090ff4d 100644 (file)
@@ -708,18 +708,19 @@ InternalType* ImplicitList::extract(typed_list* _pArgs)
 std::wstring printInLinePoly(types::SinglePoly* _pPoly, std::wstring _stVar)
 {
     std::wostringstream ostr;
-    for (int i = 0 ; i < _pPoly->getRank() ; i++)
+    double* pdblIn = _pPoly->get();
+    for (int i = 0 ; i < _pPoly->getSize() ; i++)
     {
-        double dbl = _pPoly->getCoef()->getReal()[i];
-        if (dbl != 0)
+
+        if (pdblIn[i] != 0)
         {
             DoubleFormat df;
-            getDoubleFormat(dbl, &df);
+            getDoubleFormat(pdblIn[i], &df);
             df.bPrintPoint = ostr.str().size() != 0;
             df.bPrintPlusSign = true;
             df.bPrintOne = i == 0;
             df.bPaddSign = false;
-            addDoubleValue(&ostr, dbl, &df);
+            addDoubleValue(&ostr, pdblIn[i], &df);
             if (i != 0)
             {
                 ostr << _stVar;
index 087bcfa..32d5843 100644 (file)
@@ -63,8 +63,7 @@ Polynom::~Polynom()
 
 void Polynom::createPoly(std::wstring _szVarName, int _iDims, int* _piDims, const int *_piRank)
 {
-    m_szVarName        = _szVarName;
-    m_bComplex = false;
+    m_szVarName = _szVarName;
     SinglePoly** pPoly = NULL;
     create(_piDims, _iDims, &pPoly, NULL);
 
@@ -76,14 +75,6 @@ void Polynom::createPoly(std::wstring _szVarName, int _iDims, int* _piDims, cons
             m_pRealData[i] = new SinglePoly(&pReal, _piRank[i]);
         }
     }
-    else
-    {
-        for (int i = 0 ; i < getSize() ; i++)
-        {
-            double* pReal = NULL;
-            m_pRealData[i] = new SinglePoly(&pReal, 1);
-        }
-    }
 #ifndef NDEBUG
     //Inspector::addItem(this);
 #endif
@@ -91,6 +82,7 @@ void Polynom::createPoly(std::wstring _szVarName, int _iDims, int* _piDims, cons
 
 bool Polynom::set(int _iPos, SinglePoly* _pS)
 {
+    bool bComplex = isComplex();
     if (m_pRealData == NULL || _iPos >= m_iSize)
     {
         return false;
@@ -103,10 +95,15 @@ bool Polynom::set(int _iPos, SinglePoly* _pS)
 
     m_pRealData[_iPos] = copyValue(_pS);
 
-    if (_pS->isComplex())
+    if (_pS->isComplex() && bComplex == false)
     {
         setComplex(true);
     }
+    else if (_pS->isComplex() == false && bComplex)
+    {
+        m_pRealData[_iPos]->setComplex(true);
+    }
+
     return true;
 }
 
@@ -136,9 +133,8 @@ bool Polynom::setCoef(int _iIdx, Double *_pdblCoef)
     if (_iIdx < getSize())
     {
         /*Get old SinglePoly*/
-        SinglePoly *poPoly = get(_iIdx);
-        poPoly->setRank(_pdblCoef->getSize());
-        poPoly->setCoef(_pdblCoef);
+        m_pRealData[_iIdx]->setRank(_pdblCoef->getSize() - 1);
+        m_pRealData[_iIdx]->setCoef(_pdblCoef);
     }
     else
     {
@@ -148,21 +144,15 @@ bool Polynom::setCoef(int _iIdx, Double *_pdblCoef)
     return true;
 }
 
-bool Polynom::getRank(int *_piRank)
+void Polynom::setZeros()
 {
-    if (_piRank == NULL || m_pRealData == NULL)
+    for (int i = 0; i < m_iSize; i++)
     {
-        return false;
+        m_pRealData[i]->setZeros();
     }
-
-    for (int i = 0 ; i < getSize() ; i++)
-    {
-        _piRank[i] = m_pRealData[i]->getRank();
-    }
-    return true;
 }
 
-bool Polynom::getRealRank(int *_piRank)
+bool Polynom::getRank(int *_piRank)
 {
     if (_piRank == NULL || m_pRealData == NULL)
     {
@@ -171,8 +161,9 @@ bool Polynom::getRealRank(int *_piRank)
 
     for (int i = 0 ; i < getSize() ; i++)
     {
-        _piRank[i] = m_pRealData[i]->getRank() - 1;
+        _piRank[i] = m_pRealData[i]->getRank();
     }
+
     return true;
 }
 
@@ -191,31 +182,35 @@ void Polynom::setVariableName(wstring _szVarName)
     m_szVarName = _szVarName;
 }
 
+bool Polynom::isComplex()
+{
+    if (m_iSize && m_pRealData[0])
+    {
+        return m_pRealData[0]->isComplex();
+    }
+
+    return false;
+}
+
 void Polynom::setComplex(bool _bComplex)
 {
-    if (_bComplex != m_bComplex)
+    if (_bComplex != isComplex())
     {
         for (int i = 0 ; i < getSize() ; i++)
         {
             get(i)->setComplex(_bComplex);
         }
-        m_bComplex = _bComplex;
     }
 }
 
 InternalType* Polynom::clone()
 {
-    int* piRank = new int[getSize()];
-    getRank(piRank);
-
-    Polynom* pMP = new Polynom(getVariableName(), getDims(), getDimsArray(), piRank);
-    pMP->setComplex(isComplex());
+    Polynom* pMP = new Polynom(getVariableName(), getDims(), getDimsArray());
     for (int i = 0 ; i < getSize() ; i++)
     {
-        pMP->set(i, get(i));
+        pMP->set(i, m_pRealData[i]);
     }
 
-    delete piRank;
     return pMP;
 }
 
@@ -229,16 +224,10 @@ bool Polynom::transpose(InternalType *& out)
 
     if (m_iDims == 2)
     {
-        Polynom * pMP = new Polynom();
-        out = pMP;
-        pMP->m_szVarName = this-> m_szVarName;
-        SinglePoly** pPoly = NULL;
-        int piDims[2] = {getCols(), getRows()};
-        pMP->create(piDims, 2, &pPoly, NULL);
-        pMP->setComplex(isComplex());
-
-        Transposition::transpose_clone(getRows(), getCols(), m_pRealData, pMP->m_pRealData);
-
+        int piNewDims[2] = {m_piDims[1], m_piDims[0]};
+        Polynom* pPoly = new Polynom(m_szVarName, m_iDims, piNewDims);
+        Transposition::transpose_clone(getRows(), getCols(), m_pRealData, pPoly->get());
+        out = pPoly;
         return true;
     }
 
@@ -252,16 +241,10 @@ bool Polynom::adjoint(InternalType *& out)
     {
         if (m_iDims == 2)
         {
-            Polynom * pMP = new Polynom();
-            out = pMP;
-            pMP->m_szVarName = this-> m_szVarName;
-            SinglePoly** pPoly = NULL;
-            int piDims[2] = {getCols(), getRows()};
-            pMP->create(piDims, 2, &pPoly, NULL);
-            pMP->setComplex(true);
-
-            Transposition::adjoint_clone(getRows(), getCols(), m_pRealData, pMP->m_pRealData);
-
+            int piNewDims[2] = {m_piDims[1], m_piDims[0]};
+            Polynom* pPoly = new Polynom(m_szVarName, m_iDims, piNewDims);
+            Transposition::adjoint_clone(getRows(), getCols(), m_pRealData, pPoly->get());
+            out = pPoly;
             return true;
         }
         else
@@ -277,22 +260,15 @@ bool Polynom::adjoint(InternalType *& out)
 
 Double* Polynom::evaluate(Double* _pdblValue)
 {
-    double *pR = _pdblValue->getReal();
-    double *pI = _pdblValue->getImg();
-    int iRows          = _pdblValue->getRows();
-    int iCols          = _pdblValue->getCols();
+    double *pR = _pdblValue->getReal();
+    double *pI = _pdblValue->getImg();
+    int iRows  = _pdblValue->getRows();
+    int iCols  = _pdblValue->getCols();
 
-    double *pReturnR   = NULL;
-    double *pReturnI   = NULL;
-    Double *pReturn            = new Double(getRows() * iRows, getCols() * iCols, &pReturnR, &pReturnI);
-    if (pI != NULL)
-    {
-        pReturn->setComplex(true);
-    }
-    else
-    {
-        pReturn->setComplex(false);
-    }
+    double *pReturnR = NULL;
+    double *pReturnI = NULL;
+    Double *pReturn  = new Double(getRows() * iRows, getCols() * iCols, &pReturnR, &pReturnI);
+    pReturn->setComplex(_pdblValue->isComplex());
 
     int i = 0;
     //all lines of the matrix remplacement
@@ -304,20 +280,20 @@ Double* Polynom::evaluate(Double* _pdblValue)
             {
                 for (int iPolyRow = 0 ; iPolyRow < getRows() ; iPolyRow++)
                 {
-                    double OutR        = 0;
-                    double OutI        = 0;
+                    double OutR = 0;
+                    double OutI = 0;
 
                     SinglePoly *pPoly = get(iPolyRow, iPolyCol);
                     if (pReturn->isComplex())
                     {
                         pPoly->evaluate(pR[iCol * iRows + iRow], pI[iCol * iRows + iRow], &OutR, &OutI);
-                        pReturnR[i]    = OutR;
-                        pReturnI[i]    = OutI;
+                        pReturnR[i] = OutR;
+                        pReturnI[i] = OutI;
                     }
                     else
                     {
                         pPoly->evaluate(pR[iCol * iRows + iRow], 0, &OutR, &OutI);
-                        pReturnR[i]    = OutR;
+                        pReturnR[i] = OutR;
                     }
                     i++;
                 }
@@ -331,8 +307,7 @@ void Polynom::updateRank(void)
 {
     for (int i = 0 ; i < getSize() ; i++)
     {
-        SinglePoly *pPoly = get(i);
-        pPoly->updateRank();
+        m_pRealData[i]->updateRank();
     }
 }
 
@@ -348,77 +323,87 @@ int Polynom::getMaxRank(void)
     delete[] piRank;
     return iMaxRank;
 }
-int Polynom::getRealMaxRank(void)
-{
-    return getMaxRank() - 1;
-}
 
 Double* Polynom::getCoef(void)
 {
     int iMaxRank = getMaxRank();
-    Double *pCoef = new Double(getRows(), getCols() * iMaxRank, false);
-    if (isComplex())
-    {
-        pCoef->setComplex(true);
-    }
+    int iColsOut = getCols() * (iMaxRank + 1);
+    int iSize    = getRows() * iColsOut;
 
-    double *pCoefR     = pCoef->getReal();
-    double *pCoefI     = pCoef->getImg();
+    Double *pCoef = new Double(getRows(), iColsOut, isComplex());
+    pCoef->setZeros();
+    double *pCoefR = pCoef->getReal();
 
-    for (int iRank = 0 ; iRank < iMaxRank ; iRank++)
+    if (isComplex())
     {
-        for (int i = 0 ; i < getSize() ; i++)
+        double *pCoefI = pCoef->getImg();
+        for (int i = 0 ; i < m_iSize ; i++)
         {
-            SinglePoly *pPoly  = get(i);
-            if (iRank > pPoly->getRealRank())
+            SinglePoly *pPoly = m_pRealData[i];
+            int iSize = pPoly->getSize();
+            double *pR = pPoly->get();
+            double *pI = pPoly->getImg();
+
+            for (int iRank = 0 ; iRank < iSize ; iRank++)
             {
-                pCoefR[iRank * getSize() + i] = 0;
-                if (isComplex())
-                {
-                    pCoefI[iRank * getSize() + i] = 0;
-                }
+                pCoefR[iRank * m_iSize + i] = pR[iRank];
+                pCoefI[iRank * m_iSize + i] = pI[iRank];
             }
-            else
+        }
+    }
+    else
+    {
+        for (int i = 0 ; i < m_iSize ; i++)
+        {
+            SinglePoly *pPoly = m_pRealData[i];
+            int iSize = pPoly->getSize();
+            double *pR = pPoly->get();
+            for (int iRank = 0 ; iRank < iSize ; iRank++)
             {
-                double *pR     = pPoly->getCoef()->getReal();
-                double *pI     = pPoly->getCoef()->getImg();
-
-                pCoefR[iRank * getSize() + i] = pR[iRank];
-                if (isComplex())
-                {
-                    pCoefI[iRank * getSize() + i] = pI[iRank];
-                }
+                pCoefR[iRank * m_iSize + i] = pR[iRank];
             }
         }
     }
+
     return pCoef;
 }
 
 void Polynom::setCoef(Double *_pCoef)
 {
     int iMaxRank = getMaxRank();
-
     setComplex(_pCoef->isComplex());
     double *pR = _pCoef->getReal();
-    double *pI = _pCoef->getImg();
-    for (int i = 0 ; i < getSize() ; i++)
+
+    if (isComplex())
     {
-        Double *pTemp = new Double(1, iMaxRank, _pCoef->isComplex());
-        SinglePoly *pPoly = get(i);
-        for (int iRank = 0 ; iRank < iMaxRank ; iRank++)
+        double *pI = _pCoef->getImg();
+        for (int i = 0 ; i < m_iSize ; i++)
         {
-            pTemp->getReal()[iRank] = pR[iRank * getSize() + i];
+            SinglePoly *pPoly = m_pRealData[i];
+            int iSize = pPoly->getSize();
+            double* pTempR = pPoly->get();
+            double* pTempI = pPoly->getImg();
+
+            for (int iRank = 0 ; iRank < iSize ; iRank++)
+            {
+                pTempR[iRank] = pR[iRank * m_iSize + i];
+                pTempI[iRank] = pI[iRank * m_iSize + i];
+            }
         }
-        if (isComplex())
+    }
+    else
+    {
+        for (int i = 0 ; i < m_iSize ; i++)
         {
-            for (int iRank = 0 ; iRank < iMaxRank ; iRank++)
+            SinglePoly *pPoly = m_pRealData[i];
+            int iSize = pPoly->getSize();
+            double* pTempR = pPoly->get();
+
+            for (int iRank = 0 ; iRank < iSize ; iRank++)
             {
-                pTemp->getImg()[iRank] = pI[iRank * getSize() + i];
+                pTempR[iRank] = pR[iRank * m_iSize + i];
             }
         }
-
-        pPoly->setCoef(pTemp);
-        delete pTemp;
     }
 }
 
@@ -633,7 +618,7 @@ wstring Polynom::getMatrixString(int* _piDims, int _iDims, bool _bComplex)
                 osCoef.str(L"");
 
             }
-            iLen       = piMaxLen[iCols1];
+            iLen    = piMaxLen[iCols1];
 
             //write "column x to y"
             if (iLastCol + 1 == iCols1)
@@ -770,8 +755,8 @@ wstring Polynom::getRowString(int* _piDims, int _iDims, bool _bComplex)
                 ostr << endl << L"         Column " << iLastFlush + 1 /* 2 is better than 1, no ? */ << L" to " << i << endl << endl;
             }
 
-            iLastFlush = i;
-            iLen                               = 0;
+            iLastFlush    = i;
+            iLen                = 0;
             ostr << osExp.str() << endl;
             ostr << osCoef.str() << endl;
             osExp.str(L"");
@@ -860,28 +845,31 @@ wstring Polynom::getColString(int* _piDims, int _iDims, bool _bComplex)
 
 Double* Polynom::extractCoef(int _iRank)
 {
-    Double *pdbl       = new Double(getRows(), getCols(), m_bComplex);
-    double *pReal      = pdbl->getReal();
-    double *pImg       = pdbl->getImg();
+    Double *pdbl = new Double(getRows(), getCols(), isComplex());
+    pdbl->setZeros();
+    double *pReal = pdbl->getReal();
 
-    for (int i = 0 ; i < getSize() ; i++)
+    if (isComplex())
     {
-        SinglePoly *pPoly = get(i);
-
-        if (pPoly->getRank() <= _iRank)
+        double *pImg = pdbl->getImg();
+        for (int i = 0 ; i < getSize() ; i++)
         {
-            pReal[i] = 0;
-            if (m_bComplex)
+            SinglePoly *pPoly = m_pRealData[i];
+            if (pPoly->getRank() >= _iRank)
             {
-                pImg[i]                = 0;
+                pReal[i] = pPoly->get()[_iRank];
+                pImg[i]  = pPoly->getImg()[_iRank];
             }
         }
-        else
+    }
+    else
+    {
+        for (int i = 0 ; i < getSize() ; i++)
         {
-            pReal[i]           = pPoly->getCoef()->getReal()[_iRank];
-            if (m_bComplex)
+            SinglePoly *pPoly = m_pRealData[i];
+            if (pPoly->getRank() >= _iRank)
             {
-                pImg[i]                = pPoly->getCoef()->getImg()[_iRank];
+                pReal[i] = pPoly->get()[_iRank];
             }
         }
     }
@@ -890,23 +878,36 @@ Double* Polynom::extractCoef(int _iRank)
 }
 bool Polynom::insertCoef(int _iRank, Double* _pCoef)
 {
-    double *pReal      = _pCoef->getReal();
-    double *pImg       = _pCoef->getImg();
-
-    for (int i = 0 ; i < getSize() ; i++)
+    double *pReal = _pCoef->getReal();
+    if (isComplex())
     {
-        SinglePoly *pPoly = get(i);
-        if (pPoly->getRank() <= _iRank)
+        double *pImg  = _pCoef->getImg();
+        for (int i = 0 ; i < getSize() ; i++)
         {
-            return false;
-        }
+            SinglePoly *pPoly = m_pRealData[i];
+            if (pPoly->getRank() <= _iRank)
+            {
+                return false;
+            }
 
-        pPoly->getCoef()->getReal()[_iRank] = pReal[i];
-        if (m_bComplex)
+            pPoly->get()[_iRank] = pReal[i];
+            pPoly->getImg()[_iRank] = pImg[i];
+        }
+    }
+    else
+    {
+        for (int i = 0 ; i < getSize() ; i++)
         {
-            pPoly->getCoef()->getImg()[_iRank] = pImg[i];
+            SinglePoly *pPoly = m_pRealData[i];
+            if (pPoly->getRank() <= _iRank)
+            {
+                return false;
+            }
+
+            pPoly->get()[_iRank] = pReal[i];
         }
     }
+
     return true;
 }
 
@@ -949,10 +950,7 @@ bool Polynom::operator!=(const InternalType& it)
 
 SinglePoly* Polynom::getNullValue()
 {
-    double* pR = NULL;
-    SinglePoly* pData = new SinglePoly(&pR, 1);
-    pR[0] = 0;
-    return pData;
+    return new SinglePoly();
 }
 
 Polynom* Polynom::createEmpty(int _iDims, int* _piDims, bool _bComplex)
@@ -982,17 +980,13 @@ void Polynom::deleteAll()
 
 void Polynom::deleteImg()
 {
+
 }
 
 SinglePoly** Polynom::allocData(int _iSize)
 {
     SinglePoly** pData = new SinglePoly*[_iSize];
-    for (int i = 0 ; i < _iSize ; i++)
-    {
-        double* pReal;
-        pData[i] = new SinglePoly(&pReal, 1);
-        pReal[0] = 0;
-    }
+    memset(pData, 0x00, _iSize * sizeof(SinglePoly*));
     return pData;
 }
 }
index 20168ff..fc6f368 100644 (file)
@@ -29,201 +29,214 @@ namespace types
 {
 SinglePoly::SinglePoly()
 {
-    int iRank = 1;
     double* pdblCoefR = NULL;
-    createPoly(&pdblCoefR, NULL, iRank);
+    int piDims[2] = {1, 1};
+    create(piDims, 2, &pdblCoefR, NULL);
     pdblCoefR[0] = 0;
 }
 
 SinglePoly::SinglePoly(double** _pdblCoefR, int _iRank)
 {
-    createPoly(_pdblCoefR, NULL, _iRank);
+    int piDims[2] = {_iRank + 1, 1};
+    create(piDims, 2, _pdblCoefR, NULL);
 }
 
 SinglePoly::SinglePoly(double** _pdblCoefR, double** _pdblCoefI, int _iRank)
 {
-    createPoly(_pdblCoefR, _pdblCoefI, _iRank);
+    int piDims[2] = {_iRank + 1, 1};
+    create(piDims, 2, _pdblCoefR, _pdblCoefI);
 }
 
-SinglePoly::SinglePoly(Double** _poCoefR, int _iRank)
+SinglePoly::~SinglePoly()
 {
-    double *pR = NULL;
-    double *pI = NULL;
-    createPoly(&pR, &pI, _iRank);
-    *_poCoefR = m_pdblCoef;
+    deleteAll();
 }
 
+void SinglePoly::deleteAll()
+{
+    delete[] m_pRealData;
+    m_pRealData = NULL;
+    deleteImg();
+}
 
-SinglePoly::~SinglePoly()
+void SinglePoly::deleteImg()
 {
-    if (m_pdblCoef)
+    if (m_pImgData != NULL)
     {
-        delete m_pdblCoef;
+        delete[] m_pImgData;
+        m_pImgData = NULL;
     }
 }
 
-/*Real constructor, private only*/
-void SinglePoly::createPoly(double** _pdblCoefR, double** _pdblCoefI, int _iRank)
+double SinglePoly::getNullValue()
 {
-    double *pR = NULL;
-    double *pI = NULL;
-    m_bComplex = false;
-    m_iRank     = _iRank;
+    return 0;
+}
 
-    if (m_iRank == 0)
-    {
-        m_pdblCoef = NULL;
-        return;
-    }
+SinglePoly* SinglePoly::createEmpty(int _iDims, int* _piDims, bool _bComplex)
+{
+    double* pdblData = NULL;
+    SinglePoly* pSP = new SinglePoly(&pdblData, _piDims[0] - 1);
+    pSP->setComplex(_bComplex);
 
-    if (_pdblCoefI != NULL)
-    {
-        m_pdblCoef = new Double(1, _iRank, &pR, &pI);
-    }
-    else
-    {
-        m_pdblCoef = new Double(1, _iRank, &pR);
-    }
+    return pSP;
+}
 
-    m_pdblCoef->IncreaseRef();
-    m_pdblCoef->setZeros();
-    if (_pdblCoefR != NULL)
+double* SinglePoly::allocData(int _iSize)
+{
+    double* pDbl = NULL;
+    try
     {
-        *_pdblCoefR = pR;
+        if (_iSize < 0)
+        {
+            m_pRealData = NULL;
+            m_pImgData = NULL;
+            char message[bsiz];
+            sprintf(message, _("Can not allocate negative size (%d).\n"),  _iSize);
+            ast::ScilabError se(message);
+            se.SetErrorNumber(999);
+            throw (se);
+        }
+        else
+        {
+            pDbl = new double[_iSize];
+        }
     }
-
-    if (_pdblCoefI != NULL)
+    catch (std::bad_alloc &e)
     {
-        m_bComplex = true;
-        *_pdblCoefI = pI;
+        char message[bsiz];
+        sprintf(message, _("Can not allocate %.2f MB memory.\n"),  (double) (_iSize * sizeof(double)) / 1.e6);
+        ast::ScilabError se(message);
+        se.SetErrorNumber(999);
+        throw (se);
     }
+
+    return pDbl;
 }
 
-int SinglePoly::getRank()
+double SinglePoly::copyValue(double _dblData)
 {
-    return m_iRank;
+    return _dblData;
 }
 
-int SinglePoly::getRealRank()
+int SinglePoly::getRank()
 {
-    return m_iRank - 1;
+    return m_iSize - 1;
 }
 
 bool SinglePoly::setRank(int _iRank, bool bSave)
 {
-    double *pR = NULL;
-    double *pI = NULL;
+    double *pR = NULL;
+    double *pI = NULL;
     if (bSave == false)
     {
-        if (m_iRank != _iRank)
+        if (getRank() != _iRank)
         {
-            delete m_pdblCoef;
-
-            if (m_bComplex == false)
+            int piDims[2] = {_iRank + 1, 1};
+            if (m_pImgData == false)
             {
-                createPoly(&pR, NULL, _iRank);
+                deleteAll();
+                create(piDims, 2, &pR, NULL);
             }
             else
             {
-                createPoly(&pR, &pI, _iRank);
+                deleteAll();
+                create(piDims, 2, &pR, &pI);
             }
+
             return true;
         }
+
         return true;
     }
     else
     {
-        Double *pCoef = NULL;
-        if (_iRank != 0)
+        double* pdblOldReal = m_pRealData;
+        double* pdblOldImg  = m_pImgData;
+        int iMinSize = Min(m_iSize, _iRank + 1);
+        int piDims[2] = {_iRank + 1, 1};
+
+        if (m_pImgData == false)
         {
-            pCoef = new Double(1, _iRank, &pR, &pI);
-            pCoef->set(m_pdblCoef->getReal());
-            pCoef->setComplex(m_pdblCoef->isComplex());
-            if (m_pdblCoef->isComplex())
-            {
-                pCoef->setImg(m_pdblCoef->getImg());
-            }
-            m_iRank = _iRank;
+            create(piDims, 2, &pR, NULL);
         }
         else
         {
-            m_iRank = 1;
-            pCoef = new Double(1, 1, &pR, &pI);
-            pCoef->setComplex(m_pdblCoef->isComplex());
-            pCoef->set(0, 0, 0);
+            create(piDims, 2, &pR, &pI);
+            memcpy(m_pImgData, pdblOldImg, iMinSize * sizeof(double));
         }
 
-        m_pdblCoef->DecreaseRef();
-        if (m_pdblCoef->isDeletable())
+        memcpy(m_pRealData, pdblOldReal, iMinSize * sizeof(double));
+
+        if (pdblOldImg)
         {
-            delete m_pdblCoef;
+            delete[] pdblOldImg;
+            pdblOldImg = NULL;
         }
 
-        m_pdblCoef = pCoef;
-        m_pdblCoef->IncreaseRef();
+        delete[] pdblOldReal;
+        pdblOldReal = NULL;
+
         return true;
     }
+
     return false;
 }
 
-Double* SinglePoly::getCoef()
+bool SinglePoly::setZeros()
 {
-    return m_pdblCoef;
-}
+    if (m_pRealData != NULL)
+    {
+        memset(m_pRealData, 0x00, m_iSize * sizeof(double));
+    }
+    else
+    {
+        return false;
+    }
 
-double* SinglePoly::getCoefReal()
-{
-    return m_pdblCoef->getReal();
-}
+    if (isComplex() == true)
+    {
+        if (m_pImgData != NULL)
+        {
+            memset(m_pImgData, 0x00, m_iSize * sizeof(double));
+        }
+        else
+        {
+            return false;
+        }
+    }
 
-double* SinglePoly::getCoefImg()
-{
-    return m_pdblCoef->getImg();
+    return true;
 }
 
 bool SinglePoly::setCoef(Double* _pdblCoefR)
 {
-    if (m_pdblCoef == NULL || _pdblCoefR == NULL)
+    if (m_pRealData == NULL || _pdblCoefR == NULL)
     {
         return false;
     }
 
-    double *pInR       = _pdblCoefR->getReal();
-    double *pInI       = _pdblCoefR->getImg();
+    double *pInR    = _pdblCoefR->getReal();
+    double *pInI    = _pdblCoefR->getImg();
 
     return setCoef(pInR, pInI);
 }
 
-void SinglePoly::setComplex(bool _bComplex)
-{
-    m_pdblCoef->setComplex(_bComplex);
-    m_bComplex = _bComplex;
-}
-
 bool SinglePoly::setCoef(double* _pdblCoefR, double* _pdblCoefI)
 {
-    if (m_pdblCoef == NULL)
-    {
-        return false;
-    }
-
     if (_pdblCoefI != NULL && isComplex() == false)
     {
-        m_pdblCoef->setComplex(true);
-        m_bComplex = true;
+        setComplex(true);
     }
 
-    double *pR = m_pdblCoef->getReal();
-    double *pI = m_pdblCoef->getImg();
-
-    if (_pdblCoefR != NULL && pR != NULL)
+    if (_pdblCoefR != NULL)
     {
-        memcpy(pR, _pdblCoefR, m_iRank * sizeof(double));
+        memcpy(m_pRealData, _pdblCoefR, m_iSize * sizeof(double));
     }
 
-    if (_pdblCoefI != NULL && pI != NULL)
+    if (_pdblCoefI != NULL)
     {
-        memcpy(pI, _pdblCoefI, m_iRank * sizeof(double));
+        memcpy(m_pImgData, _pdblCoefI, m_iSize * sizeof(double));
     }
 
     return true;
@@ -234,108 +247,66 @@ void SinglePoly::whoAmI()
     std::cout << "types::SinglePoly";
 }
 
-bool SinglePoly::isComplex()
-{
-    return m_bComplex;
-}
-
-GenericType* SinglePoly::getColumnValues(int _iPos)
-{
-    return NULL;
-}
-
 bool SinglePoly::evaluate(double _dblInR, double _dblInI, double *_pdblOutR, double *_pdblOutI)
 {
-    double *pCoefR = m_pdblCoef->getReal();
-    double *pCoefI = m_pdblCoef->getImg();
-
     *_pdblOutR = 0;
     *_pdblOutI = 0;
-    if (m_iRank == 0)
+    if (m_iSize == 0)
     {
         return true;
     }
 
-    for (int i = 0 ; i < m_iRank ; i++)
+    for (int i = 0 ; i < m_iSize ; i++)
     {
         //real part
-        *_pdblOutR += pCoefR[i] * pow(_dblInR, i);
+        *_pdblOutR += m_pRealData[i] * pow(_dblInR, i);
         //only if variable is complex
-        if (m_pdblCoef->isComplex())
+        if (isComplex())
         {
-            *_pdblOutR -= pCoefI[i] * pow(_dblInI, i);
+            *_pdblOutR -= m_pImgData[i] * pow(_dblInI, i);
             //img part
-            *_pdblOutI += pCoefI[i] * pow(_dblInR, i);
+            *_pdblOutI += m_pRealData[i] * pow(_dblInR, i);
         }
-        *_pdblOutI += pCoefR[i] * pow(_dblInI, i);
+        *_pdblOutI += m_pRealData[i] * pow(_dblInI, i);
     }
 
-    //old version, does not work
-    //for(int i = m_iRank - 1 ; i >= 0 ; i--)
-    //{
-    // //(a1 + ib1)(a2 + ib2)**n = (a1 + ib1) * exp(n * log(a2 + ib2))
-    // double dblLogR = 0;
-    // double dblLogI = 0;
-    // double dblExpR = 0;
-    // double dblExpI = 0;
-
-    // //log(a2 + ib2)
-    // if(_dblInI != 0)
-    // {
-    //         wlog(_dblInR, _dblInI, &dblLogR, &dblLogI);
-    // }
-    // else
-    // {
-    //         dblLogR = dlogs(_dblInR);
-    // }
-
-    // //n * log(a2 + ib2)
-    // dblLogR *= i;
-    // dblLogI *= i;
-
-    // //exp(n * log(a2 + ib2))
-    // if(dblLogI != 0)
-    // {
-    //         zexps(dblLogR, dblLogI, &dblExpR, &dblExpI);
-    // }
-    // else
-    // {
-    //         dblExpR = dexps(dblLogR);
-    // }
-
-    // //(a1 + ib1) * exp(n * log(a2 + ib2))
-    // if(m_pdblCoef->isComplex())
-    // {
-    //         *_pdblOutR += (dblExpR * pCoefR[i] - dblExpI * pCoefI[i]);
-    //         *_pdblOutI += (dblExpR * pCoefI[i] + dblExpI * pCoefR[i]);
-    // }
-    // else
-    // {
-    //         *_pdblOutR += (dblExpR * pCoefR[i]);
-    //         *_pdblOutI += (dblExpI * pCoefR[i]);
-    // }
-    //}
     return true;
 }
 
 void SinglePoly::updateRank(void)
 {
     double dblEps = getRelativeMachinePrecision();
-    int iNewRank = m_iRank;
-    double *pCoefR = getCoef()->getReal();
-    double *pCoefI = getCoef()->getImg();
-    for (int i = m_iRank - 1; i > 0 ; i--)
+    int iNewRank = getRank();
+    if (m_pImgData)
     {
-        if (fabs(pCoefR[i]) <= dblEps && (pCoefI != NULL ? fabs(pCoefI[i]) : 0) <= dblEps)
+        for (int i = getRank(); i > 0 ; i--)
         {
-            iNewRank--;
+            if (fabs(m_pRealData[i]) <= dblEps && abs(m_pImgData[i]) <= dblEps)
+            {
+                iNewRank--;
+            }
+            else
+            {
+                break;
+            }
         }
-        else
+    }
+    else
+    {
+        for (int i = getRank(); i > 0 ; i--)
         {
-            break;
+            if (fabs(m_pRealData[i]) <= dblEps)
+            {
+                iNewRank--;
+            }
+            else
+            {
+                break;
+            }
         }
     }
-    if (iNewRank < m_iRank)
+
+    if (iNewRank < getRank())
     {
         setRank(iNewRank, true);
     }
@@ -349,7 +320,7 @@ bool SinglePoly::toString(std::wostringstream& ostr)
 
 void SinglePoly::toStringReal(wstring _szVar, list<wstring>* _pListExp , list<wstring>* _pListCoef)
 {
-    toStringInternal(m_pdblCoef->getReal(), _szVar, _pListExp, _pListCoef);
+    toStringInternal(m_pRealData, _szVar, _pListExp, _pListCoef);
 }
 
 void SinglePoly::toStringImg(wstring _szVar, list<wstring>* _pListExp , list<wstring>* _pListCoef)
@@ -361,7 +332,12 @@ void SinglePoly::toStringImg(wstring _szVar, list<wstring>* _pListExp , list<wst
         return;
     }
 
-    toStringInternal(m_pdblCoef->getImg(), _szVar, _pListExp, _pListCoef);
+    toStringInternal(m_pImgData, _szVar, _pListExp, _pListCoef);
+}
+
+bool SinglePoly::subMatrixToString(wostringstream& ostr, int* _piDims, int _iDims)
+{
+    return false;
 }
 
 void SinglePoly::toStringInternal(double *_pdblVal, wstring _szVar, list<wstring>* _pListExp , list<wstring>* _pListCoef)
@@ -376,11 +352,11 @@ void SinglePoly::toStringInternal(double *_pdblVal, wstring _szVar, list<wstring
     ostemp2 << L"";
 
     //to add exponant value a the good place
-    int *piIndexExp = new int[m_iRank];
+    int *piIndexExp = new int[m_iSize];
 
-    int iLen                           = 0;
-    int iLastFlush     = 2;
-    for (int i = 0 ; i < m_iRank ; i++)
+    int iLen = 0;
+    int iLastFlush = 2;
+    for (int i = 0 ; i < m_iSize ; i++)
     {
         piIndexExp[i] = 0;
         if (isRealZero(_pdblVal[i]) == false)
@@ -435,7 +411,7 @@ void SinglePoly::toStringInternal(double *_pdblVal, wstring _szVar, list<wstring
 
     if (iLastFlush != 0)
     {
-        for (int j = iLastFlush ; j < m_iRank ; j++)
+        for (int j = iLastFlush ; j < m_iSize ; j++)
         {
             if (piIndexExp[j] == 0)
             {
@@ -482,7 +458,52 @@ bool SinglePoly::operator==(const InternalType& it)
         return false;
     }
 
-    return *(getCoef()) == *(pP->getCoef());
+    double *pdblReal = pP->get();
+    for (int i = 0 ; i < getSize() ; i++)
+    {
+        if (m_pRealData[i] != pdblReal[i])
+        {
+            return false;
+        }
+    }
+
+    //both complex
+    if (isComplex() && pP->isComplex())
+    {
+        double *pdblImg = pP->getImg();
+        for (int i = 0 ; i < m_iSize ; i++)
+        {
+            if (m_pImgData[i] != pdblImg[i])
+            {
+                return false;
+            }
+        }
+    }
+    //pdbl complex check all img values == 0
+    else if (pP->isComplex())
+    {
+        double *pdblImg = pP->getImg();
+        for (int i = 0 ; i < m_iSize ; i++)
+        {
+            if (pdblImg[i])
+            {
+                return false;
+            }
+        }
+    }
+    //complex check all img values == 0
+    else if (isComplex())
+    {
+        for (int i = 0 ; i < m_iSize ; i++)
+        {
+            if (m_pImgData[i])
+            {
+                return false;
+            }
+        }
+    }
+
+    return true;
 }
 
 bool SinglePoly::operator!=(const InternalType& it)
@@ -498,12 +519,12 @@ SinglePoly* SinglePoly::clone()
     {
         double *pI = NULL;
         pPoly = new SinglePoly(&pR, &pI, getRank());
-        pPoly->setCoef(getCoefReal(), getCoefImg());
+        pPoly->setCoef(m_pRealData, m_pImgData);
     }
     else
     {
         pPoly = new SinglePoly(&pR, getRank());
-        pPoly->setCoef(getCoefReal(), NULL);
+        pPoly->setCoef(m_pRealData, NULL);
     }
     return pPoly;
 }
@@ -517,7 +538,7 @@ SinglePoly* SinglePoly::conjugate()
         double *pI = NULL;
         SinglePoly * pPoly = new SinglePoly(&pR, &pI, getRank());
 
-        Transposition::conjugate(getRank(), getCoefReal(), pR, getCoefImg(), pI);
+        Transposition::conjugate(m_iSize, m_pRealData, pR, m_pImgData, pI);
 
         return pPoly;
     }
index 83eb396..665b8f8 100644 (file)
@@ -93,9 +93,9 @@ types::Function::ReturnValue sci_arl2_ius(types::typed_list &in, int _iRetCount,
             return types::Function::Error;
         }
 
-        types::Double* pDblCoefY = pPolyY->get(0)->getCoef();
-        iVol1 = pDblCoefY->getSize();
-        pdblY = pDblCoefY->get();
+        types::SinglePoly* pSPCoefY = pPolyY->get(0);
+        iVol1 = pSPCoefY->getSize();
+        pdblY = pSPCoefY->get();
     }
     else
     {
@@ -124,8 +124,8 @@ types::Function::ReturnValue sci_arl2_ius(types::typed_list &in, int _iRetCount,
         return types::Function::Error;
     }
 
-    pPolyDen->getRealRank(&iRankDen);
-    pdblDen = pPolyDen->get(0)->getCoef()->get();
+    pPolyDen->getRank(&iRankDen);
+    pdblDen = pPolyDen->get(0)->get();
     C2F(idegre)(pdblDen, &iRankDen, &iRankDen);
     int iSize = iRankDen + 1;
     double dblScal = 1.0 / pdblDen[iRankDen];
@@ -284,7 +284,7 @@ types::Function::ReturnValue sci_arl2_ius(types::typed_list &in, int _iRetCount,
         types::Polynom* pPolyDenOut = new types::Polynom(pPolyDen->getVariableName(), iNsol, 1, piRank);
         for (int i = 0; i < iNsol; i++)
         {
-            double* pdblDenOut = pPolyDenOut->get(i)->getCoef()->get();
+            double* pdblDenOut = pPolyDenOut->get(i)->get();
             C2F(dcopy)(&iN, pdblDenTemp + i, &iMxsol, pdblDenOut, &iOne);
             pdblDenOut[iN] = 1;
             pdblAllCoeff[i] = pdblDenOut;
@@ -307,7 +307,7 @@ types::Function::ReturnValue sci_arl2_ius(types::typed_list &in, int _iRetCount,
             types::Polynom* pPolyNumOut = new types::Polynom(pPolyDen->getVariableName(), iNsol, 1, piRank);
             for (int i = 0; i < iNsol; i++)
             {
-                double* pdblNumOut = pPolyNumOut->get(i)->getCoef()->get();
+                double* pdblNumOut = pPolyNumOut->get(i)->get();
                 double* pdblWork = new double[iN + iNg + 1];
                 C2F(lq)(&iN, pdblAllCoeff[i], pdblWork, pdblY, &iNg);
                 C2F(dscal)(&iN, &(C2F(no2f).gnrm), pdblWork, &iOne);
@@ -386,7 +386,7 @@ types::Function::ReturnValue sci_arl2_ius(types::typed_list &in, int _iRetCount,
         // retrun denominator
         int iRank = iN + 1;
         types::Polynom* pPolyDenOut = new types::Polynom(pPolyDen->getVariableName(), 1, 1, &iRank);
-        double* pdblDenOut = pPolyDenOut->get(0)->getCoef()->get();
+        double* pdblDenOut = pPolyDenOut->get(0)->get();
         C2F(dcopy)(&iRank, pDblDenTemp, &iOne, pdblDenOut, &iOne);
         out.push_back(pPolyDenOut);
 
@@ -394,7 +394,7 @@ types::Function::ReturnValue sci_arl2_ius(types::typed_list &in, int _iRetCount,
         if (_iRetCount > 1)
         {
             types::Polynom* pPolyNumOut = new types::Polynom(pPolyDen->getVariableName(), 1, 1, &iN);
-            double* pdblNumOut = pPolyNumOut->get(0)->getCoef()->get();
+            double* pdblNumOut = pPolyNumOut->get(0)->get();
             C2F(dcopy)(&iN, pdblNum, &iOne, pdblNumOut, &iOne);
             out.push_back(pPolyNumOut);
         }
index e02c735..128ea19 100644 (file)
@@ -142,12 +142,12 @@ types::Function::ReturnValue freqRational(types::typed_list &in, int _iRetCount,
             iColDen = pPolyDen->getCols();
 
             piRankDen = new int[pPolyDen->getSize()];
-            pPolyDen->getRealRank(piRankDen);
+            pPolyDen->getRank(piRankDen);
 
             pdblDen = new double*[pPolyDen->getSize()];
             for (int i = 0; i < pPolyDen->getSize(); i++)
             {
-                pdblDen[i] = pPolyDen->get(i)->getCoef()->get();
+                pdblDen[i] = pPolyDen->get(i)->get();
             }
         }
         else
@@ -192,12 +192,12 @@ types::Function::ReturnValue freqRational(types::typed_list &in, int _iRetCount,
             iColNum = pPolyNum->getCols();
 
             piRankNum = new int[pPolyNum->getSize()];
-            pPolyNum->getRealRank(piRankNum);
+            pPolyNum->getRank(piRankNum);
 
             pdblNum = new double*[pPolyNum->getSize()];
             for (int i = 0; i < pPolyNum->getSize(); i++)
             {
-                pdblNum[i] = pPolyNum->get(i)->getCoef()->get();
+                pdblNum[i] = pPolyNum->get(i)->get();
             }
         }
         else
index 6574b8a..dc054ea 100644 (file)
@@ -21,8 +21,8 @@ extern "C"
 #include "localization.h"
 #include "elem_common.h"
 
-extern void C2F(dtild)(int*, double*, int*);
-extern void C2F(expan)(double*, int*, double*, int*, double*, int*);
+    extern void C2F(dtild)(int*, double*, int*);
+    extern void C2F(expan)(double*, int*, double*, int*, double*, int*);
 }
 
 /*--------------------------------------------------------------------------*/
@@ -52,10 +52,10 @@ types::Function::ReturnValue sci_ldiv(types::typed_list &in, int _iRetCount, typ
 
     /*** get inputs arguments ***/
     // get first polynom
-    if(in[0]->isPoly())
+    if (in[0]->isPoly())
     {
         types::Polynom* pPoly1 = in[0]->getAs<types::Polynom>();
-        if(pPoly1->isComplex())
+        if (pPoly1->isComplex())
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A real polynom expected.\n"), "ldiv", 1);
             return types::Function::Error;
@@ -66,18 +66,18 @@ types::Function::ReturnValue sci_ldiv(types::typed_list &in, int _iRetCount, typ
         iCols = pPoly1->getCols();
 
         piRank1 = new int[iSize];
-        pPoly1->getRealRank(piRank1);
+        pPoly1->getRank(piRank1);
 
         pdblCoef1 = new double*[iSize];
-        for(int i = 0; i < iSize; i++)
+        for (int i = 0; i < iSize; i++)
         {
-            pdblCoef1[i] = pPoly1->get(i)->getCoef()->get();
+            pdblCoef1[i] = pPoly1->get(i)->get();
         }
     }
-    else if(in[0]->isDouble())
+    else if (in[0]->isDouble())
     {
         types::Double* pDbl1 = in[0]->getAs<types::Double>();
-        if(pDbl1->isComplex())
+        if (pDbl1->isComplex())
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), "ldiv", 1);
             return types::Function::Error;
@@ -92,7 +92,7 @@ types::Function::ReturnValue sci_ldiv(types::typed_list &in, int _iRetCount, typ
 
         pdblCoef1 = new double*[iSize];
         double* pdbl = pDbl1->get();
-        for(int i = 0; i < iSize; i++)
+        for (int i = 0; i < iSize; i++)
         {
             pdblCoef1[i] = pdbl + i;
         }
@@ -104,40 +104,40 @@ types::Function::ReturnValue sci_ldiv(types::typed_list &in, int _iRetCount, typ
     }
 
     // get second polynom
-    if(in[1]->isPoly())
+    if (in[1]->isPoly())
     {
         types::Polynom* pPoly2 = in[1]->getAs<types::Polynom>();
-        if(pPoly2->isComplex())
+        if (pPoly2->isComplex())
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A real polynom expected.\n"), "ldiv", 2);
             return types::Function::Error;
         }
 
-        if(pPoly2->getRows() != iRows || pPoly2->getCols() != iCols)
+        if (pPoly2->getRows() != iRows || pPoly2->getCols() != iCols)
         {
             Scierror(999, _("%s: Wrong size for input argument #%d: A same size as input argument %d expected.\n"), "ldiv", 2, 1);
             return types::Function::Error;
         }
 
         piRank2 = new int[iSize];
-        pPoly2->getRealRank(piRank2);
+        pPoly2->getRank(piRank2);
 
         pdblCoef2 = new double*[iSize];
-        for(int i = 0; i < iSize; i++)
+        for (int i = 0; i < iSize; i++)
         {
-            pdblCoef2[i] = pPoly2->get(i)->getCoef()->get();
+            pdblCoef2[i] = pPoly2->get(i)->get();
         }
     }
-    else if(in[1]->isDouble())
+    else if (in[1]->isDouble())
     {
         types::Double* pDbl2 = in[1]->getAs<types::Double>();
-        if(pDbl2->isComplex())
+        if (pDbl2->isComplex())
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), "ldiv", 2);
             return types::Function::Error;
         }
 
-        if(pDbl2->getRows() != iRows || pDbl2->getCols() != iCols)
+        if (pDbl2->getRows() != iRows || pDbl2->getCols() != iCols)
         {
             Scierror(999, _("%s: Wrong size for input argument #%d: A same size as input argument %d expected.\n"), "ldiv", 2, 1);
             return types::Function::Error;
@@ -148,7 +148,7 @@ types::Function::ReturnValue sci_ldiv(types::typed_list &in, int _iRetCount, typ
 
         pdblCoef2 = new double*[iSize];
         double* pdbl = pDbl2->get();
-        for(int i = 0; i < iSize; i++)
+        for (int i = 0; i < iSize; i++)
         {
             pdblCoef2[i] = pdbl + i;
         }
@@ -160,7 +160,7 @@ types::Function::ReturnValue sci_ldiv(types::typed_list &in, int _iRetCount, typ
     }
 
     // get k
-    if(in[2]->isDouble() == false)
+    if (in[2]->isDouble() == false)
     {
         Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "ldiv", 3);
         return types::Function::Error;
@@ -168,13 +168,13 @@ types::Function::ReturnValue sci_ldiv(types::typed_list &in, int _iRetCount, typ
 
     types::Double* pDbl = in[2]->getAs<types::Double>();
 
-    if(pDbl->isComplex())
+    if (pDbl->isComplex())
     {
         Scierror(999, _("%s: Wrong type for input argument #%d: A real scalar expected.\n"), "ldiv", 3);
         return types::Function::Error;
     }
 
-    if(pDbl->isScalar() == false)
+    if (pDbl->isScalar() == false)
     {
         Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), "ldiv", 3);
         return types::Function::Error;
@@ -183,10 +183,10 @@ types::Function::ReturnValue sci_ldiv(types::typed_list &in, int _iRetCount, typ
     iK = (int)pDbl->get(0);
 
     /*** perform operations ***/
-    types::Double* pDblOut = new types::Double(iRows*iK, iCols);
+    types::Double* pDblOut = new types::Double(iRows * iK, iCols);
     double* pdblout = pDblOut->get();
 
-    for(int i = 0; i < iSize; i++)
+    for (int i = 0; i < iSize; i++)
     {
         int iSize1 = piRank1[i] + 1;
         int iSize2 = piRank2[i] + 1;
index fc1f25e..10a04dd 100644 (file)
@@ -21,9 +21,9 @@ extern "C"
 #include "localization.h"
 #include "elem_common.h"
 
-extern void C2F(residu)(double*, int*, double*, int*, double*, int*, double*, double*, int*);
-extern void C2F(wesidu)(double*, double*, int*, double*, double*, int*,
-                        double*, double*, int*, double*, double*, double*, int*);
+    extern void C2F(residu)(double*, int*, double*, int*, double*, int*, double*, double*, int*);
+    extern void C2F(wesidu)(double*, double*, int*, double*, double*, int*,
+                            double*, double*, int*, double*, double*, double*, int*);
 }
 
 /*--------------------------------------------------------------------------*/
@@ -62,7 +62,7 @@ types::Function::ReturnValue sci_residu(types::typed_list &in, int _iRetCount, t
     try
     {
         /*** get inputs arguments ***/
-        for(int i = 0; i < 3; i++)
+        for (int i = 0; i < 3; i++)
         {
             if (in[i]->isDouble())
             {
@@ -76,7 +76,7 @@ types::Function::ReturnValue sci_residu(types::typed_list &in, int _iRetCount, t
 
                 pdblInR[i]  = new double*[iSize];
                 double* pdbl = pDblIn[i]->get();
-                for(int j = 0; j < iSize; i++)
+                for (int j = 0; j < iSize; i++)
                 {
                     pdblInR[i][j] = pdbl + j;
                 }
@@ -85,7 +85,7 @@ types::Function::ReturnValue sci_residu(types::typed_list &in, int _iRetCount, t
                 {
                     pdblInI[i]  = new double*[iSize];
                     double* pdbl = pDblIn[i]->get();
-                    for(int j = 0; j < iSize; i++)
+                    for (int j = 0; j < iSize; i++)
                     {
                         pdblInI[i][j] = pdbl + j;
                     }
@@ -99,42 +99,46 @@ types::Function::ReturnValue sci_residu(types::typed_list &in, int _iRetCount, t
 
                 iSize = pPoly[i]->getSize();
                 piRank[i] = new int[iSize];
-                pPoly[i]->getRealRank(piRank[i]);
+                pPoly[i]->getRank(piRank[i]);
 
                 pdblInR[i] = new double*[iSize];
-                for(int j = 0; j < iSize; j++)
-                {
-                    pdblInR[i][j] = pPoly[i]->get(j)->getCoef()->get();
-                }
-
                 if (pPoly[i]->isComplex())
                 {
                     pdblInI[i] = new double*[iSize];
-                    for(int j = 0; j < iSize; j++)
+                    for (int j = 0; j < iSize; j++)
                     {
-                        pdblInI[i][j] = pPoly[i]->get(j)->getCoef()->getImg();
+                        pdblInR[i][j] = pPoly[i]->get(j)->get();
+                        pdblInI[i][j] = pPoly[i]->get(j)->getImg();
+                    }
+                }
+                else
+                {
+                    for (int j = 0; j < iSize; j++)
+                    {
+                        pdblInR[i][j] = pPoly[i]->get(j)->get();
                     }
                 }
             }
             else
             {
-                Scierror(999, _("%s: Wrong type for input argument #%d: A Matrix or polynom expected.\n"), "residu", i+1);
+                Scierror(999, _("%s: Wrong type for input argument #%d: A Matrix or polynom expected.\n"), "residu", i + 1);
                 throw 1;
             }
         }
 
-        if(iRows[0] != iRows[1] || iCols[0] != iCols[1] || iRows[0] != iRows[2] || iCols[0] != iCols[2])
+        if (iRows[0] != iRows[1] || iCols[0] != iCols[1] || iRows[0] != iRows[2] || iCols[0] != iCols[2])
         {
             Scierror(999, _("%s: Wrong size for argument: Incompatible dimensions.\n"), "residu");
             throw 1;
         }
 
         /*** perform operations ***/
-        if(pdblInI[0] == NULL && pdblInI[1] == NULL && pdblInI[2] == NULL)
-        {// real case
+        if (pdblInI[0] == NULL && pdblInI[1] == NULL && pdblInI[2] == NULL)
+        {
+            // real case
             pDblOut = new types::Double(iRows[0], iCols[0]);
             double* pdblOut = pDblOut->get();
-            for(int i = 0; i < iRows[0] * iCols[0]; i++)
+            for (int i = 0; i < iRows[0] * iCols[0]; i++)
             {
                 int iErr = 0;
                 double v = 0;
@@ -144,7 +148,7 @@ types::Function::ReturnValue sci_residu(types::typed_list &in, int _iRetCount, t
                 int iSize3 = piRank[2][i] + 1;
                 C2F(residu)(pdblInR[0][i], &iSize1, pdblInR[1][i], &iSize2,
                             pdblInR[2][i], &iSize3, &v, &dblEps, &iErr);
-                if(iErr)
+                if (iErr)
                 {
                     Scierror(78, _("%s: An error occured in '%s'.\n"), "residu", "residu");
                     throw iErr;
@@ -154,17 +158,18 @@ types::Function::ReturnValue sci_residu(types::typed_list &in, int _iRetCount, t
             }
         }
         else
-        {// complex case
+        {
+            // complex case
             pDblOut = new types::Double(iRows[0], iCols[0], true);
             double* pdblOutR = pDblOut->get();
             double* pdblOutI = pDblOut->getImg();
 
-            for(int i= 0; i < 3; i++)
+            for (int i = 0; i < 3; i++)
             {
-                if(pdblInI[i] == NULL)
+                if (pdblInI[i] == NULL)
                 {
                     pdblInI[i] = new double*[iSize];
-                    for(int j = 0; j < iSize; j++)
+                    for (int j = 0; j < iSize; j++)
                     {
                         int iLen = piRank[i][j] + 1;
                         pdblInI[i][j] = new double[iLen];
@@ -175,18 +180,18 @@ types::Function::ReturnValue sci_residu(types::typed_list &in, int _iRetCount, t
                 }
             }
 
-            for(int i = 0; i < iRows[0] * iCols[0]; i++)
+            for (int i = 0; i < iRows[0] * iCols[0]; i++)
             {
                 int iErr    = 0;
                 double real = 0;
                 double imag = 0;
 
-                C2F(wesidu)(pdblInR[0][i], pdblInI[0][i], (piRank[0])+i,
-                            pdblInR[1][i], pdblInI[1][i], (piRank[1])+i,
-                            pdblInR[2][i], pdblInI[2][i], (piRank[2])+i,
+                C2F(wesidu)(pdblInR[0][i], pdblInI[0][i], (piRank[0]) + i,
+                            pdblInR[1][i], pdblInI[1][i], (piRank[1]) + i,
+                            pdblInR[2][i], pdblInI[2][i], (piRank[2]) + i,
                             &real, &imag, &dblEps, &iErr);
 
-                if(iErr)
+                if (iErr)
                 {
                     Scierror(78, _("%s: An error occured in '%s'.\n"), "residu", "wesidu");
                     throw iErr;
@@ -197,50 +202,50 @@ types::Function::ReturnValue sci_residu(types::typed_list &in, int _iRetCount, t
             }
         }
     }
-    catch(int error)
+    catch (int error)
     {
         iError = error;
     }
 
     // free memory
-    for(int i = 0; i < 3; i++)
+    for (int i = 0; i < 3; i++)
     {
-        if(pDblIn[i])
+        if (pDblIn[i])
         {
             delete pDblIn[i];
         }
 
-        if(pPoly[i])
+        if (pPoly[i])
         {
             delete pPoly[i];
         }
 
-        if(piRank[i])
+        if (piRank[i])
         {
             delete[] piRank[i];
         }
 
-        if(pdblInR[i])
+        if (pdblInR[i])
         {
             delete[] pdblInR[i];
         }
 
-        if(isDeletable[i])
+        if (isDeletable[i])
         {
-            for(int j = 0; j < iSize; j++)
+            for (int j = 0; j < iSize; j++)
             {
                 delete[] pdblInI[i][j];
             }
         }
 
-        if(pdblInI[i])
+        if (pdblInI[i])
         {
             delete[] pdblInI[i];
         }
     }
 
     /*** retrun output arguments ***/
-    if(iError)
+    if (iError)
     {
         return types::Function::Error;
     }
index 093efdb..b6a64c0 100644 (file)
@@ -22,8 +22,8 @@ extern "C"
 #include "localization.h"
 #include "dmp2pm.h"
 
-extern void C2F(rtitr)( int*, int*, int*, double*, int*, int*, double*, int*, int*, double*,
-                        double*, int*, double*, double*, int*, int*, int*, double*, int*);
+    extern void C2F(rtitr)( int*, int*, int*, double*, int*, int*, double*, int*, int*, double*,
+                            double*, int*, double*, double*, int*, int*, int*, double*, int*);
 
 }
 
@@ -68,9 +68,9 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
 
     /*** get inputs arguments ***/
     // get up and yp
-    if(in.size() == 5)
+    if (in.size() == 5)
     {
-        if(in[4]->isDouble() == false)
+        if (in[4]->isDouble() == false)
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A matrix expected.\n"), "rtitr", 5);
             return types::Function::Error;
@@ -78,7 +78,7 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
 
         pDblYp = in[4]->getAs<types::Double>();
 
-        if(pDblYp->isComplex())
+        if (pDblYp->isComplex())
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), "rtitr", 5);
             return types::Function::Error;
@@ -86,7 +86,7 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
 
         pdblYp = pDblYp->get();
 
-        if(in[3]->isDouble() == false)
+        if (in[3]->isDouble() == false)
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A matrix expected.\n"), "rtitr", 4);
             return types::Function::Error;
@@ -94,7 +94,7 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
 
         pDblUp = in[3]->getAs<types::Double>();
 
-        if(pDblUp->isComplex())
+        if (pDblUp->isComplex())
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), "rtitr", 4);
             return types::Function::Error;
@@ -106,10 +106,10 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
     }
 
     // get Num
-    if(in[0]->isDouble())
+    if (in[0]->isDouble())
     {
         types::Double* pDblNum = in[0]->getAs<types::Double>();
-        if(pDblNum->isComplex())
+        if (pDblNum->isComplex())
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), "rtitr", 1);
             return types::Function::Error;
@@ -120,17 +120,17 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
         iColsNum    = pDblNum->getCols();
         iMaxRankNum = 0;
         pdblNum     = new double*[iSizeNum];
-        double* pdbl= pDblNum->get();
+        double* pdbl = pDblNum->get();
 
-        for(int i = 0; i < iSizeNum; i++)
+        for (int i = 0; i < iSizeNum; i++)
         {
             pdblNum[i] = pdbl + i;
         }
     }
-    else if(in[0]->isPoly())
+    else if (in[0]->isPoly())
     {
         types::Polynom* pPolyNum = in[0]->getAs<types::Polynom>();
-        if(pPolyNum->isComplex())
+        if (pPolyNum->isComplex())
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A real polynom expected.\n"), "rtitr", 1);
             return types::Function::Error;
@@ -139,14 +139,14 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
         iSizeNum    = pPolyNum->getSize();
         iRowsNum    = pPolyNum->getRows();
         iColsNum    = pPolyNum->getCols();
-        iMaxRankNum = pPolyNum->getRealMaxRank();
+        iMaxRankNum = pPolyNum->getMaxRank();
         piRankNum   = new int[iSizeNum];
-        pPolyNum->getRealRank(piRankNum);
+        pPolyNum->getRank(piRankNum);
 
         pdblNum     = new double*[iSizeNum];
-        for(int i = 0; i < iSizeNum; i++)
+        for (int i = 0; i < iSizeNum; i++)
         {
-            pdblNum[i] = pPolyNum->get(i)->getCoef()->get();
+            pdblNum[i] = pPolyNum->get(i)->get();
         }
     }
     else
@@ -156,16 +156,16 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
     }
 
     // get Den
-    if(in[1]->isDouble())
+    if (in[1]->isDouble())
     {
         types::Double* pDblDen = in[1]->getAs<types::Double>();
-        if(pDblDen->isComplex())
+        if (pDblDen->isComplex())
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), "rtitr", 2);
             return types::Function::Error;
         }
 
-        if(pDblDen->getRows() != pDblDen->getCols())
+        if (pDblDen->getRows() != pDblDen->getCols())
         {
             Scierror(999, _("%s: Wrong size for input argument #%d: A square matrix expected.\n"), "rtitr", 2);
             return types::Function::Error;
@@ -175,23 +175,23 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
         iRowsDen    = pDblDen->getRows();
         iMaxRankDen = 0;
         pdblDen     = new double*[iSizeDen];
-        double* pdbl= pDblDen->get();
+        double* pdbl = pDblDen->get();
 
-        for(int i = 0; i < iSizeDen; i++)
+        for (int i = 0; i < iSizeDen; i++)
         {
             pdblDen[i] = pdbl + i;
         }
     }
-    else if(in[1]->isPoly())
+    else if (in[1]->isPoly())
     {
         types::Polynom* pPolyDen = in[1]->getAs<types::Polynom>();
-        if(pPolyDen->isComplex())
+        if (pPolyDen->isComplex())
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: A real polynom expected.\n"), "rtitr", 2);
             return types::Function::Error;
         }
 
-        if(pPolyDen->getRows() != pPolyDen->getCols())
+        if (pPolyDen->getRows() != pPolyDen->getCols())
         {
             Scierror(999, _("%s: Wrong size for input argument #%d: A square matrix expected.\n"), "rtitr", 2);
             return types::Function::Error;
@@ -199,14 +199,14 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
 
         iSizeDen    = pPolyDen->getSize();
         iRowsDen    = pPolyDen->getRows();
-        iMaxRankDen = pPolyDen->getRealMaxRank();
+        iMaxRankDen = pPolyDen->getMaxRank();
         piRankDen   = new int[iSizeDen];
-        pPolyDen->getRealRank(piRankDen);
+        pPolyDen->getRank(piRankDen);
 
         pdblDen     = new double*[iSizeDen];
-        for(int i = 0; i < iSizeDen; i++)
+        for (int i = 0; i < iSizeDen; i++)
         {
-            pdblDen[i] = pPolyDen->get(i)->getCoef()->get();
+            pdblDen[i] = pPolyDen->get(i)->get();
         }
     }
     else
@@ -216,7 +216,7 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
     }
 
     // get u
-    if(in[2]->isDouble() == false)
+    if (in[2]->isDouble() == false)
     {
         Scierror(999, _("%s: Wrong type for input argument #%d: A matrix expected.\n"), "rtitr", 3);
         return types::Function::Error;
@@ -224,7 +224,7 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
 
     types::Double* pDblU = in[2]->getAs<types::Double>();
 
-    if(pDblU->isComplex())
+    if (pDblU->isComplex())
     {
         Scierror(999, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), "rtitr", 3);
         return types::Function::Error;
@@ -233,7 +233,7 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
     iRowsU = pDblU->getRows();
     iColsU = pDblU->getCols();
 
-    if(iRowsDen != iRowsNum || iColsNum != iRowsU)
+    if (iRowsDen != iRowsNum || iColsNum != iRowsU)
     {
         Scierror(60, _("%s: Wrong size for argument: Incompatible dimensions.\n"), "rtitr");
         return types::Function::Error;
@@ -242,27 +242,27 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
     pdblU = pDblU->get();
 
     // check size of input argument 4 and 5
-    if(in.size() == 5)
+    if (in.size() == 5)
     {
-        if(pDblYp->getRows() != iRowsDen && pDblYp->getRows() != 0)
+        if (pDblYp->getRows() != iRowsDen && pDblYp->getRows() != 0)
         {
             Scierror(60, _("%s: Wrong size for argument: Incompatible dimensions.\n"), "rtitr");
             return types::Function::Error;
         }
 
-        if(pDblYp->getCols() != iMaxRankDen)
+        if (pDblYp->getCols() != iMaxRankDen)
         {
             Scierror(60, _("%s: Wrong size for argument: Incompatible dimensions.\n"), "rtitr");
             return types::Function::Error;
         }
 
-        if(pDblUp->getRows() != iColsNum && pDblUp->getRows() != 0)
+        if (pDblUp->getRows() != iColsNum && pDblUp->getRows() != 0)
         {
             Scierror(60, _("%s: Wrong size for argument: Incompatible dimensions.\n"), "rtitr");
             return types::Function::Error;
         }
 
-        if(pDblUp->getCols() != iMaxRankDen)
+        if (pDblUp->getCols() != iMaxRankDen)
         {
             Scierror(60, _("%s: Wrong size for argument: Incompatible dimensions.\n"), "rtitr");
             return types::Function::Error;
@@ -288,9 +288,9 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
                pdblUp, pdblU, &iRowsU, pdblYp, pdblOut, &iRowsDen, &iJob, piWork, pdblWork, &iErr);
 
     // check error
-    if(iErr)
+    if (iErr)
     {
-        if(iErr == 1)
+        if (iErr == 1)
         {
             char strValue[256];
             sprintf(strValue, "%lf", pdblWork[0]);
@@ -298,7 +298,7 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
             sciprint(_("matrix is close to singular or badly scaled. rcond = %s\n"), strValue);
             iErr = 0;
         }
-        else if(iErr == 2)
+        else if (iErr == 2)
         {
             Scierror(19, _("Problem is singular.\n"), "rtitr");
         }
@@ -312,18 +312,18 @@ types::Function::ReturnValue sci_rtitr(types::typed_list &in, int _iRetCount, ty
     delete[] pdblDen;
     delete[] pdblNum;
 
-    if(piRankDen)
+    if (piRankDen)
     {
         delete[] piRankDen;
     }
 
-    if(piRankNum)
+    if (piRankNum)
     {
         delete[] piRankNum;
     }
 
     /*** retrun output arguments ***/
-    if(iErr)
+    if (iErr)
     {
         return types::Function::Error;
     }
index 5e985bd..3442316 100644 (file)
@@ -741,7 +741,7 @@ static void Add_s(void)
     dblCoef.set(0, 0, 0);
     dblCoef.set(0, 1, 1);
 
-    Add_Poly_Constant(L"%s", L"s", 2, &dblCoef);
+    Add_Poly_Constant(L"%s", L"s", 1, &dblCoef);
 }
 
 static void Add_z(void)
@@ -751,13 +751,13 @@ static void Add_z(void)
     dblCoef.set(0, 0, 0);
     dblCoef.set(0, 1, 1);
 
-    Add_Poly_Constant(L"%z", L"z", 2, &dblCoef);
+    Add_Poly_Constant(L"%z", L"z", 1, &dblCoef);
 }
 
 static void Add_Poly_Constant(wstring _szName, wstring _szPolyVar, int _iRank, Double * _pdbl)
 {
     types::Polynom * pVar = new types::Polynom(_szPolyVar, 1, 1, &_iRank);
-    SinglePoly *poPoly = pVar->get(0, 0);
+    SinglePoly *poPoly = pVar->get(0);
 
     poPoly->setCoef(_pdbl);
     symbol::Context::getInstance()->put(symbol::Symbol(_szName), pVar);
index 093f990..ccf4a6f 100644 (file)
@@ -1150,11 +1150,11 @@ types::Function::ReturnValue sci_ode(types::typed_list &in, int _iRetCount, type
                     // first lime is the time of result stored in second line.
                     int size = 2 * iSizeList;
                     int* iRanks = (int*)MALLOC(size * sizeof(int));
-
+                    int iMaxRank = pPolyY0->getMaxRank();
                     for(int i = 0; i < iSizeList; i++)
                     {
                         iRanks[i * 2] = 1; // time rank
-                        iRanks[i * 2 + 1] = pPolyY0->getMaxRank(); // result rank
+                        iRanks[i * 2 + 1] = iMaxRank; // result rank
                     }
 
                     pPolyYOut = new types::Polynom(pPolyY0->getVariableName(), 2, iSizeList, iRanks);
@@ -1200,9 +1200,10 @@ types::Function::ReturnValue sci_ode(types::typed_list &in, int _iRetCount, type
                 {
                     int size = pDblT->getSize();
                     int* iRanks = (int*)MALLOC(size * sizeof(int));
+                    int iMaxRank = pPolyY0->getMaxRank();
                     for(int i = 0; i < size; i++)
                     {
-                        iRanks[i] = pPolyY0->getMaxRank();
+                        iRanks[i] = iMaxRank;
                     }
 
                     pPolyYOut = new types::Polynom(pPolyY0->getVariableName(), 1, pDblT->getSize(), iRanks);
index be3eab5..ad151fe 100644 (file)
@@ -59,7 +59,8 @@ ELEMENTARIES_FUNCTIONS_CXX_SOURCES = \
     src/cpp/prod.cpp \
     src/cpp/sum.cpp \
     src/cpp/max.cpp \
-    src/cpp/min.cpp
+    src/cpp/min.cpp \
+    src/cpp/clean.cpp
 
 SLATEC_SOURCES = \
     src/fortran/slatec/zwrsk.f \
index 08c4a56..0bd9401 100644 (file)
@@ -331,7 +331,8 @@ am__objects_6 = src/cpp/libscielementary_functions_algo_la-getmode.lo \
        src/cpp/libscielementary_functions_algo_la-prod.lo \
        src/cpp/libscielementary_functions_algo_la-sum.lo \
        src/cpp/libscielementary_functions_algo_la-max.lo \
-       src/cpp/libscielementary_functions_algo_la-min.lo
+       src/cpp/libscielementary_functions_algo_la-min.lo \
+       src/cpp/libscielementary_functions_algo_la-clean.lo
 am_libscielementary_functions_algo_la_OBJECTS = $(am__objects_1) \
        $(am__objects_2) $(am__objects_3) $(am__objects_4) \
        $(am__objects_5) $(am__objects_6)
@@ -843,7 +844,8 @@ ELEMENTARIES_FUNCTIONS_CXX_SOURCES = \
     src/cpp/prod.cpp \
     src/cpp/sum.cpp \
     src/cpp/max.cpp \
-    src/cpp/min.cpp
+    src/cpp/min.cpp \
+    src/cpp/clean.cpp
 
 SLATEC_SOURCES = \
     src/fortran/slatec/zwrsk.f \
@@ -1927,6 +1929,8 @@ src/cpp/libscielementary_functions_algo_la-max.lo:  \
        src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libscielementary_functions_algo_la-min.lo:  \
        src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
+src/cpp/libscielementary_functions_algo_la-clean.lo:  \
+       src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
 
 libscielementary_functions-algo.la: $(libscielementary_functions_algo_la_OBJECTS) $(libscielementary_functions_algo_la_DEPENDENCIES) $(EXTRA_libscielementary_functions_algo_la_DEPENDENCIES) 
        $(AM_V_CXXLD)$(CXXLINK) $(am_libscielementary_functions_algo_la_rpath) $(libscielementary_functions_algo_la_OBJECTS) $(libscielementary_functions_algo_la_LIBADD) $(LIBS)
@@ -2217,6 +2221,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscielementary_functions_algo_la-vfrexp.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscielementary_functions_algo_la-vmul.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscielementary_functions_algo_la-xerhlt.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscielementary_functions_algo_la-clean.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscielementary_functions_algo_la-cumprod.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscielementary_functions_algo_la-cumsum.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscielementary_functions_algo_la-diag.Plo@am__quote@
@@ -2709,6 +2714,13 @@ src/cpp/libscielementary_functions_algo_la-min.lo: src/cpp/min.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscielementary_functions_algo_la-min.lo `test -f 'src/cpp/min.cpp' || echo '$(srcdir)/'`src/cpp/min.cpp
 
+src/cpp/libscielementary_functions_algo_la-clean.lo: src/cpp/clean.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscielementary_functions_algo_la-clean.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscielementary_functions_algo_la-clean.Tpo -c -o src/cpp/libscielementary_functions_algo_la-clean.lo `test -f 'src/cpp/clean.cpp' || echo '$(srcdir)/'`src/cpp/clean.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libscielementary_functions_algo_la-clean.Tpo src/cpp/$(DEPDIR)/libscielementary_functions_algo_la-clean.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/clean.cpp' object='src/cpp/libscielementary_functions_algo_la-clean.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscielementary_functions_algo_la-clean.lo `test -f 'src/cpp/clean.cpp' || echo '$(srcdir)/'`src/cpp/clean.cpp
+
 sci_gateway/cpp/libscielementary_functions_la-sci_isequal.lo: sci_gateway/cpp/sci_isequal.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscielementary_functions_la-sci_isequal.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_isequal.Tpo -c -o sci_gateway/cpp/libscielementary_functions_la-sci_isequal.lo `test -f 'sci_gateway/cpp/sci_isequal.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_isequal.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_isequal.Tpo sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_isequal.Plo
index 4b2d047..5fdc3be 100644 (file)
@@ -97,9 +97,9 @@ types::Function::ReturnValue sci_abs(types::typed_list &in, int _iRetCount, type
                 int rank = pPolyIn->get(i)->getRank();
                 types::SinglePoly* pSP = new types::SinglePoly(&data, rank);
 
-                for (int j = 0; j < rank; j++)
+                for (int j = 0; j < rank + 1; j++)
                 {
-                    data[j] = dabsz(pPolyIn->get(i)->getCoefReal()[j], pPolyIn->get(i)->getCoefImg()[j]);
+                    data[j] = dabsz(pPolyIn->get(i)->get()[j], pPolyIn->get(i)->getImg()[j]);
                 }
 
                 pPolyOut->set(i, pSP);
@@ -114,9 +114,9 @@ types::Function::ReturnValue sci_abs(types::typed_list &in, int _iRetCount, type
                 int rank = pPolyIn->get(i)->getRank();
                 types::SinglePoly* pSP = new types::SinglePoly(&data, rank);
 
-                for (int j = 0; j < rank; j++)
+                for (int j = 0; j < rank + 1; j++)
                 {
-                    data[j] = dabss(pPolyIn->get(i)->getCoefReal()[j]);
+                    data[j] = dabss(pPolyIn->get(i)->get()[j]);
                 }
 
                 pPolyOut->set(i, pSP);
index baf4c36..6d32a00 100644 (file)
@@ -113,10 +113,10 @@ types::Function::ReturnValue sci_ceil(types::typed_list &in, int _iRetCount, typ
                 int rank = pPolyIn->get(i)->getRank();
                 types::SinglePoly* pSP = new types::SinglePoly(&dataReal, &dataImg, rank);
 
-                for (int j = 0; j < rank; j++)
+                for (int j = 0; j < rank + 1; j++)
                 {
-                    dataReal[j] = dceils(pPolyIn->get(i)->getCoefReal()[j]);
-                    dataImg[j]  = dceils(pPolyIn->get(i)->getCoefImg()[j]);
+                    dataReal[j] = dceils(pPolyIn->get(i)->get()[j]);
+                    dataImg[j]  = dceils(pPolyIn->get(i)->getImg()[j]);
                 }
 
                 pPolyOut->set(i, pSP);
@@ -131,9 +131,9 @@ types::Function::ReturnValue sci_ceil(types::typed_list &in, int _iRetCount, typ
                 int rank = pPolyIn->get(i)->getRank();
                 types::SinglePoly* pSP = new types::SinglePoly(&dataReal, rank);
 
-                for (int j = 0; j < rank; j++)
+                for (int j = 0; j < rank + 1; j++)
                 {
-                    dataReal[j] = dceils(pPolyIn->get(i)->getCoefReal()[j]);
+                    dataReal[j] = dceils(pPolyIn->get(i)->get()[j]);
                 }
 
                 pPolyOut->set(i, pSP);
index ec004f9..36348cb 100644 (file)
 #include "double.hxx"
 #include "overload.hxx"
 #include "execvisitor.hxx"
-
+#include "clean.hxx"
 
 extern "C"
 {
 #include "Scierror.h"
 #include "localization.h"
-#include "basic_functions.h"
 }
 
 /*--------------------------------------------------------------------------*/
@@ -34,12 +33,9 @@ types::Function::ReturnValue sci_clean(types::typed_list &in, int _iRetCount, ty
     double* pdReal  = NULL;
     double* pdImg   = NULL;
 
-    double dNorm    = 0;
-    double dEps     = 0;
     double dEpsR    = 1E-10;
     double dEpsA    = 1E-10;
 
-    bool bComplex   = false;
     int iSize       = 0;
 
     //Only for types::Sparse case
@@ -67,27 +63,14 @@ types::Function::ReturnValue sci_clean(types::typed_list &in, int _iRetCount, ty
         pdReal = pDblOut->get();
         if (pDblOut->isComplex())
         {
-            bComplex = true;
             pdImg = pDblOut->getImg();
         }
     }
     else if (in[0]->isPoly())
     {
         types::Polynom* pPolyIn = in[0]->getAs<types::Polynom>();
-        int* piRanks = new int[pPolyIn->getSize()];
-        pPolyIn->getRank(piRanks);
-        pPolyOut = new types::Polynom(pPolyIn->getVariableName(), pPolyIn->getDims(), pPolyIn->getDimsArray(), piRanks);
-
-        pDblOut = pPolyIn->getCoef();
-        iSize = pDblOut->getSize();
-        pdReal = pDblOut->get();
-        if (pDblOut->isComplex())
-        {
-            bComplex = true;
-            pdImg = pDblOut->getImg();
-        }
-
-        delete[] piRanks;
+        iSize = pPolyIn->getSize();
+        pPolyOut = pPolyIn->clone()->getAs<types::Polynom>();
     }
     else if (in[0]->isSparse())
     {
@@ -100,13 +83,12 @@ types::Function::ReturnValue sci_clean(types::typed_list &in, int _iRetCount, ty
         pCols = pRows + iSize;
 
         pdReal = new double[iSize];
-        pdImg  = new double[iSize];
-        pSparseIn->outputValues(pdReal, pdImg);
-
         if (pSparseIn->isComplex())
         {
-            bComplex = true;
+            pdImg  = new double[iSize];
         }
+
+        pSparseIn->outputValues(pdReal, pdImg);
     }
     else
     {
@@ -154,32 +136,17 @@ types::Function::ReturnValue sci_clean(types::typed_list &in, int _iRetCount, ty
     }
 
     /***** perform operation *****/
-    if (bComplex)
+    if (in[0]->isPoly())
     {
-        dNorm = wasums(iSize, pdReal, pdImg);
-        dEps = std::max(dEpsA, dEpsR * dNorm);
-
         for (int i = 0 ; i < iSize ; i++)
         {
-            if (dabss(pdImg[i]) <= dEps)
-            {
-                pdImg[i] = 0;
-            }
+            types::SinglePoly* pSP = pPolyOut->get(i);
+            clean(pSP->get(), pSP->getImg(), pSP->getSize(), dEpsA, dEpsR);
         }
     }
     else
     {
-        int iOne = 1;
-        dNorm = C2F(dasum)(&iSize, pdReal, &iOne);
-        dEps = std::max(dEpsA, dEpsR * dNorm);
-    }
-
-    for (int i = 0 ; i < iSize ; i++)
-    {
-        if (dabss(pdReal[i]) <= dEps)
-        {
-            pdReal[i] = 0;
-        }
+        clean(pdReal, pdImg, iSize, dEpsA, dEpsR);
     }
 
     /***** set result *****/
@@ -189,21 +156,20 @@ types::Function::ReturnValue sci_clean(types::typed_list &in, int _iRetCount, ty
     }
     else if (in[0]->isPoly())
     {
-        pPolyOut->setCoef(pDblOut);
         pPolyOut->updateRank();
-        delete pDblOut;
-        pDblOut = NULL;
         out.push_back(pPolyOut);
     }
     else if (in[0]->isSparse())
     {
-        if (bComplex)
+        if (pdImg)
         {
             for (int i = 0 ; i < iSize ; i++)
             {
                 std::complex<double> cplx = complex<double>(pdReal[i], pdImg[i]);
                 pSparseOut->set(pRows[i] - 1, pCols[i] - 1, cplx, false);
             }
+
+            delete[] pdImg;
         }
         else
         {
@@ -216,7 +182,6 @@ types::Function::ReturnValue sci_clean(types::typed_list &in, int _iRetCount, ty
         pSparseOut->finalize();
 
         delete[] pdReal;
-        delete[] pdImg;
         delete[] pRows;
         out.push_back(pSparseOut);
     }
index e26203e..d8d9b8a 100644 (file)
@@ -48,11 +48,11 @@ types::Function::ReturnValue sci_conj(types::typed_list &in, int _iRetCount, typ
 
     if (in[0]->isDouble())
     {
-        pDblOut = in[0]->getAs<types::Double>()->clone()->getAs<types::Double>();
+        pDblOut = in[0]->clone()->getAs<types::Double>();
     }
     else if (in[0]->isPoly())
     {
-        pPolyOut = in[0]->getAs<types::Polynom>()->clone()->getAs<types::Polynom>();
+        pPolyOut = in[0]->clone()->getAs<types::Polynom>();
         pDblOut = pPolyOut->getCoef();
     }
     else
index 874c96c..ebad178 100644 (file)
@@ -318,11 +318,12 @@ types::Function::ReturnValue sci_cumsum(types::typed_list &in, int _iRetCount, t
         }
         else
         {
-            int* piRanks = (int*)malloc(pPolyIn->getSize() * sizeof(int));
+            int* piRanks = new int[pPolyIn->getSize()];
             pPolyIn->getRank(piRanks);
             pPolyOut = new types::Polynom(pPolyIn->getVariableName(), pPolyIn->getDims(), pPolyIn->getDimsArray(), piRanks);
             pPolyOut->setComplex(pPolyIn->isComplex());
             cumsum(pPolyIn, iOrientation, pPolyOut);
+            delete[] piRanks;
         }
     }
 
index 319f59c..099faad 100644 (file)
@@ -113,10 +113,10 @@ types::Function::ReturnValue sci_floor(types::typed_list &in, int _iRetCount, ty
                 int rank = pPolyIn->get(i)->getRank();
                 types::SinglePoly* pSP = new types::SinglePoly(&dataReal, &dataImg, rank);
 
-                for (int j = 0; j < rank; j++)
+                for (int j = 0; j < rank + 1; j++)
                 {
-                    dataReal[j] = dfloors(pPolyIn->get(i)->getCoefReal()[j]);
-                    dataImg[j]  = dfloors(pPolyIn->get(i)->getCoefImg()[j]);
+                    dataReal[j] = dfloors(pPolyIn->get(i)->get()[j]);
+                    dataImg[j]  = dfloors(pPolyIn->get(i)->getImg()[j]);
                 }
 
                 pPolyOut->set(i, pSP);
@@ -131,9 +131,9 @@ types::Function::ReturnValue sci_floor(types::typed_list &in, int _iRetCount, ty
                 int rank = pPolyIn->get(i)->getRank();
                 types::SinglePoly* pSP = new types::SinglePoly(&dataReal, rank);
 
-                for (int j = 0; j < rank; j++)
+                for (int j = 0; j < rank + 1; j++)
                 {
-                    dataReal[j] = dfloors(pPolyIn->get(i)->getCoefReal()[j]);
+                    dataReal[j] = dfloors(pPolyIn->get(i)->get()[j]);
                 }
 
                 pPolyOut->set(i, pSP);
index 3f57f80..af0cea7 100644 (file)
@@ -90,34 +90,21 @@ types::Function::ReturnValue sci_imag(types::typed_list &in, int _iRetCount, typ
     }
     else if (in[0]->isPoly())
     {
-        types::Polynom* pPolyIn = in[0]->getAs<types::Polynom>();
-        types::Polynom* pPolyOut = new types::Polynom(pPolyIn->getVariableName(), pPolyIn->getDims(), pPolyIn->getDimsArray());
+        types::Polynom* pPolyIn  = in[0]->getAs<types::Polynom>();
+        types::Polynom* pPolyOut = NULL;
 
-        double* dataReal = NULL;
-
-        if (pPolyIn->isComplex() == false)
-        {
-            // Create a polynom null of size of input polynom
-            for (int i = 0; i < pPolyIn->getSize(); i++)
-            {
-                types::SinglePoly* pSP = new types::SinglePoly(&dataReal, 1);
-                dataReal[0]  = 0;
-                pPolyOut->set(i, pSP);
-                delete pSP;
-                pSP = NULL;
-            }
-        }
-        else
+        if (pPolyIn->isComplex())
         {
+            pPolyOut = new types::Polynom(pPolyIn->getVariableName(), pPolyIn->getDims(), pPolyIn->getDimsArray());
             for (int i = 0; i < pPolyIn->getSize(); i++)
             {
                 int rank = pPolyIn->get(i)->getRank();
                 int iNewRank = rank;
 
                 // Reduce the rank of output polynom if the last ranks are null
-                for (int j = rank - 1 ; j > 0 ; j--)
+                for (int j = rank ; j > 0 ; j--)
                 {
-                    if (pPolyIn->get(i)->getCoefImg()[j] == 0.0)
+                    if (pPolyIn->get(i)->getImg()[j] == 0.0)
                     {
                         iNewRank--;
                     }
@@ -127,11 +114,12 @@ types::Function::ReturnValue sci_imag(types::typed_list &in, int _iRetCount, typ
                     }
                 }
 
+                double* dataReal = NULL;
                 types::SinglePoly* pSP = new types::SinglePoly(&dataReal, iNewRank);
 
-                for (int j = 0; j < iNewRank; j++)
+                for (int j = 0; j < iNewRank + 1; j++)
                 {
-                    dataReal[j]  = pPolyIn->get(i)->getCoefImg()[j];
+                    dataReal[j] = pPolyIn->get(i)->getImg()[j];
                 }
 
                 pPolyOut->set(i, pSP);
@@ -139,6 +127,16 @@ types::Function::ReturnValue sci_imag(types::typed_list &in, int _iRetCount, typ
                 pSP = NULL;
             }
         }
+        else
+        {
+            int iSize = pPolyIn->getSize();
+            int* piRanks = new int[iSize];
+            memset(piRanks, 0x00, iSize * sizeof(int));
+            pPolyOut = new types::Polynom(pPolyIn->getVariableName(), pPolyIn->getDims(), pPolyIn->getDimsArray(), piRanks);
+            pPolyOut->setZeros();
+            delete[] piRanks;
+        }
+
         out.push_back(pPolyOut);
     }
     else
index 873e2fd..33d4035 100644 (file)
@@ -112,18 +112,18 @@ types::Function::ReturnValue sci_imult(types::typed_list &in, int _iRetCount, ty
 
             if (pPolyIn->isComplex())
             {
-                for (int j = 0; j < rank; j++)
+                for (int j = 0; j < rank + 1; j++)
                 {
-                    dataReal[j] = pPolyIn->get(i)->getCoefImg()[j] * -1;
-                    dataImg[j]  = pPolyIn->get(i)->getCoefReal()[j];
+                    dataReal[j] = pPolyIn->get(i)->getImg()[j] * -1;
+                    dataImg[j]  = pPolyIn->get(i)->get()[j];
                 }
             }
             else
             {
-                for (int j = 0; j < rank; j++)
+                for (int j = 0; j < rank + 1; j++)
                 {
                     dataReal[j] = 0;
-                    dataImg[j]  = pPolyIn->get(i)->getCoefReal()[j];
+                    dataImg[j]  = pPolyIn->get(i)->get()[j];
                 }
             }
 
index c1d5471..2fbf10b 100644 (file)
@@ -142,24 +142,24 @@ types::Function::ReturnValue sci_int(types::typed_list &in, int _iRetCount, type
                 int rank = pPolyIn->get(i)->getRank();
                 types::SinglePoly* pSP = new types::SinglePoly(&dataReal, &dataImg, rank);
 
-                for (int j = 0; j < rank; j++)
+                for (int j = 0; j < rank + 1; j++)
                 {
-                    if (finite(pPolyIn->get(i)->getCoefReal()[j]))
+                    if (finite(pPolyIn->get(i)->get()[j]))
                     {
-                        dataReal[j] = (double)(long long int)pPolyIn->get(i)->getCoefReal()[j];
+                        dataReal[j] = (double)(long long int)pPolyIn->get(i)->get()[j];
                     }
                     else
                     {
-                        dataReal[j] = pPolyIn->get(i)->getCoefReal()[j];
+                        dataReal[j] = pPolyIn->get(i)->get()[j];
                     }
 
-                    if (finite(pPolyIn->get(i)->getCoefImg()[j]))
+                    if (finite(pPolyIn->get(i)->getImg()[j]))
                     {
-                        dataImg[j]  = (double)(long long int)pPolyIn->get(i)->getCoefImg()[j];
+                        dataImg[j]  = (double)(long long int)pPolyIn->get(i)->getImg()[j];
                     }
                     else
                     {
-                        dataImg[j] = pPolyIn->get(i)->getCoefImg()[j];
+                        dataImg[j] = pPolyIn->get(i)->getImg()[j];
                     }
                 }
 
@@ -176,9 +176,9 @@ types::Function::ReturnValue sci_int(types::typed_list &in, int _iRetCount, type
                 int rank = pPolyIn->get(i)->getRank();
                 pSP = new types::SinglePoly(&dataReal, rank);
 
-                for (int j = 0; j < rank; j++)
+                for (int j = 0; j < rank + 1; j++)
                 {
-                    double dblVal = pPolyIn->get(i)->getCoefReal()[j];
+                    double dblVal = pPolyIn->get(i)->get()[j];
                     if (finite(dblVal))
                     {
                         dataReal[j] = (double)((long long)dblVal);
index bfa2e29..86a464d 100644 (file)
@@ -140,9 +140,9 @@ types::Function::ReturnValue sci_isreal(types::typed_list &in, int _iRetCount, t
         for (int i = 0; i < pPolyIn->getSize(); i++)
         {
             int rank = pPolyIn->get(i)->getRank();
-            for (int j = 0; j < rank; j++)
+            for (int j = 0; j < rank + 1; j++)
             {
-                if (fabs(pPolyIn->get(i)->getCoefImg()[j]) > dEps)
+                if (fabs(pPolyIn->get(i)->getImg()[j]) > dEps)
                 {
                     out.push_back(new types::Bool(false));
                     return types::Function::OK;
index ef2d598..b21ad99 100644 (file)
@@ -94,7 +94,7 @@ types::Function::ReturnValue sci_real(types::typed_list &in, int _iRetCount, typ
         types::Polynom* pPolyOut = new types::Polynom(pPolyIn->getVariableName(), pPolyIn->getDims(), pPolyIn->getDimsArray(), piRanks);
         for (int i = 0; i < pPolyIn->getSize(); i++)
         {
-            memcpy(pPolyOut->get(i)->getCoef()->get(), pPolyIn->get(i)->getCoef()->get(), (piRanks[i] + 1) * sizeof(double));
+            memcpy(pPolyOut->get(i)->get(), pPolyIn->get(i)->get(), (piRanks[i] + 1) * sizeof(double));
         }
 
         delete[] piRanks;
index 85a9b5c..cfc5dfd 100644 (file)
@@ -50,17 +50,17 @@ types::Function::ReturnValue sci_round(types::typed_list &in, int _iRetCount, ty
         /***** perform operation *****/
         for (int compterElem = 0; compterElem < pPolyIn->getSize(); compterElem++)
         {
-            types::Double* pDblIn  = pPolyIn->get(compterElem)->getCoef();
-            types::Double* pDblOut = pPolyOut->get(compterElem)->getCoef();
+            types::SinglePoly* pSPIn  = pPolyIn->get(compterElem);
+            types::SinglePoly* pSPOut = pPolyOut->get(compterElem);
 
-            double* pRealIn  = pDblIn->get();
-            double* pRealOut = pDblOut->get();
+            double* pRealIn  = pSPIn->get();
+            double* pRealOut = pSPOut->get();
 
             if (pPolyIn->isComplex())
             {
-                double* pImgIn  = pDblIn->getImg();
-                double* pImgOut = pDblOut->getImg();
-                for (int i = 0; i < piRankPolyIn[compterElem]; i++)
+                double* pImgIn  = pSPIn->getImg();
+                double* pImgOut = pSPOut->getImg();
+                for (int i = 0; i < piRankPolyIn[compterElem] + 1; i++)
                 {
                     pRealOut[i] = C2F(danints)(pRealIn + i);
                     pImgOut[i]  = C2F(danints)(pImgIn + i);
@@ -68,7 +68,7 @@ types::Function::ReturnValue sci_round(types::typed_list &in, int _iRetCount, ty
             }
             else
             {
-                for (int i = 0; i < piRankPolyIn[compterElem]; i++)
+                for (int i = 0; i < piRankPolyIn[compterElem] + 1; i++)
                 {
                     pRealOut[i] = C2F(danints)(pRealIn + i);
                 }
index 4620268..3b773b3 100644 (file)
@@ -114,11 +114,8 @@ types::Function::ReturnValue sci_tril(types::typed_list &in, int _iRetCount, typ
                 int iSize = min(max(i - iOffset, 0), iRows);
                 for (int j = 0; j < iSize; j++)
                 {
-                    double* dblReal = NULL;
-                    double* dblImg  = NULL;
-                    types::SinglePoly* pSP = new types::SinglePoly(&dblReal, &dblImg, 1);
-                    dblReal[0] = 0;
-                    dblImg[0]  = 0;
+                    types::SinglePoly* pSP = new types::SinglePoly();
+                    pSP->setComplex(true);
                     pPolyOut->set(i * iRows + j, pSP);
                     delete pSP;
                 }
@@ -131,9 +128,7 @@ types::Function::ReturnValue sci_tril(types::typed_list &in, int _iRetCount, typ
                 int iSize = min(max(i - iOffset, 0), iRows);
                 for (int j = 0; j < iSize; j++)
                 {
-                    double* dbl = NULL;
-                    types::SinglePoly* pSP = new types::SinglePoly(&dbl, 1);
-                    dbl[0] = 0;
+                    types::SinglePoly* pSP = new types::SinglePoly();
                     pPolyOut->set(i * iRows + j, pSP);
                     delete pSP;
                 }
index a379721..6fd4261 100644 (file)
@@ -114,8 +114,12 @@ types::Function::ReturnValue sci_triu(types::typed_list &in, int _iRetCount, typ
         types::Polynom* pPolyIn = in[0]->getAs<types::Polynom>();
         int iRows = pPolyIn->getRows();
         int iCols = pPolyIn->getCols();
+        int* piRanks = new int[iRows * iCols];
+        memset(piRanks, 0x00, iRows * iCols * sizeof(int));
+        types::Polynom* pPolyOut = new types::Polynom(pPolyIn->getVariableName(), iRows, iCols, piRanks);
+        delete[] piRanks;
+        pPolyOut->setZeros();
 
-        types::Polynom* pPolyOut = new types::Polynom(pPolyIn->getVariableName(), iRows, iCols);
         for (int i = 0 ; i < iCols ; i++)
         {
             int iSize = min(max(i + 1 - iOffset, 0), iRows);
index 59efe8e..826e338 100644 (file)
@@ -206,6 +206,7 @@ lib /DEF:"$(ProjectDir)cacsd_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platfor
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="..\cpp\clean.cpp" />
     <ClCompile Include="..\cpp\cumprod.cpp" />
     <ClCompile Include="..\cpp\cumsum.cpp" />
     <ClCompile Include="..\cpp\diag.cpp" />
@@ -298,6 +299,7 @@ lib /DEF:"$(ProjectDir)cacsd_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platfor
     <ClInclude Include="..\..\includes\unsfdcopy.h" />
     <ClInclude Include="..\..\includes\vfinite.h" />
     <ClInclude Include="..\..\includes\xerhlt.h" />
+    <ClInclude Include="..\cpp\clean.hxx" />
     <ClInclude Include="..\cpp\cumprod.hxx" />
     <ClInclude Include="..\cpp\cumsum.hxx" />
     <ClInclude Include="..\cpp\diag.hxx" />
index 87fabad..f4ee7dd 100644 (file)
     <ClCompile Include="..\cpp\prod.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\cpp\clean.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\dynlib_elementary_functions.h">
     <ClInclude Include="..\..\includes\gsort.hxx">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\cpp\clean.hxx">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="elementary_functions_f_Import.def">
diff --git a/scilab/modules/elementary_functions/src/cpp/clean.cpp b/scilab/modules/elementary_functions/src/cpp/clean.cpp
new file mode 100644 (file)
index 0000000..b77998d
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2014 - Scilab Enterprises - Cedric Delamarre
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+/*--------------------------------------------------------------------------*/
+#include "clean.hxx"
+
+extern "C"
+{
+#include "basic_functions.h"
+}
+
+/*--------------------------- Double ---------------------------------------*/
+void clean(double* pdblReal, double* pdblImg, int iSize, double dEpsA, double dEpsR)
+{
+    if (pdblImg)
+    {
+        double dNorm = wasums(iSize, pdblReal, pdblImg);
+        double dEps = Max(dEpsA, dEpsR * dNorm);
+        for (int i = 0 ; i < iSize ; i++)
+        {
+            if (dabss(pdblImg[i]) <= dEps)
+            {
+                pdblImg[i] = 0;
+            }
+
+            if (dabss(pdblReal[i]) <= dEps)
+            {
+                pdblReal[i] = 0;
+            }
+        }
+    }
+    else
+    {
+        int iOne = 1;
+        double dNorm = C2F(dasum)(&iSize, pdblReal, &iOne);
+        double dEps = Max(dEpsA, dEpsR * dNorm);
+        for (int i = 0 ; i < iSize ; i++)
+        {
+            if (dabss(pdblReal[i]) <= dEps)
+            {
+                pdblReal[i] = 0;
+            }
+        }
+    }
+}
diff --git a/scilab/modules/elementary_functions/src/cpp/clean.hxx b/scilab/modules/elementary_functions/src/cpp/clean.hxx
new file mode 100644 (file)
index 0000000..0712cf5
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2014 - Scilab Enterprises - Cedric Delamarre
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#ifndef __CLEAN_H__
+#define __CLEAN_H__
+
+extern "C"
+{
+#include "dynlib_elementary_functions.h"
+}
+
+ELEMENTARY_FUNCTIONS_IMPEXP void clean(double* pdblReal, double* pdblImg, int iSize, double dEpsA, double dEpsR);
+
+#endif /* __CLEAN_H__ */
index 9f88f18..426e906 100644 (file)
@@ -103,9 +103,9 @@ int cumprod(types::Double* pIn, int iOrientation, types::Double* pOut)
 int cumprod(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
 {
     int iErr        = 0;
-    int iRank       = 0;
+    int iSize       = 0;
     int iOutRank    = 0;
-    int iLastRank   = 0;
+    int iLastSize   = 0;
 
     double* pdRData         = NULL;
     double* pdIData         = NULL;
@@ -120,13 +120,13 @@ int cumprod(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
     if (iOrientation == 0) // all
     {
         // set first element
-        iRank = pIn->get(0)->getRank();
-        pdblReal = pIn->get(0)->getCoefReal();
+        iSize = pIn->get(0)->getSize();
+        pdblReal = pIn->get(0)->get();
         if (bComplex)
         {
-            pSP = new types::SinglePoly(&pdRData, &pdIData, iRank);
-            pdblImg = pIn->get(0)->getCoefImg();
-            for (int j = 0; j < iRank; j++)
+            pSP = new types::SinglePoly(&pdRData, &pdIData, iSize - 1);
+            pdblImg = pIn->get(0)->getImg();
+            for (int j = 0; j < iSize; j++)
             {
                 pdRData[j] = pdblReal[j];
                 pdIData[j] = pdblImg[j];
@@ -134,15 +134,15 @@ int cumprod(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
         }
         else
         {
-            pSP = new types::SinglePoly(&pdRData, iRank);
-            for (int j = 0; j < iRank; j++)
+            pSP = new types::SinglePoly(&pdRData, iSize - 1);
+            for (int j = 0; j < iSize; j++)
             {
                 pdRData[j] = pdblReal[j];
             }
         }
 
         pOut->set(0, pSP);
-        iLastRank = iRank;
+        iLastSize = iSize;
         pdblLastReal = pdblReal;
         pdblLastImg = pdblImg;
 
@@ -151,23 +151,23 @@ int cumprod(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
         {
             for (int i = 1; i < pIn->getSize(); i++)
             {
-                pdblReal = pIn->get(i)->getCoefReal();
-                pdblImg = pIn->get(i)->getCoefImg();
-                iRank = pIn->get(i)->getRank();
+                pdblReal = pIn->get(i)->get();
+                pdblImg = pIn->get(i)->getImg();
+                iSize = pIn->get(i)->getSize();
 
-                iOutRank = iLastRank + iRank - 1;
+                iOutRank = iLastSize - 1 + iSize - 1;
 
                 pSP = new types::SinglePoly(&pdRData, &pdIData, iOutRank);
-                pSP->getCoef()->setZeros();
+                pSP->setZeros();
 
-                iMultiComplexPolyByComplexPoly( pdblReal, pdblImg, iRank,
-                                                pdblLastReal, pdblLastImg, iLastRank,
-                                                pdRData, pdIData, iOutRank);
+                iMultiComplexPolyByComplexPoly( pdblReal, pdblImg, iSize,
+                                                pdblLastReal, pdblLastImg, iLastSize,
+                                                pdRData, pdIData, iOutRank + 1);
 
                 pOut->set(i, pSP);
                 pdblLastReal = pdRData;
                 pdblLastImg = pdIData;
-                iLastRank = iOutRank;
+                iLastSize = iOutRank + 1;
                 delete pSP;
             }
         }
@@ -175,18 +175,18 @@ int cumprod(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
         {
             for (int i = 1; i < pIn->getSize(); i++)
             {
-                pdblReal = pIn->get(i)->getCoefReal();
-                iRank = pIn->get(i)->getRank();
+                pdblReal = pIn->get(i)->get();
+                iSize = pIn->get(i)->getSize();
 
-                iOutRank = iLastRank + iRank - 1;
+                iOutRank = iLastSize - 1 + iSize - 1;
 
                 pSP = new types::SinglePoly(&pdRData, iOutRank);
-                pSP->getCoef()->setZeros();
-                iMultiScilabPolynomByScilabPolynom(pdblReal, iRank, pdblLastReal, iLastRank, pdRData, iOutRank);
+                pSP->setZeros();
+                iMultiScilabPolynomByScilabPolynom(pdblReal, iSize, pdblLastReal, iLastSize, pdRData, iOutRank + 1);
 
                 pOut->set(i, pSP);
                 pdblLastReal = pdRData;
-                iLastRank = iOutRank;
+                iLastSize = iOutRank + 1;
                 delete pSP;
             }
         }
@@ -207,12 +207,12 @@ int cumprod(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
             {
                 for (int i = j; i < iIncrement + j; i++) // set the first values in out
                 {
-                    pdblReal = pIn->get(i)->getCoefReal();
-                    pdblImg = pIn->get(i)->getCoefImg();
-                    iRank = pIn->get(i)->getRank();
-                    pSP = new types::SinglePoly(&pdRData, &pdIData, iRank);
+                    pdblReal = pIn->get(i)->get();
+                    pdblImg = pIn->get(i)->getImg();
+                    iSize = pIn->get(i)->getSize();
+                    pSP = new types::SinglePoly(&pdRData, &pdIData, iSize - 1);
 
-                    for (int j = 0; j < iRank; j++)
+                    for (int j = 0; j < iSize; j++)
                     {
                         pdRData[j] = pdblReal[j];
                         pdIData[j] = pdblImg[j];
@@ -225,19 +225,19 @@ int cumprod(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
                 {
                     for (int i = (iIncrement * k) + j; i < (iIncrement * (k + 1)) + j; i++)
                     {
-                        iLastRank = pOut->get(i - iIncrement)->getRank();
-                        pdblLastReal = pOut->get(i - iIncrement)->getCoefReal();
-                        pdblLastImg = pOut->get(i - iIncrement)->getCoefImg();
-                        iRank = pIn->get(i)->getRank();
-                        pdblReal = pIn->get(i)->getCoefReal();
-                        pdblImg = pIn->get(i)->getCoefImg();
-
-                        iOutRank = iLastRank + iRank - 1;
+                        iLastSize = pOut->get(i - iIncrement)->getSize();
+                        pdblLastReal = pOut->get(i - iIncrement)->get();
+                        pdblLastImg = pOut->get(i - iIncrement)->getImg();
+                        iSize = pIn->get(i)->getSize();
+                        pdblReal = pIn->get(i)->get();
+                        pdblImg = pIn->get(i)->getImg();
+
+                        iOutRank = iLastSize - 1 + iSize - 1;
                         pSP = new types::SinglePoly(&pdRData, &pdIData, iOutRank);
 
-                        iMultiComplexPolyByComplexPoly(pdblReal, pdblImg, iRank,
-                                                       pdblLastReal, pdblLastImg, iLastRank,
-                                                       pdRData, pdIData, iOutRank);
+                        iMultiComplexPolyByComplexPoly(pdblReal, pdblImg, iSize,
+                                                       pdblLastReal, pdblLastImg, iLastSize,
+                                                       pdRData, pdIData, iOutRank + 1);
 
                         pOut->set(i, pSP);
                         delete pSP;
@@ -251,11 +251,11 @@ int cumprod(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
             {
                 for (int i = j; i < iIncrement + j; i++) // set the first values in out
                 {
-                    pdblReal = pIn->get(i)->getCoefReal();
-                    iRank = pIn->get(i)->getRank();
-                    pSP = new types::SinglePoly(&pdRData, iRank);
+                    pdblReal = pIn->get(i)->get();
+                    iSize = pIn->get(i)->getSize();
+                    pSP = new types::SinglePoly(&pdRData, iSize - 1);
 
-                    for (int j = 0; j < iRank; j++)
+                    for (int j = 0; j < iSize; j++)
                     {
                         pdRData[j] = pdblReal[j];
                     }
@@ -267,15 +267,15 @@ int cumprod(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
                 {
                     for (int i = (iIncrement * k) + j; i < (iIncrement * (k + 1)) + j; i++)
                     {
-                        iLastRank = pOut->get(i - iIncrement)->getRank();
-                        pdblLastReal = pOut->get(i - iIncrement)->getCoefReal();
-                        iRank = pIn->get(i)->getRank();
-                        pdblReal = pIn->get(i)->getCoefReal();
+                        iLastSize = pOut->get(i - iIncrement)->getSize();
+                        pdblLastReal = pOut->get(i - iIncrement)->get();
+                        iSize = pIn->get(i)->getSize();
+                        pdblReal = pIn->get(i)->get();
 
-                        iOutRank = iLastRank + iRank - 1;
+                        iOutRank = iLastSize - 1 + iSize - 1;
                         pSP = new types::SinglePoly(&pdRData, iOutRank);
 
-                        iMultiScilabPolynomByScilabPolynom(pdblReal, iRank, pdblLastReal, iLastRank, pdRData, iOutRank);
+                        iMultiScilabPolynomByScilabPolynom(pdblReal, iSize, pdblLastReal, iLastSize, pdRData, iOutRank + 1);
 
                         pOut->set(i, pSP);
                         delete pSP;
index 5180ba1..1f42142 100644 (file)
@@ -118,12 +118,12 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
     {
         // set first element
         iRank = pIn->get(0)->getRank();
-        pdblReal = pIn->get(0)->getCoefReal();
+        pdblReal = pIn->get(0)->get();
         if (bComplex)
         {
             pSP = new types::SinglePoly(&pdRData, &pdIData, iRank);
-            pdblImg = pIn->get(0)->getCoefImg();
-            for (int j = 0; j < iRank; j++)
+            pdblImg = pIn->get(0)->getImg();
+            for (int j = 0; j < iRank + 1; j++)
             {
                 pdRData[j] = pdblReal[j];
                 pdIData[j] = pdblImg[j];
@@ -132,7 +132,7 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
         else
         {
             pSP = new types::SinglePoly(&pdRData, iRank);
-            for (int j = 0; j < iRank; j++)
+            for (int j = 0; j < iRank + 1; j++)
             {
                 pdRData[j] = pdblReal[j];
             }
@@ -148,15 +148,15 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
         {
             for (int i = 1; i < pIn->getSize(); i++)
             {
-                pdblReal = pIn->get(i)->getCoefReal();
-                pdblImg  = pIn->get(i)->getCoefImg();
+                pdblReal = pIn->get(i)->get();
+                pdblImg  = pIn->get(i)->getImg();
                 iRank    = pIn->get(i)->getRank();
 
                 iOutRank = std::max(iRank, iLastRank);
                 iMin     = std::min(iRank, iLastRank);
 
                 pSP = new types::SinglePoly(&pdRData, &pdIData, iOutRank);
-                for (int j = 0; j < iMin; j++)
+                for (int j = 0; j < iMin + 1; j++)
                 {
                     pdRData[j] = pdblReal[j] + pdblLastReal[j];
                     pdIData[j] = pdblImg[j]  + pdblLastImg[j];
@@ -164,7 +164,7 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
 
                 if (iOutRank == iRank)
                 {
-                    for (int j = iMin; j < iOutRank; j++)
+                    for (int j = iMin + 1; j < iOutRank + 1; j++)
                     {
                         pdRData[j] = pdblReal[j];
                         pdIData[j] = pdblImg[j];
@@ -172,7 +172,7 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
                 }
                 else
                 {
-                    for (int j = iMin; j < iOutRank; j++)
+                    for (int j = iMin + 1; j < iOutRank + 1; j++)
                     {
                         pdRData[j] = pdblLastReal[j];
                         pdIData[j] = pdblLastImg[j];
@@ -190,28 +190,28 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
         {
             for (int i = 1; i < pIn->getSize(); i++)
             {
-                pdblReal = pIn->get(i)->getCoefReal();
+                pdblReal = pIn->get(i)->get();
                 iRank    = pIn->get(i)->getRank();
 
                 iOutRank = std::max(iRank, iLastRank);
                 iMin     = std::min(iRank, iLastRank);
 
                 pSP = new types::SinglePoly(&pdRData, iOutRank);
-                for (int j = 0; j < iMin; j++)
+                for (int j = 0; j < iMin + 1; j++)
                 {
                     pdRData[j] = pdblReal[j] + pdblLastReal[j];
                 }
 
                 if (iOutRank == iRank)
                 {
-                    for (int j = iMin; j < iOutRank; j++)
+                    for (int j = iMin + 1; j < iOutRank + 1; j++)
                     {
                         pdRData[j] = pdblReal[j];
                     }
                 }
                 else
                 {
-                    for (int j = iMin; j < iOutRank; j++)
+                    for (int j = iMin + 1; j < iOutRank + 1; j++)
                     {
                         pdRData[j] = pdblLastReal[j];
                     }
@@ -240,13 +240,13 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
             {
                 for (int i = j; i < iIncrement + j; i++) // set the first values in out
                 {
-                    pdblReal = pIn->get(i)->getCoefReal();
-                    pdblImg  = pIn->get(i)->getCoefImg();
+                    pdblReal = pIn->get(i)->get();
+                    pdblImg  = pIn->get(i)->getImg();
                     iRank    = pIn->get(i)->getRank();
 
                     pSP = new types::SinglePoly(&pdRData, &pdIData, iRank);
 
-                    for (int j = 0; j < iRank; j++)
+                    for (int j = 0; j < iRank + 1; j++)
                     {
                         pdRData[j] = pdblReal[j];
                         pdIData[j] = pdblImg[j];
@@ -260,18 +260,18 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
                     for (int i = (iIncrement * k) + j; i < (iIncrement * (k + 1)) + j; i++)
                     {
                         iLastRank    = pOut->get(i - iIncrement)->getRank();
-                        pdblLastReal = pOut->get(i - iIncrement)->getCoefReal();
-                        pdblLastImg  = pOut->get(i - iIncrement)->getCoefImg();
+                        pdblLastReal = pOut->get(i - iIncrement)->get();
+                        pdblLastImg  = pOut->get(i - iIncrement)->getImg();
 
                         iRank    = pIn->get(i)->getRank();
-                        pdblReal = pIn->get(i)->getCoefReal();
-                        pdblImg  = pIn->get(i)->getCoefImg();
+                        pdblReal = pIn->get(i)->get();
+                        pdblImg  = pIn->get(i)->getImg();
 
                         iOutRank = std::max(iRank, iLastRank);
                         iMin     = std::min(iRank, iLastRank);
 
                         pSP = new types::SinglePoly(&pdRData, &pdIData, iOutRank);
-                        for (int j = 0; j < iMin; j++)
+                        for (int j = 0; j < iMin + 1; j++)
                         {
                             pdRData[j] = pdblReal[j] + pdblLastReal[j];
                             pdIData[j] = pdblImg[j]  + pdblLastImg[j];
@@ -279,7 +279,7 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
 
                         if (iOutRank == iRank)
                         {
-                            for (int j = iMin; j < iOutRank; j++)
+                            for (int j = iMin + 1; j < iOutRank + 1; j++)
                             {
                                 pdRData[j] = pdblReal[j];
                                 pdIData[j] = pdblImg[j];
@@ -287,7 +287,7 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
                         }
                         else
                         {
-                            for (int j = iMin; j < iOutRank; j++)
+                            for (int j = iMin + 1; j < iOutRank + 1; j++)
                             {
                                 pdRData[j] = pdblLastReal[j];
                                 pdIData[j] = pdblLastImg[j];
@@ -305,12 +305,12 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
             {
                 for (int i = j; i < iIncrement + j; i++) // set the first values in out
                 {
-                    pdblReal = pIn->get(i)->getCoefReal();
+                    pdblReal = pIn->get(i)->get();
                     iRank    = pIn->get(i)->getRank();
 
                     pSP = new types::SinglePoly(&pdRData, iRank);
 
-                    for (int j = 0; j < iRank; j++)
+                    for (int j = 0; j < iRank + 1; j++)
                     {
                         pdRData[j] = pdblReal[j];
                     }
@@ -323,30 +323,30 @@ int cumsum(types::Polynom* pIn, int iOrientation, types::Polynom* pOut)
                     for (int i = (iIncrement * k) + j; i < (iIncrement * (k + 1)) + j; i++)
                     {
                         iLastRank    = pOut->get(i - iIncrement)->getRank();
-                        pdblLastReal = pOut->get(i - iIncrement)->getCoefReal();
+                        pdblLastReal = pOut->get(i - iIncrement)->get();
 
                         iRank    = pIn->get(i)->getRank();
-                        pdblReal = pIn->get(i)->getCoefReal();
+                        pdblReal = pIn->get(i)->get();
 
                         iOutRank = std::max(iRank, iLastRank);
                         iMin     = std::min(iRank, iLastRank);
 
                         pSP = new types::SinglePoly(&pdRData, iOutRank);
-                        for (int j = 0; j < iMin; j++)
+                        for (int j = 0; j < iMin + 1; j++)
                         {
                             pdRData[j] = pdblReal[j] + pdblLastReal[j];
                         }
 
                         if (iOutRank == iRank)
                         {
-                            for (int j = iMin; j < iOutRank; j++)
+                            for (int j = iMin + 1; j < iOutRank + 1; j++)
                             {
                                 pdRData[j] = pdblReal[j];
                             }
                         }
                         else
                         {
-                            for (int j = iMin; j < iOutRank; j++)
+                            for (int j = iMin + 1; j < iOutRank + 1; j++)
                             {
                                 pdRData[j] = pdblLastReal[j];
                             }
index 9ca27ef..02714bb 100644 (file)
@@ -47,49 +47,16 @@ types::InternalType* diag(types::Polynom* pIn,  int iStartPos)
         if (iSize)
         {
             pPolyOut = new types::Polynom(pIn->getVariableName(), iSize, 1);
-            pPolyOut->setComplex(pIn->isComplex());
         }
         else
         {
             return types::Double::Empty();
         }
 
-        if (pIn->isComplex())
-        {
-            for (int i = 0; i < iSize; i++)
-            {
-                iRank = pIn->get(i * (iSize + 1))->getRank();
-                pSP = new types::SinglePoly(&pdRData, &pdIData, iRank);
-                iPos = (i + iStartCol) * iRows + (i + iStartRow);
-
-                for (int j = 0; j < iRank; j++)
-                {
-                    pdRData[j] = pIn->get(iPos)->getCoefReal()[j];
-                    pdIData[j] = pIn->get(iPos)->getCoefImg()[j];
-                }
-
-                pPolyOut->set(i, pSP);
-                delete pSP;
-                pSP = NULL;
-            }
-        }
-        else
+        for (int i = 0; i < iSize; i++)
         {
-            for (int i = 0; i < iSize; i++)
-            {
-                iRank = pIn->get(i * (iSize + 1))->getRank();
-                pSP = new types::SinglePoly(&pdRData, iRank);
-                iPos = (i + iStartCol) * iRows + (i + iStartRow);
-
-                for (int j = 0; j < iRank; j++)
-                {
-                    pdRData[j] = pIn->get(iPos)->getCoefReal()[j];
-                }
-
-                pPolyOut->set(i, pSP);
-                delete pSP;
-                pSP = NULL;
-            }
+            iPos = (i + iStartCol) * iRows + (i + iStartRow);
+            pPolyOut->set(i, pIn->get(iPos));
         }
     }
     else // pIn is a vector
@@ -106,49 +73,20 @@ types::InternalType* diag(types::Polynom* pIn,  int iStartPos)
             iStartCol = iStartPos;
         }
 
-        pPolyOut = new types::Polynom(pIn->getVariableName(), iSize, iSize);
+        int* piRanks = new int[iSize * iSize];
+        memset(piRanks, 0x00, iSize * iSize * sizeof(int));
+        pPolyOut = new types::Polynom(pIn->getVariableName(), iSize, iSize, piRanks);
+        delete[] piRanks;
+        pPolyOut->setZeros();
         pPolyOut->setComplex(pIn->isComplex());
 
-        if (pIn->isComplex())
-        {
-            for (int i = 0; i < iSizeOfVector; i++)
-            {
-                iRank = pIn->get(i)->getRank();
-                pSP = new types::SinglePoly(&pdRData, &pdIData, iRank);
-                iPos = (i + iStartCol) * iSize + (i + iStartRow);
-
-                for (int j = 0; j < iRank; j++)
-                {
-                    pdRData[j] = pIn->get(i)->getCoefReal()[j];
-                    pdIData[j] = pIn->get(i)->getCoefImg()[j];
-                }
-
-                pPolyOut->set(iPos, pSP);
-                delete pSP;
-                pSP = NULL;
-            }
-        }
-        else
+        for (int i = 0; i < iSizeOfVector; i++)
         {
-            for (int i = 0; i < iSizeOfVector; i++)
-            {
-                iRank = pIn->get(i)->getRank();
-                pSP = new types::SinglePoly(&pdRData, iRank);
-                iPos = (i + iStartCol) * iSize + (i + iStartRow);
-
-                for (int j = 0; j < iRank; j++)
-                {
-                    pdRData[j] = pIn->get(i)->getCoefReal()[j];
-                }
-
-                pPolyOut->set(iPos, pSP);
-                delete pSP;
-                pSP = NULL;
-            }
+            iPos = (i + iStartCol) * iSize + (i + iStartRow);
+            pPolyOut->set(iPos, pIn->get(i));
         }
     }
 
-    pPolyOut->updateRank();
     return pPolyOut;
 }
 
index 3c4253f..363653f 100644 (file)
@@ -153,19 +153,19 @@ types::Polynom* prod(types::Polynom* pIn, int iOrientation)
         pOut->setComplex(pIn->isComplex());
 
         // do prod
-        double* pdblRealOut = pOut->get(0)->getCoef()->getReal();
+        double* pdblRealOut = pOut->get(0)->get();
         if (pIn->isComplex())
         {
-            double* pdblImgOut = pOut->get(0)->getCoef()->getImg();
+            double* pdblImgOut = pOut->get(0)->getImg();
 
             // alloc temporary workspace
-            double* pdblTempReal = new double[iRankMax];
-            double* pdblTempImg  = new double[iRankMax];
+            double* pdblTempReal = new double[iRankMax + 1];
+            double* pdblTempImg  = new double[iRankMax + 1];
 
             // init output to 1 + 0s + 0s²...
             pdblRealOut[0] = 1;
             pdblImgOut[0]  = 0;
-            for (i