* `linspace(a, b, n<=0)` now returns `[]` instead of b.
* `strange([])` now returns `%nan` instead of `[]`, as all other functions for statistical dispersion.
* `stdev(x, dir>ndims(x))` now yields an error instead of returning `zeros(x)`.
+* `mean` and `stdev` can now be overloaded.
* `write`: Writing string or string matrix in a file does not add blank space before each value.
* `bitor`, `bitxor` and `bitand` are upgraded:
- positive signed encoded integers are now accepted.
* [#15137](http://bugzilla.scilab.org/show_bug.cgi?id=15137): ilib_build cannot build a library with more than 999 function entries in Scilab 6
* [#15138](http://bugzilla.scilab.org/show_bug.cgi?id=15138): Scilab crashes at start on Windows
* [#15139](http://bugzilla.scilab.org/show_bug.cgi?id=15139): Fix return in try/catch expression
+* [#15144](http://bugzilla.scilab.org/show_bug.cgi?id=15144): `mean` and `stdev` could not be overloaded.
### Bugs fixed in 6.0.0:
* [#592](http://bugzilla.scilab.org/show_bug.cgi?id=592): `linspace(a, b, n<=0)` returned `b` instead of `[]`
<literal>y=mean(x,'m')</literal> is the mean along the first non singleton
dimension of x (for compatibility with Matlab).
</para>
+ <note>
+ <literal>mean()</literal> can be overloaded.
+ </note>
</refsection>
<refsection>
<title>Examples</title>
</member>
</simplelist>
</refsection>
+ <refsection role="history">
+ <title>History</title>
+ <revhistory>
+ <revision>
+ <revnumber>6.0.1</revnumber>
+ <revdescription>
+ mean() is now overloadable.
+ </revdescription>
+ </revision>
+ </revhistory>
+ </refsection>
</refentry>
returns the deviation along the <literal>n</literal>-th dimension.
</para>
<note>
- If <varname>m</varname> is a scalar, then it is expanded to match the size of
- <code>mean(x)</code> along the <literal>n</literal>-th dimension.
+ <itemizedlist>
+ <listitem>
+ If <varname>m</varname> is a scalar, then it is expanded to match the size of
+ <code>mean(x)</code> along the <literal>n</literal>-th dimension.
+ </listitem>
+ <listitem>
+ <literal>stdev()</literal> can be overloaded.
+ </listitem>
+ </itemizedlist>
</note>
</refsection>
<refsection role="examples">
</revdescription>
</revision>
<revision>
- <revnumber>6.0</revnumber>
+ <revnumber>6.0.0</revnumber>
<revdescription>
stdev(x, orien>ndims(x)) no longer returns zeros(x) but yields an error.
</revdescription>
</revision>
+ <revision>
+ <revnumber>6.0.1</revnumber>
+ <revdescription>
+ stdev() is now overloadable.
+ </revdescription>
+ </revision>
</revhistory>
</refsection>
</refentry>
Par extension, <literal>y=stdev(x,n)</literal> avec <literal>n</literal> un entier positif
retourne la déviation suivant la <literal>n</literal>-ème dimension.
</para>
+ <note>
+ <literal>stdev()</literal> peut être étendue par surdéfinition.
+ </note>
</refsection>
<refsection>
<title>Exemples</title>
</revdescription>
</revision>
<revision>
- <revnumber>6.0</revnumber>
+ <revnumber>6.0.0</revnumber>
<revdescription>
stdev(x, orien>ndims(x)) ne donne plus zeros(x) mais produit une erreur.
</revdescription>
</revision>
+ <revision>
+ <revnumber>6.0.1</revnumber>
+ <revdescription>
+ stdev() peut désormais être étendue par surdéfinition.
+ </revdescription>
+ </revision>
</revhistory>
</refsection>
</refentry>
<literal>y=mean(x,'m')</literal> は,
xの最初の1でない次元に沿った平均です(Matlabとの互換用).
</para>
+ <note>
+ <literal>mean()</literal> can be overloaded.
+ </note>
</refsection>
<refsection>
<title>例</title>
</member>
</simplelist>
</refsection>
+ <refsection role="history">
+ <title>履歴</title>
+ <revhistory>
+ <revision>
+ <revnumber>6.0.1</revnumber>
+ <revdescription>
+ mean() is now overloadable.
+ </revdescription>
+ </revision>
+ </revhistory>
+ </refsection>
</refentry>
標準偏差を返します.
</para>
<note>
- <varname>m</varname> がスカラーの場合,
- <literal>n</literal>番目の次元方向が
- <code>mean(x)</code> の大きさに一致するように拡張されます.
+ <itemizedlist>
+ <listitem>
+ <varname>m</varname> がスカラーの場合,
+ <literal>n</literal>番目の次元方向が
+ <code>mean(x)</code> の大きさに一致するように拡張されます.
+ </listitem>
+ <listitem>
+ <literal>stdev()</literal> can be overloaded.
+ </listitem>
+ </itemizedlist>
</note>
</refsection>
<refsection role="examples">
</revdescription>
</revision>
<revision>
- <revnumber>6.0</revnumber>
+ <revnumber>6.0.0</revnumber>
<revdescription>
stdev(x, orien>ndims(x)) no longer returns zeros(x) but yields an error.
</revdescription>
</revision>
+ <revision>
+ <revnumber>6.0.1</revnumber>
+ <revdescription>
+ stdev() is now overloadable.
+ </revdescription>
+ </revision>
</revhistory>
</refsection>
</refentry>
-
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 1999 - INRIA - Carlos Klimann
//
+// Copyright (C) 1999 - INRIA - Carlos Klimann
// Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2017 - Samuel GOUGEON : http://bugzilla.scilab.org/15144
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
-//
-
function [y] = mean(x,orient)
- //
// NOTES
// - modified by bruno to handle the case when x is an hypermatrix
// - restricted to matrix or hypermatrix of "constants" (that is
[lhs,rhs] = argn()
// some arguments checking
if rhs == 0 | rhs > 2 then
- error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"), "mean", 1, 2)),
+ msg = gettext("%s: Wrong number of input argument: %d to %d expected.\n");
+ error(msprintf(msg, "mean", 1, 2));
else
if type(x) <> 1 then
- error(msprintf(gettext("%s: Wrong type for input argument #%d: Real vector or matrix expected.\n"), "mean", 1))
+ ovname = "%" + typeof(x,"overload") + "_mean";
+ if isdef(ovname)
+ if isdef("orient","l")
+ execstr("y = " + ovname + "(x, orient);")
+ else
+ execstr("y = " + ovname + "(x);")
+ end
+ return
+ else
+ msg = gettext("%s: Function not defined for given argument #%d type.\nCheck arguments or define function %s for overloading.\n");
+ error(msprintf(msg, "mean", 1, ovname+"()"))
+ end
end
if rhs == 2 then
end
end
if floor(orient) <> orient | orient < 1 | orient > length(size(x)) then
- error(msprintf(gettext("%s: Wrong type for input argument #%d: Scalar or vector expected.\n"), "mean", 2)),
+ msg = gettext("%s: Wrong type for input argument #%d: Scalar or vector expected.\n");
+ error(msprintf(msg, "mean", 2));
end
end
end
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2013 - Scilab Enteprises - Paul Bignier: added mean squared deviation
-// (third input argument)
// Copyright (C) 2000 - INRIA - Carlos Klimann
-//
// Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2013 - Scilab Enteprises - Paul Bignier: added given mean
+// Copyright (C) 2017 - Samuel GOUGEON : http://bugzilla.scilab.org/15144
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
-//
function sd = stdev(x, o, m)
//
error(msprintf(msg, "stdev", 1, 3))
end
+ if type(x)== 1
+ if ~isreal(x) then
+ msg = _("%s: Argument #%d: Array of real numbers expected.\n")
+ error(msprintf(msg, "stdev", 1))
+ end
+ else
+ ovname = "%" + typeof(x,"overload")+"_stdev";
+ if isdef(ovname)
+ tmp = "sd = " + ovname + "(x";
+ if isdef("o","l")
+ tmp = tmp + ", o";
+ end
+ if isdef("m","l")
+ tmp = tmp + ", m";
+ end
+ execstr(tmp + ");")
+ return
+ else
+ msg = gettext("%s: Function not defined for given argument #%d type.\nCheck arguments or define function %s for overloading.\n");
+ error(msprintf(msg, "mean", 1, ovname+"()"))
+ end
+ end
+
if rhs < 2 then
o = "*"
on = 0
return
end
- if type(x) ~= 1 | ~isreal(x) then
- tmp = _("%s: Wrong type for input argument #%d: A real matrix expected.\n")
- error(msprintf(tmp, "stdev", 1))
- end
-
siz = size(x);
if rhs == 3 then
if typeof(m) ~= "constant" | ~isreal(m) then
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2017 - Samuel GOUGEON
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// =============================================================================
+// Tests for mean()
+// =============================================================================
+// <-- NO CHECK REF -->
+// <-- CLI SHELL MODE -->
+
+assert_checkequal(mean(0), 0);
+assert_checkequal(mean(zeros(3,3)), 0);
+assert_checkequal(mean(zeros(3,3,3)), 0);
+assert_checkequal(mean(1, 1), 1);
+assert_checkequal(mean(1, 2), 1);
+
+
+// Overloading
+m = rand(3,4)*100;
+ // for a built-in type
+function s = %i_mean(ob, varargin)
+ s = mean(double(ob), varargin(:));
+endfunction
+ob = uint8(m);
+r = fix(m);
+assert_checkequal(mean(ob),mean(r));
+assert_checkequal(mean(ob, 1), mean(r, 1));
+assert_checkequal(mean(ob, 2), mean(r, 2));
+ // for a typed list
+function s = %mytype_size(ob, varargin)
+ s = size(ob.mat, varargin(:));
+endfunction
+function s = %mytype_mean(ob, varargin)
+ s = mean(ob.mat, varargin(:));
+endfunction
+ob = mlist(["mytype","mat","title"], m, "A test object");
+assert_checkequal(mean(ob),mean(m));
+assert_checkequal(mean(ob, 1), mean(m, 1));
+assert_checkequal(mean(ob, 2), mean(m, 2));
+
+
+++ /dev/null
-//<-- CLI SHELL MODE -->
-// =============================================================================
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2010 - DIGITEO - Bruno JOFRET
-//
-// This file is distributed under the same license as the Scilab package.
-// =============================================================================
-// =============================================================================
-// Tests for standard deviation
-// =============================================================================
-assert_checkequal(stdev(0), 0);
-assert_checkequal(stdev(zeros(3,3)), 0);
-assert_checkequal(stdev(zeros(3,3,3)), 0);
-assert_checkequal(stdev(1, 1), 0);
-assert_checkequal(stdev(1, 2), 0);
-rand("seed", 0);
-a = rand(3, 3, 3);
-refY = 0.272002431404198;
-y0 = stdev(a);
-ys = stdev(a, "*");
-assert_checkalmostequal(y0, refY);
-assert_checkalmostequal(ys, refY);
-refY = [0.3899896462733005 0.1836990129394737 0.1038925147784040];
-refY(:, :, 2) = [0.3177134004419370 0.2681129484277341 0.0087779568439578];
-refY(:, :, 3) = [0.2897656318619816 0.3895404996160437 0.1425603832951185];
-y1 = stdev(a, 1);
-yr = stdev(a, "r");
-assert_checkalmostequal(y1, refY);
-assert_checkalmostequal(yr, refY);
-refY = [0.3394940617212404 ; 0.0475705580641355 ; 0.4523801086433633];
-refY(:, :, 2) = [0.342549229474548 ; 0.2004197906845895 ; 0.2310186249368761];
-refY(:, :, 3) = [0.3165165021017580 ; 0.2336663995922139 ; 0.1479958923819589];
-y2 = stdev(a, 2);
-yc = stdev(a, "c");
-assert_checkalmostequal(y2, refY);
-assert_checkalmostequal(yc, refY);
-// Mean squared deviation
-refY = 0.2669178254690693;
-ys = stdev(a, "*", mean(a));
-assert_checkalmostequal(ys, refY);
-refY = [0.3184252127793632 0.1499896159848785 0.0848278831005502];
-refY(:, :, 2) = [0.2594119051757631 0.2189133056936967 0.0071671717506227];
-refY(:, :, 3) = [0.2365926476856702 0.3180584860693779 0.1164000655362104];
-y1 = stdev(a, 1, mean(a,"r"));
-yr = stdev(a, "r", mean(a,"r"));
-assert_checkalmostequal(y1, refY);
-assert_checkalmostequal(yr, refY);
-refY = [0.2771957406406592 ; 0.0388411980121906 ; 0.3693668119870194];
-refY(:, :, 2) = [0.2796902746653962 ; 0.1636420738442178 ; 0.1886259173915840];
-refY(:, :, 3) = [0.2584346417732888 ; 0.1907878163447345 ; 0.1208381401212172];
-y2 = stdev(a, 2, mean(a,"c"));
-yc = stdev(a, "c", mean(a,"c"));
-assert_checkalmostequal(y2, refY);
-assert_checkalmostequal(yc, refY);
-//<-- CLI SHELL MODE -->
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2010 - DIGITEO - Bruno JOFRET
// =============================================================================
// Tests for standard deviation
// =============================================================================
+// <-- NO CHECK REF -->
+// <-- CLI SHELL MODE -->
assert_checkequal(stdev(0), 0);
assert_checkequal(stdev(zeros(3,3)), 0);
yc = stdev(a, "c", mean(a,"c"));
assert_checkalmostequal(y2, refY);
assert_checkalmostequal(yc, refY);
+
+// Overloading
+m = rand(3,4)*100;
+ // for a built-in type
+function s = %i_stdev(ob, varargin)
+ s = stdev(double(ob), varargin(:));
+endfunction
+ob = uint8(m);
+r = fix(m);
+assert_checkequal(stdev(ob),stdev(r));
+assert_checkequal(stdev(ob, 1), stdev(r, 1));
+assert_checkequal(stdev(ob, 2), stdev(r, 2));
+assert_checkequal(stdev(ob, 2, 0.1), stdev(r, 2, 0.1));
+assert_checkequal(stdev(ob, 1, 0:0.05:0.16), stdev(r, 1, 0:0.05:0.16));
+ // for a typed list
+function s = %mytype_size(ob, varargin)
+ s = size(ob.mat, varargin(:));
+endfunction
+function s = %mytype_stdev(ob, varargin)
+ s = stdev(ob.mat, varargin(:));
+endfunction
+ob = mlist(["mytype","mat","title"], m, "A test object");
+assert_checkequal(stdev(ob),stdev(m));
+assert_checkequal(stdev(ob, 1), stdev(m, 1));
+assert_checkequal(stdev(ob, 2), stdev(m, 2));
+assert_checkequal(stdev(ob, 2, 10), stdev(m, 2, 10));
+assert_checkequal(stdev(ob, 1, 0:5:16), stdev(m, 1, 0:5:16));
+
+