bug 2374 fixed + other missing related overloading functions added
Serge Steer [Tue, 15 Apr 2008 09:23:45 +0000 (09:23 +0000)]
53 files changed:
scilab/modules/overloading/macros/%hm_a_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%hm_i_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%hm_m_p.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%hm_m_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%hm_m_s.sci
scilab/modules/overloading/macros/%hm_s_hm.sci
scilab/modules/overloading/macros/%hm_s_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%hm_string.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%hm_x_p.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%hm_x_s.sci
scilab/modules/overloading/macros/%p_a_r.sci
scilab/modules/overloading/macros/%p_i_r.sci
scilab/modules/overloading/macros/%p_m_hm.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%p_m_r.sci
scilab/modules/overloading/macros/%p_s_r.sci
scilab/modules/overloading/macros/%p_x_hm.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%p_x_r.sci
scilab/modules/overloading/macros/%r_a_hm.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_a_p.sci
scilab/modules/overloading/macros/%r_a_r.sci
scilab/modules/overloading/macros/%r_a_s.sci
scilab/modules/overloading/macros/%r_d_r.sci
scilab/modules/overloading/macros/%r_d_s.sci
scilab/modules/overloading/macros/%r_e.sci
scilab/modules/overloading/macros/%r_i_hm.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_i_p.sci
scilab/modules/overloading/macros/%r_i_r.sci
scilab/modules/overloading/macros/%r_i_s.sci
scilab/modules/overloading/macros/%r_m_hm.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_m_p.sci
scilab/modules/overloading/macros/%r_m_r.sci
scilab/modules/overloading/macros/%r_m_s.sci
scilab/modules/overloading/macros/%r_matrix.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_p.sci
scilab/modules/overloading/macros/%r_q_r.sci
scilab/modules/overloading/macros/%r_r_s.sci
scilab/modules/overloading/macros/%r_s_hm.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_s_p.sci
scilab/modules/overloading/macros/%r_s_r.sci
scilab/modules/overloading/macros/%r_s_s.sci
scilab/modules/overloading/macros/%r_x_p.sci
scilab/modules/overloading/macros/%r_x_r.sci
scilab/modules/overloading/macros/%r_x_s.sci
scilab/modules/overloading/macros/%s_a_r.sci
scilab/modules/overloading/macros/%s_b_s.sci
scilab/modules/overloading/macros/%s_i_hm.sci
scilab/modules/overloading/macros/%s_i_p.sci
scilab/modules/overloading/macros/%s_i_r.sci
scilab/modules/overloading/macros/%s_l_r.sci
scilab/modules/overloading/macros/%s_m_r.sci
scilab/modules/overloading/macros/%s_s_r.sci
scilab/modules/overloading/macros/generic_i_hm.sci
scilab/modules/overloading/tests/unit_tests/rational.tst [new file with mode: 0644]

diff --git a/scilab/modules/overloading/macros/%hm_a_r.sci b/scilab/modules/overloading/macros/%hm_a_r.sci
new file mode 100644 (file)
index 0000000..78fde47
--- /dev/null
@@ -0,0 +1,31 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
+function f=%hm_a_r(m,f)
+//f=  m+f
+//!
+
+[num,den]=f(['num','den'])
+szf=size(den)
+szm=size(m)
+
+if and(szf>=0)&and(szm>=0) then
+  num=num(:);den=den(:);m=m(:)
+  if prod(szf)==1&prod(szm)>1 then
+    den=den(ones(m))
+  end
+  [num,den]=simp(num+m.*den,den)
+  num=matrix(num,szf)
+  den=matrix(den,szf)
+  f=rlist(num,den,f.dt)
+else
+  error(8)
+end
+
+endfunction
+
diff --git a/scilab/modules/overloading/macros/%hm_i_r.sci b/scilab/modules/overloading/macros/%hm_i_r.sci
new file mode 100644 (file)
index 0000000..5a25515
--- /dev/null
@@ -0,0 +1,12 @@
+function N=%r_i_hm(varargin)
+  //author Serge Steer INRIA
+  M=varargin($);
+  N=varargin($-1);//inserted matrix
+//  M(i,...)=N
+  Den=ones(M);
+  M(varargin(1:$-2))=N.num  
+  Den(varargin(1:$-2))=N.den
+  N.num=M
+  N.den=Den
+
+endfunction
diff --git a/scilab/modules/overloading/macros/%hm_m_p.sci b/scilab/modules/overloading/macros/%hm_m_p.sci
new file mode 100644 (file)
index 0000000..0182004
--- /dev/null
@@ -0,0 +1,16 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
+
+function M1=%hm_m_p(M1,M2)
+  if size(M2,'*')<>1 then
+    M1=M1*mlist(['hm','dims','entries'],size(M2),matrix(M2,-1,1))
+  else
+    M1.entries=M1.entries*M2
+  end
+endfunction
diff --git a/scilab/modules/overloading/macros/%hm_m_r.sci b/scilab/modules/overloading/macros/%hm_m_r.sci
new file mode 100644 (file)
index 0000000..e7f1015
--- /dev/null
@@ -0,0 +1,34 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
+
+function f2=%hm_m_r(n1,f2)
+// %s_m_r(n1,f2)  
+//operation  f2=n1*f2
+//author Serge Steer INRIA
+//!
+[n2,d2]=f2(['num','den']);
+sz2=size(n2);
+if prod(sz2)==0 then  f2=[],return,end
+sz1=size(n1);
+n1=n1(:)
+
+if  or(sz2==-1) then 
+  n2=n2+0;d2=d2+0;
+end  
+
+//
+if prod(sz2)==1 then
+    num=n1*n2,
+    den=d2(ones(n1))
+else,
+  error(10)
+end,
+
+f2=rlist(matrix(num,sz1),matrix(den,sz1),f2.dt)
+endfunction
index 7be1321..6daf2d8 100644 (file)
@@ -8,9 +8,9 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
 function M1=%hm_m_s(M1,M2)
-if size(M2,'*')<>1 then
-  M1=M1*mlist(['hm','dims','entries'],size(M2),matrix(M2,-1,1))
-else
-  M1.entries=M1.entries*M2
-end
+  if size(M2,'*')<>1 then
+    M1=M1*mlist(['hm','dims','entries'],size(M2),matrix(M2,-1,1))
+  else
+    M1.entries=M1.entries*M2
+  end
 endfunction
index 9741795..b056cba 100644 (file)
@@ -8,10 +8,10 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
 function M1=%hm_s_hm(M1,M2)
-
 // hypermatrix substraction
-if or(M1('dims')<>M2('dims')) then
-  error(8)
-end
-M1('entries')=M1('entries')-M2('entries')
+//author Serge Steer
+  if or(M1('dims')<>M2('dims')) then
+    error(9)
+  end
+  M1('entries')=M1('entries')-M2('entries')
 endfunction
diff --git a/scilab/modules/overloading/macros/%hm_s_r.sci b/scilab/modules/overloading/macros/%hm_s_r.sci
new file mode 100644 (file)
index 0000000..2ecf372
--- /dev/null
@@ -0,0 +1,31 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
+function f=%hm_s_r(m,f)
+//f=  m-f
+  //author Serge Steer INRIA
+//!
+[num,den]=f(['num','den'])
+szf=size(den)
+szm=size(m)
+
+if and(szf>=0)&and(szm>=0) then
+  num=num(:);den=den(:);m=m(:)
+  if prod(szf)==1&prod(szm)>1 then
+    den=den(ones(m))
+  end
+  [num,den]=simp(-num+m.*den,den)
+  num=matrix(num,szf)
+  den=matrix(den,szf)
+  f=rlist(num,den,f.dt)
+else
+  error(9)
+end
+
+endfunction
+
diff --git a/scilab/modules/overloading/macros/%hm_string.sci b/scilab/modules/overloading/macros/%hm_string.sci
new file mode 100644 (file)
index 0000000..b7f1f94
--- /dev/null
@@ -0,0 +1,3 @@
+function a=%hm_string(a)
+  a.entries=string(a.entries)
+endfunction
diff --git a/scilab/modules/overloading/macros/%hm_x_p.sci b/scilab/modules/overloading/macros/%hm_x_p.sci
new file mode 100644 (file)
index 0000000..61a45f3
--- /dev/null
@@ -0,0 +1,17 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
+
+function M1=%hm_x_p(M1,M2)
+//author Serge Steer
+  if size(M2,'*')<>1 then
+    error('inconsistent element-wise operation')
+  else
+    M1.entries=M1.entries.*M2
+  end
+endfunction
index fbbc558..367811f 100644 (file)
@@ -8,10 +8,10 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
 function M1=%hm_x_s(M1,M2)
-
-if size(M2,'*')<>1 then
-  error('inconsistent element-wise operation')
-else
-  M1('entries')=M1('entries').*M2
-end
+//author Serge Steer
+  if size(M2,'*')<>1 then
+    error('inconsistent element-wise operation')
+  else
+    M1.entries=M1.entries.*M2
+  end
 endfunction
index 440a046..34ffac9 100644 (file)
@@ -9,25 +9,37 @@
 
 function f=%p_a_r(m,f)
 //f=  m+f
+// author Serge Steer, INRIA
 //!
 [num,den]=f(['num','den'])
-[nf,mf]=size(f)
-[nm,mm]=size(m)
+szf=size(den)
+szm=size(m)
 
-if nf>=0&nm>=0 then
-  if size(num,'*')==1&size(m,'*')>1 then
-    den=den*ones(m)
+if and(szf>=0)&and(szm>=0) then
+  if prod(szf)==1&prod(szm)>1 then
+    den=den(ones(m))
+    szf=szm
+  end
+
+  if size(szf,'*')>2 then
+    num=num(:);den=den(:);m=m(:)
   end
   [num,den]=simp(num+m.*den,den)
+  num=matrix(num,szf)
+  den=matrix(den,szf)
 else
-  //at least one matrix is eye*x
-  if nf<0&nm<0 then
+  //at leat one matrix is eye*x
+  if size(szf,'*')>2|size(szm,'*')>2 then
+  error(8)
+  end
+  if or(szf<0)&or(szm<0) then
     [num,den]=simp(num+m.*den,den)
-  elseif nf<0 then
+  elseif or(szf<0) then
     [num,den]=simp(num+m.*den,den*ones(m))
-  elseif nm<0 then
-    [num,den]=simp(num+m*eye(den).*den,den)
+  elseif or(szm<0) then
+    [num,den]=simp(num+(m+0)*eye(den).*den,den)
   end
 end
-f=rlist(num,den,f('dt'))
+f=rlist(num,den,f.dt)
 endfunction
