bug 14199: wrong management of matrix dimensions 07/17307/3
Antoine ELIAS [Mon, 12 Oct 2015 09:19:55 +0000 (11:19 +0200)]
Change-Id: Ia0ffab00ddce47a266105c388b82d8dab7b63c04

12 files changed:
scilab/CHANGES_6.0.X
scilab/modules/elementary_functions/Makefile.am
scilab/modules/elementary_functions/Makefile.in
scilab/modules/elementary_functions/includes/elem_func_gw.hxx
scilab/modules/elementary_functions/includes/gw_elementary_functions.h
scilab/modules/elementary_functions/sci_gateway/c/sci_sqrt.c [deleted file]
scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw/elem_func_gw.vcxproj
scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw/elem_func_gw.vcxproj.filters
scilab/modules/elementary_functions/sci_gateway/cpp/sci_sqrt.cpp [new file with mode: 0644]
scilab/modules/elementary_functions/tests/nonreg_tests/bug_14199.dia.ref [new file with mode: 0644]
scilab/modules/elementary_functions/tests/nonreg_tests/bug_14199.tst [new file with mode: 0644]
scilab/modules/overloading/macros/%hm_sqrt.sci [deleted file]

index 00c3dd5..a8892f8 100644 (file)
@@ -107,6 +107,8 @@ Scilab Bug Fixes
 
 * Bug #14159 fixed - Matplot crashed Scilab on boolean input.
 
+* Bug #14199 fixed - sqrt returned wrong dimension results on matrix with more than dimensions.
+
 
             Changes between version 5.5.2 and 6.0.0-alpha-1 of Scilab
             =========================================================
index d6b9b63..7da5f0e 100644 (file)
@@ -278,7 +278,6 @@ ELEMENTARIES_FUNCTIONS_FORTRAN_SOURCES = \
     src/fortran/danints.f
 
 GATEWAY_C_SOURCES = \
-    sci_gateway/c/sci_sqrt.c \
     sci_gateway/c/sci_number_properties.c \
     sci_gateway/c/sci_testmatrix.c \
     sci_gateway/c/sci_nearfloat.c \
@@ -336,7 +335,8 @@ GATEWAY_CXX_SOURCES =  \
     sci_gateway/cpp/sci_tril.cpp \
     sci_gateway/cpp/sci_real.cpp \
     sci_gateway/cpp/sci_round.cpp \
-    sci_gateway/cpp/sci_sign.cpp
+    sci_gateway/cpp/sci_sign.cpp \
+    sci_gateway/cpp/sci_sqrt.cpp
 
 EISPACK_SOURCES = src/fortran/eispack/balbak.f
 
index 5d63f4a..3814ffa 100644 (file)
@@ -349,9 +349,7 @@ libscielementary_functions_algo_la_OBJECTS =  \
 libscielementary_functions_la_DEPENDENCIES =  \
        libdummy-elementary_functions.la \
        libscielementary_functions-algo.la
-am__objects_7 =  \
-       sci_gateway/c/libscielementary_functions_la-sci_sqrt.lo \
-       sci_gateway/c/libscielementary_functions_la-sci_number_properties.lo \
+am__objects_7 = sci_gateway/c/libscielementary_functions_la-sci_number_properties.lo \
        sci_gateway/c/libscielementary_functions_la-sci_testmatrix.lo \
        sci_gateway/c/libscielementary_functions_la-sci_nearfloat.lo \
        sci_gateway/c/libscielementary_functions_la-sci_isequalbitwise.lo \
@@ -407,7 +405,8 @@ am__objects_8 =  \
        sci_gateway/cpp/libscielementary_functions_la-sci_tril.lo \
        sci_gateway/cpp/libscielementary_functions_la-sci_real.lo \
        sci_gateway/cpp/libscielementary_functions_la-sci_round.lo \
