refactor unary minus operation 26/15026/6
Antoine ELIAS [Tue, 12 Aug 2014 13:42:18 +0000 (15:42 +0200)]
Change-Id: Ide96a8ddc6eefefd24f333874a5f66cb59eeeaac

17 files changed:
scilab/modules/ast/Makefile.am
scilab/modules/ast/Makefile.in
scilab/modules/ast/ast.vcxproj
scilab/modules/ast/ast.vcxproj.filters
scilab/modules/ast/includes/operations/types_addition.hxx
scilab/modules/ast/includes/operations/types_opposite.hxx [new file with mode: 0644]
scilab/modules/ast/includes/operations/types_substraction.hxx
scilab/modules/ast/includes/types/int.hxx
scilab/modules/ast/includes/types/sparseOp.hxx
scilab/modules/ast/src/cpp/operations/operations.cpp
scilab/modules/ast/src/cpp/operations/types_addition.cpp
scilab/modules/ast/src/cpp/operations/types_opposite.cpp [new file with mode: 0644]
scilab/modules/ast/src/cpp/operations/types_substraction.cpp
scilab/modules/ast/tests/unit_tests/substraction.dia.ref [deleted file]
scilab/modules/ast/tests/unit_tests/substraction.tst [deleted file]
scilab/modules/ast/tests/unit_tests/subtraction.dia.ref [new file with mode: 0644]
scilab/modules/ast/tests/unit_tests/subtraction.tst [new file with mode: 0644]

index 2c8f06d..8c8c59f 100644 (file)
@@ -36,6 +36,7 @@ libsciast_la_SOURCES = \
     src/cpp/operations/types_power.cpp \
     src/cpp/operations/types_divide.cpp \
     src/cpp/operations/types_substraction.cpp \
+    src/cpp/operations/types_opposite.cpp \
     src/c/operations/matrix_multiplication.c \
     src/c/operations/matrix_transpose.c \
     src/c/operations/matrix_kronecker.c \
index 1be2390..66455b2 100644 (file)
@@ -179,6 +179,7 @@ am__libsciast_la_SOURCES_DIST = src/cpp/ast/runvisitor.cpp \
        src/cpp/operations/types_power.cpp \
        src/cpp/operations/types_divide.cpp \
        src/cpp/operations/types_substraction.cpp \
+       src/cpp/operations/types_opposite.cpp \
        src/c/operations/matrix_multiplication.c \
        src/c/operations/matrix_transpose.c \
        src/c/operations/matrix_kronecker.c \
@@ -249,6 +250,7 @@ am_libsciast_la_OBJECTS = src/cpp/ast/libsciast_la-runvisitor.lo \
        src/cpp/operations/libsciast_la-types_power.lo \
        src/cpp/operations/libsciast_la-types_divide.lo \
        src/cpp/operations/libsciast_la-types_substraction.lo \
+       src/cpp/operations/libsciast_la-types_opposite.lo \
        src/c/operations/libsciast_la-matrix_multiplication.lo \
        src/c/operations/libsciast_la-matrix_transpose.lo \
        src/c/operations/libsciast_la-matrix_kronecker.lo \
@@ -705,6 +707,7 @@ libsciast_la_SOURCES = src/cpp/ast/runvisitor.cpp \
        src/cpp/operations/types_power.cpp \
        src/cpp/operations/types_divide.cpp \
        src/cpp/operations/types_substraction.cpp \
+       src/cpp/operations/types_opposite.cpp \
        src/c/operations/matrix_multiplication.c \
        src/c/operations/matrix_transpose.c \
        src/c/operations/matrix_kronecker.c \
@@ -1189,6 +1192,9 @@ src/cpp/operations/libsciast_la-types_divide.lo:  \
 src/cpp/operations/libsciast_la-types_substraction.lo:  \
        src/cpp/operations/$(am__dirstamp) \
        src/cpp/operations/$(DEPDIR)/$(am__dirstamp)
+src/cpp/operations/libsciast_la-types_opposite.lo:  \
+       src/cpp/operations/$(am__dirstamp) \
+       src/cpp/operations/$(DEPDIR)/$(am__dirstamp)
 src/c/operations/$(am__dirstamp):
        @$(MKDIR_P) src/c/operations
        @: > src/c/operations/$(am__dirstamp)
@@ -1448,6 +1454,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/operations/$(DEPDIR)/libsciast_la-types_kronecker.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/operations/$(DEPDIR)/libsciast_la-types_ldivide.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/operations/$(DEPDIR)/libsciast_la-types_multiplication.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/operations/$(DEPDIR)/libsciast_la-types_opposite.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/operations/$(DEPDIR)/libsciast_la-types_or_and.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/operations/$(DEPDIR)/libsciast_la-types_power.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/operations/$(DEPDIR)/libsciast_la-types_substraction.Plo@am__quote@
@@ -1786,6 +1793,13 @@ src/cpp/operations/libsciast_la-types_substraction.lo: src/cpp/operations/types_
 @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) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/operations/libsciast_la-types_substraction.lo `test -f 'src/cpp/operations/types_substraction.cpp' || echo '$(srcdir)/'`src/cpp/operations/types_substraction.cpp
 
+src/cpp/operations/libsciast_la-types_opposite.lo: src/cpp/operations/types_opposite.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/operations/libsciast_la-types_opposite.lo -MD -MP -MF src/cpp/operations/$(DEPDIR)/libsciast_la-types_opposite.Tpo -c -o src/cpp/operations/libsciast_la-types_opposite.lo `test -f 'src/cpp/operations/types_opposite.cpp' || echo '$(srcdir)/'`src/cpp/operations/types_opposite.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/operations/$(DEPDIR)/libsciast_la-types_opposite.Tpo src/cpp/operations/$(DEPDIR)/libsciast_la-types_opposite.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/operations/types_opposite.cpp' object='src/cpp/operations/libsciast_la-types_opposite.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) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/operations/libsciast_la-types_opposite.lo `test -f 'src/cpp/operations/types_opposite.cpp' || echo '$(srcdir)/'`src/cpp/operations/types_opposite.cpp
+
 src/cpp/parse/libsciast_la-parser.lo: src/cpp/parse/parser.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/parse/libsciast_la-parser.lo -MD -MP -MF src/cpp/parse/$(DEPDIR)/libsciast_la-parser.Tpo -c -o src/cpp/parse/libsciast_la-parser.lo `test -f 'src/cpp/parse/parser.cpp' || echo '$(srcdir)/'`src/cpp/parse/parser.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/parse/$(DEPDIR)/libsciast_la-parser.Tpo src/cpp/parse/$(DEPDIR)/libsciast_la-parser.Plo
index a1a6384..b8d6bfd 100644 (file)
@@ -339,6 +339,7 @@ lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
     <ClInclude Include="includes\operations\types_kronecker.hxx" />
     <ClInclude Include="includes\operations\types_ldivide.hxx" />
     <ClInclude Include="includes\operations\types_multiplication.hxx" />
+    <ClInclude Include="includes\operations\types_opposite.hxx" />
     <ClInclude Include="includes\operations\types_or_and.hxx" />
     <ClInclude Include="includes\operations\types_power.hxx" />
     <ClInclude Include="includes\operations\types_substraction.hxx" />
@@ -436,6 +437,7 @@ lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
     <ClCompile Include="src\cpp\operations\types_kronecker.cpp" />
     <ClCompile Include="src\cpp\operations\types_ldivide.cpp" />
     <ClCompile Include="src\cpp\operations\types_multiplication.cpp" />
+    <ClCompile Include="src\cpp\operations\types_opposite.cpp" />
     <ClCompile Include="src\cpp\operations\types_or_and.cpp" />
     <ClCompile Include="src\cpp\operations\types_power.cpp" />
     <ClCompile Include="src\cpp\operations\types_substraction.cpp" />
index 1b6141e..d32edff 100644 (file)
     <ClInclude Include="includes\types\overload.hxx">
       <Filter>Header Files\types</Filter>
     </ClInclude>