+
index 3ed7cea..2f747fd 100644 (file)
@@ -7,20 +7,20 @@
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-function s1=%p_i_r(i,j,s1,s2)
-//s2(i,j)=s1, s1 matrix of polynomials
+function s1=%p_i_r(varargin)
+//Author Serge Steer, INRIA
 //!
+  s2=varargin($)
+  s1=varargin($-1)
+  //s2(i,...)=s1, s1 matrix of polynomials
 
-[lhs,rhs]=argn(0)
-if rhs==3 then
-  [s1,s2]=(j,s1)
-  [n1,n2]=size(s2('den'))
-  n=s2('num');n(i)=s1
-  d=ones(n);d(1:n1,1:n2)=s2('den');d(i)=ones(s1);
-else
-  [n1,n2]=size(s2('den'))
-  n=s2('num');n(i,j)=s1
-  d=ones(n);d(1:n1,1:n2)=s2('den');d(i,j)=ones(s1);
-end
-s1=rlist(n,d,s2('dt'))
+  num=s2.num;
+  sz2=size(num)
+  ind=list(); for i=sz2,ind($+1)=1:i,end
+  num(varargin(1:$-2))=s1
+  den=ones(num);
+  den(ind(:))=s2.den;
+  den(varargin(1:$-2))=ones(s1);
+
+  s1=rlist(num,den,s2.dt)
 endfunction
diff --git a/scilab/modules/overloading/macros/%p_m_hm.sci b/scilab/modules/overloading/macros/%p_m_hm.sci
new file mode 100644 (file)
index 0000000..846bd55
--- /dev/null
@@ -0,0 +1,17 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
+
+function M2=%p_m_hm(M1,M2)
+//author Serge Steer INRIA
+  if size(M1,'*')<>1 then
+    M2=hypermat(size(M1),M1)*M2
+  else
+    M2.entries=M1*M2.entries
+  end
+endfunction
index 311b189..458ff2a 100644 (file)
@@ -7,46 +7,61 @@
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-function f=%p_m_r(p,f)
+function f2=%p_m_r(n1,f2)
 // r=%p_m_r(p,f)  <=> r= p*f with p=polynomial matrix
 // and f= rational
+//author Serge Steer INRIA
+  
 //!
 
-[n2,d2]=f(['num','den']);
-[l1,m1]=size(p);[l2,m2]=size(n2);
-//
-indef=%f
-if l1==-1 then 
-  p=p+0;l1=1;m1=1;
-  if l2*m2==1 then indef=%t,else error(14),end
-end
-if l2==-1 then 
-  n2=n2+0;d2=d2+0;l2=1;m2=1;
-  if l1*m1==1 then indef=%t,else error(14),end
-end  
+  [n2,d2]=f2(['num','den']);
+  sz1=size(n1);sz2=size(n2);
+  if prod(sz1)==0|prod(sz2)==0 then  f2=[],return,end
 
-if mini([l1*m1,l2*m2])==1 then
-  num=p*n2,
-  den=ones(l1,m1)*d2,
-else
 
-  if m1<>l2 then error(10),end
+  indef=%f
+  if or(sz1==-1) then 
+    n1=n1+0;sz1=[1 1];
+    if  prod(sz2)==1 then indef=%t,else error(14),end
+  end
+  if  or(sz2==-1) then 
+    n2=n2+0;d2=d2+0;sz2=[1 1];
+    if prod(sz1)==1 then indef=%t,else error(14),end
+  end  
+
   //
-  for j=1:m2,
-    y=lcm(d2(:,j))
-    for i=1:l1,
-      x=0;
-      for k=1:m1,
-       x=x+p(i,k)*pdiv(y,d2(k,j))*n2(k,j),
+  if prod(sz1)==1 then
+    num=n1*n2,
+    den=d2
+  elseif prod(sz2)==1 then
+    num=n1*n2,
+    den=d2(ones(n1))
+  else,
+    if size(sz1,'*')>2|size(sz2,'*')>2 then error(10),end
+    if sz1(2)<>sz2(1) then error(10),end,
+    l1=sz1(1);m1=sz1(2);m2=sz2(2);
+    for j=1:m2,
+      [y,fact]=lcm(d2(:,j)),
+      n2(:,j)=n2(:,j).*fact,
+      den(1:l1,j)=ones(l1,1)*y,
+      for i=1:l1,
+       num(i,j)=n1(i,:)*n2(:,j),
       end
-      num(i,j)=x,den(i,j)=y,
     end
   end
-end
-[num,den]=simp(num,den)
-if indef then
-  num=num*eye()
-  den=den*eye()
-end
-f=rlist(num,den,f('dt'))
+  
+  if ndims(num)<=2 then
+    [num,den]=simp(num,den),
+  else
+    sz=size(num)
+    [num,den]=simp(num.entries,den.entries),
+    num=matrix(num,sz)
+    den=matrix(den,sz)
+  end
+
+  if indef then
+    num=num*eye()
+    den=den*eye()
+  end
+  f2=rlist(num,den,f2.dt)
 endfunction
index 898b41d..bf04fe0 100644 (file)
@@ -8,27 +8,37 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
 function f=%p_s_r(m,f)
-//f=%p_s_r(m,f) <=> f=  m-f
+//f=  m-f
+//author Serge Steer INRIA
 //!
+  [num,den]=f(['num','den'])
+  szf=size(den)
+  szm=size(m)
 
-[num,den]=f(['num','den'])
-[nf,mf]=size(f)
-[nm,mm]=size(m)
+  if and(szf>=0)&and(szm>=0) then
+    if prod(szf)==1&prod(szm)>1 then
+      den=den(ones(m))
+      szf=szm
+    end
 
-if nf>=0&nm>=0 then
-  if size(num,'*')==1&size(m,'*')>1 then
-    den=den*ones(m)
-  end
-  [num,den]=simp(-num+m.*den,den)
-else
-  //at leat one matrix is eye*x
-  if nf<0&nm<0 then
+    if size(szf,'*')>2 then
+      num=num(:);den=den(:);m=m(:)
+    end
     [num,den]=simp(-num+m.*den,den)
-  elseif nf<0 then
-    [num,den]=simp(-num+m.*den,den*ones(m))
-  elseif nm<0 then
-    [num,den]=simp(-num+m*eye(den).*den,den)
+    num=matrix(num,szf)
+    den=matrix(den,szf)
+  else
+    //at leat one matrix is eye*x
+    if size(szf,'*')>2|size(szm,'*')>2 then
+      error(9)
+    end
+    if or(szf<0)&or(szm<0) then
+      [num,den]=simp(-num+m.*den,den)
+    elseif or(szf<0) then
+      [num,den]=simp(-num+m.*den,den*ones(m))
+    elseif or(szm<0) then
+      [num,den]=simp(-num+(m+0)*eye(den).*den,den)
+    end
   end
-end
-f=rlist(num,den,f('dt'))
+  f=rlist(num,den,f.dt)
 endfunction
diff --git a/scilab/modules/overloading/macros/%p_x_hm.sci b/scilab/modules/overloading/macros/%p_x_hm.sci
new file mode 100644 (file)
index 0000000..b6963c4
--- /dev/null
@@ -0,0 +1,12 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
+function h=%p_x_hm(p,h)
+//author Serge Steer INRIA
+  h.entries=p.*h.entries
+endfunction
index 3355592..cabbbde 100644 (file)
@@ -9,7 +9,16 @@
 
 function r=%p_x_r(p,r)
 // r=%p_x_r(p,r)  <=> r=p.*r   polynomial.* rational
+//author Serge Steer, INRIA
 //!
 
-r('num')=p.*r('num')
+  r.num=p.*r.num
+  sz=size(r.num)
+  if size(sz,'*')<=2 then
+    r=simp(r)
+  else
+    [num,den]=simp(r.num.entries,r.den.entries)
+    r.num=matrix(num,sz)
+    r.den=matrix(den,sz)
+  end
 endfunction
diff --git a/scilab/modules/overloading/macros/%r_a_hm.sci b/scilab/modules/overloading/macros/%r_a_hm.sci
new file mode 100644 (file)
index 0000000..c597d78
--- /dev/null
@@ -0,0 +1,31 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
+
+function f=%r_a_hm(f,m)
+//f = f+m, 
+//f: transfer matrix, m : hypermatrix
+  //author Serge Steer INRIA
+//!
+  [num,den]=f(['num','den'])
+  szf=size(den)
+  szm=size(m)
+
+  if and(szf>=0)&and(szm>=0) then
+    num=num(:);den=den(:);m=m(:)
+    if prod(szf)==1&prod(szm)>1 then
+      den=den(ones(m))
+    end
+    [num,den]=simp(num+m.*den,den)
+    num=matrix(num,szf)
+    den=matrix(den,szf)
+    f=rlist(num,den,f.dt)
+  else
+    error(8)
+  end
+endfunction
index 540f01d..7b69870 100644 (file)
@@ -9,26 +9,38 @@
 
 function f=%r_a_p(f,m)
 //f = f+m, 
-//f: transfer matrix, m : scalar or constant matrix
+//f: transfer matrix, m : polynomial matrix
+//author Serge Steer INRIA
 //!
-[num,den]=f(['num','den'])
-[nf,mf]=size(num)
-[nm,mm]=size(m)
+  [num,den]=f(['num','den'])
+  szf=size(den)
+  szm=size(m)
 
-if nf>=0&nm>=0 then
-  if size(num,'*')==1&size(m,'*')>1 then
-    den=den*ones(m)
-  end
-  [num,den]=simp(num+m.*den,den)
-else
-  //at leat one matrix is eye*x
-  if nf<0&nm<0 then
+  if and(szf>=0)&and(szm>=0) then
+    if prod(szf)==1&prod(szm)>1 then
+      den=den(ones(m))
+      szf=szm
+    end
+
+    if size(szf,'*')>2 then
+      num=num(:);den=den(:);m=m(:)
+    end
     [num,den]=simp(num+m.*den,den)
-  elseif nf<0 then
-    [num,den]=simp(num+m.*den,den*ones(m))
-  elseif nm<0 then
-    [num,den]=simp(num+m*eye(den).*den,den)
+    num=matrix(num,szf)
+    den=matrix(den,szf)
+  else
+    //at leat one matrix is eye*x
+    if size(szf,'*')>2|size(szm,'*')>2 then
+      error(8)
+    end
+    if or(szf<0)&or(szm<0) then
+      [num,den]=simp(num+m.*den,den)
+    elseif or(szf<0) then
+      [num,den]=simp(num+m.*den,den*ones(m))
+    elseif or(szm<0) then
+      [num,den]=simp(num+(m+0)*eye(den).*den,den)
+    end
   end
-end
-f=rlist(num,den,f('dt'))
+  f=rlist(num,den,f.dt)
+  
 endfunction
