summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStéphane MOTTELET <stephane.mottelet@utc.fr>2018-10-19 23:48:38 +0200
committerClément DAVID <clement.david@esi-group.com>2019-11-20 17:56:42 +0100
commitc1f299d7479323d2928302da8de3a7a81bbbfee0 (patch)
treec85ccb49f2fda5114f4662dc2895904dd334ede9
parentd79ab01128a04f7776503d4f3b7a5e250a113c34 (diff)
downloadscilab-c1f299d7479323d2928302da8de3a7a81bbbfee0.zip
scilab-c1f299d7479323d2928302da8de3a7a81bbbfee0.tar.gz
[elementary_functions] linspace() c++ gateway gives tremendous speedup
40x speedup for typical sizes: Scilab 6.0.1: --> tic;for i=1:100000;linspace(0,2*%pi,1000);end;toc() ans = 20.667936 Scilab master: --> tic;for i=1:100000;linspace(0,2*%pi,1000);end;toc() ans = 0.476891 and linear interpolation between arrays of any dimensions, e.g. --> linspace(rand(2,2),rand(2,2),5) ans = (:,:,1) 0.8782165 0.5608486 0.068374 0.6623569 (:,:,2) 0.84025 0.5567008 0.1009091 0.5547864 (:,:,3) 0.8022836 0.552553 0.1334442 0.4472159 (:,:,4) 0.7643171 0.5484051 0.1659793 0.3396453 (:,:,5) 0.7263507 0.5442573 0.1985144 0.2320748 Change-Id: I81362a2d858f1a465f4becc6ae8a29aea4dbda28
-rw-r--r--scilab/modules/elementary_functions/Makefile.am9
-rw-r--r--scilab/modules/elementary_functions/Makefile.in26
-rw-r--r--scilab/modules/elementary_functions/help/en_US/elementarymatrices/linspace.xml15
-rw-r--r--scilab/modules/elementary_functions/includes/elem_func_gw.hxx1
-rw-r--r--scilab/modules/elementary_functions/macros/%i_linspace.sci (renamed from scilab/modules/elementary_functions/macros/linspace.sci)70
-rw-r--r--scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw.cpp1
-rw-r--r--scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw/elem_func_gw.vcxproj3
-rw-r--r--scilab/modules/elementary_functions/sci_gateway/cpp/sci_linspace.cpp198
8 files changed, 278 insertions, 45 deletions
diff --git a/scilab/modules/elementary_functions/Makefile.am b/scilab/modules/elementary_functions/Makefile.am
index 69b4067..e429925 100644
--- a/scilab/modules/elementary_functions/Makefile.am
+++ b/scilab/modules/elementary_functions/Makefile.am
@@ -336,10 +336,11 @@ GATEWAY_CXX_SOURCES = \
336 sci_gateway/cpp/sci_sign.cpp \ 336 sci_gateway/cpp/sci_sign.cpp \
337 sci_gateway/cpp/sci_sqrt.cpp \ 337 sci_gateway/cpp/sci_sqrt.cpp \
338 sci_gateway/cpp/sci_issquare.cpp \ 338 sci_gateway/cpp/sci_issquare.cpp \
339 sci_gateway/cpp/sci_isvector.cpp\ 339 sci_gateway/cpp/sci_isvector.cpp \
340 sci_gateway/cpp/sci_nearfloat.cpp\ 340 sci_gateway/cpp/sci_nearfloat.cpp \
341 sci_gateway/cpp/sci_permute.cpp\ 341 sci_gateway/cpp/sci_permute.cpp \
342 sci_gateway/cpp/sci_bitstring.cpp 342 sci_gateway/cpp/sci_bitstring.cpp \
343 sci_gateway/cpp/sci_linspace.cpp
343 344
344EISPACK_SOURCES = src/fortran/eispack/balbak.f 345EISPACK_SOURCES = src/fortran/eispack/balbak.f
345 346
diff --git a/scilab/modules/elementary_functions/Makefile.in b/scilab/modules/elementary_functions/Makefile.in
index 9879ef8..021c9af 100644
--- a/scilab/modules/elementary_functions/Makefile.in
+++ b/scilab/modules/elementary_functions/Makefile.in
@@ -413,7 +413,8 @@ am__objects_8 = \
413 sci_gateway/cpp/libscielementary_functions_la-sci_isvector.lo \ 413 sci_gateway/cpp/libscielementary_functions_la-sci_isvector.lo \
414 sci_gateway/cpp/libscielementary_functions_la-sci_nearfloat.lo \ 414 sci_gateway/cpp/libscielementary_functions_la-sci_nearfloat.lo \
415 sci_gateway/cpp/libscielementary_functions_la-sci_permute.lo \ 415 sci_gateway/cpp/libscielementary_functions_la-sci_permute.lo \
416 sci_gateway/cpp/libscielementary_functions_la-sci_bitstring.lo 416 sci_gateway/cpp/libscielementary_functions_la-sci_bitstring.lo \
417 sci_gateway/cpp/libscielementary_functions_la-sci_linspace.lo
417am_libscielementary_functions_la_OBJECTS = $(am__objects_7) \ 418am_libscielementary_functions_la_OBJECTS = $(am__objects_7) \
418 $(am__objects_8) 419 $(am__objects_8)
419libscielementary_functions_la_OBJECTS = \ 420libscielementary_functions_la_OBJECTS = \
@@ -474,6 +475,7 @@ am__depfiles_remade = sci_gateway/c/$(DEPDIR)/libscielementary_functions_la-sci_
474 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_issquare.Plo \ 475 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_issquare.Plo \
475 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_isvector.Plo \ 476 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_isvector.Plo \
476 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_kron.Plo \ 477 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_kron.Plo \
478 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_linspace.Plo \
477 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log.Plo \ 479 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log.Plo \
478 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Plo \ 480 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Plo \
479 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_matrix.Plo \ 481 sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_matrix.Plo \
@@ -1264,10 +1266,11 @@ GATEWAY_CXX_SOURCES = \
1264 sci_gateway/cpp/sci_sign.cpp \ 1266 sci_gateway/cpp/sci_sign.cpp \
1265 sci_gateway/cpp/sci_sqrt.cpp \ 1267 sci_gateway/cpp/sci_sqrt.cpp \
1266 sci_gateway/cpp/sci_issquare.cpp \ 1268 sci_gateway/cpp/sci_issquare.cpp \
1267 sci_gateway/cpp/sci_isvector.cpp\ 1269 sci_gateway/cpp/sci_isvector.cpp \
1268 sci_gateway/cpp/sci_nearfloat.cpp\ 1270 sci_gateway/cpp/sci_nearfloat.cpp \
1269 sci_gateway/cpp/sci_permute.cpp\ 1271 sci_gateway/cpp/sci_permute.cpp \
1270 sci_gateway/cpp/sci_bitstring.cpp 1272 sci_gateway/cpp/sci_bitstring.cpp \
1273 sci_gateway/cpp/sci_linspace.cpp
1271 1274
1272EISPACK_SOURCES = src/fortran/eispack/balbak.f 1275EISPACK_SOURCES = src/fortran/eispack/balbak.f
1273 1276
@@ -2259,6 +2262,9 @@ sci_gateway/cpp/libscielementary_functions_la-sci_permute.lo: \
2259sci_gateway/cpp/libscielementary_functions_la-sci_bitstring.lo: \ 2262sci_gateway/cpp/libscielementary_functions_la-sci_bitstring.lo: \
2260 sci_gateway/cpp/$(am__dirstamp) \ 2263 sci_gateway/cpp/$(am__dirstamp) \
2261 sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp) 2264 sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
2265sci_gateway/cpp/libscielementary_functions_la-sci_linspace.lo: \
2266 sci_gateway/cpp/$(am__dirstamp) \
2267 sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
2262 2268
2263libscielementary_functions.la: $(libscielementary_functions_la_OBJECTS) $(libscielementary_functions_la_DEPENDENCIES) $(EXTRA_libscielementary_functions_la_DEPENDENCIES) 2269libscielementary_functions.la: $(libscielementary_functions_la_OBJECTS) $(libscielementary_functions_la_DEPENDENCIES) $(EXTRA_libscielementary_functions_la_DEPENDENCIES)
2264 $(AM_V_CXXLD)$(CXXLINK) $(am_libscielementary_functions_la_rpath) $(libscielementary_functions_la_OBJECTS) $(libscielementary_functions_la_LIBADD) $(LIBS) 2270 $(AM_V_CXXLD)$(CXXLINK) $(am_libscielementary_functions_la_rpath) $(libscielementary_functions_la_OBJECTS) $(libscielementary_functions_la_LIBADD) $(LIBS)
@@ -2323,6 +2329,7 @@ distclean-compile:
2323@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_issquare.Plo@am__quote@ # am--include-marker 2329@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_issquare.Plo@am__quote@ # am--include-marker
2324@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_isvector.Plo@am__quote@ # am--include-marker 2330@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_isvector.Plo@am__quote@ # am--include-marker
2325@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_kron.Plo@am__quote@ # am--include-marker 2331@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_kron.Plo@am__quote@ # am--include-marker
2332@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_linspace.Plo@am__quote@ # am--include-marker
2326@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log.Plo@am__quote@ # am--include-marker 2333@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log.Plo@am__quote@ # am--include-marker
2327@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Plo@am__quote@ # am--include-marker 2334@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Plo@am__quote@ # am--include-marker
2328@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_matrix.Plo@am__quote@ # am--include-marker 2335@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_matrix.Plo@am__quote@ # am--include-marker
@@ -3252,6 +3259,13 @@ sci_gateway/cpp/libscielementary_functions_la-sci_bitstring.lo: sci_gateway/cpp/
3252@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 3259@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
3253@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_bitstring.lo `test -f 'sci_gateway/cpp/sci_bitstring.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_bitstring.cpp 3260@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_bitstring.lo `test -f 'sci_gateway/cpp/sci_bitstring.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_bitstring.cpp
3254 3261
3262sci_gateway/cpp/libscielementary_functions_la-sci_linspace.lo: sci_gateway/cpp/sci_linspace.cpp
3263@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_linspace.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_linspace.Tpo -c -o sci_gateway/cpp/libscielementary_functions_la-sci_linspace.lo `test -f 'sci_gateway/cpp/sci_linspace.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_linspace.cpp
3264@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_linspace.Tpo sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_linspace.Plo
3265@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='sci_gateway/cpp/sci_linspace.cpp' object='sci_gateway/cpp/libscielementary_functions_la-sci_linspace.lo' libtool=yes @AMDEPBACKSLASH@
3266@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
3267@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_linspace.lo `test -f 'sci_gateway/cpp/sci_linspace.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_linspace.cpp
3268
3255.f.o: 3269.f.o:
3256 $(AM_V_F77)$(F77COMPILE) -c -o $@ $< 3270 $(AM_V_F77)$(F77COMPILE) -c -o $@ $<
3257 3271
@@ -3500,6 +3514,7 @@ distclean: distclean-am
3500 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_issquare.Plo 3514 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_issquare.Plo
3501 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_isvector.Plo 3515 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_isvector.Plo
3502 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_kron.Plo 3516 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_kron.Plo
3517 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_linspace.Plo
3503 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log.Plo 3518 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log.Plo
3504 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Plo 3519 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Plo
3505 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_matrix.Plo 3520 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_matrix.Plo
@@ -3661,6 +3676,7 @@ maintainer-clean: maintainer-clean-am
3661 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_issquare.Plo 3676 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_issquare.Plo
3662 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_isvector.Plo 3677 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_isvector.Plo
3663 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_kron.Plo 3678 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_kron.Plo
3679 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_linspace.Plo
3664 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log.Plo 3680 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log.Plo
3665 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Plo 3681 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_log1p.Plo
3666 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_matrix.Plo 3682 -rm -f sci_gateway/cpp/$(DEPDIR)/libscielementary_functions_la-sci_matrix.Plo
diff --git a/scilab/modules/elementary_functions/help/en_US/elementarymatrices/linspace.xml b/scilab/modules/elementary_functions/help/en_US/elementarymatrices/linspace.xml
index f493808..97d7c62 100644
--- a/scilab/modules/elementary_functions/help/en_US/elementarymatrices/linspace.xml
+++ b/scilab/modules/elementary_functions/help/en_US/elementarymatrices/linspace.xml
@@ -172,6 +172,21 @@ x(:,1:$-1) - x(:,2:$)
172 -13 -14 -13 -14 -13 -14 -13 -14 -14 172 -13 -14 -13 -14 -13 -14 -13 -14 -14
173 13 14 13 14 13 14 13 14 14 173 13 14 13 14 13 14 13 14 14
174]]></screen> 174]]></screen>
175 <programlisting role="example"><![CDATA[
176// shape interpolation between a sphere and a cone
177[T,P]=meshgrid(linspace(0,2*%pi,32),linspace(-%pi/2,%pi/2,32));
178X=cos(T).*cos(P);
179Y=sin(T).*cos(P);
180
181Z=linspace(sin(P),cos(P)-1,100);
182
183h=uicontrol("style","slider","units","normalized",...
184"position",[0.2 0.03 0.6 0.05],"min",1,"max",100,...
185"callback",...
186"drawlater;delete(gca().children);mesh(X,Y,Z(:,:,h.value));isoview;drawnow")
187
188execstr(h.callback)
189 ]]></programlisting>
175 </refsection> 190 </refsection>
176 <refsection role="see also"> 191 <refsection role="see also">
177 <title>See also</title> 192 <title>See also</title>
diff --git a/scilab/modules/elementary_functions/includes/elem_func_gw.hxx b/scilab/modules/elementary_functions/includes/elem_func_gw.hxx
index 1df9b49..97880a8 100644
--- a/scilab/modules/elementary_functions/includes/elem_func_gw.hxx
+++ b/scilab/modules/elementary_functions/includes/elem_func_gw.hxx
@@ -68,6 +68,7 @@ CPP_GATEWAY_PROTOTYPE(sci_int);
68CPP_GATEWAY_PROTOTYPE(sci_isequal); 68CPP_GATEWAY_PROTOTYPE(sci_isequal);
69CPP_GATEWAY_PROTOTYPE(sci_isreal); 69CPP_GATEWAY_PROTOTYPE(sci_isreal);
70CPP_GATEWAY_PROTOTYPE(sci_kron); 70CPP_GATEWAY_PROTOTYPE(sci_kron);
71CPP_GATEWAY_PROTOTYPE(sci_linspace);
71CPP_GATEWAY_PROTOTYPE(sci_log); 72CPP_GATEWAY_PROTOTYPE(sci_log);
72CPP_GATEWAY_PROTOTYPE(sci_log1p); 73CPP_GATEWAY_PROTOTYPE(sci_log1p);
73CPP_GATEWAY_PROTOTYPE(sci_matrix); 74CPP_GATEWAY_PROTOTYPE(sci_matrix);
diff --git a/scilab/modules/elementary_functions/macros/linspace.sci b/scilab/modules/elementary_functions/macros/%i_linspace.sci
index 654b850..ff72c0f 100644
--- a/scilab/modules/elementary_functions/macros/linspace.sci
+++ b/scilab/modules/elementary_functions/macros/%i_linspace.sci
@@ -12,7 +12,7 @@
12// For more information, see the COPYING file which you should have received 12// For more information, see the COPYING file which you should have received
13// along with this program. 13// along with this program.
14 14
15function y = linspace(d1, d2, n) 15function y = %i_linspace(d1, d2, n)
16 // Linearly spaced vector. 16 // Linearly spaced vector.
17 // linspace(x1, x2) generates a row vector of 100 linearly 17 // linspace(x1, x2) generates a row vector of 100 linearly
18 // equally spaced points between x1 and x2. 18 // equally spaced points between x1 and x2.
@@ -88,39 +88,39 @@ function y = linspace(d1, d2, n)
88endfunction 88endfunction
89// ----------------- 89// -----------------
90function y = linspace_integers_64(d1,d2,n) 90function y = linspace_integers_64(d1,d2,n)
91 s = d2>=d1 91 s = d2>=d1
92 span = zeros(d1) 92 span = zeros(d1)
93 if typeof(d1)=="int64" then 93 if typeof(d1)=="int64" then
94 span = uint64(span) 94 span = uint64(span)
95 end 95 end
96 span(s) = d2(s) - d1(s) 96 span(s) = d2(s) - d1(s)
97 span(~s) = d1(~s) - d2(~s) 97 span(~s) = d1(~s) - d2(~s)
98 step = span/(n-1) 98 step = span/(n-1)
99 y = iconvert(zeros(size(d1,1),n), inttype(d1)) 99 y = iconvert(zeros(size(d1,1),n), inttype(d1))
100 if or(s) // d2 > d1 100 if or(s) // d2 > d1
101 y(s,:) = d1(s)*ones(1,n) + step(s)*(0:n-1) 101 y(s,:) = d1(s)*ones(1,n) + step(s)*(0:n-1)
102 end 102 end
103 if or(~s) 103 if or(~s)
104 y(~s,:) = d1(~s)*ones(1,n) - step(~s)*(0:n-1) 104 y(~s,:) = d1(~s)*ones(1,n) - step(~s)*(0:n-1)
105 end 105 end
106 y(:,$) = d2 106 y(:,$) = d2
107 // Computing the balancing corrections 107 // Computing the balancing corrections
108 // We computes actual intervals 108 // We computes actual intervals
109 if typeof(d1)=="uint64" then 109 if typeof(d1)=="uint64" then
110 i = int64(zeros(size(d1,1),n-1)) 110 i = int64(zeros(size(d1,1),n-1))
111 i(s, :) = y(s, 2:$) - y(s, 1:$-1) 111 i(s, :) = y(s, 2:$) - y(s, 1:$-1)
112 i(~s,:) = y(~s, 1:$-1) - y(~s, 2:$) 112 i(~s,:) = y(~s, 1:$-1) - y(~s, 2:$)
113 else // int64 113 else // int64
114 i = diff(y,1,2); 114 i = diff(y,1,2);
115 end 115 end
116 // diff wrt the 1st interval's width 116 // diff wrt the 1st interval's width
117 e = i - i(:,1) * ones(1,n-1) 117 e = i - i(:,1) * ones(1,n-1)
118 118
119 // Computing corrections 119 // Computing corrections
120 S = mean(double(e), 'c') * ones(1,n-1) 120 S = mean(double(e), "c") * ones(1,n-1)
121 cumE = cumsum(e, 'c') 121 cumE = cumsum(e, "c")
122 cumS = cumsum(S, 'c') 122 cumS = cumsum(S, "c")
123 delta = cumS - cumE 123 delta = cumS - cumE
124 // Applying the corrections 124 // Applying the corrections
125 y(:,2:$) = y(:,2:$) + delta 125 y(:,2:$) = y(:,2:$) + delta
126endfunction 126endfunction
diff --git a/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw.cpp b/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw.cpp
index d5ab0e3..878ef95 100644
--- a/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw.cpp
+++ b/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw.cpp
@@ -61,6 +61,7 @@ int ElemFuncModule::Load()
61 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"isreal", &sci_isreal, MODULE_NAME)); 61 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"isreal", &sci_isreal, MODULE_NAME));
62 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"isequal", &sci_isequal, MODULE_NAME)); 62 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"isequal", &sci_isequal, MODULE_NAME));
63 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"kron", &sci_kron, MODULE_NAME)); 63 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"kron", &sci_kron, MODULE_NAME));
64 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"linspace", &sci_linspace, MODULE_NAME));
64 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"log", &sci_log, MODULE_NAME)); 65 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"log", &sci_log, MODULE_NAME));
65 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"log1p", &sci_log1p, MODULE_NAME)); 66 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"log1p", &sci_log1p, MODULE_NAME));
66 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"matrix", &sci_matrix, MODULE_NAME)); 67 symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"matrix", &sci_matrix, MODULE_NAME));
diff --git a/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw/elem_func_gw.vcxproj b/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw/elem_func_gw.vcxproj
index 1a8b8b2..adddfa1 100644
--- a/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw/elem_func_gw.vcxproj
+++ b/scilab/modules/elementary_functions/sci_gateway/cpp/elem_func_gw/elem_func_gw.vcxproj
@@ -241,6 +241,7 @@ lib /DEF:"$(ProjectDir)elementary_functions_Import.def" /SUBSYSTEM:WINDOWS /MACH
241 <ClCompile Include="..\sci_isequal.cpp" /> 241 <ClCompile Include="..\sci_isequal.cpp" />
242 <ClCompile Include="..\sci_isreal.cpp" /> 242 <ClCompile Include="..\sci_isreal.cpp" />
243 <ClCompile Include="..\sci_kron.cpp" /> 243 <ClCompile Include="..\sci_kron.cpp" />
244 <ClCompile Include="..\sci_linspace.cpp" />
244 <ClCompile Include="..\sci_log.cpp" /> 245 <ClCompile Include="..\sci_log.cpp" />
245 <ClCompile Include="..\sci_log1p.cpp" /> 246 <ClCompile Include="..\sci_log1p.cpp" />
246 <ClCompile Include="..\sci_matrix.cpp" /> 247 <ClCompile Include="..\sci_matrix.cpp" />
@@ -331,4 +332,4 @@ lib /DEF:"$(ProjectDir)elementary_functions_Import.def" /SUBSYSTEM:WINDOWS /MACH
331 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 332 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
332 <ImportGroup Label="ExtensionTargets"> 333 <ImportGroup Label="ExtensionTargets">
333 </ImportGroup> 334 </ImportGroup>
334</Project> \ No newline at end of file 335</Project>
diff --git a/scilab/modules/elementary_functions/sci_gateway/cpp/sci_linspace.cpp b/scilab/modules/elementary_functions/sci_gateway/cpp/sci_linspace.cpp
new file mode 100644
index 0000000..5b104c4
--- /dev/null
+++ b/scilab/modules/elementary_functions/sci_gateway/cpp/sci_linspace.cpp
@@ -0,0 +1,198 @@
1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2018- Stéphane MOTTELET
4 *
5 * This file is hereby licensed under the terms of the GNU GPL v2.0,
6 * For more information, see the COPYING file which you should have received
7 * along with this program.
8 *
9 */
10
11#include "double.hxx"
12#include "function.hxx"
13#include "int.hxx"
14#include "overload.hxx"
15
16extern "C"
17{
18#include "Scierror.h"
19#include "localization.h"
20}
21
22bool fillRange(double* pdblOut, double* pdblMin, double* pdblMax, int iRows, int iCols);
23
24/* ==================================================================== */
25types::Function::ReturnValue sci_linspace(types::typed_list &in, int _iRetCount, types::typed_list &out)
26{
27 int iCols = 100;
28 types::Double* pDblOut;
29
30 if (in.size() != 2 & in.size() != 3)
31 {
32 Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "linspace", 2,3);
33 return types::Function::Error;
34 }
35
36 if (_iRetCount > 1)
37 {
38 Scierror(78, _("%s: Wrong number of output argument(s): %d expected."), "linspace", 1);
39 return types::Function::Error;
40 }
41
42 types::Double* pDbl[2];
43 for (int i=0; i<2; i++)
44 {
45 if (in[i]->isDouble())
46 {
47 pDbl[i] = in[i]->getAs<types::Double>();
48 }
49 else
50 {
51 // other types -> overload
52 std::wstring wstFuncName = L"%" + in[i]->getShortTypeStr() + L"_linspace";
53 return Overload::call(wstFuncName, in, _iRetCount, out);
54 }
55 }
56
57 // Check dimensions are the same
58 int iDims0 = pDbl[0]->getDims();
59 int* piDims0 = pDbl[0]->getDimsArray();
60 int iDims1 = pDbl[1]->getDims();
61 int* piDims1 = pDbl[1]->getDimsArray();
62 if (iDims0 != iDims1)
63 {
64 Scierror(999, _("%s: Arguments %d and %d must have same dimensions.\n"), "linspace",1,2);
65 return types::Function::Error;
66 }
67 for (int i = 0; i < iDims0; i++)
68 {
69 if (piDims0[i] != piDims1[i])
70 {
71 Scierror(999, _("%s: Arguments %d and %d must have same dimensions.\n"), "linspace",1,2);
72 return types::Function::Error;
73 }
74 }
75
76 if (in.size() == 3)
77 {
78 if (in[2]->isDouble() && in[2]->getAs<types::Double>()->isComplex() == false
79 && in[2]->getAs<types::Double>()->getSize() == 1)
80 {
81 double dblCols = in[2]->getAs<types::Double>()->get(0);
82 if (std::floor(dblCols) != dblCols)
83 {
84 Scierror(999, _("%s: Argument #%d: An integer value expected.\n"), "linspace",3);
85 return types::Function::Error;
86 }
87 if (dblCols <= 0)
88 {
89 // empty matrix case
90 out.push_back(types::Double::Empty());
91 return types::Function::OK;
92 }
93 iCols = (int) dblCols;
94 }
95 else
96 {
97 Scierror(999, _("%s: Argument #%d: An integer value expected.\n"), "linspace",3);
98 return types::Function::Error;
99 }
100 }
101
102 // yet another empty matrix case
103 if (pDbl[0]->getSize() == 0)
104 {
105 out.push_back(types::Double::Empty());
106 return types::Function::OK;
107 }
108
109 // generation is done by considering array as a column vector
110 int iRows = pDbl[0]->getSize();
111 // pDblOut is resized later
112 pDblOut = new types::Double(iRows,iCols);
113
114 if (!fillRange(pDblOut->get(), pDbl[0]->get(), pDbl[1]->get(), iRows, iCols))
115 {
116 // if Infs or NaNs
117 pDblOut->killMe();
118 return types::Function::Error;
119 }
120
121 if (pDbl[0]->isComplex() || pDbl[1]->isComplex())
122 {
123 int iReal;
124 for (iReal = 0; iReal < 2; iReal++) {
125 if (!pDbl[iReal]->isComplex())
126 {
127 pDbl[iReal] = pDbl[iReal]->clone();
128 pDbl[iReal]->setComplex(true);
129 break;
130 }
131 }
132 // Complexify pDblOut
133 pDblOut->setComplex(true);
134 bool status = fillRange(pDblOut->getImg(), pDbl[0]->getImg(), pDbl[1]->getImg(), iRows, iCols);
135 if (iReal < 2)
136 {
137 pDbl[iReal]->killMe();
138 }
139 if (status != true) // if Infs or NaNs
140 {
141 pDblOut->killMe();
142 return types::Function::Error;
143 }
144 }
145
146 int *piNewDims = new int[iDims0+1];
147 // keep the first dimension unchanged
148 piNewDims[0] = piDims0[0];
149 int iDim = 1;
150 for (int i=1; i<iDims0; i++)
151 {
152 // squeeze subsequent single dimensions
153 if (piDims0[i]>1)
154 {
155 piNewDims[iDim++] = piDims0[i];
156 }
157 }
158 // add the suplementary dimension
159 piNewDims[iDim++] = iCols;
160 // reshape the matrix:
161 pDblOut->reshape(piNewDims, iDim);
162 out.push_back(pDblOut);
163
164 return types::Function::OK;
165}
166
167bool fillRange(double* pdblOut, double* pdblMin, double* pdblMax, int iRows, int iCols)
168{
169 double* step = new double[iRows];
170 for (int j = 0, k = (iCols-1)*iRows; j < iRows; j++)
171 {
172 step[j] = (pdblMax[j]-pdblMin[j])/(iCols-1);
173 // checking Infs and NaNs
174 int indInfOrNan = std::isinf(pdblMin[j]) || std::isnan(pdblMin[j]) ? 1 : 0;
175 indInfOrNan = indInfOrNan == 0 ? (std::isinf(pdblMax[j]) || std::isnan(pdblMax[j]) ? 2 : 0) : indInfOrNan;
176 if (indInfOrNan > 0)
177 {
178 delete[] step;
179 Scierror(999, _("%s: Argument #%d: %%nan and %%inf values are forbidden.\n"), "linspace",indInfOrNan);
180 return false;
181 }
182 // last column is enforced (http://bugzilla.scilab.org/10966)
183 pdblOut[k++] = pdblMax[j];
184 }
185 // doing the linear range generation
186 for (int i = 0; i<iCols-1; i++)
187 {
188 for (int j = 0; j < iRows; j++)
189 {
190 *(pdblOut++) = pdblMin[j]+i*step[j];
191 }
192 }
193 delete[] step;
194
195 return true;
196}
197
198