comparison scripts/sparse/spdiags.m @ 14666:1e77f6078692

spdiags.m: correctly treat row vector arguments
author David Bateman <dbateman@free.fr>
date Mon, 21 May 2012 02:31:05 +0200
parents f3d52523cde1
children 1c89599167a6
comparison
equal deleted inserted replaced
14665:4f458e882516 14666:1e77f6078692
77 A = m - spdiags (B, c, nr, nc) + spdiags (v, c, nr, nc); 77 A = m - spdiags (B, c, nr, nc) + spdiags (v, c, nr, nc);
78 else 78 else
79 ## Create new matrix of size mxn using v,c 79 ## Create new matrix of size mxn using v,c
80 [j, i, v] = find (v); 80 [j, i, v] = find (v);
81 offset = max (min (c(:), n-m), 0); 81 offset = max (min (c(:), n-m), 0);
82 j = j + offset(i); 82 j = j(:) + offset(i(:));
83 i = j-c(:)(i); 83 i = j - c(:)(i(:));
84 idx = i > 0 & i <= m & j > 0 & j <= n; 84 idx = i > 0 & i <= m & j > 0 & j <= n;
85 A = sparse (i(idx), j(idx), v(idx), m, n); 85 A = sparse (i(idx), j(idx), v(idx), m, n);
86 endif 86 endif
87 87
88 endfunction 88 endfunction
89 89
90 90
91 %!assert (spdiags (zeros (1,0),1,1,1), sparse (0)) 91 %!assert (spdiags (zeros (1,0),1,1,1), sparse (0))
92 %!assert (spdiags (zeros (0,1),1,1,1), sparse (0)) 92 %!assert (spdiags (zeros (0,1),1,1,1), sparse (0))
93 93 %!assert (spdiags ([0.5 -1 0.5], 0:2, 1, 1), sparse(0.5))