index eea7f99..59c785b 100644 (file)
@@ -9,55 +9,63 @@
 
 function f=%r_a_r(s1,s2)
 //f=s1+s2 s1,s2 : rational matrices
+//author Serge Steer, INRIA
 //!
-[s1,s2]=sysconv(s1,s2),
-[num1,den1]=s1(['num','den']),
-[num2,den2]=s2(['num','den']),
-[m1,n1]=size(num1)
-[m2,n2]=size(num2)
+  if ndims(s1)<2&ndims(s2)<2 then [s1,s2]=sysconv(s1,s2),end
+  [num1,den1]=s1(['num','den']),
+  [num2,den2]=s2(['num','den']),
+  sz1=size(num1)
+  sz2=size(num2)
 
-if m1==-1 then
-  num1=num1+0
-  den1=den1+0
-  n1=1
-end
-if m2==-1 then
-  num2=num2+0
-  den2=den2+0
-  n2=1
-end
+  if and(sz1>=0)&and(sz2>=0) then
+    num1=num1(:);den1=den1(:);
+    num2=num2(:);den2=den2(:);
 
-if m1==-1&m2==-1 then
-  // both are eye*x
-  [den1,fact]=lcm([den1;den2])
-  [num1,den1]=simp([num1,num2]*fact,den1)
-  f=rlist(num1*eye(),den1*eye(),s1('dt')),
-  return
-end
-m1=abs(m1);m2=abs(m2)
-if m1*n1==1&m2*n2>1 then
-  //scalar +matrix:replace scalar by scalar*ones(matrix)
-  num1=num1*ones(num2)
-  den1=den1*ones(num2)
-  m1=m2
-  n1=n2
-elseif m2*n2==1&m1*n1>1 then
-  // matrix+scalar:replace scalar by scalar*ones(matrix)
-  num2=num2*ones(num1)
-  den2=den2*ones(den1)
-  m2=m1
-  n2=n1
-end
+    if prod(sz1)==1&prod(sz2)>1 then
+      den1=den1(ones(den2))
+      num1=num1(ones(num2))
+      sz1=sz2
+    elseif prod(sz2)==1&prod(sz1)>1 then
+      den2=den2(ones(den1))
+      num2=num2(ones(num1))
+      sz2=sz1
+    end
+    if and(sz1<>sz2) then error(8),end
+    for l=1:prod(sz1)
+      [den,fact]=lcm([den1(l);den2(l)])
+      num1(l)=[num1(l),num2(l)]*fact
+      den1(l)=den
+    end,
+    [num1,den1]=simp(num1,den1),
+    f=rlist(matrix(num1,sz1),matrix(den1,sz1),s1.dt)
+  else
+    if size(sz1,'*')>2|size(sz2,'*')>2 then error(8),end
+    
+    if or(sz1<0)&or(sz2<0) then
+      // both are eye*x
+      [den1,fact]=lcm([den1;den2])
+      [num1,den1]=simp([num1,num2]*fact,den1)
+      f=rlist(num1*eye(),den1*eye(),s1('dt')),
+    elseif  or(sz1<0) then
+      den1=den1+0;num1=num1+0
+      for l=1:min(sz2)
+       [den,fact]=lcm([den1;den2(l,l)])
+       num2(l,l)=[num1,num2(l,l)]*fact
+       den2(l,l)=den
+      end
+      [num2,den2]=simp(num2,den2),
+      f=rlist(num2,den2,s1.dt)
+    elseif or(sz2<0) then
+      den2=den2+0;num2=num2+0
+      for l=1:min(sz1)
+       [den,fact]=lcm([den1(l,l);den2])
+       num1(l,l)=[num1(l,l),num2]*fact
+       den1(l,l)=den
+      end
+      [num1,den1]=simp(num1,den1),
+      f=rlist(num1,den1,s1.dt)
+    end
+  end
 
-if m1<>m2|n1<>n2 then error(9),end
 
-for l=1:m1
-  for k=1:n1
-    [den,fact]=lcm([den1(l,k);den2(l,k)])
-    num1(l,k)=[num1(l,k),num2(l,k)]*fact
-    den1(l,k)=den
-  end,
-end,
-[num1,den1]=simp(num1,den1),
-f=rlist(num1,den1,s1('dt'))
 endfunction
index dc615b0..5c6540f 100644 (file)
 function f=%r_a_s(f,m)
 //f = f+m, 
 //f: transfer matrix, m : scalar or scalar matrix
+//author Serge Steer INRIA
 //!
 [num,den]=f(['num','den'])
-[nf,mf]=size(num)
-[nm,mm]=size(m)
+szf=size(den)
+szm=size(m)
 
-if nf>=0&nm>=0 then
-  if size(num,'*')==1&size(m,'*')>1 then
-    den=den*ones(m)
+if and(szf>=0)&and(szm>=0) then
+  if prod(szf)==1&prod(szm)>1 then
+    den=den(ones(m))
+    szf=szm
+  end
+
+  if size(szf,'*')>2 then
+    num=num(:);den=den(:);m=m(:)
   end
   [num,den]=simp(num+m.*den,den)
+  num=matrix(num,szf)
+  den=matrix(den,szf)
 else
   //at leat one matrix is eye*x
-  if nf<0&nm<0 then
+  if size(szf,'*')>2|size(szm,'*')>2 then
+  error(8)
+  end
+  if or(szf<0)&or(szm<0) then
     [num,den]=simp(num+m.*den,den)
-  elseif nf<0 then
+  elseif or(szf<0) then
     [num,den]=simp(num+m.*den,den*ones(m))
-  elseif nm<0 then
+  elseif or(szm<0) then
     [num,den]=simp(num+(m+0)*eye(den).*den,den)
   end
 end
-f=rlist(num,den,f('dt'))
+f=rlist(num,den,f.dt)
 endfunction
index 21969ea..7c615b7 100644 (file)
 function f=%r_d_r(s1,s2)
 // f=s1./s2
 //!
-
-[s1,s2]=sysconv(s1,s2)
-[num,den]=simp(s1('num').*s2('den'),s1('den').*s2('num'))
-f=rlist(num,den,s1('dt'))
+  if ndims(s1)<=2& ndims(s2)<=2 then
+    [s1,s2]=sysconv(s1,s2)
+    [num,den]=simp(s1.num.*s2.den,s1.den.*s2.num)
+    f=rlist(num,den,s1.dt)
+  else
+    if size(s1,'*')==1 then 
+      sz=size(s2)
+    else
+      sz=size(s1)
+    end
+    [num,den]=simp(s1.num(:).*s2.den(:),s1.den(:).*s2.num(:))
+    f=rlist(matrix(num,sz),matrix(den,sz),s1.dt)
+  end  
 endfunction
index 2245547..3b58ea9 100644 (file)
@@ -11,6 +11,6 @@ function r=%r_d_s(r,m)
 // r=r./m
 //!
 
-if size(m,'*')==0 then r=[],return,end
-r=rlist(r('num').*ones(m),r('den').*m,r('dt'))
+  if size(m,'*')==0 then r=[],return,end
+  r=rlist(r.num./m,r.den.*ones(m),r.dt)
 endfunction
index 118ccbd..54b51c9 100644 (file)
@@ -7,15 +7,13 @@
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-function f=%r_e(i,j,f)
+function r=%r_e(varargin)
 // %r_e(i,j,f) extraction f(i,j) in a rational matrix
+//author Serge Steer, INRIA
 //!
-
-[lhs,rhs]=argn(0)
-if rhs==2 then 
-  f=rlist(j('num')(i),j('den')(i),j('dt'))
-elseif rhs==3 then
-  f=rlist(f('num')(i,j),f('den')(i,j),f('dt'))
-end
-if f('num')==[] then f=[],end
+  f=varargin($)
+  num=f.num
+  den=f.den
+  r=rlist(num(varargin(1:$-1)),den(varargin(1:$-1)),f.dt)
+  if r.num==[] then r=[],end
 endfunction
diff --git a/scilab/modules/overloading/macros/%r_i_hm.sci b/scilab/modules/overloading/macros/%r_i_hm.sci
new file mode 100644 (file)
index 0000000..e2465c4
--- /dev/null
@@ -0,0 +1,13 @@
+function N=%r_i_hm(varargin)
+  //author Serge Steer INRIA
+  M=varargin($);
+  N=varargin($-1);//inserted matrix
+  //  M(i,...)=N,  M hypermatrix; N rational matrix
+  Num=M;
+  Den=ones(M);
+  Num(varargin(1:$-2))=N.num
+  Den(varargin(1:$-2))=N.den
+  N.num=Num;
+  N.den=Den;
+endfunction
index 7a6ad54..2b4e8d6 100644 (file)
@@ -7,18 +7,16 @@
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-function f2=%r_i_p(i,j,f2,n)
-// f2=%r_i_p(i,j,f2,p)   insertion
+function f2=%r_i_p(varargin)
+// /author Serge Steer INRIA
 //
-
-[lhs,rhs]=argn(0)
-if rhs==3 then
-  n=f2;f2=j
+  f2=varargin($-1)
+  n= varargin($)
+  // f2=%r_i_p(i,j,f2,p)   insertion
   d=ones(n);
-  n(i)=f2('num'),d(i)=f2('den')
-else
+  n(varargin(1:$-2))=f2.num;
   d=ones(n);
-  n(i,j)=f2('num'),d(i,j)=f2('den')
-end
-f2=rlist(n,d,f2('dt'))
+  d(varargin(1:$-2))=f2.den;
+
+  f2=rlist(n,d,f2('dt'))
 endfunction
index a01efba..00c8c73 100644 (file)
@@ -7,21 +7,22 @@
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-function s1=%r_i_r(i,j,s1,s2)
+function s1=%r_i_r(varargin)
+//author Serge Steer INRIA
+  s1=varargin($-1)
+  s2=varargin($)
 // %r_i_r(i,j,s1,s2) insertion  s2(i,j)=s1
-//!
 
-[lhs,rhs]=argn(0)
-if rhs==3 then
-  [s1,s2]=sysconv(j,s1)
-  [n1,n2]=size(s2('den'))
-  n=s2('num');n(i)=s1('num'),
-  d=ones(n);d(1:n1,1:n2)=s2('den');d(i)=s1('den')
-else
   [s1,s2]=sysconv(s1,s2)
-  [n1,n2]=size(s2('den'))
-  n=s2('num');n(i,j)=s1('num'),
-  d=ones(n);d(1:n1,1:n2)=s2('den');d(i,j)=s1('den')
-end
-s1=rlist(n,d,s1('dt'))
+  n=s2.num;
+  n(varargin(1:$-2))=s1.num,
+  if ndims(s2.den)<=2 then
+    d=ones(n);
+    [n1,n2]=size(s2.den)
+    d(1:n1,1:n2)=s2.den;
+    d(varargin(1:$-2))=s1.den
+  else
+    d=generic_i_hm(1,varargin(1:$-2),s1.den,s2.den)
+  end
+  s1=rlist(n,d,s1.dt)
 endfunction