-       sci_gateway/cpp/libscielementary_functions_la-sci_sign.lo
+       sci_gateway/cpp/libscielementary_functions_la-sci_sign.lo \
+       sci_gateway/cpp/libscielementary_functions_la-sci_sqrt.lo
 am_libscielementary_functions_la_OBJECTS = $(am__objects_7) \
        $(am__objects_8)
 libscielementary_functions_la_OBJECTS =  \
@@ -1081,7 +1080,6 @@ ELEMENTARIES_FUNCTIONS_FORTRAN_SOURCES = \
     src/fortran/danints.f
 
 GATEWAY_C_SOURCES = \
-    sci_gateway/c/sci_sqrt.c \
     sci_gateway/c/sci_number_properties.c \
     sci_gateway/c/sci_testmatrix.c \
     sci_gateway/c/sci_nearfloat.c \
@@ -1139,7 +1137,8 @@ GATEWAY_CXX_SOURCES = \
     sci_gateway/cpp/sci_tril.cpp \
     sci_gateway/cpp/sci_real.cpp \
     sci_gateway/cpp/sci_round.cpp \
-    sci_gateway/cpp/sci_sign.cpp
+    sci_gateway/cpp/sci_sign.cpp \
+    sci_gateway/cpp/sci_sqrt.cpp
 
 EISPACK_SOURCES = src/fortran/eispack/balbak.f
 
@@ -1948,9 +1947,6 @@ sci_gateway/c/$(am__dirstamp):
 sci_gateway/c/$(DEPDIR)/$(am__dirstamp):
        @$(MKDIR_P) sci_gateway/c/$(DEPDIR)
        @: > sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
-sci_gateway/c/libscielementary_functions_la-sci_sqrt.lo:  \
-       sci_gateway/c/$(am__dirstamp) \
-       sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/c/libscielementary_functions_la-sci_number_properties.lo:  \
        sci_gateway/c/$(am__dirstamp) \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
@@ -2125,6 +2121,9 @@ sci_gateway/cpp/libscielementary_functions_la-sci_round.lo:  \
 sci_gateway/cpp/libscielementary_functions_la-sci_sign.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscielementary_functions_la-sci_sqrt.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 
 libscielementary_functions.la: $(libscielementary_functions_la_OBJECTS) $(libscielementary_functions_la_DEPENDENCIES) $(EXTRA_libscielementary_functions_la_DEPENDENCIES) 
        $(AM_V_CXXLD)$(CXXLINK) $(am_libscielementary_functions_la_rpath) $(libscielementary_functions_la_OBJECTS) $(libscielementary_functions_la_LIBADD) $(LIBS)
@@ -2157,7 +2156,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_log10.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_nearfloat.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_number_properties.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_sqrt.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_testmatrix.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-elem_func_gw.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_abs.Plo@am__quote@
@@ -2202,6 +2200,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_sin.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_sinh.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_size.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_sqrt.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_sum.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_tan.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_tanh.Plo@am__quote@
@@ -2587,13 +2586,6 @@ src/c/libscielementary_functions_algo_la-convertbase.lo: src/c/convertbase.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/c/libscielementary_functions_algo_la-convertbase.lo `test -f 'src/c/convertbase.c' || echo '$(srcdir)/'`src/c/convertbase.c
 
-sci_gateway/c/libscielementary_functions_la-sci_sqrt.lo: sci_gateway/c/sci_sqrt.c
-@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libscielementary_functions_la-sci_sqrt.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_sqrt.Tpo -c -o sci_gateway/c/libscielementary_functions_la-sci_sqrt.lo `test -f 'sci_gateway/c/sci_sqrt.c' || echo '$(srcdir)/'`sci_gateway/c/sci_sqrt.c
-@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_sqrt.Tpo sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_sqrt.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='sci_gateway/c/sci_sqrt.c' object='sci_gateway/c/libscielementary_functions_la-sci_sqrt.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libscielementary_functions_la-sci_sqrt.lo `test -f 'sci_gateway/c/sci_sqrt.c' || echo '$(srcdir)/'`sci_gateway/c/sci_sqrt.c
-
 sci_gateway/c/libscielementary_functions_la-sci_number_properties.lo: sci_gateway/c/sci_number_properties.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscielementary_functions_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libscielementary_functions_la-sci_number_properties.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_number_properties.Tpo -c -o sci_gateway/c/libscielementary_functions_la-sci_number_properties.lo `test -f 'sci_gateway/c/sci_number_properties.c' || echo '$(srcdir)/'`sci_gateway/c/sci_number_properties.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_number_properties.Tpo sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_number_properties.Plo
