File: adj2sp.sci

package info (click to toggle)
scilab 5.3.3-10
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 330,656 kB
file content (97 lines) | stat: -rw-r--r-- 3,575 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) XXXX-2008 - INRIA
// Copyright (C) 2010 - DIGITEO - Michael Baudin
// 
// 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 A=adj2sp(varargin)
    // adjacency to sparse conversion.
    // See adj2sp.xml for help.
    //
    // Check number of arguments
    [lhs, rhs] = argn()
    if ( and(rhs <> [3 4]) ) then
        lstr = gettext("%s: Wrong number of input arguments: %d to %d expected.\n")
        error ( msprintf(lstr,"adj2sp",3,4))
    end
    if ( and(lhs <> [0 1]) ) then
        lstr = gettext("%s: Wrong number of output arguments: %d to %d expected.\n")
        error ( msprintf(lstr,"adj2sp",0,1))
    end
    //
    // Get arguments
    xadj = varargin(1)
    iadj = varargin(2)
    v = varargin(3)
    //
    // Get size of the matrix
    if ( rhs == 3 ) then
      m = max(iadj)
      n = size(xadj,"*")-1
      mn = [m,n]
    else
      mn = varargin(4)
    end
    //
    // Check type of arguments
    if ( typeof(xadj) <> "constant" ) then
        lstr = gettext("%s: Wrong type for input argument #%d.\n")
        error ( msprintf(lstr,"adj2sp",1))
    end
    if ( typeof(iadj) <> "constant" ) then
        lstr = gettext("%s: Wrong type for input argument #%d.\n")
        error ( msprintf(lstr,"adj2sp",2))
    end
    if ( typeof(mn) <> "constant" ) then
        lstr = gettext("%s: Wrong type for input argument #%d.\n")
        error ( msprintf(lstr,"adj2sp",3))
    end
    //
    // Check size of arguments
    if ( size(mn,"*") <> 2 ) then
        lstr = gettext("%s: Wrong size for input argument #%d: %s has size %d, but %d is expected.\n")
        error ( msprintf(lstr,"adj2sp",4,"mn",size(mn,"*"),2))
    end
    //
    // Check content of arguments
    if ( mn(1) < 0 ) then
        lstr = gettext("%s: Wrong value for input argument #%d: %s=%d, but a positive value is expected.\n")
        error ( msprintf(lstr,"adj2sp",4,"mn(1)",mn(1)))
    end
    if ( mn(2) < 0 ) then
        lstr = gettext("%s: Wrong value for input argument #%d: %s=%d, but a positive value is expected.\n")
        error ( msprintf(lstr,"adj2sp",4,"mn(2)",mn(2)))
    end
    if ( int(mn(1)) <> mn(1) ) then
        lstr = gettext("%s: Wrong value for input argument #%d: %s=%s, but a floating point integer is expected.\n")
        error ( msprintf(lstr,"adj2sp",4,"mn(1)",string(mn(1))))
    end
    if ( int(mn(2)) <> mn(2) ) then
        lstr = gettext("%s: Wrong value for input argument #%d: %s=%s, but a floating point integer is expected.\n")
        error ( msprintf(lstr,"adj2sp",4,"mn(2)",string(mn(2))))
    end
    if ( mn(1) <> max(iadj) ) then
        lstr = gettext("%s: Wrong value for input argument #%d: %s=%d, which does not match %s: %d.\n")
        error ( msprintf(lstr,"adj2sp",4,"mn(1)",mn(1),"max(iadj)",max(iadj)))
    end
    if ( mn(2) <> size(xadj,"*")-1 ) then
        lstr = gettext("%s: Wrong value for input argument #%d: %s=%d, which does not match size of %s: %d.\n")
        error ( msprintf(lstr,"adj2sp",4,"mn(2)",mn(2),"xadj",size(xadj,"*")))
    end
    //
    // Make xadj, iadj, mn column matrices
    xadj = xadj(:)
    iadj = iadj(:)
    mn = mn(:)
    //
    // Proceed...
    nza = size(iadj,"*")
    j = fadj2sp(xadj,mn(2),nza)
    A = sparse([j,iadj],v,[mn(2),mn(1)])'
endfunction