index 624735c..173d425 100644 (file)
@@ -7,12 +7,14 @@
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-function f2=%r_i_s(i,j,f2,n)
-// %r_i_s(i,j,r,m) 
-//!
-  [lhs,rhs]=argn(0)
-  if rhs==3 then
-    n=f2;f2=j
+function f2=%r_i_s(varargin)
+//author Serge Steer INRIA
+  f2=varargin($-1)
+  n= varargin($)
+// %r_i_s(i,j,f2,n) 
+
+  if size(varargin)==3 then
+    i= varargin(1)
     if (type(i)==10|type(i)==15) then //cell or struct case
       f2=createstruct(i,f2)
       if type(i(1))<>10 & i(2)=="entries" then
@@ -23,10 +25,12 @@ function f2=%r_i_s(i,j,f2,n)
       return
     end
     d=ones(n);
-    n(i)=f2('num'),d(i)=f2('den')
+    n(i)=f2.num,d(i)=f2.den
   else
     d=ones(n);
-    n(i,j)=f2('num'),d(i,j)=f2('den')
+    n(varargin(1:$-2))=f2.num;
+    d=ones(n);
+    d(varargin(1:$-2))=f2.den;
   end
-  f2=rlist(n,d,f2('dt'))
+  f2=rlist(n,d,f2.dt)
 endfunction
diff --git a/scilab/modules/overloading/macros/%r_m_hm.sci b/scilab/modules/overloading/macros/%r_m_hm.sci
new file mode 100644 (file)
index 0000000..cfa9b06
--- /dev/null
@@ -0,0 +1,34 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
+
+function f1=%r_m_hm(f1,n2)
+// %r_m_s(f1,n2)  
+//f1 =  f1*n2
+//author Serge Steer INRIA
+//!
+
+  [n1,d1]=f1(['num','den']),
+  sz1=size(n1);
+  if prod(sz1)==0 then return,end
+  sz2=size(n2);
+  n2=n2(:)
+
+  if or(sz1==-1) then 
+    n1=n1+0;d1=d1+0;
+  end
+  if prod(sz1)==1 then
+    num=n1*n2,
+    den=d1(ones(n2))
+  else,
+    error(10)
+  end,
+
+  f1=rlist(matrix(num,sz2),matrix(den,sz2),f1.dt)
+endfunction
+
index 7641bb9..49e738e 100644 (file)
@@ -12,36 +12,43 @@ function [f1]=%r_m_p(f1,n2)
 // f1=rational n2=polynomial
 //!
 
-[n1,d1]=f1(['num','den']),
-[l1,m1]=size(n1);[l2,m2]=size(n2),
-//
-indef=%f
-if l1==-1 then 
-  n1=n1+0;d1=d1+0;l1=1;m1=1;
-  if l2*m2==1 then indef=%t,else error(14),end
-end
-if l2==-1 then 
-  n2=n2+0;l2=1;m2=1;
-  if l1*m1==1 then indef=%t,else error(14),end
-end 
-if mini([l1*m1,l2*m2])==1 then,
-  num=n1*n2,
-  den=d1*ones(l2,m2),
-else,
-  if m1<>l2 then error(10),end,
-  for i=1:l1,
-    n=n1(i,:);
-    [y,fact]=lcm(d1(i,:)),
-    den(i,1:m2)=ones(1,m2)*y,
+  [n1,d1]=f1(['num','den']),
+  [l1,m1]=size(n1);[l2,m2]=size(n2),
+  //
+  indef=%f
+  if l1==-1 then 
+    n1=n1+0;d1=d1+0;l1=1;m1=1;
+    if l2*m2==1 then indef=%t,else error(14),end
+  end
+  if l2==-1 then 
+    n2=n2+0;l2=1;m2=1;
+    if l1*m1==1 then indef=%t,else error(14),end
+  end 
+  if mini([l1*m1,l2*m2])==1 then,
+    num=n1*n2,
+    den=d1*ones(l2,m2),
+  else,
+    if m1<>l2 then error(10),end,
+    for i=1:l1,
+      n=n1(i,:);
+      [y,fact]=lcm(d1(i,:)),
+      den(i,1:m2)=ones(1,m2)*y,
       for j=1:m2,
         num(i,j)=n*(n2(:,j).*matrix(fact,l2,1)),
       end,
+    end,
   end,
-end,
-[num,den]=simp(num,den),
-if indef then
-  num=num*eye()
-  den=den*eye()
-end
-f1=rlist(num,den,f1('dt'))
+  if ndims(num)<=2 then
+    [num,den]=simp(num,den),
+  else
+    sz=size(num)
+    [num,den]=simp(num.entries,den.entries),
+    num=matrix(num,sz)
+    den=matrix(den,sz)
+  end
+  if indef then
+    num=num*eye()
+    den=den*eye()
+  end
+  f1=rlist(num,den,f1('dt'))
 endfunction
index 15072d4..818cf95 100644 (file)
@@ -12,22 +12,32 @@ function s1=%r_m_r(s1,s2)
 //!
 
 [s1,s2]=sysconv(s1,s2),
-[n1,d1]=s1(['num','den']);[n2,d2]=s2(['num','den']);
-[l1,m1]=size(n1);[l2,m2]=size(n2),
+[n1,d1]=s1(['num','den']);
+[n2,d2]=s2(['num','den']);
+sz1=size(n1)
+sz2=size(n2)
+
 indef=%f
-if l1==-1 then 
-  n1=n1+0;d1=d1+0;l1=1;m1=1;
-  if l2*m2==1 then indef=%t,else error(14),end
+if or(sz1==-1) then 
+  n1=n1+0;d1=d1+0;sz1=[1 1]
+  if prod(sz2)==1 then indef=%t,else error(14),end
 end
-if l2==-1 then 
-  n2=n2+0;d2=d2+0;l2=1;m2=1;
-  if l1*m1==1 then indef=%t,else error(14),end
+if or(sz2==-1) then 
+  n2=n2+0;d2=d2+0;sz2=[1 1]
+  if  prod(sz1)==1 then indef=%t,else error(14),end
 end  
-if mini([l1*m1,l2*m2])==1 then
-  num=n1*n2
-  den=d1*d2
+if prod(sz1)==1 then
+  [num,den]=simp(n1.*n2(:),d1.*d2(:)),
+  num=matrix(num,sz2)
+  den=matrix(den,sz2)
+elseif prod(sz2)==1 then
+  [num,den]=simp(n1(:).*n2,d1(:).*d2),
+  num=matrix(num,sz1)
+  den=matrix(den,sz1)
 else
-  if m1<>l2 then error(10),end
+  if size(sz1,'*')>2|size(sz2,'*')>2 then error(10),end
+  if sz1(2)<>sz2(1) then error(10),end,
+  l1=sz1(1);m1=sz1(2);m2=sz2(2);
   for i=1:l1, pp(i)=lcm(d1(i,:)),end,
   for j=1:m2,
     y=lcm(d2(:,j)),
@@ -40,11 +50,12 @@ else
       num(i,j)=x,den(i,j)=yij,
     end
   end
+  [num,den]=simp(num,den),
 end
-[num,den]=simp(num,den),
+
 if indef then
   num=num*eye()
   den=den*eye()
 end
-s1=rlist(num,den,s1('dt'))
+s1=rlist(num,den,s1.dt)
 endfunction
index d6a8ecf..e8b2f0f 100644 (file)
 function f1=%r_m_s(f1,n2)
 // %r_m_s(f1,n2)  
 //f1 =  f1*n2
+//author Serge Steer INRIA
 //!
 
 [n1,d1]=f1(['num','den']),
-[l1,m1]=size(n1);[l2,m2]=size(n2),
-if l1*m1==0|l2*m2==0 then,f1=[];return;end
+sz1=size(n1);sz2=size(n2);
+if prod(sz1)==0|prod(sz2)==0 then return,end
+
 
 indef=%f
-if l1==-1 then 
-  n1=n1+0;d1=d1+0;l1=1;m1=1;
-  if l2*m2==1 then indef=%t,else error(14),end
+if or(sz1==-1) then 
+  n1=n1+0;d1=d1+0;sz1=[1 1];
+  if prod(sz2)==1 then indef=%t,else error(14),end
 end
-if l2==-1 then 
-  n2=n2+0;l2=1;m2=1;
-  if l1*m1==1 then indef=%t,else error(14),end
+if  or(sz2==-1) then 
+  n2=n2+0;sz2=[1 1];
+  if prod(sz1)==1 then indef=%t,else error(14),end
 end 
 //
-if mini([l1*m1,l2*m2])==1 then,
-  num=n1*n2,
-  den=d1*ones(l2,m2),
+if prod(sz1)==1 then
+    num=n1*n2,
+    den=d1(ones(n2))
+elseif prod(sz2)==1 then
+    num=n1*n2,
+    den=d1
 else,
-  if m1<>l2 then error(10),end,
+  if size(sz1,'*')>2|size(sz2,'*')>2 then error(10),end
+  if sz1(2)<>sz2(1) then error(10),end,
+  l1=sz1(1);l2=sz2(1);m2=sz2(2)
   for i=1:l1,
     n=n1(i,:);
     [y,fact]=lcm(d1(i,:)),
@@ -39,11 +46,12 @@ else,
       num(i,j)=n*(n2(:,j).*matrix(fact,l2,1)),
     end,
   end,
+  [num,den]=simp(num,den),
 end,
-[num,den]=simp(num,den),
+
 if indef then
   num=num*eye()
   den=den*eye()
 end
-f1=rlist(num,den,f1('dt'))
+f1=rlist(num,den,f1.dt)
 endfunction
diff --git a/scilab/modules/overloading/macros/%r_matrix.sci b/scilab/modules/overloading/macros/%r_matrix.sci
new file mode 100644 (file)
index 0000000..385dc07
--- /dev/null
@@ -0,0 +1,12 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
+function r=%r_matrix(r,varargin)
+  r.num=matrix(r.num,varargin(:))  
+  r.den=matrix(r.den,varargin(:))
+endfunction
index bebc1fe..ee8142f 100644 (file)
 function %r_p(h)
 //used to display rational fraction with complex coefficients
 //The real case is hard coded
+if size(size(h),'*')>2 then
+  //hypermatrix case 
+  %hmr_p(h)
+  return
+end
 
 [m,n]=size(h)
 del='!'
@@ -163,3 +168,24 @@ else
   txt=[t1;part(dash,ones(1,l1));t2]
 end
 endfunction