@@ -3080,6 +3072,13 @@ sci_gateway/cpp/libscielementary_functions_la-sci_sign.lo: sci_gateway/cpp/sci_s
 @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_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscielementary_functions_la-sci_sign.lo `test -f 'sci_gateway/cpp/sci_sign.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_sign.cpp
 
+sci_gateway/cpp/libscielementary_functions_la-sci_sqrt.lo: sci_gateway/cpp/sci_sqrt.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_sqrt.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_sqrt.Tpo -c -o sci_gateway/cpp/libscielementary_functions_la-sci_sqrt.lo `test -f 'sci_gateway/cpp/sci_sqrt.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_sqrt.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_sqrt.Tpo sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_sqrt.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_sqrt.cpp' object='sci_gateway/cpp/libscielementary_functions_la-sci_sqrt.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_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscielementary_functions_la-sci_sqrt.lo `test -f 'sci_gateway/cpp/sci_sqrt.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_sqrt.cpp
+
 .f.o:
        $(AM_V_F77)$(F77COMPILE) -c -o $@ $<
 
index 946db86..b535902 100644 (file)
@@ -85,6 +85,7 @@ CPP_GATEWAY_PROTOTYPE(sci_tanh);
 CPP_GATEWAY_PROTOTYPE(sci_acosh);
 CPP_GATEWAY_PROTOTYPE(sci_asinh);
 CPP_GATEWAY_PROTOTYPE(sci_atanh);
+CPP_GATEWAY_PROTOTYPE(sci_sqrt);
 
 bool getDimsFromArguments(types::typed_list& in, const std::string& _pstName, int* _iDims, int** _piDims, bool* _alloc);
 
index 8708147..b4263ec 100644 (file)
@@ -58,7 +58,7 @@ C_GATEWAY_PROTOTYPE(sci_number_properties);
 //C_GATEWAY_PROTOTYPE(sci_round);
 //C_GATEWAY_PROTOTYPE(sci_sign);
 //C_GATEWAY_PROTOTYPE(sci_sin);
-C_GATEWAY_PROTOTYPE(sci_sqrt);
+//C_GATEWAY_PROTOTYPE(sci_sqrt);
 //C_GATEWAY_PROTOTYPE(sci_tan);
 C_GATEWAY_PROTOTYPE(sci_testmatrix);
 //C_GATEWAY_PROTOTYPE(sci_tril);
