1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA - Farid BELAHCENE
3 // Copyright (C) DIGITEO - 2011 - Allan CORNET
4 // Copyright (C) 2013 - Samuel GOUGEON : restriction to decimal numbers removed
6 // Copyright (C) 2012 - 2016 - Scilab Enterprises
8 // This file is hereby licensed under the terms of the GNU GPL v2.0,
9 // pursuant to article 5.3.4 of the CeCILL v.2.1.
10 // This file was originally licensed under the terms of the CeCILL v2.1,
11 // and continues to be available under such terms.
12 // For more information, see the COPYING file which you should have received
13 // along with this program.
15 function y = flipdim(x, dim, sb)
18 // Given x, a scalar/vector/matrix of any type, two integers dim and sb, this function flips the x components by blocks along the dimension number dim (x and y have the same size).
20 // x : a scalar/vector/array
21 // dim : a positive integer
22 // sb : size of the block to permute
24 // y : a scalar/vector/array
30 msg = _("%s: Wrong number of input argument(s): %d to %d expected.\n");
31 error(msprintf(msg, "flipdim", 2, 3));
34 if size(dim, "*") <> 1 then
35 msg = _("%s: Wrong size for input argument #%d: A positive integer expected.\n")
36 error(msprintf(msg, "flipdim", 2));
37 elseif type(dim) <> 8 & (type(dim) <> 1 | dim < 1 ) then
38 msg = _("%s: Wrong type for input argument #%d: A positive integer expected.\n");
39 error(msprintf(msg, "flipdim", 2));
42 if size(sb, "*") <> 1 then
43 msg = _("%s: Wrong size for input argument #%d: A positive integer expected.\n")
44 error(msprintf(msg, "flipdim", 3));
45 elseif type(sb) <> 8 & (type(sb) <> 1 | sb < 1 ) then
46 msg = _("%s: Wrong type for input argument #%d: A positive integer expected.\n");
47 error(msprintf(msg, "flipdim", 3));
49 msg = _("%s: Cannot flip hypermatrix blockwise. %d input arguments expected.\n");
50 error(msprintf(msg, "flipdim", 2));
62 elseif or(dim == [1 2]) & ndims(x) < 3 then // flipdim(x, dim, sb) is not suited for hypermatrices.
69 if modulo(nC, sb) ~= 0 then
70 msg = _("%s: Wrong value for input argument #%d: A divisor of the selected dimension size expected.\n");
71 error(msprintf(msg, "flipdim", 3));
73 nb = nC/sb; // Number of blocks.
74 c2 = ((nb:-1:1).*.ones(1,sb))*sb + ones(1, nb).*.(1-sb:0);
87 for k = dim + 1:ndims(x)