Mercurial > octave-nkf
comparison liboctave/boolMatrix.cc @ 6979:2883ea1c5c18
[project @ 2007-10-08 20:23:48 by dbateman]
author | dbateman |
---|---|
date | Mon, 08 Oct 2007 20:26:01 +0000 |
parents | ace8d8d26933 |
children | 93c65f2a5668 |
comparison
equal
deleted
inserted
replaced
6978:b75630794a11 | 6979:2883ea1c5c18 |
---|---|
75 return b; | 75 return b; |
76 } | 76 } |
77 | 77 |
78 // other operations | 78 // other operations |
79 | 79 |
80 boolMatrix | |
81 boolMatrix::diag (void) const | |
82 { | |
83 return diag (0); | |
84 } | |
85 | |
86 boolMatrix | |
87 boolMatrix::diag (octave_idx_type k) const | |
88 { | |
89 octave_idx_type nnr = rows (); | |
90 octave_idx_type nnc = cols (); | |
91 if (k > 0) | |
92 nnc -= k; | |
93 else if (k < 0) | |
94 nnr += k; | |
95 | |
96 boolMatrix d; | |
97 | |
98 if (nnr > 0 && nnc > 0) | |
99 { | |
100 octave_idx_type ndiag = (nnr < nnc) ? nnr : nnc; | |
101 | |
102 d.resize (ndiag, 1); | |
103 | |
104 if (k > 0) | |
105 { | |
106 for (octave_idx_type i = 0; i < ndiag; i++) | |
107 d.xelem (i) = elem (i, i+k); | |
108 } | |
109 else if (k < 0) | |
110 { | |
111 for (octave_idx_type i = 0; i < ndiag; i++) | |
112 d.xelem (i) = elem (i-k, i); | |
113 } | |
114 else | |
115 { | |
116 for (octave_idx_type i = 0; i < ndiag; i++) | |
117 d.xelem (i) = elem (i, i); | |
118 } | |
119 } | |
120 else | |
121 (*current_liboctave_error_handler) | |
122 ("diag: requested diagonal out of range"); | |
123 | |
124 return d; | |
125 } | |
126 | |
80 // FIXME Do these really belong here? Maybe they should be | 127 // FIXME Do these really belong here? Maybe they should be |
81 // in a base class? | 128 // in a base class? |
82 | 129 |
83 boolMatrix | 130 boolMatrix |
84 boolMatrix::all (int dim) const | 131 boolMatrix::all (int dim) const |