1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) INRIA
3//
4// Copyright (C) 2012 - 2016 - Scilab Enterprises
5//
6// This file is hereby licensed under the terms of the GNU GPL v2.0,
7// pursuant to article 5.3.4 of the CeCILL v.2.1.
8// This file was originally licensed under the terms of the CeCILL v2.1,
9// and continues to be available under such terms.
10// For more information, see the COPYING file which you should have received
11// along with this program.
12
13function f2=%s_m_r(n1,f2)
14    // %s_m_r(n1,f2)
15    //operation  f2=n1*f2
16    //author Serge Steer INRIA
17    //!
18
19    fname = "%s_m_r";
20
21    [n2,d2] = f2(["num","den"]);
22    sz1 = size(n1);
23    sz2 = size(n2);
24    if prod(sz1)==0 | prod(sz2)==0 then  f2=[],return,end
25
26
27    indef=%f
28    if or(sz1==-1) then
29        n1 = n1+0;
30        sz1 = [1 1];
31        if prod(sz2)==1 then
32            indef = %t
33        else
34            msg = _("%s: Eye variable undefined in this context.\n")
35            error(msprintf(msg, fname))
36        end
37    end
38
39    if  or(sz2==-1) then
40        n2 = n2+0;
41        d2 = d2+0;
42        sz2 = [1 1];
43        if prod(sz1)==1 then
44            indef = %t
45        else
46            msg = _("%s: Eye variable undefined in this context.\n")
47            error(msprintf(msg, fname))
48        end
49    end
50
51    //
52    if prod(sz1)==1 then
53        num = n1*n2,
54        den = d2
55    elseif prod(sz2)==1 then
56        num = n1*n2,
57        den = d2(ones(n1))
58    else
59        if size(sz1,"*")>2 | size(sz2,"*")>2 then
60            msg = _("%s: Hypermatrix not supported.\n")
61            error(msprintf(msg, fname))
62        end
63        if sz1(2) <> sz2(1) then
64            msg = _("%s: Arguments #%d and #%d: Incompatible sizes.\n")
65            error(msprintf(msg, fname, 1, 2))
66        end
67
68        l1 = sz1(1);
69        m1 = sz1(2);
70        m2 = sz2(2);
71        for j = 1:m2,
72            [y,fact] = lcm(d2(:,j)),
73            n2(:,j) = n2(:,j).*fact,
74            den(1:l1,j) = ones(l1,1)*y
75            for i = 1:l1
76                num(i,j) = n1(i,:)*n2(:,j)
77            end,
78        end,
79        [num,den] = simp(num,den)
80    end
81
82    if indef then
83        num = num*eye()
84        den = den*eye()
85    end
86    f2 = rlist(num,den,f2.dt)
87endfunction
88