diff --git a/scilab/modules/elementary_functions/sci_gateway/c/sci_sqrt.c b/scilab/modules/elementary_functions/sci_gateway/c/sci_sqrt.c
deleted file mode 100644 (file)
index f36930b..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2006 - INRIA - Allan CORNET
- *
- * 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.1-en.txt
- *
- */
-/*--------------------------------------------------------------------------*/
-#include <string.h>
-#include "gw_elementary_functions.h"
-#include "basic_functions.h"
-#include "api_scilab.h"
-
-
-int sci_sqrt(char *fname, void* pvApiCtx)
-{
-    SciErr sciErr;
-    int i;
-    int iRet                                           = 0;
-    int iComplex                               = 0;
-    int iRows                                          = 0;
-    int iCols                                          = 0;
-    int* piAddr                                        = NULL;
-
-    double* pdblReal           = NULL;
-    double* pdblImg                    = NULL;
-    double* pdblRealRet        = NULL;
-    double* pdblImgRet = NULL;
-
-
-    CheckRhs(1, 1);
-    CheckLhs(1, 1);
-
-    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        return 0;
-    }
-
-    if (!isDoubleType(pvApiCtx, piAddr))
-    {
-        OverLoad(1);
-        return 0;
-    }
-
-    if (isVarComplex(pvApiCtx, piAddr))
-    {
-        iComplex = 1;
-        sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal, &pdblImg);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            return 0;
-        }
-    }
-    else
-    {
-        iComplex = 0;
-        sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            return 0;
-        }
-    }
-
-    for (i = 0 ; i < iRows * iCols && iComplex == 0 ; i++)
-    {
-        if (pdblReal[i] < 0)
-        {
-            iComplex = 1;
-        }
-    }
-
-    if (iComplex)
-    {
-        sciErr = allocComplexMatrixOfDouble(pvApiCtx, Rhs + 1, iRows, iCols, &pdblRealRet, &pdblImgRet);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            return 0;
-        }
-
-        if (isVarComplex(pvApiCtx, piAddr))
-        {
-            for (i = 0 ; i < iRows * iCols ; i++)
-            {
-                zsqrts(pdblReal[i], pdblImg[i], &pdblRealRet[i], &pdblImgRet[i]);
-            }
-        }
-        else
-        {
-            for (i = 0 ; i < iRows * iCols ; i++)
-            {
-                zsqrts(pdblReal[i], 0, &pdblRealRet[i], &pdblImgRet[i]);
-            }
-        }
-    }
-    else
-    {
-        sciErr = allocMatrixOfDouble(pvApiCtx, Rhs + 1, iRows, iCols, &pdblRealRet);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            return 0;
-        }
-
-        for (i = 0 ; i < iRows * iCols ; i++)
-        {
-            pdblRealRet[i] = dsqrts(pdblReal[i]);
-        }
-    }
-    LhsVar(1) = Rhs + 1;
-    PutLhsVar();
-    return 0;
-}
-/*--------------------------------------------------------------------------*/
index 8de4910..d7a9565 100644 (file)
@@ -210,7 +210,6 @@ lib /DEF:"$(ProjectDir)elementary_functions_Import.def" /SUBSYSTEM:WINDOWS /MACH
     <ClCompile Include="..\..\c\sci_log10.c" />
     <ClCompile Include="..\..\c\sci_nearfloat.c" />
     <ClCompile Include="..\..\c\sci_number_properties.c" />
-    <ClCompile Include="..\..\c\sci_sqrt.c" />
     <ClCompile Include="..\..\c\sci_testmatrix.c" />
     <ClCompile Include="..\elem_func_gw.cpp" />
     <ClCompile Include="..\sci_abs.cpp" />
@@ -256,6 +255,7 @@ lib /DEF:"$(ProjectDir)elementary_functions_Import.def" /SUBSYSTEM:WINDOWS /MACH
     <ClCompile Include="..\sci_sin.cpp" />
     <ClCompile Include="..\sci_sinh.cpp" />
     <ClCompile Include="..\sci_size.cpp" />
+    <ClCompile Include="..\sci_sqrt.cpp" />
     <ClCompile Include="..\sci_sum.cpp" />
     <ClCompile Include="..\sci_tan.cpp" />
     <ClCompile Include="..\sci_tanh.cpp" />
index 64949aa..50e1323 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
     <Filter Include="Source Files">
@@ -51,9 +51,6 @@
     <ClCompile Include="..\..\c\sci_number_properties.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\c\sci_sqrt.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\c\sci_testmatrix.c">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="..\sci_atanh.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\sci_sqrt.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\..\includes\elem_func_gw.hxx">
