summaryrefslogtreecommitdiff
path: root/modules/overloading/macros/%b_diag.sci
blob: f15807a72275356842c25f968f063219d35a74c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 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.1-en.txt
function d=%b_diag(a,k)

    [lhs,rhs]=argn(0)
    if rhs==1 then k=0,end
    [m,n]=size(a)
    if m>1&n>1 then
        if k<=0 then
            mn=min(m+k,n)
            i0=-k+1
        else
            mn=min(m,n-k)
            i0=k*m+1
        end
        a=matrix(a,m*n,1)
        i=i0+((0:mn-1)*(m+1))
        d=a(i)
    else
        nn = max(m,n)+abs(k)
        mn=max(m,n)
        i=(1:mn)+((1:mn)+(k-1))*nn
        d(i)=a
        d=matrix(d,nn,nn)
    end
endfunction