+    <ClInclude Include="includes\operations\types_opposite.hxx">
+      <Filter>Header Files\operations</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="src\cpp\ast\debugvisitor.cpp">
     <ClCompile Include="src\cpp\types\callable.cpp">
       <Filter>Source Files\types</Filter>
     </ClCompile>
+    <ClCompile Include="src\cpp\operations\types_opposite.cpp">
+      <Filter>Source Files\operations</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
index e5f7cd2..ff93ec2 100644 (file)
@@ -29,7 +29,6 @@ void fillAddFunction();
 
 //define arrays on operation functions
 typedef types::InternalType*(*add_function)(types::InternalType*, types::InternalType*);
-add_function getAddFunction(types::InternalType::ScilabId leftId, types::InternalType::ScilabId rightId);
 
 #define DECLARE_ADD_PROTO(x) template<class T, class U, class O> inline types::InternalType* x(T *_pL, U *_pR)
 //Double, int , bool
diff --git a/scilab/modules/ast/includes/operations/types_opposite.hxx b/scilab/modules/ast/includes/operations/types_opposite.hxx
new file mode 100644 (file)
index 0000000..0f5d834
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+*
+*  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 __TYPES_OPPOSITE_HXX__
+#define __TYPES_OPPOSITE_HXX__
+
+#include "internal.hxx"
+#include "sparse.hxx"
+#include "polynom.hxx"
+
+void fillOppositeFunction();
+
+//define arrays on operation functions
+typedef types::InternalType*(*opposite_function)(types::InternalType*);
+
+#define DECLARE_OPPOSITE_PROTO(x) template<class T, class O> inline types::InternalType* x(T *_pL)
+DECLARE_OPPOSITE_PROTO(opposite_E);
+DECLARE_OPPOSITE_PROTO(opposite_I);
+DECLARE_OPPOSITE_PROTO(opposite_IC);
+DECLARE_OPPOSITE_PROTO(opposite_S);
+DECLARE_OPPOSITE_PROTO(opposite_SC);
+DECLARE_OPPOSITE_PROTO(opposite_M);
+DECLARE_OPPOSITE_PROTO(opposite_MC);
+
+#undef DECLARE_OPPOSITE_PROTO
+
+template<> inline types::InternalType* opposite_M<types::Sparse, types::Sparse>(types::Sparse* _pL);
+template<> inline types::InternalType* opposite_MC<types::Sparse, types::Sparse>(types::Sparse* _pL);
+
+template<> inline types::InternalType* opposite_S<types::Polynom, types::Polynom>(types::Polynom* _pL);
+template<> inline types::InternalType* opposite_SC<types::Polynom, types::Polynom>(types::Polynom* _pL);
+template<> inline types::InternalType* opposite_M<types::Polynom, types::Polynom>(types::Polynom* _pL);
+template<> inline types::InternalType* opposite_MC<types::Polynom, types::Polynom>(types::Polynom* _pL);
+
+
+template<typename T, typename O> inline static void opposite(T l, O* o)
+{
+    *o = (O)(-l);
+}
+
+template<typename T, typename O> inline static void opposite(T l, T lc, O* o, O* oc)
+{
+    *o = (O)(-l);
+    *oc = (O)(-lc);
+}
+
+template<typename T, typename O> inline static void opposite(T* l, long long size, O* o)
+{
+    for (int i = 0; i < size ; ++i)
+    {
+        o[i] = (O)(-l[i]);
+    }
+}
+
+template<typename T, typename O> inline static void opposite(T* l, T* lc, long long size, O* o, O* oc)
+{
+    for (int i = 0; i < size ; ++i)
+    {
+        o[i] = (O)(-l[i]);
+        oc[i] = (O)(-lc[i]);
+    }
+}
+
+
+#endif /* __TYPES_OPPOSITE_HXX__ */
index 0ccdf3a..68b8663 100644 (file)
 #include "polynom.hxx"
 #include "sparse.hxx"
 
-// FIXME : remove using namespace
-using namespace types;
+void fillSubtractFunction();
+void fillOppositeFunction();
 
-int SubstractDoubleToDouble(Double* _pDouble1, Double* _pDouble2, Double **_pDoubleOut);
-int SubstractPolyToDouble(Double *_pDouble, Polynom *_pPoly, Polynom **_pPolyOut);
-int SubstractDoubleToPoly(Polynom *_pPoly, Double *_pDouble, Polynom **_pPolyOut);
-int SubstractPolyToPoly(Polynom *_pPoly1, Polynom *_pPoly2, Polynom **_pPolyOut);
+//define arrays on operation functions
+typedef types::InternalType*(*opposite_function)(types::InternalType*);
+
+
+#define DECLARE_OPPOSITE_PROTO(x) template<class T, class O> inline types::InternalType* x(T *_pL)
+DECLARE_OPPOSITE_PROTO(opposite_S);
+DECLARE_OPPOSITE_PROTO(opposite_M);
+
+
+typedef types::InternalType*(*subtract_function)(types::InternalType*, types::InternalType*);
+
+int SubstractDoubleToDouble(types::Double* _pDouble1, types::Double* _pDouble2, types::Double **_pDoubleOut);
+int SubstractPolyToDouble(types::Double *_pDouble, types::Polynom *_pPoly, types::Polynom **_pPolyOut);
+int SubstractDoubleToPoly(types::Polynom *_pPoly, types::Double *_pDouble, types::Polynom **_pPolyOut);
+int SubstractPolyToPoly(types::Polynom *_pPoly1, types::Polynom *_pPoly2, types::Polynom **_pPolyOut);
 
 //Sparse
-int SubstractSparseToSparse(Sparse* _pSparse1, Sparse* _pSparse2, GenericType **_pSparseOut);
-int SubstractSparseToDouble(Sparse* _pSparse, Double* _pDouble, GenericType **_pDoubleOut);
-int SubstractDoubleToSparse(Double* _pDouble, Sparse* _pSparse, GenericType **_pDoubleOut);
+int SubstractSparseToSparse(types::Sparse* _pSparse1, types::Sparse* _pSparse2, types::GenericType **_pSparseOut);
+int SubstractSparseToDouble(types::Sparse* _pSparse, types::Double* _pDouble, types::GenericType **_pDoubleOut);
+int SubstractDoubleToSparse(types::Double* _pDouble, types::Sparse* _pSparse, types::GenericType **_pDoubleOut);
 
 #endif /* __TYPES_SUB_H__ */
index 2363b22..74354b8 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <sstream>
 #include <string>
+#include <limits>       // std::numeric_limits
 #include "tostring_common.hxx"
 
 namespace types
@@ -175,8 +176,16 @@ private :
             _piDims[1]  = 0;
             int iPos    = ArrayOf<T>::getIndex(_piDims);
 
-            getSignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
-            addSignedIntValue(&ostr, ArrayOf<T>::get(iPos), iWidth);
+            if (isSigned())
+            {
+                getSignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
+                addSignedIntValue(&ostr, ArrayOf<T>::get(iPos), iWidth);
+            }
+            else
+            {
+                getUnsignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
+                addUnsignedIntValue(&ostr, ArrayOf<T>::get(iPos), iWidth);
+            }
             ostr << std::endl;
         }
         else if (GenericType::getCols() == 1)
@@ -191,7 +200,14 @@ private :
                 _piDims[0] = i;
                 int iWidth = 0;
                 int iPos = ArrayOf<T>::getIndex(_piDims);
-                getSignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
+                if (isSigned())
+                {
+                    getSignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
+                }
+                else
+                {
+                    getUnsignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
+                }
                 iWidthMax = std::max(iWidthMax, iWidth);
             }
 
@@ -208,7 +224,14 @@ private :
                 _piDims[0]  = i;
                 int iPos    = ArrayOf<T>::getIndex(_piDims);
 
-                addSignedIntValue(&ostr, ArrayOf<T>::get(iPos), iWidthMax);
+                if (isSigned())
+                {
+                    addSignedIntValue(&ostr, ArrayOf<T>::get(iPos), iWidthMax);
+                }
+                else
+                {
+                    addUnsignedIntValue(&ostr, ArrayOf<T>::get(iPos), iWidthMax);
+                }
                 ostr << std::endl;
             }
         }