diff --git a/scilab/modules/elementary_functions/sci_gateway/cpp/sci_sqrt.cpp b/scilab/modules/elementary_functions/sci_gateway/cpp/sci_sqrt.cpp
new file mode 100644 (file)
index 0000000..6ff58b3
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015 - 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.1-en.txt
+ *
+ */
+/*--------------------------------------------------------------------------*/
+#include "elem_func_gw.hxx"
+#include "double.hxx"
+#include "overload.hxx"
+
+extern "C"
+{
+#include "Scierror.h"
+#include "localization.h"
+#include "basic_functions.h"
+}
+
+const char fname[] = "sqrt";
+
+types::Function::ReturnValue sci_sqrt(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    if (in.size() != 1)
+    {
+        Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), fname, 1);
+        return types::Function::Error;
+    }
+
+    if (_iRetCount > 1)
+    {
+        Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), fname, 1);
+        return types::Function::Error;
+    }
+
+    if (in[0]->isDouble() == false)
+    {
+        std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_sqrt";
+        return Overload::call(wstFuncName, in, _iRetCount, out);
+    }
+
+    types::Double* input = in[0]->getAs<types::Double>();
+    bool isComplex = input->isComplex();
+    int size = input->getSize();
+    double* pR = input->get();
+
+    //check neg on input values for real matrix
+    if (isComplex == false)
+    {
+        for (int i = 0; i < size; ++i)
+        {
+            if (pR[i] < 0)
+            {
+                isComplex = true;
+                break;
+            }
+        }
+    }
+
+    types::Double* output = new types::Double(input->getDims(), input->getDimsArray(), isComplex);
+    double* pOR = output->get();
+
+    if (isComplex)
+    {
+        double* pOI = output->getImg();
+        if (input->isComplex())
+        {
+            double* pI = input->getImg();
+            for (int i = 0; i < size; ++i)
+            {
+                zsqrts(pR[i], pI[i], &pOR[i], &pOI[i]);
+            }
+        }
+        else
+        {
+            for (int i = 0; i < size; ++i)
+            {
+                zsqrts(pR[i], 0, &pOR[i], &pOI[i]);
+            }
+        }
+    }
+    else
+    {
+        for (int i = 0; i < size; ++i)
+        {
+            pOR[i] = std::sqrt(pR[i]);
+        }
+    }
+
+    out.push_back(output);
+    return types::Function::OK;
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/elementary_functions/tests/nonreg_tests/bug_14199.dia.ref b/scilab/modules/elementary_functions/tests/nonreg_tests/bug_14199.dia.ref
new file mode 100644 (file)
index 0000000..96e0d50
--- /dev/null
@@ -0,0 +1,26 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+// <-- Non-regression test for bug 14199 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=14199
+//
+// <-- Short Description -->
+//    sqrt does not manage matrix with more than 2 dims
+m = rand(3, 3, 3);
+val = sqrt(m);
+ref = zeros(3, 3, 3);
+for i=1:3
+    for j=1:3
+        for k=1:3
+            ref(i,j,k) = sqrt(m(i,j,k));
+        end
+    end
+end
+assert_checkequal(size(val), size(m));
+assert_checkequal(val, ref);
diff --git a/scilab/modules/elementary_functions/tests/nonreg_tests/bug_14199.tst b/scilab/modules/elementary_functions/tests/nonreg_tests/bug_14199.tst
new file mode 100644 (file)
index 0000000..04ab038
--- /dev/null
@@ -0,0 +1,31 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+
+// <-- Non-regression test for bug 14199 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=14199
+//
+// <-- Short Description -->
+//    sqrt does not manage matrix with more than 2 dims
+
+m = rand(3, 3, 3);
+val = sqrt(m);
+ref = zeros(3, 3, 3);
+
+for i=1:3
+    for j=1:3
+        for k=1:3
+            ref(i,j,k) = sqrt(m(i,j,k));
+        end
+    end
+end
+
+assert_checkequal(size(val), size(m));
+assert_checkequal(val, ref);
\ No newline at end of file
diff --git a/scilab/modules/overloading/macros/%hm_sqrt.sci b/scilab/modules/overloading/macros/%hm_sqrt.sci
deleted file mode 100644 (file)
index a03c9ce..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA
-//
-// 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.1-en.txt
-
-function M=%hm_sqrt(M)
-
-    M("entries")=sqrt(M("entries"))
-endfunction