1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
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.
13 function d = %sp_diag(a,k)
14 // %sp_diag - implement diag function for sparse matrix, rational matrix ,..
17 if rhs==1 then k=0,end
23 l = find(ij(:,1)==(ij(:,2)-k))
35 if l==[] then d=sparse([],[],[mn,1]);return;end
36 d=sparse([ij(l,1)-i0,ones(ij(l,1))],v(l),[mn,1])
38 if m>1 then ij=ij(:,1);else ij=ij(:,2);end
41 d=sparse([],[],[nn,nn])
44 d=sparse([ij,ij+k],v,[nn,nn])
46 d=sparse([ij-k,ij],v,[nn,nn])