@@ -226,7 +249,15 @@ private :
                 _piDims[1]  = i;
                 int iPos    = ArrayOf<T>::getIndex(_piDims);
 
-                getSignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
+                if (isSigned())
+                {
+                    getSignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
+                }
+                else
+                {
+                    getUnsignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
+                }
+
                 iLen = iWidth + static_cast<int>(ostemp.str().size());
                 if (iLen > iLineLen)
                 {
@@ -244,7 +275,14 @@ private :
                     iLastVal = i;
                 }
 
-                addSignedIntValue(&ostemp, ArrayOf<T>::get(iPos), iWidth);
+                if (isSigned())
+                {
+                    addSignedIntValue(&ostemp, ArrayOf<T>::get(iPos), iWidth);
+                }
+                else
+                {
+                    addUnsignedIntValue(&ostemp, ArrayOf<T>::get(iPos), iWidth);
+                }
             }
 
             if (iLastVal != 0)
@@ -274,7 +312,14 @@ private :
                     _piDims[1]  = iCols1;
                     int iPos    = ArrayOf<T>::getIndex(_piDims);
 
-                    getSignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
+                    if (isSigned())
+                    {
+                        getSignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
+                    }
+                    else
+                    {
+                        getUnsignedIntFormat(ArrayOf<T>::get(iPos), &iWidth);
+                    }
                     piSize[iCols1] = std::max(piSize[iCols1], iWidth);
                 }
 
@@ -306,7 +351,14 @@ private :
                             _piDims[1]  = iCols2;
                             int iPos    = ArrayOf<T>::getIndex(_piDims);
 
-                            addSignedIntValue(&ostemp, ArrayOf<T>::get(iPos), piSize[iCols2]);
+                            if (isSigned())
+                            {
+                                addSignedIntValue(&ostemp, ArrayOf<T>::get(iPos), piSize[iCols2]);
+                            }
+                            else
+                            {
+                                addUnsignedIntValue(&ostemp, ArrayOf<T>::get(iPos), piSize[iCols2]);
+                            }
                         }
                         ostemp << std::endl;
                     }
@@ -353,7 +405,14 @@ private :
                     _piDims[1]  = iCols2;
                     int iPos    = ArrayOf<T>::getIndex(_piDims);
 
-                    addSignedIntValue(&ostemp, ArrayOf<T>::get(iPos), piSize[iCols2]);
+                    if (isSigned())
+                    {
+                        addSignedIntValue(&ostemp, ArrayOf<T>::get(iPos), piSize[iCols2]);
+                    }
+                    else
+                    {
+                        addUnsignedIntValue(&ostemp, ArrayOf<T>::get(iPos), piSize[iCols2]);
+                    }
                 }
                 ostemp << std::endl;
             }
@@ -438,6 +497,16 @@ private :
     {
         return is_same_int<T, unsigned long long>::value;
     }
+
+    bool isUnsigned()
+    {
+        return !isSigned();
+    }
+
+    bool isSigned()
+    {
+        return std::numeric_limits<T>::is_signed;
+    }
 };
 
 template<> inline InternalType::ScilabType Int<char>::getType()
index db712a7..81eb6e7 100644 (file)
@@ -291,7 +291,7 @@ types::SparseBool* cwiseOp(types::Sparse const& op1, types::Sparse const& op2)
         }
         else
         {
-            Sparse temp(op2);
+            types::Sparse temp(op2);
             temp.toComplex();
             res = cwiseOp(*op1.matrixCplx, *temp.matrixCplx, Op<std::complex<double> >());
         }
@@ -301,7 +301,7 @@ types::SparseBool* cwiseOp(types::Sparse const& op1, types::Sparse const& op2)
 
         if (op2.isComplex())
         {
-            Sparse* temp = new Sparse(op1);
+            types::Sparse* temp = new types::Sparse(op1);
             temp->toComplex();
             res = cwiseOp(*temp->matrixCplx, *op2.matrixCplx, Op<std::complex<double> >());
         }
index ef98bf1..fb06eeb 100644 (file)
@@ -3,8 +3,10 @@
 
 #include "operations.hxx"
 #include "types_addition.hxx"
+#include "types_opposite.hxx"
 
 void initOperationArray()
 {
     fillAddFunction();
+    fillOppositeFunction();
 }
index e993b37..dade513 100644 (file)
@@ -35,12 +35,6 @@ using namespace types;
 //define arrays on operation functions
 static add_function pAddfunction[types::InternalType::IdLast][types::InternalType::IdLast] = {NULL};
 
