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

« back to all changes in this revision

Viewing changes to macros/m2sci/sci_files/sci_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 [tree]=sci_diag(tree)
 
2
// Copyright INRIA
 
3
// M2SCI function
 
4
// Conversion function for Matlab diag()
 
5
// Input: tree = Matlab funcall tree
 
6
// Ouput: tree = Scilab equivalent for tree
 
7
// Emulation function: mtlb_diag()
 
8
// V.C.
 
9
 
 
10
// B = diag(A,k)
 
11
if rhs==2 then
 
12
  [A,k] = getrhs(tree)
 
13
  // In Scilab k must be a real or complex matrix
 
14
  k = convert2double(k)
 
15
  tree.rhs=Rhs(A,k)
 
16
 
 
17
  // Compute dims to for inference
 
18
  if typeof(k)=="cste" then
 
19
    if A.dims(1)==1 then // diag of a row vector
 
20
      n=A.dims(2)+k.value
 
21
      m=n
 
22
    elseif A.dims(2)==1 then // diag of a column vector
 
23
      n=A.dims(1)+k.value
 
24
      m=n
 
25
    else
 
26
      m=Unknown;
 
27
      n=Unknown;
 
28
    end
 
29
  else
 
30
    m=Unknown;
 
31
    n=Unknown;
 
32
  end
 
33
  tree.lhs(1).dims=list(m,n)
 
34
 
 
35
  if or(A.vtype==[String,Unknown]) then
 
36
    tree.name="mtlb_diag"
 
37
    tree.lhs(1).type=A.type
 
38
  else
 
39
    if A.vtype==Boolean then
 
40
      tree.rhs=Rhs(Funcall("bool2s",1,list(A),list()),k)
 
41
      tree.lhs(1).type=Type(Boolean,Real)
 
42
    else
 
43
      tree.lhs(1).type=A.type
 
44
    end
 
45
  end
 
46
// B = diag(A)
 
47
else
 
48
  A = getrhs(tree)
 
49
 
 
50
  // Compute dims to for inference
 
51
  if A.dims(1)==1 then // diag of a row vector
 
52
    n=A.dims(2)
 
53
    m=n
 
54
  elseif A.dims(2)==1 then // diag of a column vector
 
55
    n=A.dims(1)
 
56
    m=n
 
57
  elseif not_a_vector(A) then
 
58
    m=min(A.dims);
 
59
    if not_empty(A) then
 
60
      n=1
 
61
    else
 
62
      n=Unknown;
 
63
    end
 
64
  else
 
65
    m=Unknown;
 
66
    n=Unknown;
 
67
  end
 
68
  tree.lhs(1).dims=list(m,n)
 
69
 
 
70
  if or(A.vtype==[String,Unknown]) then
 
71
    tree.name="mtlb_diag"
 
72
    tree.lhs(1).type=A.type
 
73
  else
 
74
    if A.vtype==Boolean then
 
75
      tree.rhs=Rhs(Funcall("bool2s",1,list(A),list()))
 
76
      tree.lhs(1).type=Type(Boolean,Real)
 
77
    else
 
78
      tree.lhs(1).type=A.type
 
79
    end
 
80
  end
 
81
end
 
82
endfunction