1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2019 - Samuel GOUGEON
5 // This file is hereby licensed under the terms of the GNU GPL v2.0,
6 // pursuant to article 5.3.4 of the CeCILL v.2.1.
7 // This file was originally licensed under the terms of the CeCILL v2.1,
8 // and continues to be available under such terms.
9 // For more information, see the COPYING file which you should have received
10 // along with this program.
12 function x = %s_y_s(b, a)
13 // x = b ./. a such that b = x .*. a
14 // a, b: arrays of any sizes, including hypermatrices
16 // size(a) = (p, q, ..)
17 // size(x) = (m, n, ..)
18 // size(b) = (m*p, n*q, ..)
20 // Extended size of a:
21 sa = [size(a) ones(1, ndims(b)-ndims(a))]; // [p, q,..]
25 if or(sx <> int(sx)) then
26 msg = _("%s: Arguments #%d and #%d: Incompatible sizes.\n")
27 error(msprintf(msg, "./. :", 1, 2))
30 Sx = list(); for s = sx, Sx($+1) = s, end
32 // Reordering b components to allow a matricial processing:
33 ia = matrix(1:prod(sa), sa);
34 tmp = ones(Sx(:)) .*. ia;
35 [tmp, k] = gsort(tmp,"g","i");
36 b = matrix(b(k), prod(sx), prod(sa))
38 // Least square Processing
41 // Reshaping the raw result