-add_function getAddFunction(types::InternalType::ScilabId leftId, types::InternalType::ScilabId rightId)
-{
-    return pAddfunction[leftId][rightId];
-}
-
-
 void fillAddFunction()
 {
 #define scilab_fill_add(id1, id2, func, typeIn1, typeIn2, typeOut) \
diff --git a/scilab/modules/ast/src/cpp/operations/types_opposite.cpp b/scilab/modules/ast/src/cpp/operations/types_opposite.cpp
new file mode 100644 (file)
index 0000000..6c32ad5
--- /dev/null
@@ -0,0 +1,229 @@
+/*
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+*
+*  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 "types_opposite.hxx"
+#include "double.hxx"
+#include "polynom.hxx"
+#include "int.hxx"
+#include "sparse.hxx"
+#include "generic_operations.hxx"
+
+using namespace types;
+static opposite_function pOppositefunction[types::InternalType::IdLast] = {NULL};
+
+void fillOppositeFunction()
+{
+#define scilab_fill_opposite(id1, func, typeIn1, typeOut) \
+    pOppositefunction[types::InternalType::Id ## id1] = (opposite_function)&opposite_##func<typeIn1, typeOut>
+
+    //Empty
+    scilab_fill_opposite(Empty, E, Double, Double);
+
+    //Identity
+    scilab_fill_opposite(Identity, I, Double, Double);
+    scilab_fill_opposite(IdentityComplex, IC, Double, Double);
+
+    //Scalar
+    scilab_fill_opposite(ScalarDouble, S, Double, Double);
+    scilab_fill_opposite(ScalarDoubleComplex, SC, Double, Double);
+    scilab_fill_opposite(ScalarInt8, S, Int8, Int8);
+    scilab_fill_opposite(ScalarUInt8, S, UInt8, UInt8);
+    scilab_fill_opposite(ScalarInt16, S, Int16, Int16);
+    scilab_fill_opposite(ScalarUInt16, S, UInt16, UInt16);
+    scilab_fill_opposite(ScalarInt32, S, Int32, Int32);
+    scilab_fill_opposite(ScalarUInt32, S, UInt32, UInt32);
+    scilab_fill_opposite(ScalarInt64, S, Int64, Int64);
+    scilab_fill_opposite(ScalarUInt64, S, UInt64, UInt64);
+    scilab_fill_opposite(ScalarPolynom, S, Polynom, Polynom);
+    scilab_fill_opposite(ScalarPolynomComplex, SC, Polynom, Polynom);
+
+    //Matrix
+    scilab_fill_opposite(Double, M, Double, Double);
+    scilab_fill_opposite(DoubleComplex, MC, Double, Double);
+    scilab_fill_opposite(Int8, M, Int8, Int8);
+    scilab_fill_opposite(UInt8, M, UInt8, UInt8);
+    scilab_fill_opposite(Int16, M, Int16, Int16);
+    scilab_fill_opposite(UInt16, M, UInt16, UInt16);
+    scilab_fill_opposite(Int32, M, Int32, Int32);
+    scilab_fill_opposite(UInt32, M, UInt32, UInt32);
+    scilab_fill_opposite(Int64, M, Int64, Int64);
+    scilab_fill_opposite(UInt64, M, UInt64, UInt64);
+
+    scilab_fill_opposite(Sparse, M, Sparse, Sparse);
+    scilab_fill_opposite(SparseComplex, MC, Sparse, Sparse);
+
+    scilab_fill_opposite(Polynom, M, Polynom, Polynom);
+    scilab_fill_opposite(PolynomComplex, MC, Polynom, Polynom);
+
+
+#undef scilab_fill_subtract
+}
+
+types::InternalType* GenericUnaryMinus(types::InternalType* _pL)
+{
+    InternalType *pResult = NULL;
+
+    opposite_function opp = pOppositefunction[_pL->getId()];
+    if (opp)
+    {
+        pResult = opp(_pL);
+        if (pResult)
+        {
+            return pResult;
+        }
+    }
+
+    /*
+    ** Default case : Return NULL will Call Overloading.
+    */
+    return NULL;
+}
+
+
+template<class T, class O>
+types::InternalType* opposite_E(T *_pL)
+{
+    return _pL;
+}
+
+template<class T, class O>
+types::InternalType* opposite_I(T *_pL)
+{
+    double* pR = NULL;
+    O* pOut = new types::Double(-1, -1, &pR);
+    opposite(_pL->get(0), pR);
+    return pOut;
+}
+
+template<class T, class O>
+types::InternalType* opposite_IC(T *_pL)
+{
+    double* pR = NULL;
+    double* pI = NULL;
+    O* pOut = new types::Double(-1, -1, &pR, &pI);
+    opposite(_pL->get(0), _pL->getImg(0), pR, pI);
+    return pOut;
+}
+
+template<class T, class O>
+types::InternalType* opposite_S(T *_pL)
+{
+    O* pOut = new O(0);
+    opposite(_pL->get(0), pOut->get());
+    return pOut;
+}
+
+template<class T, class O>
+types::InternalType* opposite_SC(T *_pL)
+{
+    O* pOut = new O(0.0, 0.0);
+    opposite(_pL->get(0), _pL->getImg(0), pOut->get(), pOut->getImg());
+    return pOut;
+}
+
+template<class T, class O>
+types::InternalType* opposite_M(T *_pL)
+{
+    int iDimsL = _pL->getDims();
+    int* piDimsL = _pL->getDimsArray();
+
+    O* pOut = new O(iDimsL, piDimsL);
+
+    int iSize = pOut->getSize();
+
+    opposite(_pL->get(), iSize, pOut->get());
+    return pOut;
+}
+
+template<class T, class O>
+types::InternalType* opposite_MC(T *_pL)
+{
+    int iDimsL = _pL->getDims();
+    int* piDimsL = _pL->getDimsArray();
+
+    O* pOut = new O(iDimsL, piDimsL, true);
+
+    int iSize = pOut->getSize();
+
+    opposite(_pL->get(), _pL->getImg(), iSize, pOut->get(), pOut->getImg());
+    return pOut;
+}
+
+//Sparse
+template<>
+types::InternalType* opposite_M<types::Sparse, types::Sparse>(types::Sparse *_pL)
+{
+    types::Sparse* pOut = (types::Sparse*)(_pL->clone());
+    pOut->opposite();
+    return pOut;
+}
+
+template<>
+types::InternalType* opposite_MC<types::Sparse, types::Sparse>(types::Sparse *_pL)
+{
+    types::Sparse* pOut = (types::Sparse*)(_pL->clone());
+    pOut->opposite();
+    return pOut;
+}
+
+//Polynom
+template<>
+types::InternalType* opposite_S<types::Polynom, types::Polynom>(types::Polynom *_pL)
+{
+    types::Polynom* pOut = (types::Polynom*)_pL->clone();
+    types::SinglePoly* pSPL = _pL->get(0);
+    types::SinglePoly* pSPO = pOut->get(0);
+    opposite(pSPL->get(), pSPL->getSize(), pSPO->get());
+    return pOut;
+}
+
+template<>
+types::InternalType* opposite_SC<types::Polynom, types::Polynom>(types::Polynom *_pL)
+{
+    types::Polynom* pOut = (types::Polynom*)_pL->clone();
+    types::SinglePoly* pSPL = _pL->get(0);
+    types::SinglePoly* pSPO = pOut->get(0);
+    opposite(pSPL->get(), pSPL->getImg(), pSPL->getSize(), pSPO->get(), pSPO->getImg());
+    return pOut;
+}
+
+template<>
+types::InternalType* opposite_M<types::Polynom, types::Polynom>(types::Polynom *_pL)
+{
+    types::Polynom* pOut = (types::Polynom*)_pL->clone();
+
+    int iSize = _pL->getSize();
+
+    for (int i = 0 ; i < iSize ; ++i)
+    {
+        types::SinglePoly* pSPL = _pL->get(i);
+        types::SinglePoly* pSPO = pOut->get(i);
+        opposite(pSPL->get(), pSPL->getSize(), pSPO->get());
+    }
+    return pOut;
+}
+
+template<>
+types::InternalType* opposite_MC<types::Polynom, types::Polynom>(types::Polynom *_pL)
+{
+    types::Polynom* pOut = (types::Polynom*)_pL->clone();
+
+    int iSize = _pL->getSize();
+
+    for (int i = 0 ; i < iSize ; ++i)
+    {
+        types::SinglePoly* pSPL = _pL->get(i);
+        types::SinglePoly* pSPO = pOut->get(i);
+        opposite(pSPL->get(), pSPL->getImg(), pSPL->getSize(), pSPO->get(), pSPO->getImg());
+    }
+    return pOut;
+}
index 0fbc1d5..20c8dd8 100644 (file)
@@ -28,187 +28,13 @@ extern "C"
 
 using namespace types;
 
