~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to macros/percent/%sp_diag.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function d=%sp_diag(a,k)
 
2
// %sp_diag - implement diag function for sparse matrix, rational matrix ,..
 
3
// Copyright INRIA
 
4
[lhs,rhs]=argn(0)
 
5
if rhs==1 then k=0,end
 
6
 
 
7
  [ij,v,sz]=spget(a)
 
8
  m=sz(1);n=sz(2)
 
9
  if m>1&n>1 then
 
10
    l=find(ij(:,1)==(ij(:,2)-k))
 
11
    if k<=0 then
 
12
      mn=mini(m+k,n)
 
13
      i0=-k
 
14
    else
 
15
      mn=min(m,n-k)
 
16
      i0=0
 
17
    end
 
18
    kk=abs(k)
 
19
    if l==[] then d=sparse([],[],[mn,1]);return;end
 
20
    d=sparse([ij(l,1)-i0,ones(ij(l,1))],v(l),[mn,1])
 
21
  else
 
22
    if m>1 then ij=ij(:,1);else ij=ij(:,2);end
 
23
    nn = max(m,n)+abs(k)
 
24
    if ij==[] then 
 
25
      d=sparse([],[],[nn,nn])
 
26
    else
 
27
      if k>0 then
 
28
        d=sparse([ij,ij+k],v,[nn,nn])
 
29
      else
 
30
        d=sparse([ij-k,ij],v,[nn,nn])
 
31
      end
 
32
    end
 
33
  end
 
34
endfunction