flipdim() works only on indices of components. While it would be useful for any type of data,
there is therefore no reason to restrict its application to decimal numbers.
Change-Id: I58e8fdc365f3535fbdefedf3ab6498fac31929f4
* Bug #12808 fixed - Add missing </td> in doc generation (note, warning, ...).
+* Bug #12813 fixed - flipdim() function extended to any type of input data.
+
* Bug #12816 fixed - Numbers pasted in editvar were not parsed according to locale.
* Bug #12823 fixed - In help generation (toolbox) links were not correctly handled.
<!--
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2008 - INRIA - Farid BELAHCENE
- *
+ * Copyright (C) 2013 - Samuel GOUGEON : restriction to decimal numbers removed. Examples added for booleans, integer-encoded numbers, text, polynomials, rationals
+ *
* 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
+ * are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
*
-->
</refnamediv>
<refsynopsisdiv>
<title>Calling Sequence</title>
- <synopsis>y=flipdim(x,dim)</synopsis>
+ <synopsis>y = flipdim(x, dim)</synopsis>
</refsynopsisdiv>
<refsection>
<title>Arguments</title>
<variablelist>
<varlistentry>
- <term>x</term>
+ <term>x, y</term>
+
<listitem>
- <para>a scalar, a vector or an array of real or complex numbers.</para>
+ <para>scalars, vectors, matrices, or hypermatrices of any type, of same sizes</para>
+
</listitem>
</varlistentry>
<varlistentry>
<para>a positive integer</para>
</listitem>
</varlistentry>
- <varlistentry>
- <term>y</term>
- <listitem>
- <para>a scalar, a vector or an array of reals</para>
- </listitem>
- </varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Description</title>
<para>
- Given <literal>x</literal>, a scalar/vector/array of real or complex numbers and
+ Given <literal>x</literal>, a scalar/vector/matrix/hypermatrix of any type and
<literal>dim</literal> a positive integer, this function flips the x
components along the dimension number <literal>dim</literal> of
<literal>x</literal> (<literal>x</literal> and <literal>y</literal> have
</refsection>
<refsection>
<title>Examples</title>
- <programlisting role="example"><![CDATA[
-// example 1: flip x components along the first dimension
-x=[1 2 3 4; 5 6 7 8];
-dim=1;
-y=flipdim(x,dim)
+ <programlisting role="example"><![CDATA[
+// Example 1: flip x components along the first dimension
+x = [1 2 3 4; 5 6 7 8];
+dim = 1;
+y = flipdim(x, dim)
-// example 2: flip x components along the second dimension
-dim=2;
-y=flipdim(x,dim)
+// Example 2: flip x components along the second dimension
+dim = 2;
+y = flipdim(x, dim)
-// example 3: flip x components along the third dimension
-x=matrix(1:48,[3 2,4,2]);
-dim=3;
-y=flipdim(x,dim)
+// Example 3: flip x components along the third dimension
+x = matrix(1:24, [3 2 4]);
+dim = 3;
+y = flipdim(x, dim)
// Example 4: the first example with complex
-x=[1+%i 2*%i 3 4; 5 6-%i 7 8*%pi*%i];
-dim=1;
-y=flipdim(x,dim)
+x = [1+%i 2*%i 3 4; 5 6-%i 7 8*%pi*%i];
+dim = 1;
+y = flipdim(x, dim)
+
+// Integer-encoded numbers:
+x = int16(grand(4, 3, 2, "uin", -9, 9));
+y = flipdim(x, 1)
+
+// Booleans:
+x = (grand(3, 4, "uin", -9, 9) > 0);
+y = flipdim(x, 2)
+
+// Texts:
+x = matrix(strsplit("a":"x", 1:23), 4, 6);
+x = x+x;
+flipdim(x, 2)
+
+// Polynomials:
+x = inv_coeff(grand(3, 9, "uin", 0, 3), 2);
+flipdim(x, 1)
+
+// Rationals:
+n = inv_coeff(grand(3, 9, "uin", 0, 3), 2);
+d = inv_coeff(grand(3, 9, "uin", 0, 3), 2);
+r = n./d;
+flipdim(r, 2)
]]></programlisting>
</refsection>
+ <refsection>
+ <title>History</title>
+ <revhistory>
+ <revision>
+ <revnumber>5.5.0</revnumber>
+ <revremark>Extension from decimals to any type: booleans, integer-encoded numbers, texts, polynomials and rationals.</revremark>
+ </revision>
+ </revhistory>
+ </refsection>
</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - INRIA - Farid BELAHCENE
+ * Copyright (C) 2013 - Samuel GOUGEON : restriction to decimal numbers removed. Examples added for booleans, integer-encoded numbers, text, polynomials, rationals
+ *
+ * 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
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="flipdim" xml:lang="fr">
+ <refnamediv>
+ <refname>flipdim</refname>
+ <refpurpose>
+ retourne les éléments de <literal>x</literal> selon une dimension
+ </refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>Séquence d'appel</title>
+ <synopsis>y = flipdim(x, dim)</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Paramètres</title>
+ <variablelist>
+ <varlistentry>
+ <term>x, y</term>
+ <listitem>
+ <para>scalaires, vecteurs, matrices, ou hypermatrices de n'importe quel type, de même taille</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>dim</term>
+ <listitem>
+ <para>entier positif</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Description</title>
+ <para>
+ A partir de <literal>x</literal>, un scalaire/vecteur/matrice/hypermatrice de n'importe quel type et
+ <literal>dim</literal> un entier positif, cette fonction retourne les éléments de
+ <literal>x</literal> selon le nombre dimension <literal>dim</literal> de
+ <literal>x</literal> (<literal>x</literal> et <literal>y</literal> ont la même taille)
+ </para>
+ </refsection>
+ <refsection>
+ <title>Exemples</title>
+ <programlisting role="example"><![CDATA[
+// Exemple 1 : selon la première dimension
+x = [1 2 3 4; 5 6 7 8];
+dim = 1;
+y = flipdim(x, dim)
+
+// Exemple 2 : selon la deuxième dimension
+dim = 2;
+y = flipdim(x, dim)
+
+// Exemple 3 : selon la troisième dimension
+x = matrix(1:24, [3 2 4]);
+dim = 3;
+y = flipdim(x, dim)
+
+// Exemple 4 : premier exemple, mais avec des complexes
+x = [1+%i 2*%i 3 4; 5 6-%i 7 8*%pi*%i];
+dim = 1;
+y = flipdim(x, dim)
+
+// Entiers :
+x = int16(grand(4, 3, 2, "uin", -9, 9));
+y = flipdim(x, 1)
+
+// Booléens :
+x = (grand(3, 4, "uin", -9, 9) > 0);
+y = flipdim(x, 2)
+
+// Textes :
+x = matrix(strsplit("a":"x", 1:23), 4, 6);
+x = x+x;
+flipdim(x, 2)
+
+// Polynômes :
+x = inv_coeff(grand(3, 9, "uin", 0, 3), 2);
+flipdim(x, 1)
+
+// Rationals :
+n = inv_coeff(grand(3, 9, "uin", 0 ,3), 2);
+d = inv_coeff(grand(3, 9, "uin", 0, 3), 2);
+r = n./d;
+flipdim(r, 2)
+ ]]></programlisting>
+ </refsection>
+ <refsection>
+ <title>History</title>
+ <revhistory>
+ <revision>
+ <revnumber>5.5.0</revnumber>
+ <revremark>Extension de décimaux à tout type: booléens, entiers, textes, polynômes et rationals.</revremark>
+ </revision>
+ </revhistory>
+ </refsection>
+</refentry>
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA - Farid BELAHCENE
// Copyright (C) DIGITEO - 2011 - Allan CORNET
+// Copyright (C) 2013 - Samuel GOUGEON : restriction to decimal numbers removed
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
function y = flipdim(x, dim)
// FLIPDIM function
- // Given x, a scalar/vector/matix of reals and an integer dim, this function flips the x components along the dimension number dim (x and y have the same size).
+ // Given x, a scalar/vector/matrix of any type and an integer dim, this function flips the x components along the dimension number dim (x and y have the same size).
// -Inputs :
- // x : a scalar/vector/array of reals
+ // x : a scalar/vector/array
// dim : a positive integer
// -Output :
- // y : a scalar/vector/array of reals
+ // y : a scalar/vector/array
//
// F.Belahcene
rhs = argn(2);
if rhs <> 2 then
- error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"flipdim", 2));
+ msg = _("%s: Wrong number of input argument(s): %d expected.\n");
+ error(msprintf(msg, "flipdim", 2));
end
- if size(dim,"*")<>1 then
- error(msprintf(gettext("%s: Wrong size for input argument #%d: A positive integer expected.\n"),"flipdim",2));
- elseif type(dim)<>8 & (type(dim)<>1 | dim<1) then
- error(msprintf(gettext("%s: Wrong type for input argument #%d: A positive integer expected.\n"),"flipdim",2));
- end
-
- if ndims(x)==2 & type(x)<>1 then
- error(msprintf(gettext("%s: Wrong value for input argument #%d: Real matrix expected.\n"),"flipdim",1));
- elseif ndims(x)>2 & type(x.entries)<>1
- error(msprintf(gettext("%s: Wrong value for input argument #%d: Real matrix expected.\n"),"flipdim",1));
+ if size(dim, "*") <> 1 then
+ msg = _("%s: Wrong size for input argument #%d: A positive integer expected.\n")
+ error(msprintf(msg, "flipdim", 2));
+ elseif type(dim) <> 8 & (type(dim) <> 1 | dim < 1 ) then
+ msg = _("%s: Wrong type for input argument #%d: A positive integer expected.\n");
+ error(msprintf(msg, "flipdim", 2));
end
dim = floor(dim);
for k = 1:dim - 1
l(k) = eye();
end
- l(dim) = $:-1:1
+ l(dim) = $:-1:1;
for k = dim + 1:ndims(x)
l(k) = eye();
end
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
// Copyright (C) 2012 - Scilab Enterprises - Sylvestre Ledru
//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
-x=[1 2 3 4; 5 6 7 8];
-dim=1;
-y=flipdim(x,dim);
-assert_checkequal([5,6,7,8;1,2,3,4],y);
-dim=2;
-y=flipdim(x,dim);
-assert_checkequal([4,3,2,1;8,7,6,5],y);
-x=matrix(1:48,[3 2,4,2]);
-dim=3;
-ref=hypermat([3,2,4,2],[19;20;21;22;23;24;13;14;15;16;17;18;7;8;9;10;11;12;1;2;3;4;5;6;43;44;45;46;47;48;37;38;39;40;41;42;31;32;33;34;35;36;25;26;27;28;29;30]);
-y=flipdim(x,dim);
-assert_checkequal(y,ref);
-x=[1+%i 2*%i 3 4; 5 6-%i 7 8*%pi*%i];
-dim=1;
-y=flipdim(x,dim);
-ref=[ 5, 6-%i, 7,%i*25.132741;1+%i,%i*2, 3, 4];
-assert_checkalmostequal(y,ref);
+//
+// <-- CLI SHELL MODE -->
+//
+// <-- ENGLISH IMPOSED -->
+//
+// Along dimension 1:
+x = [1 2 3 4; 5 6 7 8];
+dim = 1;
+y = flipdim(x, dim);
+assert_checkequal([5 6 7 8; 1 2 3 4], y);
+// Along dimension 2:
+dim = 2;
+y = flipdim(x, dim);
+assert_checkequal([4 3 2 1; 8 7 6 5], y);
+// Along dimension 3:
+x = matrix(1:24, [3 2 4]);
+dim = 3;
+ref = hypermat([3 2 4], [19;20;21;22;23;24;13;14;15;16;17;18;7;8;9;10;11;12;1;2;3;4;5;6]);
+y = flipdim(x, dim);
+assert_checkequal(y, ref);
+// Complexes:
+y = flipdim(x*%i, dim);
+assert_checkequal(y, ref*%i);
+// Integer-encoded numbers:
+y = flipdim(int16(x), dim);
+assert_checkequal(y, int16(ref));
+// Booleans:
+ref_bool = hypermat([3 2 4], [%T;%T;%T;%T;%T;%T;%T;%T;%T;%T;%T;%T;%F;%F;%F;%T;%T;%F;%F;%F;%F;%F;%F;%F]);
+y = flipdim(x < 15, 2);
+assert_checkequal(y, ref_bool);
+// Texts:
+x_txt = matrix(strsplit("a":"x", 1:23), 4, 6);
+x_txt = x_txt + x_txt;
+ref_txt = ["uu" "qq" "mm" "ii" "ee" "aa"; "vv" "rr" "nn" "jj" "ff" "bb";
+ "ww" "ss" "oo" "kk" "gg" "cc";
+ "xx" "tt" "pp" "ll" "hh" "dd" ];
+y = flipdim(x_txt, 2);
+assert_checkequal(y, ref_txt);
+// Polynomials:
+x_pol = inv_coeff([x(:,:,1) x(:,:,2) x(:,:,3) x(:,:,4) [0;1;2]], 2);
+X = poly(0, "x");
+ref_pol = [3+12*X+21*X^2 6+15*X+24*X^2 9+18*X+2*X^2;
+2+11*X+20*X^2 5+14*X+23*X^2 8+17*X+X^2;
+1+10*X+19*X^2 4+13*X+22*X^2 7+16*X ];
+y = flipdim(x_pol, 1);
+assert_checkequal(y, ref_pol);
+// Rationals:
+r = (x_pol) ./ X;
+ref_r = ref_pol ./ X;
+y = flipdim(r, 1);
+assert_checkequal(y, ref_r);
+// Hypermatrices:
+x = matrix(1:48, [3 2 4 2]);
+dim = 3;
+ref = hypermat([3 2 4 2], [19;20;21;22;23;24;13;14;15;16;17;18;7;8;9;10;11;12;1;2;3;4;5;6;43;44;45;46;47;48;37;38;39;40;41;42;31;32;33;34;35;36;25;26;27;28;29;30]);
+y = flipdim(x, dim);
+assert_checkequal(y, ref);
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
// Copyright (C) 2012 - Scilab Enterprises - Sylvestre Ledru
//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
-x=[1 2 3 4; 5 6 7 8];
-dim=1;
-y=flipdim(x,dim);
-assert_checkequal([5,6,7,8;1,2,3,4],y);
-
-dim=2;
-y=flipdim(x,dim);
-assert_checkequal([4,3,2,1;8,7,6,5],y);
-
-x=matrix(1:48,[3 2,4,2]);
-dim=3;
-ref=hypermat([3,2,4,2],[19;20;21;22;23;24;13;14;15;16;17;18;7;8;9;10;11;12;1;2;3;4;5;6;43;44;45;46;47;48;37;38;39;40;41;42;31;32;33;34;35;36;25;26;27;28;29;30]);
-y=flipdim(x,dim);
-assert_checkequal(y,ref);
-
-x=[1+%i 2*%i 3 4; 5 6-%i 7 8*%pi*%i];
-dim=1;
-y=flipdim(x,dim);
-ref=[ 5, 6-%i, 7,%i*25.132741;1+%i,%i*2, 3, 4];
-assert_checkalmostequal(y,ref);
+//
+// <-- CLI SHELL MODE -->
+//
+// <-- ENGLISH IMPOSED -->
+//
+// Along dimension 1:
+x = [1 2 3 4; 5 6 7 8];
+dim = 1;
+y = flipdim(x, dim);
+assert_checkequal([5 6 7 8; 1 2 3 4], y);
+
+// Along dimension 2:
+dim = 2;
+y = flipdim(x, dim);
+assert_checkequal([4 3 2 1; 8 7 6 5], y);
+
+// Along dimension 3:
+x = matrix(1:24, [3 2 4]);
+dim = 3;
+ref = hypermat([3 2 4], [19;20;21;22;23;24;13;14;15;16;17;18;7;8;9;10;11;12;1;2;3;4;5;6]);
+y = flipdim(x, dim);
+assert_checkequal(y, ref);
+
+// Complexes:
+y = flipdim(x*%i, dim);
+assert_checkequal(y, ref*%i);
+
+// Integer-encoded numbers:
+y = flipdim(int16(x), dim);
+assert_checkequal(y, int16(ref));
+
+// Booleans:
+ref_bool = hypermat([3 2 4], [%T;%T;%T;%T;%T;%T;%T;%T;%T;%T;%T;%T;%F;%F;%F;%T;%T;%F;%F;%F;%F;%F;%F;%F]);
+y = flipdim(x < 15, 2);
+assert_checkequal(y, ref_bool);
+
+// Texts:
+x_txt = matrix(strsplit("a":"x", 1:23), 4, 6);
+x_txt = x_txt + x_txt;
+ref_txt = ["uu" "qq" "mm" "ii" "ee" "aa"; "vv" "rr" "nn" "jj" "ff" "bb";
+"ww" "ss" "oo" "kk" "gg" "cc";
+"xx" "tt" "pp" "ll" "hh" "dd" ];
+y = flipdim(x_txt, 2);
+assert_checkequal(y, ref_txt);
+
+// Polynomials:
+x_pol = inv_coeff([x(:,:,1) x(:,:,2) x(:,:,3) x(:,:,4) [0;1;2]], 2);
+X = poly(0, "x");
+ref_pol = [3+12*X+21*X^2 6+15*X+24*X^2 9+18*X+2*X^2;
+2+11*X+20*X^2 5+14*X+23*X^2 8+17*X+X^2;
+1+10*X+19*X^2 4+13*X+22*X^2 7+16*X ];
+y = flipdim(x_pol, 1);
+assert_checkequal(y, ref_pol);
+
+// Rationals:
+r = (x_pol) ./ X;
+ref_r = ref_pol ./ X;
+y = flipdim(r, 1);
+assert_checkequal(y, ref_r);
+
+// Hypermatrices:
+x = matrix(1:48, [3 2 4 2]);
+dim = 3;
+ref = hypermat([3 2 4 2], [19;20;21;22;23;24;13;14;15;16;17;18;7;8;9;10;11;12;1;2;3;4;5;6;43;44;45;46;47;48;37;38;39;40;41;42;31;32;33;34;35;36;25;26;27;28;29;30]);
+y = flipdim(x, dim);
+assert_checkequal(y, ref);