+
+function   %hmr_p(h)
+// hypermatrix display
+  dims=size(h)
+  num=h.num
+  den=h.den
+  nd=size(dims,'*')
+  I=(1:dims(3));
+  for k=4:nd
+    I=[ones(1,dims(k)).*.I;
+       (1:dims(k)).*.ones(1,size(I,2))];
+  end
+  k=1;sz=dims(1)*dims(2)
+  for II=I
+    tit='(:,:,'+strcat(string(II'),',')+')'
+    write(%io(2),tit)
+    hb=rlist(matrix(num.entries(k:k-1+sz),dims(1),dims(2)),matrix(den.entries(k:k-1+sz),dims(1),dims(2)),h.dt)
+    disp(hb)
+    k=k+sz
+  end
+endfunction
index d21a16e..93208c5 100644 (file)
@@ -9,9 +9,20 @@
 
 function s1=%r_q_r(s1,s2)
 // %r_q_r(s1,s2) <=> s1= s1.\s2   for rationals
+//author Serge Steer, INRIA  
 //!
-
-[s1,s2]=sysconv(s1,s2)
-[num,den]=simp(s1('den').*s2('num'),s1('num').*s2('den'))
-s1=rlist(num,den,s1('dt'))
+  if ndims(s1)<=2& ndims(s2)<=2 then
+    [s1,s2]=sysconv(s1,s2)
+    [num,den]=simp(s1.den.*s2.num,s1.num.*s2.den)
+    s1=rlist(num,den,s1.dt)
+  else
+    if size(s1,'*')==1 then 
+      sz=size(s2)
+    else
+      sz=size(s1)
+    end
+    [num,den]=simp(s1.den(:).*s2.num(:),s1.num(:).*s2.den(:))
+    s1=rlist(matrix(num,sz),matrix(den,sz),s1.dt)
+  end  
+  
 endfunction
index 4ed8c66..1a706b3 100644 (file)
@@ -9,30 +9,30 @@
 
 function a=%r_r_s(a,b)
 // a/b a rational matrix, b scalar matrix
+//author Serge Steer
 //!
-
-if size(b,'*')==0 then a=[],return,end
-
-[ma,na]=size(a('num'))
-[mb,nb]=size(b);
-if mb*nb==1 then 
-  a(2)=a(2)/b,
-  if ma==-1|mb==-1 then a(3)=a(3)*eye(),end
-  return,
-end
-na=abs(na);ma=abs(ma)
-mb=abs(mb);nb=abs(nb)
-if na==1 then
-  a=rlist(num/b,ones(nb,mb)*den,a('dt'))
-else
-  [num,den]=a(['num','den']);
-  dd=[];nn=[]
-  for i=1:ma,
-    [y,fact]=lcm(den(i,:)),
-    nn=[nn;(num(i,:).*fact)/b];
-    dd=[dd;y]
+  if size(b,'*')==0 then a=[],return,end
+  [mb,nb]=size(b);
+  if mb*nb==1 then 
+    a.num=a.num/b,
+    if or(size(a)==-1)|mb==-1 then 
+      a.den=a.den*eye(),
+    end
+    return,
+  end
+  [ma,na]=abs(size(a.num))
+  mb=abs(mb);nb=abs(nb)
+  if na==1 then
+    a=rlist(a.num/b,ones(nb,mb)*a.den,a.dt)
+  else
+    [num,den]=a(['num','den']);
+    dd=[];nn=[]
+    for i=1:ma,
+      [y,fact]=lcm(den(i,:)),
+      nn=[nn;(num(i,:).*fact)/b];
+      dd=[dd;y]
+    end
+    [num,den]=simp(nn,dd*ones(1,mb))
+    a=rlist(num,den,a.dt)
   end
-  [num,den]=simp(nn,dd*ones(1,mb))
-  a=rlist(num,den,a('dt'))
-end
 endfunction
diff --git a/scilab/modules/overloading/macros/%r_s_hm.sci b/scilab/modules/overloading/macros/%r_s_hm.sci
new file mode 100644 (file)
index 0000000..dbfcba3
--- /dev/null
@@ -0,0 +1,31 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
+
+function f=%r_s_hm(f,m)
+//f = f-m, 
+//f: transfer matrix, m : hypermatrix
+//author Serge Steer INRIA
+//!
+  [num,den]=f(['num','den'])
+  szf=size(den)
+  szm=size(m)
+
+  if and(szf>=0)&and(szm>=0) then
+    num=num(:);den=den(:);m=m(:)
+    if prod(szf)==1&prod(szm)>1 then
+      den=den(ones(m))
+    end
+    [num,den]=simp(num-m.*den,den)
+    num=matrix(num,szf)
+    den=matrix(den,szf)
+    f=rlist(num,den,f.dt)
+  else
+    error(9)
+  end
+endfunction
index 8521616..2bf1202 100644 (file)
 function f=%r_s_p(f,m)
 //f = f-m, 
 //f: transfer matrix, m : scalar or scalar matrix
+//author Serge Steer INRIA
 //!
+  [num,den]=f(['num','den'])
+  szf=size(den)
+  szm=size(m)
 
-[num,den]=f(['num','den'])
-[nf,mf]=size(num)
-[nm,mm]=size(m)
+  if and(szf>=0)&and(szm>=0) then
+    if prod(szf)==1&prod(szm)>1 then
+      den=den(ones(m))
+      szf=szm
+    end
 
-if nf>=0&nm>=0 then
-  if size(num,'*')==1&size(m,'*')>1 then
-    den=den*ones(m)
-  end
-  [num,den]=simp(num-m.*den,den)
-else
-  //at leat one matrix is eye*x
-  if nf<0&nm<0 then
+    if size(szf,'*')>2 then
+      num=num(:);den=den(:);m=m(:)
+    end
     [num,den]=simp(num-m.*den,den)
-  elseif nf<0 then
-    [num,den]=simp(num-m.*den,den*ones(m))
-  elseif nm<0 then
-    [num,den]=simp(num-m*eye(den).*den,den)
+    num=matrix(num,szf)
+    den=matrix(den,szf)
+  else
+    //at leat one matrix is eye*x
+    if size(szf,'*')>2|size(szm,'*')>2 then
+      error(9)
+    end
+    if or(szf<0)&or(szm<0) then
+      [num,den]=simp(num-m.*den,den)
+    elseif or(szf<0) then
+      [num,den]=simp(num-m.*den,den*ones(m))
+    elseif or(szm<0) then
+      [num,den]=simp(num-(m+0)*eye(den).*den,den)
+    end
   end
-end
-f=rlist(num,den,f('dt'))
+  f=rlist(num,den,f.dt)
 endfunction
index f7e101b..b6ffd33 100644 (file)
 function f=%r_s_r(s1,s2)
 //f=s1-s2 s1,s2 : rational matrices
 //!
+  if ndims(s1)<2&ndims(s2)<2 then [s1,s2]=sysconv(s1,s2),end
+  [num1,den1]=s1(['num','den']),
+  [num2,den2]=s2(['num','den']),
+  sz1=size(num1)
+  sz2=size(num2)
+  if and(sz1>=0)&and(sz2>=0) then
+    num1=num1(:);den1=den1(:);
+    num2=num2(:);den2=den2(:);
 
-[s1,s2]=sysconv(s1,s2),
-[num1,den1]=s1(['num','den']),
-[num2,den2]=s2(['num','den']),
-[m1,n1]=size(num1)
-[m2,n2]=size(num2)
+    if prod(sz1)==1&prod(sz2)>1 then
+      den1=den1(ones(den2))
+      num1=num1(ones(num2))
+      sz1=sz2
+    elseif prod(sz2)==1&prod(sz1)>1 then
+      den2=den2(ones(den1))
+      num2=num2(ones(num1))
+      sz2=sz1
+    end
+    if and(sz1<>sz2) then error(8),end
+    for l=1:prod(sz1)
+      [den,fact]=lcm([den1(l);den2(l)])
+      num1(l)=[num1(l),-num2(l)]*fact
+      den1(l)=den
+    end,
+    [num1,den1]=simp(num1,den1),
+    f=rlist(matrix(num1,sz1),matrix(den1,sz1),s1.dt)
+  else
 
-if m1==-1 then
-  num1=num1+0
-  den1=den1+0
-  n1=1
-end
-if m2==-1 then
-  num2=num2+0
-  den2=den2+0
-  n2=1
-end
-
-if m1==-1&m2==-1 then
-  // both are eye*x
-  [den1,fact]=lcm([den1;den2])
-  [num1,den1]=simp([num1,-num2]*fact,den1)
-  f=rlist(num1*eye(),den1*eye(),s1('dt')),
-  return
-end
-m1=abs(m1);m2=abs(m2)
-if m1*n1==1&m2*n2>1 then
-  //scalar +matrix:replace scalar by scalar*ones(matrix)
-  num1=num1*ones(num2)
-  den1=den1*ones(num2)
-  m1=m2
-  n1=n2
-elseif m2*n2==1&m1*n1>1 then
-  // matrix+scalar:replace scalar by scalar*ones(matrix)
-  num2=num2*ones(num1)
-  den2=den2*ones(den1)
-  m2=m1
-  n2=n1
-end
-
-if m1<>m2|n1<>n2 then error(9),end
-
-for l=1:m1
-  for k=1:n1
-    [den,fact]=lcm([den1(l,k);den2(l,k)])
-    num1(l,k)=[num1(l,k),-num2(l,k)]*fact
-    den1(l,k)=den
-  end,
-end,
-[num1,den1]=simp(num1,den1),
-f=rlist(num1,den1,s1('dt'))
+    if size(sz1,'*')>2|size(sz2,'*')>2 then error(8),end
+    
+    if or(sz1<0)&or(sz2<0) then
+      // both are eye*x
+      [den1,fact]=lcm([den1;den2])
+      [num1,den1]=simp([num1,-num2]*fact,den1)
+      f=rlist(num1*eye(),den1*eye(),s1('dt')),
+    elseif  or(sz1<0) then
+      den1=den1+0;num1=num1+0
+      for l=1:min(sz2)
+       [den,fact]=lcm([den1;den2(l,l)])
+       num2(l,l)=[num1,-num2(l,l)]*fact
+       den2(l,l)=den
+      end
+      [num2,den2]=simp(num2,den2),
+      f=rlist(num2,den2,s1.dt)
+    elseif or(sz2<0) then
+      den2=den2+0;num2=num2+0
+      for l=1:min(sz1)
+       [den,fact]=lcm([den1(l,l);den2])
+       num1(l,l)=[num1(l,l),-num2]*fact
+       den1(l,l)=den
+      end
+      [num1,den1]=simp(num1,den1),
+      f=rlist(num1,den1,s1.dt)
+    end
+  end
 endfunction
index 55454a0..0f3ff45 100644 (file)
 function f=%r_s_s(f,m)
 //f = f-m, 
 //f: transfer matrix, m : scalar or scalar matrix
+//author Serge Steer INRIA
 //!
+  [num,den]=f(['num','den'])
+  szf=size(den)
+  szm=size(m)
 
-[num,den]=f(['num','den'])
-[nf,mf]=size(num)
-[nm,mm]=size(m)
+  if and(szf>=0)&and(szm>=0) then
+    if prod(szf)==1&prod(szm)>1 then
+      den=den(ones(m))
+      szf=szm
+    end
 
-if nf>=0&nm>=0 then
-  if size(num,'*')==1&size(m,'*')>1 then
-    den=den*ones(m)
-  end
-  [num,den]=simp(num-m.*den,den)
-else
-  //at leat one matrix is eye*x
-  if nf<0&nm<0 then
+    if size(szf,'*')>2 then
+      num=num(:);den=den(:);m=m(:)
+    end
     [num,den]=simp(num-m.*den,den)
-  elseif nf<0 then
-    [num,den]=simp(num-m.*den,den*ones(m))
-  elseif nm<0 then
-    [num,den]=simp(num-m*eye(den).*den,den)
+    num=matrix(num,szf)
+    den=matrix(den,szf)
+  else
+    //at leat one matrix is eye*x
+    if size(szf,'*')>2|size(szm,'*')>2 then
+      error(9)
+    end
+    if or(szf<0)&or(szm<0) then
+      [num,den]=simp(num-m.*den,den)
+    elseif or(szf<0) then
+      [num,den]=simp(num-m.*den,den*ones(m))
+    elseif or(szm<0) then
+      [num,den]=simp(num-(m+0)*eye(den).*den,den)
+    end
   end
-end
-f=rlist(num,den,f('dt'))
+  f=rlist(num,den,f.dt)
 endfunction
index 1d3b649..46775c1 100644 (file)
@@ -8,9 +8,17 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
 function f1=%r_x_p(f1,f2)
-// %r_x_p(r,p)=r.*p    
+// %r_x_p(r,p)=r.*p   
+//author Serge Steer, INRIA
 //!
-
-
-f1('num')=f1('num').*f2
+  f1.num=f1.num.*f2
+  sz=size(f1.num)
+  if size(sz,'*')<=2 then
+    
+    f1=simp(f1)
+  else
+    [num,den]=simp(f1.num.entries,f1.den.entries)
+    f1.num=matrix(num,sz)
+    f1.den=matrix(den,sz)
+  end
 endfunction
index 2960308..1b4f878 100644 (file)
@@ -1,9 +1,27 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+// 
+// 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-en.txt
 
 function f=%r_x_r(s1,s2)
 // %r_x_r(r1,r2)=r1.*r2    r1,r2 rationals
 //!
-// Copyright INRIA
-[s1,s2]=sysconv(s1,s2)
-[num,den]=simp(s1('num').*s2('num'),s1('den').*s2('den'))
-f=rlist(num,den,s1('dt'))
+//author Serge Steer INRIA
+  if ndims(s1)<=2& ndims(s2)<=2 then
+    [s1,s2]=sysconv(s1,s2)
+    [num,den]=simp(s1.num.*s2.num,s1.den.*s2.den)
+    f=rlist(num,den,s1.dt)
+  else
+    if size(s1,'*')==1 then 
+      sz=size(s2)
+    else
+      sz=size(s1)
+    end
+    [num,den]=simp(s1.num(:).*s2.num(:),s1.den(:).*s2.den(:))
+    f=rlist(matrix(num,sz),matrix(den,sz),s1.dt)
+  end
 endfunction
index 1037728..6a9f51b 100644 (file)
@@ -8,11 +8,12 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 function f1=%r_x_s(f1,n2)
 // %r_x_s(r,M)=r.*M      rational .* constant
+//author Serge Steer INRIA
 //!
 
 if size(n2,'*')==0
   f1=[]
 else
-  f1('num')=f1('num').*n2
+  f1.num=f1.num.*n2
 end
 endfunction
index c70b1f6..dc7e9bf 100644 (file)
@@ -8,25 +8,37 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 function f=%s_a_r(m,f)
 //f=  m+f
+// author Serge Steer, INRIA
 //!
 [num,den]=f(['num','den'])
-[nf,mf]=size(f)
-[nm,mm]=size(m)
+szf=size(den)
+szm=size(m)
 
-if nf>=0&nm>=0 then
-  if size(num,'*')==1&size(m,'*')>1 then
-    den=den*ones(m)
+if and(szf>=0)&and(szm>=0) then
+  if prod(szf)==1&prod(szm)>1 then
+    den=den(ones(m))
+    szf=szm
+  end
+
+  if size(szf,'*')>2 then
+    num=num(:);den=den(:);m=m(:)
   end
   [num,den]=simp(num+m.*den,den)
+  num=matrix(num,szf)
+  den=matrix(den,szf)
 else
   //at leat one matrix is eye*x
-  if nf<0&nm<0 then
+  if size(szf,'*')>2|size(szm,'*')>2 then
+  error(8)
+  end
+  if or(szf<0)&or(szm<0) then
     [num,den]=simp(num+m.*den,den)
-  elseif nf<0 then
+  elseif or(szf<0) then
     [num,den]=simp(num+m.*den,den*ones(m))
-  elseif nm<0 then
+  elseif or(szm<0) then
     [num,den]=simp(num+(m+0)*eye(den).*den,den)
   end
 end
-f=rlist(num,den,f('dt'))
+f=rlist(num,den,f.dt)
 endfunction
+
index 0da7721..f2fb50b 100644 (file)
@@ -14,7 +14,6 @@ function r=%s_b_s(varargin)
   select type(varargin(3))
   case 8 then
     it=inttype(varargin(3))
-    pause
     r=iconvert(varargin(1),it):iconvert(varargin(2),it):varargin(3)
   else
     error('Not yet implemented')
index 93a79d3..8bf6370 100644 (file)
@@ -14,6 +14,8 @@ function M=%s_i_hm(varargin)
   select type(M.entries) 
   case 1 then //destination is an hypermat of double
     M=generic_i_hm(0,varargin(:))
+  case 2 then //destination is an hypermat of polynomials
+    M=generic_i_hm(0,varargin(:))
   case 4 then //destination is an hypermat of boolean
     N=varargin($-1)
     if N<>[] then N=N<>0,end
index 408d589..2859c40 100644 (file)
@@ -9,9 +9,8 @@
 
 function M=%s_i_p(varargin)
 //insertion of an polynomial matrix in an matrix of numbers for more than 2 indices
-
   M=varargin($)
   M=mlist(['hm','dims','entries'],int32(size(M)),M(:))
   varargin($)=M;
-  M=generic_i_hm('',varargin(:))
+  M=generic_i_hm(0,varargin(:))
 endfunction
index 2d1970a..7a079a0 100644 (file)
@@ -7,20 +7,23 @@
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-function s1=%s_i_r(i,j,s1,s2)
-//s2(i,j)=s1 s1 matrix of scalar
-//!
-
-[lhs,rhs]=argn(0)
-if rhs==3 then
-  [s1,s2]=(j,s1)
-  [n1,n2]=size(s2('den'))
-  n=s2('num');n(i)=s1
-  d=ones(n);d(1:n1,1:n2)=s2('den');d(i)=ones(s1);
-else
-  [n1,n2]=size(s2('den'))
-  n=s2('num');n(i,j)=s1
-  d=ones(n);d(1:n1,1:n2)=s2('den');d(i,j)=ones(s1);
-end
-s1=rlist(n,d,s2('dt'))
+function s2=%s_i_r(varargin)
+//author Serge Steer INRIA    
+  s1=varargin($-1)
+  s2=varargin($)
+  //s2(i,j)=s1 s1 matrix of scalar
+  if s1==[] then
+    num=s2.num;den=s2.den;
+    num(varargin(1:$-2))=[];
+    den(varargin(1:$-2))=[];
+    s2=rlist(num,den,s2.dt)
+  else
+    num=s2.num;
+    ind=list(); for i=size(num),ind($+1)=1:i;end
+    num(varargin(1:$-2))=s1
+    den=ones(num)
+    den(ind(:))=s2.den;
+    den(varargin(1:$-2))=1
+    s2=rlist(num,den,s2.dt)
+  end
 endfunction
index 69506a3..6ed3102 100644 (file)
 function b=%s_l_r(a,b)
 // a\b a scalar matrix, b rational matrix
 //!
-if  size(a,'*')==0  then b=[],return,end
-if size(a,1)==-1 then a=a+0,end
+  if  size(a,'*')==0  then b=[],return,end
+  if size(a,1)==-1 then a=a+0,end
 
-[ma,na]=size(a);
-if ma==1&na==1 then 
-  b('num')=a\b('num'),
-elseif size(b('num'),1)==1 then
-  b=rlist(a\b('num'),ones(na,ma)*b('den'),b('dt'))
-else
-  [num,den]=b(['num','den']);
+  [ma,na]=size(a);
+  if ma==1&na==1 then 
+    b.num=a\b.num,
+  elseif size(b.num,1)==1 then
+    b=rlist(a\b.num,ones(na,ma)*b.den,b.dt)
+  else
+    [num,den]=b(['num','den']);
 
-  dd=[];nn=[]
-  for j=1:size(num,2)
-    [y,fact]=lcm(den(:,j)),
-    nn=[nn,a\(num(:,j).*fact)];
-    dd=[dd y]
+    dd=[];nn=[]
+    for j=1:size(num,2)
+      [y,fact]=lcm(den(:,j)),
+      nn=[nn,a\(num(:,j).*fact)];
+      dd=[dd y]
+    end
+    [num,den]=simp(nn,ones(na,1)*dd)
+    b=rlist(num,den,b.dt)
   end
-  [num,den]=simp(nn,ones(na,1)*dd)
-  b=rlist(num,den,b('dt'))
-end
 endfunction
index 6c5ef85..1ad551e 100644 (file)
 function f2=%s_m_r(n1,f2)
 // %s_m_r(n1,f2)  
 //operation  f2=n1*f2
+//author Serge Steer INRIA
 //!
-[n2,d2]=f2(['num','den']);
-[l1,m1]=size(n1);[l2,m2]=size(n2),
-if l1*m1==0|l2*m2==0 then
-  f2=[]
-  return
-end
-indef=%f
-if l1==-1 then 
-  n1=n1+0;l1=1;m1=1;
-  if l2*m2==1 then indef=%t,else error(14),end
-end
-if l2==-1 then 
-  n2=n2+0;d2=d2+0;l2=1;m2=1;
-  if l1*m1==1 then indef=%t,else error(14),end
-end  
+  [n2,d2]=f2(['num','den']);
+  sz1=size(n1);sz2=size(n2);
+  if prod(sz1)==0|prod(sz2)==0 then  f2=[],return,end
 
-//
-if mini([l1*m1,l2*m2])==1 then,
-  num=n1*n2,
-  den=ones(l1,m1)*d2,
-else,
- if m1<>l2 then error(10),end,
-  for j=1:m2,
-    [y,fact]=lcm(d2(:,j)),
-    n2(:,j)=n2(:,j).*fact,
-    den(1:l1,j)=ones(l1,1)*y,
-    for i=1:l1,
-      num(i,j)=n1(i,:)*n2(:,j),
+
+  indef=%f
+  if or(sz1==-1) then 
+    n1=n1+0;sz1=[1 1];
+    if  prod(sz2)==1 then indef=%t,else error(14),end
+  end
+  if  or(sz2==-1) then 
+    n2=n2+0;d2=d2+0;sz2=[1 1];
+    if prod(sz1)==1 then indef=%t,else error(14),end
+  end  
+
+  //
+  if prod(sz1)==1 then
+    num=n1*n2,
+    den=d2
+  elseif prod(sz2)==1 then
+    num=n1*n2,
+    den=d2(ones(n1))
+  else,
+    if size(sz1,'*')>2|size(sz2,'*')>2 then error(10),end
+    if sz1(2)<>sz2(1) then error(10),end,
+    l1=sz1(1);m1=sz1(2);m2=sz2(2);
+    for j=1:m2,
+      [y,fact]=lcm(d2(:,j)),
+      n2(:,j)=n2(:,j).*fact,
+      den(1:l1,j)=ones(l1,1)*y,
+      for i=1:l1,
+       num(i,j)=n1(i,:)*n2(:,j),
+      end,
     end,
+    [num,den]=simp(num,den),
   end,
-end,
-[num,den]=simp(num,den),
-if indef then
-  num=num*eye()
-  den=den*eye()
-end
-f2=rlist(num,den,f2('dt'))
+
+  if indef then
+    num=num*eye()
+    den=den*eye()
+  end
+  f2=rlist(num,den,f2.dt)
 endfunction
index 0a5cab6..56d736b 100644 (file)
@@ -6,29 +6,39 @@
 // you should have received as part of this distribution.  The terms
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-
 function f=%s_s_r(m,f)
 //f=  m-f
+//author Serge Steer INRIA
 //!
+  [num,den]=f(['num','den'])
+  szf=size(den)
+  szm=size(m)
 
-[num,den]=f(['num','den'])
-[nf,mf]=size(f)
-[nm,mm]=size(m)
+  if and(szf>=0)&and(szm>=0) then
+    if prod(szf)==1&prod(szm)>1 then
+      den=den(ones(m))
+      szf=szm
+    end
 
-if nf>=0&nm>=0 then
-  if size(num,'*')==1&size(m,'*')>1 then
-    den=den*ones(m)
-  end
-  [num,den]=simp(-num+m.*den,den)
-else
-  //at leat one matrix is eye*x
-  if nf<0&nm<0 then
+    if size(szf,'*')>2 then
+      num=num(:);den=den(:);m=m(:)
+    end
     [num,den]=simp(-num+m.*den,den)
-  elseif nf<0 then
-    [num,den]=simp(-num+m.*den,den*ones(m))
-  elseif nm<0 then
-    [num,den]=simp(-num+m*eye(den).*den,den)
+    num=matrix(num,szf)
+    den=matrix(den,szf)
+  else
+    //at leat one matrix is eye*x
+    if size(szf,'*')>2|size(szm,'*')>2 then
+      error(9)
+    end
+    if or(szf<0)&or(szm<0) then
+      [num,den]=simp(-num+m.*den,den)
+    elseif or(szf<0) then
+      [num,den]=simp(-num+m.*den,den*ones(m))
+    elseif or(szm<0) then
+      [num,den]=simp(-num+(m+0)*eye(den).*den,den)
+    end
   end
-end
-f=rlist(num,den,f('dt'))
+  f=rlist(num,den,f.dt)
 endfunction
+
index 659d9d3..928b9d3 100644 (file)
@@ -36,7 +36,7 @@ function M=generic_i_hm(default_value,varargin)
     // corresponding dimension
     // if yes insertion is the extraction of the complement.
     ok=[];
-    for k=1:rhs-3
+    for k=1:rhs-2
       dk=varargin(k)
       if or(type(dk)==[2 129]) then 
        dk=horner(dk,dims(k)),
@@ -57,13 +57,20 @@ function M=generic_i_hm(default_value,varargin)
       end
       
     end
+
     if size(ok,'*')==0 then
       M=[]
     else //use extraction
       [Ndims,I]=convertindex(dims,varargin(1:$-2));
       dims(ok)=size(I1,'*')
+      while dims($)==1&size(dims,'*')>2, dims($)=[],end
       M.entries=M.entries(I);
-      M.dims=int32(dims')
+      if size(dims,'*')==2 then
+       M=matrix(M.entries,dims)
+      else
+       M.dims=int32(dims')
+      end
+      
       //M=M(varargin(1:rhs-2))
     end
     
diff --git a/scilab/modules/overloading/tests/unit_tests/rational.tst b/scilab/modules/overloading/tests/unit_tests/rational.tst
new file mode 100644 (file)
index 0000000..d3a256e
--- /dev/null
@@ -0,0 +1,403 @@
+s=poly(0,'s');
+h=1/(2*s);
+if or(size(h)<>[1 1]) then pause,end
+if h.num<>1|h.den<>2*s then pause,end
+h=1./(2*s);
+if h.num<>1|h.den<>2*s then pause,end
+
+//basic operations with 2D matrices
+H=[h h];
+if or(H.num<>[1 1])|or(H.den<>[2*s 2*s]) then pause,end
+H=[h;h];
+if or(H.num<>[1;1])|or(H.den<>[2*s;2*s]) then pause,end
+
+H=[h 3];
+if or(H.num<>[1 3])|or(H.den<>[2*s 1]) then pause,end
+H=[h;5];
+if or(H.num<>[1;5])|or(H.den<>[2*s;1]) then pause,end
+
+H=[3 h];
+if or(H.num<>[3 1])|or(H.den<>[1 2*s]) then pause,end
+H=[5;h];
+if or(H.num<>[5;1])|or(H.den<>[1;2*s]) then pause,end
+
+H=[3 h;s 2];
+if H(1,1)<>3 then pause,end
+if H(1,2)<>h then pause,end
+if or(H(1,[2 1])<>[h 3]) then pause,end
+if or(H(1,[2 2])<>[h h]) then pause,end
+
+if or(H(1,:)<>[3 h]) then pause,end
+if or(H(:,1)<>[3;s]) then pause,end
+if or(H([2 1],:)<>[s 2;3 h]) then pause,end
+if or(H([1 1],:)<>[3 h;3 h]) then pause,end
+
+if or(matrix(H,-1,1)<>[3;s;h;2]) then pause,end
+
+H=h;H(1,3)=1/s;
+if or(H.num<>[1 0 1])|or(H.den<>[2*s 1 s]) then pause,end
+
+H=h;H(3,1)=1/s;
+if or(H.num<>[1 0 1]')|or(H.den<>[2*s 1 s]') then pause,end
+
+H=h;H(1,3)=1.5;
+if or(H.num<>[1 0 1.5])|or(H.den<>[2*s 1 1]) then pause,end
+
+H=h;H(3,1)=1.5;
+if or(H.num<>[1 0 1.5]')|or(H.den<>[2*s 1 1]') then pause,end
+
+H=1.5;H(1,3)=1/s;
+if or(H.num<>[1.5 0 1])|or(H.den<>[1 1 s]) then pause,end
+H=1.5;H(3,1)=1/s;
+if or(H.num<>[1.5 0 1]')|or(H.den<>[1 1 s]') then pause,end
+
+H=[h s;1 h];H(:,1)=[];
+if or(H<>[s;h]) then pause,end
+
+H=[h s;1 h];H(2,:)=[];
+if or(H<>[h s]) then pause,end
+
+
+H=h+h;c=coeff(H.den,1);
+if H.num/c<>1|H.den/c<>s then pause,end
+
+H=h+1;
+if H.num<>1+2*s|H.den<>2*s then pause,end
+
+H=1+h;
+if H.num<>1+2*s|H.den<>2*s then pause,end
+
+H=h+[];
+if H<>h then pause,end
+H=[]+h;
+if H<>h then pause,end
+
+H=h+s;
+if H.num<>1+2*s^2|H.den<>2*s then pause,end
+
+H=s+h;
+if H.num<>1+2*s^2|H.den<>2*s then pause,end
+
+
+H=h-h;
+if H.num<>0|H.den<>1 then pause,end
+
+H=h-1;
+if H.num<>1-2*s|H.den<>2*s then pause,end
+
+H=1-h;
+if H.num<>-1+2*s|H.den<>2*s then pause,end
+
+H=[h h+1]-1;
+if H(1,1)<>h-1 then pause,end
+if H(1,2)<>h then pause,end
+
+H=[h h+1]-2*h;
+if or(H.num<>[-2 -2+4*s])|or(H.den<>[4*s 4*s]) then pause,end
+
+H=-2*h+[h h+1];
+if or(H.num<>[-2 -2+4*s])|or(H.den<>[4*s 4*s]) then pause,end
+
+// *
+
+H=h*h;
+if or(H.num<>1)|or(H.den<>4*s^2) then pause,end
+
+H=h*2;
+if or(H.num<>2)|or(H.den<>2*s) then pause,end
+
+H=2*h;
+if or(H.num<>2)|or(H.den<>2*s) then pause,end
+
+H=h*s;
+if or(H.num<>1)|or(H.den<>2) then pause,end
+
+H=s*h;
+if or(H.num<>1)|or(H.den<>2) then pause,end
+
+H=[h h+1]*h;
+if or(H<>[h*h, (h+1)*h]) then pause,end
+
+H=h*[h h+1];
+if or(H<>[h*h, (h+1)*h]) then pause,end
+
+H=[h h+1]*2;
+if or(H<>[h*2, (h+1)*2]) then pause,end
+
+H=2*[h h+1];
+if or(H<>[h*2, (h+1)*2]) then pause,end
+
+
+H=[h h+1]*s;
+if or(H<>[h*s, (h+1)*s]) then pause,end
+
+H=s*[h h+1];
+if or(H<>[h*s, (h+1)*s]) then pause,end
+
+H=[h 1;s 3]*[1;h];
+if or(H<>[h+h;s+3*h]) then pause,end
+
+H=[h 1]*[h 1;s 3];
+if or(H<>[h*h+s,h+3]) then pause,end
+
+H=[h 1;s 3]*[1;2];
+if or(H<>[h+2;s+6]) then pause,end
+
+H=[2 1]*[h 1;s 3];
+if or(H<>[2*h+s,2+3]) then pause,end
+
+// .*
+
+H=h.*h;
+if or(H.num<>1)|or(H.den<>4*s^2) then pause,end
+
+H=h.*2;
+if or(H.num<>2)|or(H.den<>2*s) then pause,end
+
+H=2 .*h;
+if or(H.num<>2)|or(H.den<>2*s) then pause,end
+
+H=h.*s;
+if or(H.num<>1)|or(H.den<>2) then pause,end
+
+H=s.*h;
+if or(H.num<>1)|or(H.den<>2) then pause,end
+
+H=[h h+1].*h;
+if or(H<>[h*h, (h+1)*h]) then pause,end
+
+H=h.*[h h+1];
+if or(H<>[h*h, (h+1)*h]) then pause,end
+
+H=[h h+1].*2;
+if or(H<>[h*2, (h+1)*2]) then pause,end
+
+H=2 .*[h h+1];
+if or(H<>[h*2, (h+1)*2]) then pause,end
+
+
+H=[h h+1].*s;
+if or(H<>[h*s, (h+1)*s]) then pause,end
+
+H=s.*[h h+1];
+if or(H<>[h*s, (h+1)*s]) then pause,end
+
+H=[3 h;s 2].*[3 h;s 2];
+if or(H<>[9 h*h;s*s 4]) then pause,end
+
+
+// /
+
+H=h/2;
+if or(H.num<>0.5)|or(H.den<>2*s) then pause,end
+
+H=h/s;
+if or(H.num<>1)|or(H.den<>2*s^2) then pause,end
+
+
+H=h/(h+1);
+if or(H.num<>2)|or(H.den<>2+4*s) then pause,end
+
+H=[h h-1]/2;
+if or(H<>[h/2 (h-1)/2]) then pause,end
+
+H=[h h-1]/s;
+if or(H<>[h/s (h-1)/s]) then pause,end
+
+H=1/h;
+if or(H.num<>2*s)|or(H.den<>1) then pause,end
+
+H=[1 2]/h;
+if or(H<>[1/h 2/h]) then pause,end
+
+H=[s+1 s-2]/h;
+if or(H<>[(s+1)/h (s-2)/h]) then pause,end
+
+H=[h+1 (h+1)*(h-1)]/h;
+if or(H<>[(h+1)/h ((h+1)*(h-1))/h]) then pause,end
+
+H=(eye(2,2)/[3 h;s 2])*[3 h;s 2];
+if or(coeff(H.num)./coeff(H.den)<>eye(2,2)) then pause,end
+
+
+// ./
+
+H=h./2;
+if or(H.num<>0.5)|or(H.den<>2*s) then pause,end
+
+H=h./s;
+if or(H.num<>1)|or(H.den<>2*s^2) then pause,end
+
+
+H=h./(h+1);
+if or(H.num<>2)|or(H.den<>2+4*s) then pause,end
+
+H=[h h-1]./2;
+if or(H<>[h/2 (h-1)/2]) then pause,end
+
+H=[h h-1]./s;
+if or(H<>[h/s (h-1)/s]) then pause,end
+
+H=1 ./h;
+if or(H.num<>2*s)|or(H.den<>1) then pause,end
+
+H=[1 2]./h;
+if or(H<>[1/h 2/h]) then pause,end
+
+H=[s+1 s-2]./h;
+if or(H<>[(s+1)/h (s-2)/h]) then pause,end
+
+H=[h+1 (h+1)*(h-1)]./h;
+if or(H<>[(h+1)/h ((h+1)*(h-1))/h]) then pause,end
+
+H=[3 h;s 2]./[3 h;s 2];
+if or(coeff(H.num)./coeff(H.den)<>ones(2,2)) then pause,end
+
+// .\
+
+H=2 .\h;
+if or(H.num<>0.5)|or(H.den<>2*s) then pause,end
+
+H=s.\h;
+if or(H.num<>1)|or(H.den<>2*s^2) then pause,end
+
+
+H=(h+1).\h;
+if or(H.num<>2)|or(H.den<>2+4*s) then pause,end
+
+H=2 .\[h h-1];
+if or(H<>[h/2 (h-1)/2]) then pause,end
+
+H=s.\[h h-1];
+if or(H<>[h/s (h-1)/s]) then pause,end
+
+H=1 ./h;
+if or(H.num<>2*s)|or(H.den<>1) then pause,end
+
+H=h.\[1 2];
+if or(H<>[1/h 2/h]) then pause,end
+
+H=h.\[s+1 s-2];
+if or(H<>[(s+1)/h (s-2)/h]) then pause,end
+
+H=h.\[h+1 (h+1)*(h-1)];
+if or(H<>[(h+1)/h ((h+1)*(h-1))/h]) then pause,end
+
+H=[3 h;s 2]./[3 h;s 2];
+if or(coeff(H.num)./coeff(H.den)<>ones(2,2)) then pause,end
+
+// hypermatrices of rationnals
+
+clear H;H(1,1,2)=h;
+if H(1,1,1)<>rlist(0,1,[]) |H(1,1,2)<>h then pause,end
+H(2,1,2)=h+1;
+if or(size(H)<>[2 1 2]) then pause,end
+
+if or(H(:,1,1)<>[0;0]) then pause,end
+if or(H([2 2],1,2)<>[h+1;h+1]) then pause,end
+
+clear H;H(1,1,2)=h;H(2,1,1)=1;
+if or(H(:,1,1)<>[0;1])|or(H(:,1,2)<>[h;0]) then pause,end
+
+clear H;H(1,1,2)=h;H(1,1,:)=3;
+if or(H(1,1,1)<>3)|or(H(1,1,2)<>3) then pause,end
+
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;
+if or(H(1:2,1,1)<>[%s;%s]) then pause,end
+
+clear H;H(2,2,2)=s;H(2,1,1)=h;
+if or(H(:,:,1)<>[0 0;h 0])|or(H(:,:,2)<>[0 0;0 s]) then pause,end
+
+clear H;H(2,2,2)=8;H(2,1,1)=h;
+if or(H(:,:,1)<>[0 0;h 0])|or(H(:,:,2)<>[0 0;0 8]) then pause,end
+
+clear H;H(2,2,2)=8;H(2,1,1)=h;
+H(:,:,1)=[];
+if or(H<>[0 0;0 8]) then pause,end
+
+clear H;H(2,2,2)=8;H(2,1,1)=h;
+H2=H(2,:,:);H(1,:,:)=[];
+if or(H<>H2) then pause,end
+
+clear H;H(2,2,2)=8;H(2,1,1)=h;
+H2=H(:,2,:);H(:,1,:)=[];
+if or(H<>H2) then pause,end
+
+
+clear H;H(2,2,2)=h;H=H+1;
+if or(H(:,:,1)<>ones(2,2))|or(H(:,:,2)<>[1 1;1 h+1]) then pause,end
+
+clear H;H(2,2,2)=h;H=1+H;
+if or(H(:,:,1)<>ones(2,2))|or(H(:,:,2)<>[1 1;1 h+1]) then pause,end
+
+clear H;H(2,2,2)=h;H=H+s;
+if or(H(:,:,1)<>s*ones(2,2))|or(H(:,:,2)<>[s s;s h+s]) then pause,end
+
+clear H;H(2,2,2)=h;H=s+H;
+if or(H(:,:,1)<>s*ones(2,2))|or(H(:,:,2)<>[s s;s h+s]) then pause,end
+
+clear H;H(2,2,2)=h;H=H-1;
+if or(H(:,:,1)<>-ones(2,2))|or(H(:,:,2)<>[-1 -1;-1 h-1]) then pause,end
+
+clear H;H(2,2,2)=h;H=1-H;
+if or(H(:,:,1)<>ones(2,2))|or(H(:,:,2)<>[1 1;1 1-h]) then pause,end
+
+clear H;H(2,2,2)=h;H=H-s;
+if or(H(:,:,1)<>-s*ones(2,2))|or(H(:,:,2)<>[-s -s;-s h-s]) then pause,end
+
+clear H;H(2,2,2)=h;H=s-H;
+if or(H(:,:,1)<>s*ones(2,2))|or(H(:,:,2)<>[s s;s -h+s]) then pause,end
+
+clear H;H(2,2,2)=s;H(2,1,1)=h;H=H+H;
+if or(H(:,:,1)<>[0 0;h+h 0])|or(H(:,:,2)<>[0 0;0 s+s]) then pause,end
+
+clear H;H(2,2,2)=s;H(2,1,1)=h;H=H-H;
+if or(H(:,:,1)<>[0 0;0 0])|or(H(:,:,2)<>[0 0;0 0]) then pause,end
+
+// *
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=H*h;
+if or(H(:,:,1)<>[s*h;s*h])|or(H(:,:,2)<>[h*h;0]) then pause,end
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=h*H;
+if or(H(:,:,1)<>[s*h;s*h])|or(H(:,:,2)<>[h*h;0]) then pause,end
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=H*2;
+if or(H(:,:,1)<>[s*2;s*2])|or(H(:,:,2)<>[h*2;0]) then pause,end
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=2*H;
+if or(H(:,:,1)<>[s*2;s*2])|or(H(:,:,2)<>[h*2;0]) then pause,end
+
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=H*s;
+if or(H(:,:,1)<>[s*s;s*s])|or(H(:,:,2)<>[h*s;0]) then pause,end
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=s*H;
+if or(H(:,:,1)<>[s*s;s*s])|or(H(:,:,2)<>[h*s;0]) then pause,end
+
+
+// .*
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=H.*h;
+if or(H(:,:,1)<>[s*h;s*h])|or(H(:,:,2)<>[h*h;0]) then pause,end
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=h.*H;
+if or(H(:,:,1)<>[s*h;s*h])|or(H(:,:,2)<>[h*h;0]) then pause,end
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=H.*2;
+if or(H(:,:,1)<>[s*2;s*2])|or(H(:,:,2)<>[h*2;0]) then pause,end
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=2 .*H;
+if or(H(:,:,1)<>[s*2;s*2])|or(H(:,:,2)<>[h*2;0]) then pause,end
+
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=H.*s;
+if or(H(:,:,1)<>[s*s;s*s])|or(H(:,:,2)<>[h*s;0]) then pause,end
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=s.*H;
+if or(H(:,:,1)<>[s*s;s*s])|or(H(:,:,2)<>[h*s;0]) then pause,end
+
+
+clear H;H(1,1,2)=h;H(1:2,1,1)=%s;H=H.*H;
+if or(H(:,:,1)<>[s*s;s*s])|or(H(:,:,2)<>[h*h;0]) then pause,end
+
+