-InternalType* GenericUnaryMinus(InternalType* _pRightOperand)
-{
-    // - Double
-    if (_pRightOperand->isDouble())
-    {
-        Double *pR = dynamic_cast<Double*>(_pRightOperand->clone());
-        bool bComplex = pR->isComplex();
-        double* pReal = pR->get();
-
-        if (bComplex)
-        {
-            double* pImg = pR->getImg();
-            for (int i = 0 ; i < pR->getSize() ; i++)
-            {
-                pReal[i] *= -1;
-                pImg[i]  *= -1;
-            }
-        }
-        else
-        {
-            for (int i = 0 ; i < pR->getSize() ; i++)
-            {
-                pReal[i] *= -1;
-            }
-        }
-
-        return pR;
-    }
-
-    // - Polynom
-    if (_pRightOperand->isPoly())
-    {
-        double* pReal = NULL;
-        double* pImg  = NULL;
-
-        SinglePoly* pSPCoef = NULL;
-
-        Polynom *pR = dynamic_cast<Polynom*>(_pRightOperand->clone());
-        bool bComplex = pR->isComplex();
-
-        if (bComplex)
-        {
-            for (int i = 0; i < pR->getSize(); i++)
-            {
-                pSPCoef = pR->get(i);
-                pReal = pSPCoef->get();
-                pImg = pSPCoef->getImg();
-
-                for (int j = 0; j < pSPCoef->getSize(); j++)
-                {
-                    pReal[j] *= -1;
-                    pImg[j] *= -1;
-                }
-            }
-        }
-        else
-        {
-            for (int i = 0; i < pR->getSize(); i++)
-            {
-                pSPCoef = pR->get(i);
-                pReal = pSPCoef->get();
-
-                for (int j = 0; j < pSPCoef->getSize(); j++)
-                {
-                    pReal[j] *= -1;
-                }
-            }
-        }
-
-        return pR;
-    }
-
-    // - Int
-    if (_pRightOperand->isInt())
-    {
-        switch (_pRightOperand->getType())
-        {
-            case InternalType::ScilabInt8 :
-            {
-                Int8 *pR = _pRightOperand->clone()->getAs<Int8>();
-                char* pReal = pR->get();
-
-                for (int i = 0 ; i < pR->getSize() ; i++)
-                {
-                    pReal[i] *= -1;
-                }
-                return pR;
-            }
-            case InternalType::ScilabInt16 :
-            {
-                Int16 *pR = _pRightOperand->clone()->getAs<Int16>();
-                short* pReal = pR->get();
+//define arrays on operation functions
+static subtract_function pSubtractfunction[types::InternalType::IdLast][types::InternalType::IdLast] = {NULL};
 
-                for (int i = 0 ; i < pR->getSize() ; i++)
-                {
-                    pReal[i] *= -1;
-                }
-                return pR;
-            }
-            case InternalType::ScilabInt32 :
-            {
-                Int32 *pR = _pRightOperand->clone()->getAs<Int32>();
-                int* pReal = pR->get();
-
-                for (int i = 0 ; i < pR->getSize() ; i++)
-                {
-                    pReal[i] *= -1;
-                }
-                return pR;
-            }
-            case InternalType::ScilabInt64 :
-            {
-                Int64 *pR = _pRightOperand->clone()->getAs<Int64>();
-                long long* pReal = pR->get();
-
-                for (int i = 0 ; i < pR->getSize() ; i++)
-                {
-                    pReal[i] *= -1;
-                }
-                return pR;
-            }
-            case InternalType::ScilabUInt8 :
-            {
-                UInt8 *pR = _pRightOperand->clone()->getAs<UInt8>();
-                unsigned char* pReal = pR->get();
-
-                for (int i = 0 ; i < pR->getSize() ; i++)
-                {
-                    pReal[i] *= -1;
-                }
-                return pR;
-            }
-            case InternalType::ScilabUInt16 :
-            {
-                UInt16 *pR = _pRightOperand->clone()->getAs<UInt16>();
-                unsigned short* pReal = pR->get();
-
-                for (int i = 0 ; i < pR->getSize() ; i++)
-                {
-                    pReal[i] *= -1;
-                }
-                return pR;
-            }
-            case InternalType::ScilabUInt32 :
-            {
-                UInt32 *pR = _pRightOperand->clone()->getAs<UInt32>();
-                unsigned int* pReal = pR->get();
-
-                for (int i = 0 ; i < pR->getSize() ; i++)
-                {
-                    pReal[i] *= -1;
-                }
-                return pR;
-            }
-            case InternalType::ScilabUInt64 :
-            {
-                UInt64 *pR = _pRightOperand->clone()->getAs<UInt64>();
-                unsigned long long* pReal = pR->get();
-
-                for (int i = 0 ; i < pR->getSize() ; i++)
-                {
-                    pReal[i] *= -1;
-                }
-                return pR;
-            }
-            default :
-                return NULL;
-        }
-    }
-
-    // - Sparse
-    if (_pRightOperand->isSparse())
-    {
-        Sparse* pSp = dynamic_cast<Sparse*>(_pRightOperand)->multiply(-1);
-        return pSp;
-    }
-
-    /*
-    ** Default case : Return NULL will Call Overloading.
-    */
-    return NULL;
+void fillSubtractFunction()
+{
+#define scilab_fill_subtract(id1, id2, func, typeIn1, typeIn2, typeOut) \
+    pSubtractfunction[types::InternalType::Id ## id1][types::InternalType::Id ## id2] = (subtract_function)&subtract_##func<typeIn1, typeIn2, typeOut>
 }
 
 InternalType* GenericMinus(InternalType* _pLeftOperand, InternalType* _pRightOperand)
diff --git a/scilab/modules/ast/tests/unit_tests/substraction.dia.ref b/scilab/modules/ast/tests/unit_tests/substraction.dia.ref
deleted file mode 100644 (file)
index 5687ddf..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-// ============================================================================
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2012 - DIGITEO - Antoine ELIAS
-//
-//  This file is distributed under the same license as the Scilab package.
-// ============================================================================
-// <-- JVM NOT MANDATORY -->
-r = 2;
-R = [1,2;3,4];
-R3(:,:,1) = R;
-R3(:,:,2) = R';
-c = 1 - 2*%i;
-C = [1+2*%i,2+4*%i;3+6*%i,4+8*%i];
-C3(:,:,1) = C;
-C3(:,:,2) = C';
-// double - double
-//r - r
-assert_checkequal(r - r, 0);
-//r - c
-assert_checkequal(r - c, 1+%i*2);
-//c - r
-assert_checkequal(c - r, -1-%i*2);
-//c - c
-assert_checkequal(c - c, 0*%i);
-//double - DOUBLE
-//r - R
-assert_checkequal(r - R, [1,0;-1,-2]);
-rR3ref(:,:,1) = [1,0;-1,-2];
-rR3ref(:,:,2) = [1,-1;0,-2] ;
-assert_checkequal(r - R3, rR3ref);
-//r - C
-assert_checkequal(r - C, [ 1-%i*2,-%i*4;-1-%i*6,-2-%i*8]);
-rC3ref(:,:,1) = [ 1-%i*2,-%i*4;-1-%i*6,-2-%i*8];
-rC3ref(:,:,2) = [ 1+%i*2,-1+%i*6;%i*4,-2+%i*8];
-assert_checkequal(r - C3, rC3ref);
-//c - R
-assert_checkequal(c - R, [-%i*2,-1-%i*2;-2-%i*2,-3-%i*2]);
-cR3ref(:,:,1) = [-%i*2,-1-%i*2;-2-%i*2,-3-%i*2];
-cR3ref(:,:,2) = [-%i*2,-2-%i*2;-1-%i*2,-3-%i*2];
-assert_checkequal(c - R3, cR3ref);
-//c - C
-assert_checkequal(c - C, [-%i*4,-1-%i*6;-2-%i*8,-3-%i*10]);
-cC3ref(:,:,1) = [-%i*4,-1-%i*6;-2-%i*8,-3-%i*10];
-cC3ref(:,:,2) = [0,-2+%i*4;-1+%i*2,-3+%i*6];
-assert_checkequal(c - C3, cC3ref);
-//DOUBLE - double
-//R - r
-assert_checkequal(R - r, [-1,0;1,2]);
-R3rref(:,:,1) = [-1,0;1,2];
-R3rref(:,:,2) = [-1,1;0,2];
-assert_checkequal(R3 - r, R3rref);
-//R - c
-assert_checkequal(R - c, [%i*2, 1+%i*2; 2+%i*2, 3+%i*2]);
-R3cref(:,:,1) = [%i*2, 1+%i*2; 2+%i*2, 3+%i*2];
-R3cref(:,:,2) = [%i*2, 2+%i*2; 1+%i*2, 3+%i*2];
-assert_checkequal(R3 - c, R3cref);
-//C - r
-assert_checkequal(C - r, [-1+%i*2,%i*4; 1+%i*6, 2+%i*8]);
-C3rref(:,:,1) = [-1+%i*2,%i*4; 1+%i*6, 2+%i*8];
-C3rref(:,:,2) = [-1-%i*2, 1-%i*6;-%i*4, 2-%i*8];
-assert_checkequal(C3 - r, C3rref);
-//c - c
-assert_checkequal(C - c, [%i*4, 1+%i*6; 2+%i*8, 3+%i*10]);
-C3cref(:,:,1) = [%i*4, 1+%i*6; 2+%i*8, 3+%i*10];
-C3cref(:,:,2) = [0, 2-%i*4; 1-%i*2, 3-%i*6];
-assert_checkequal(C3 - c, C3cref);
-//DOUBLE - DOUBLE
-//R - R
-assert_checkequal(R - R, [0,0;0,0]);
-R3R3ref(:,:,1) = [0,0;0,0];
-R3R3ref(:,:,2) = [0,0;0,0];
-assert_checkequal(R3 - R3, R3R3ref);
-//R - C
-assert_checkequal(R - C, [-%i*2,-%i*4;-%i*6,-%i*8]);
-R3C3ref(:,:,1) = [-%i*2,-%i*4;-%i*6,-%i*8];
-R3C3ref(:,:,2) = [%i*2,%i*6;%i*4,%i*8];
-assert_checkequal(R3 - C3, R3C3ref);
-//C - R
-assert_checkequal(C - R, [%i*2,%i*4;%i*6,%i*8]);
-C3R3ref(:,:,1) = [%i*2,%i*4;%i*6,%i*8];
-C3R3ref(:,:,2) = [-%i*2,-%i*6;-%i*4,-%i*8];
-assert_checkequal(C3 - R3, C3R3ref);
-//C - C
-assert_checkequal(C - C, [0,0;0,0]*%i);
-C3C3ref(:,:,1) = [0,0;0,0];
-C3C3ref(:,:,2) = [0,0;0,0];
-assert_checkequal(C3 - C3, C3C3ref*%i);
diff --git a/scilab/modules/ast/tests/unit_tests/substraction.tst b/scilab/modules/ast/tests/unit_tests/substraction.tst
deleted file mode 100644 (file)
index f016b12..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-// ============================================================================
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2012 - DIGITEO - Antoine ELIAS
-//
-//  This file is distributed under the same license as the Scilab package.
-// ============================================================================
-
-// <-- JVM NOT MANDATORY -->
-
-r = 2;
-R = [1,2;3,4];
-R3(:,:,1) = R;
-R3(:,:,2) = R';
-c = 1 - 2*%i;
-C = [1+2*%i,2+4*%i;3+6*%i,4+8*%i];
-C3(:,:,1) = C;
-C3(:,:,2) = C';
-
-
-// double - double
-
-//r - r
-assert_checkequal(r - r, 0);
-//r - c
-assert_checkequal(r - c, 1+%i*2);
-//c - r
-assert_checkequal(c - r, -1-%i*2);
-//c - c
-assert_checkequal(c - c, 0*%i);
-
-
-//double - DOUBLE
-
-//r - R
-assert_checkequal(r - R, [1,0;-1,-2]);
-rR3ref(:,:,1) = [1,0;-1,-2];
-rR3ref(:,:,2) = [1,-1;0,-2] ;
-assert_checkequal(r - R3, rR3ref);
-//r - C
-assert_checkequal(r - C, [ 1-%i*2,-%i*4;-1-%i*6,-2-%i*8]);
-rC3ref(:,:,1) = [ 1-%i*2,-%i*4;-1-%i*6,-2-%i*8];
-rC3ref(:,:,2) = [ 1+%i*2,-1+%i*6;%i*4,-2+%i*8];
-assert_checkequal(r - C3, rC3ref);
-//c - R
-assert_checkequal(c - R, [-%i*2,-1-%i*2;-2-%i*2,-3-%i*2]);
-cR3ref(:,:,1) = [-%i*2,-1-%i*2;-2-%i*2,-3-%i*2];
-cR3ref(:,:,2) = [-%i*2,-2-%i*2;-1-%i*2,-3-%i*2];
-assert_checkequal(c - R3, cR3ref);
-//c - C
-assert_checkequal(c - C, [-%i*4,-1-%i*6;-2-%i*8,-3-%i*10]);
-cC3ref(:,:,1) = [-%i*4,-1-%i*6;-2-%i*8,-3-%i*10];
-cC3ref(:,:,2) = [0,-2+%i*4;-1+%i*2,-3+%i*6];
-assert_checkequal(c - C3, cC3ref);
-
-
-//DOUBLE - double
-
-//R - r
-assert_checkequal(R - r, [-1,0;1,2]);
-R3rref(:,:,1) = [-1,0;1,2];
-R3rref(:,:,2) = [-1,1;0,2];
-assert_checkequal(R3 - r, R3rref);
-//R - c
-assert_checkequal(R - c, [%i*2, 1+%i*2; 2+%i*2, 3+%i*2]);
-R3cref(:,:,1) = [%i*2, 1+%i*2; 2+%i*2, 3+%i*2];
-R3cref(:,:,2) = [%i*2, 2+%i*2; 1+%i*2, 3+%i*2];
-assert_checkequal(R3 - c, R3cref);
-//C - r
-assert_checkequal(C - r, [-1+%i*2,%i*4; 1+%i*6, 2+%i*8]);
-C3rref(:,:,1) = [-1+%i*2,%i*4; 1+%i*6, 2+%i*8];
-C3rref(:,:,2) = [-1-%i*2, 1-%i*6;-%i*4, 2-%i*8];
-assert_checkequal(C3 - r, C3rref);
-//c - c
-assert_checkequal(C - c, [%i*4, 1+%i*6; 2+%i*8, 3+%i*10]);
-C3cref(:,:,1) = [%i*4, 1+%i*6; 2+%i*8, 3+%i*10];
-C3cref(:,:,2) = [0, 2-%i*4; 1-%i*2, 3-%i*6];
-assert_checkequal(C3 - c, C3cref);
-
-//DOUBLE - DOUBLE
-//R - R
-assert_checkequal(R - R, [0,0;0,0]);
-R3R3ref(:,:,1) = [0,0;0,0];
-R3R3ref(:,:,2) = [0,0;0,0];
-assert_checkequal(R3 - R3, R3R3ref);
-//R - C
-assert_checkequal(R - C, [-%i*2,-%i*4;-%i*6,-%i*8]);
-R3C3ref(:,:,1) = [-%i*2,-%i*4;-%i*6,-%i*8];
-R3C3ref(:,:,2) = [%i*2,%i*6;%i*4,%i*8];
-assert_checkequal(R3 - C3, R3C3ref);
-//C - R
-assert_checkequal(C - R, [%i*2,%i*4;%i*6,%i*8]);
-C3R3ref(:,:,1) = [%i*2,%i*4;%i*6,%i*8];
-C3R3ref(:,:,2) = [-%i*2,-%i*6;-%i*4,-%i*8];
-assert_checkequal(C3 - R3, C3R3ref);
-//C - C
-assert_checkequal(C - C, [0,0;0,0]*%i);
-C3C3ref(:,:,1) = [0,0;0,0];
-C3C3ref(:,:,2) = [0,0;0,0];
-assert_checkequal(C3 - C3, C3C3ref*%i);
diff --git a/scilab/modules/ast/tests/unit_tests/subtraction.dia.ref b/scilab/modules/ast/tests/unit_tests/subtraction.dia.ref
new file mode 100644 (file)
index 0000000..b2ebc65
--- /dev/null
@@ -0,0 +1,156 @@
+// ============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - DIGITEO - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// ============================================================================
+// <-- JVM NOT MANDATORY -->
+r = 2;
+R = [1,2;3,4];
+R3(:,:,1) = R;
+R3(:,:,2) = R';
+c = 1 + 2*%i;
+C = [1+2*%i,2+4*%i;3+6*%i,4+8*%i];
+C3(:,:,1) = C;
+C3(:,:,2) = C';
+e = eye();
+ei = (5+%i) * eye();
+p = 1 + %s - %s**2;
+pc = 1 + %s - %s**2 + ( 2 - 3 * %s + 4 * %s**2 ) * %i;
+P = [2*p, -3*p;4*p,-5*p];
+PC = [2*pc, -3*pc;4*pc,-5*pc];
+SP = sparse([1,2;4,5;3,10],[1,2,3]);
+SPC = sparse([1,2;4,5;3,10],[1,2,3]) * ( 1 + 4*%i);
+i8 = int8(-8);
+i16 = int16(-16);
+i32 = int32(-32);
+i64 = int64(-64);
+ui8 = uint8(8);
+ui16 = uint16(16);
+ui32 = uint32(32);
+ui64 = uint64(64);
+I8 = int8([-8 -16 ; -24 -32]);
+I16 = int16([-16 -32 ; -48 -64]);
+I32 = int32([-32 -64 ; -96 -128]);
+I64 = int64([-64 -128 ; -192 -256]);
+UI8 = uint8([8 16 ; 24 32]);
+UI16 = uint16([16 32 ; 48 64]);
+UI32 = uint32([32 64 ; 96 128]);
+UI64 = uint64([64 128 ; 192 256]);
+// double - double
+//r - r
+assert_checkequal(r - r, 0);
+//r - c
+assert_checkequal(r - c, 1-%i*2);
+//c - r
+assert_checkequal(c - r, -1+%i*2);
+//c - c
+assert_checkequal(c - c, 0*%i);
+//double - DOUBLE
+//r - R
+assert_checkequal(r - R, [1,0;-1,-2]);
+rR3ref(:,:,1) = [1,0;-1,-2];
+rR3ref(:,:,2) = [1,-1;0,-2] ;
+assert_checkequal(r - R3, rR3ref);
+//r - C
+assert_checkequal(r - C, [ 1-%i*2,-%i*4;-1-%i*6,-2-%i*8]);
+rC3ref(:,:,1) = [ 1-%i*2,-%i*4;-1-%i*6,-2-%i*8];
+rC3ref(:,:,2) = [ 1+%i*2,-1+%i*6;%i*4,-2+%i*8];
+assert_checkequal(r - C3, rC3ref);
+//c - R
+assert_checkequal(c - R, [%i*2,-1+%i*2;-2+%i*2,-3+%i*2]);
+cR3ref(:,:,1) = [%i*2,-1+%i*2;-2+%i*2,-3+%i*2];
+cR3ref(:,:,2) = [%i*2,-2+%i*2;-1+%i*2,-3+%i*2];
+assert_checkequal(c - R3, cR3ref);
+//c - C
+assert_checkequal(c - C, [0,-1-%i*2;-2-%i*4,-3-%i*6]);
+cC3ref(:,:,1) = [0,-1-%i*2;-2-%i*4,-3-%i*6];
+cC3ref(:,:,2) = [%i*4,-2+%i*8;-1+%i*6,-3+%i*10];
+assert_checkequal(c - C3, cC3ref);
+//DOUBLE - double
+//R - r
+assert_checkequal(R - r, [-1,0;1,2]);
+R3rref(:,:,1) = [-1,0;1,2];
+R3rref(:,:,2) = [-1,1;0,2];
+assert_checkequal(R3 - r, R3rref);
+//R - c
+assert_checkequal(R - c, [-%i*2, 1-%i*2; 2-%i*2, 3-%i*2]);
+R3cref(:,:,1) = [-%i*2, 1-%i*2; 2-%i*2, 3-%i*2];
+R3cref(:,:,2) = [-%i*2, 2-%i*2; 1-%i*2, 3-%i*2];
+assert_checkequal(R3 - c, R3cref);
+//C - r
+assert_checkequal(C - r, [-1+%i*2,%i*4; 1+%i*6, 2+%i*8]);
+C3rref(:,:,1) = [-1+%i*2,%i*4; 1+%i*6, 2+%i*8];
+C3rref(:,:,2) = [-1-%i*2, 1-%i*6;-%i*4, 2-%i*8];
+assert_checkequal(C3 - r, C3rref);
+//c - c
+assert_checkequal(C - c, [0, 1+%i*2; 2+%i*4, 3+%i*6]);
+C3cref(:,:,1) = [0, 1+%i*2; 2+%i*4, 3+%i*6];
+C3cref(:,:,2) = [-%i*4, 2-%i*8; 1-%i*6, 3-%i*10];
+assert_checkequal(C3 - c, C3cref);
+//DOUBLE - DOUBLE
+//R - R
+assert_checkequal(R - R, [0,0;0,0]);
+R3R3ref(:,:,1) = [0,0;0,0];
+R3R3ref(:,:,2) = [0,0;0,0];
+assert_checkequal(R3 - R3, R3R3ref);
+//R - C
+assert_checkequal(R - C, [-%i*2,-%i*4;-%i*6,-%i*8]);
+R3C3ref(:,:,1) = [-%i*2,-%i*4;-%i*6,-%i*8];
+R3C3ref(:,:,2) = [%i*2,%i*6;%i*4,%i*8];
+assert_checkequal(R3 - C3, R3C3ref);
+//C - R
+assert_checkequal(C - R, [%i*2,%i*4;%i*6,%i*8]);
+C3R3ref(:,:,1) = [%i*2,%i*4;%i*6,%i*8];
+C3R3ref(:,:,2) = [-%i*2,-%i*6;-%i*4,-%i*8];
+assert_checkequal(C3 - R3, C3R3ref);
+//C - C
+assert_checkequal(C - C, [0,0;0,0]*%i);
+C3C3ref(:,:,1) = [0,0;0,0];
+C3C3ref(:,:,2) = [0,0;0,0];
+assert_checkequal(C3 - C3, C3C3ref*%i);
+// OPPOSITE
+// - []
+assert_checkequal(-[], []);
+// - eye
+assert_checkequal(-e, eye() * -1);
+// - eye complex
+assert_checkequal(-ei, (-5-%i) * eye());
+// - double
+assert_checkequal(-r, -2);
+// - double complex
+assert_checkequal(-c, - 1 - 2*%i);
+// - DOUBLE
+assert_checkequal(-R, [-1 -2;-3 -4]);
+// - DOUBLE COMPLEX
+assert_checkequal(-C, [-1-2*%i -2-4*%i;-3-6*%i -4-8*%i]);
+// - int
+assert_checkequal(-i8, int8(8));
+assert_checkequal(-i16, int16(16));
+assert_checkequal(-i32, int32(32));
+assert_checkequal(-i64, int64(64));
+assert_checkequal(-ui8, uint8(-8));
+assert_checkequal(-ui16, uint16(-16));
+assert_checkequal(-ui32, uint32(-32));
+assert_checkequal(-ui64, uint64(-64));
+// - INT
+assert_checkequal(-I8, int8([8 16 ; 24 32]));
+assert_checkequal(-I16, int16([16 32 ; 48 64]));
+assert_checkequal(-I32, int32([32 64 ; 96 128]));
+assert_checkequal(-I64, int64([64 128 ; 192 256]));
+assert_checkequal(-UI8, uint8([-8 -16 ; -24 -32]));
+assert_checkequal(-UI16, uint16([-16 -32 ; -48 -64]));
+assert_checkequal(-UI32, uint32([-32 -64 ; -96 -128]));
+assert_checkequal(-UI64, uint64([-64 -128 ; -192 -256]));
+// - SPARSE
+assert_checkequal(-SP, sparse([1,2;4,5;3,10],[-1,-2,-3]));
+// - SPARSE COMPLEX
+assert_checkequal(-SPC, sparse([1,2;4,5;3,10],[1,2,3]) * ( -1 - 4*%i));
+// - polynom
+assert_checkequal(-p, -1-%s+%s**2);
+// - polynom complex
+assert_checkequal(-pc, - 1 - %s + %s**2 + ( - 2 + 3 * %s - 4 * %s**2 ) * %i);
+// - POLYNOM
+assert_checkequal(-P, [-2-2*%s+2*%s**2 3+3*%s-3*%s**2; -4-4*%s+4*%s**2, 5+5*%s-5*%s**2]);
+// - POLYNOM COMPLEX
+assert_checkequal(-PC, [-2-2*%s+2*%s**2 3+3*%s-3*%s**2; -4-4*%s+4*%s**2, 5+5*%s-5*%s**2] + ([-4+6*%s-8*%s**2 6-9*%s+12*%s**2; -8+12*%s-16*%s**2 10-15*%s+20*%s**2] * %i));
diff --git a/scilab/modules/ast/tests/unit_tests/subtraction.tst b/scilab/modules/ast/tests/unit_tests/subtraction.tst
new file mode 100644 (file)
index 0000000..df294ff
--- /dev/null
@@ -0,0 +1,172 @@
+// ============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - DIGITEO - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// ============================================================================
+
+// <-- JVM NOT MANDATORY -->
+
+r = 2;
+R = [1,2;3,4];
+R3(:,:,1) = R;
+R3(:,:,2) = R';
+c = 1 + 2*%i;
+C = [1+2*%i,2+4*%i;3+6*%i,4+8*%i];
+C3(:,:,1) = C;
+C3(:,:,2) = C';
+e = eye();
+ei = (5+%i) * eye();
+p = 1 + %s - %s**2;
+pc = 1 + %s - %s**2 + ( 2 - 3 * %s + 4 * %s**2 ) * %i;
+P = [2*p, -3*p;4*p,-5*p];
+PC = [2*pc, -3*pc;4*pc,-5*pc];
+SP = sparse([1,2;4,5;3,10],[1,2,3]);
+SPC = sparse([1,2;4,5;3,10],[1,2,3]) * ( 1 + 4*%i);
+
+i8 = int8(-8);
+i16 = int16(-16);
+i32 = int32(-32);
+i64 = int64(-64);
+ui8 = uint8(8);
+ui16 = uint16(16);
+ui32 = uint32(32);
+ui64 = uint64(64);
+
+I8 = int8([-8 -16 ; -24 -32]);
+I16 = int16([-16 -32 ; -48 -64]);
+I32 = int32([-32 -64 ; -96 -128]);
+I64 = int64([-64 -128 ; -192 -256]);
+UI8 = uint8([8 16 ; 24 32]);
+UI16 = uint16([16 32 ; 48 64]);
+UI32 = uint32([32 64 ; 96 128]);
+UI64 = uint64([64 128 ; 192 256]);
+// double - double
+
+//r - r
+assert_checkequal(r - r, 0);
+//r - c
+assert_checkequal(r - c, 1-%i*2);
+//c - r
+assert_checkequal(c - r, -1+%i*2);
+//c - c
+assert_checkequal(c - c, 0*%i);
+
+
+//double - DOUBLE
+
+//r - R
+assert_checkequal(r - R, [1,0;-1,-2]);
+rR3ref(:,:,1) = [1,0;-1,-2];
+rR3ref(:,:,2) = [1,-1;0,-2] ;
+assert_checkequal(r - R3, rR3ref);
+//r - C
+assert_checkequal(r - C, [ 1-%i*2,-%i*4;-1-%i*6,-2-%i*8]);
+rC3ref(:,:,1) = [ 1-%i*2,-%i*4;-1-%i*6,-2-%i*8];
+rC3ref(:,:,2) = [ 1+%i*2,-1+%i*6;%i*4,-2+%i*8];
+assert_checkequal(r - C3, rC3ref);
+//c - R
+assert_checkequal(c - R, [%i*2,-1+%i*2;-2+%i*2,-3+%i*2]);
+cR3ref(:,:,1) = [%i*2,-1+%i*2;-2+%i*2,-3+%i*2];
+cR3ref(:,:,2) = [%i*2,-2+%i*2;-1+%i*2,-3+%i*2];
+assert_checkequal(c - R3, cR3ref);
+//c - C
+assert_checkequal(c - C, [0,-1-%i*2;-2-%i*4,-3-%i*6]);
+cC3ref(:,:,1) = [0,-1-%i*2;-2-%i*4,-3-%i*6];
+cC3ref(:,:,2) = [%i*4,-2+%i*8;-1+%i*6,-3+%i*10];
+assert_checkequal(c - C3, cC3ref);
+
+
+//DOUBLE - double
+
+//R - r
+assert_checkequal(R - r, [-1,0;1,2]);
+R3rref(:,:,1) = [-1,0;1,2];
+R3rref(:,:,2) = [-1,1;0,2];
+assert_checkequal(R3 - r, R3rref);
+//R - c
+assert_checkequal(R - c, [-%i*2, 1-%i*2; 2-%i*2, 3-%i*2]);
+R3cref(:,:,1) = [-%i*2, 1-%i*2; 2-%i*2, 3-%i*2];
+R3cref(:,:,2) = [-%i*2, 2-%i*2; 1-%i*2, 3-%i*2];
+assert_checkequal(R3 - c, R3cref);
+//C - r
+assert_checkequal(C - r, [-1+%i*2,%i*4; 1+%i*6, 2+%i*8]);
+C3rref(:,:,1) = [-1+%i*2,%i*4; 1+%i*6, 2+%i*8];
+C3rref(:,:,2) = [-1-%i*2, 1-%i*6;-%i*4, 2-%i*8];
+assert_checkequal(C3 - r, C3rref);
+//c - c
+assert_checkequal(C - c, [0, 1+%i*2; 2+%i*4, 3+%i*6]);
+C3cref(:,:,1) = [0, 1+%i*2; 2+%i*4, 3+%i*6];
+C3cref(:,:,2) = [-%i*4, 2-%i*8; 1-%i*6, 3-%i*10];
+assert_checkequal(C3 - c, C3cref);
+
+//DOUBLE - DOUBLE
+//R - R
+assert_checkequal(R - R, [0,0;0,0]);
+R3R3ref(:,:,1) = [0,0;0,0];
+R3R3ref(:,:,2) = [0,0;0,0];
+assert_checkequal(R3 - R3, R3R3ref);
+//R - C
+assert_checkequal(R - C, [-%i*2,-%i*4;-%i*6,-%i*8]);
+R3C3ref(:,:,1) = [-%i*2,-%i*4;-%i*6,-%i*8];
+R3C3ref(:,:,2) = [%i*2,%i*6;%i*4,%i*8];
+assert_checkequal(R3 - C3, R3C3ref);
+//C - R
+assert_checkequal(C - R, [%i*2,%i*4;%i*6,%i*8]);
+C3R3ref(:,:,1) = [%i*2,%i*4;%i*6,%i*8];
+C3R3ref(:,:,2) = [-%i*2,-%i*6;-%i*4,-%i*8];
+assert_checkequal(C3 - R3, C3R3ref);
+//C - C
+assert_checkequal(C - C, [0,0;0,0]*%i);
+C3C3ref(:,:,1) = [0,0;0,0];
+C3C3ref(:,:,2) = [0,0;0,0];
+assert_checkequal(C3 - C3, C3C3ref*%i);
+
+
+// OPPOSITE
+
+// - []
+assert_checkequal(-[], []);
+// - eye
+assert_checkequal(-e, eye() * -1);
+// - eye complex
+assert_checkequal(-ei, (-5-%i) * eye());
+// - double
+assert_checkequal(-r, -2);
+// - double complex
+assert_checkequal(-c, - 1 - 2*%i);
+// - DOUBLE
+assert_checkequal(-R, [-1 -2;-3 -4]);
+// - DOUBLE COMPLEX
+assert_checkequal(-C, [-1-2*%i -2-4*%i;-3-6*%i -4-8*%i]);
+// - int
+assert_checkequal(-i8, int8(8));
+assert_checkequal(-i16, int16(16));
+assert_checkequal(-i32, int32(32));
+assert_checkequal(-i64, int64(64));
+assert_checkequal(-ui8, uint8(-8));
+assert_checkequal(-ui16, uint16(-16));
+assert_checkequal(-ui32, uint32(-32));
+assert_checkequal(-ui64, uint64(-64));
+// - INT
+assert_checkequal(-I8, int8([8 16 ; 24 32]));
+assert_checkequal(-I16, int16([16 32 ; 48 64]));
+assert_checkequal(-I32, int32([32 64 ; 96 128]));
+assert_checkequal(-I64, int64([64 128 ; 192 256]));
+assert_checkequal(-UI8, uint8([-8 -16 ; -24 -32]));
+assert_checkequal(-UI16, uint16([-16 -32 ; -48 -64]));
+assert_checkequal(-UI32, uint32([-32 -64 ; -96 -128]));
+assert_checkequal(-UI64, uint64([-64 -128 ; -192 -256]));
+// - SPARSE
+assert_checkequal(-SP, sparse([1,2;4,5;3,10],[-1,-2,-3]));
+// - SPARSE COMPLEX
+assert_checkequal(-SPC, sparse([1,2;4,5;3,10],[1,2,3]) * ( -1 - 4*%i));
+// - polynom
+assert_checkequal(-p, -1-%s+%s**2);
+// - polynom complex
+assert_checkequal(-pc, - 1 - %s + %s**2 + ( - 2 + 3 * %s - 4 * %s**2 ) * %i);
+// - POLYNOM
+assert_checkequal(-P, [-2-2*%s+2*%s**2 3+3*%s-3*%s**2; -4-4*%s+4*%s**2, 5+5*%s-5*%s**2]);
+// - POLYNOM COMPLEX
+assert_checkequal(-PC, [-2-2*%s+2*%s**2 3+3*%s-3*%s**2; -4-4*%s+4*%s**2, 5+5*%s-5*%s**2] + ([-4+6*%s-8*%s**2 6-9*%s+12*%s**2; -8+12*%s-16*%s**2 10-15*%s+20*%s**2] * %i));
+