Mercurial > octave-nkf
comparison test/test_diag_perm.m @ 8965:42aff15e059b
Implement diag \ sparse and sparse / diag.
Not pretty, but somewhat efficient and preserves sparsity.
author | Jason Riedy <jason@acm.org> |
---|---|
date | Mon, 09 Mar 2009 17:49:14 -0400 |
parents | f4f4d65faaa0 |
children | 1bba53c0a38d |
comparison
equal
deleted
inserted
replaced
8964:f4f4d65faaa0 | 8965:42aff15e059b |
---|---|
155 %! A = rand (n); | 155 %! A = rand (n); |
156 %! A(n, n-2) = NaN; | 156 %! A(n, n-2) = NaN; |
157 %! A(4, 1) = Inf; | 157 %! A(4, 1) = Inf; |
158 %! assert (Dr * A * Dc, A .* kron (dr, dc), eps); | 158 %! assert (Dr * A * Dc, A .* kron (dr, dc), eps); |
159 | 159 |
160 ## sparse inverse row scaling with a zero factor | |
161 %!test | |
162 %! n = 8; | |
163 %! A = sprand (n, n, .5); | |
164 %! scalefact = rand (n, 1); | |
165 %! Dr = diag (scalefact); | |
166 %! scalefact(n-1) = Inf; | |
167 %! Dr(n-1, n-1) = 0; | |
168 %! assert (full (Dr \ A), full (A) ./ repmat (scalefact, 1, n)); | |
169 | |
170 ## narrow sparse inverse row scaling | |
171 %!test | |
172 %! n = 8; | |
173 %! A = sprand (n, n, .5); | |
174 %! scalefact = rand (n-2, 1); | |
175 %! Dr = diag (scalefact, n, n-2); | |
176 %! assert (full (Dr \ A), Dr \ full(A)) | |
177 | |
178 ## sparse inverse column scaling with a zero factor | |
179 %!test | |
180 %! n = 11; | |
181 %! A = sprand (n, n, .5); | |
182 %! scalefact = rand (1, n); | |
183 %! Dc = diag (scalefact); | |
184 %! scalefact(n-1) = Inf; | |
185 %! Dc(n-1, n-1) = 0; | |
186 %! assert (full (A / Dc), full(A) / Dc) | |
187 | |
188 ## short sparse inverse column scaling | |
189 %!test | |
190 %! n = 7; | |
191 %! A = sprand (n, n, .5); | |
192 %! scalefact = rand (1, n-2) + I () * rand(1, n-2); | |
193 %! Dc = diag (scalefact, n-2, n); | |
194 %! assert (full (A / Dc), full(A) / Dc) |