Permalink
Browse files

Fixed triplet bug in sparse_to_csr

  • Loading branch information...
1 parent e8064bb commit 7f12199d065198a04974c017cab0424bfe7bba71 David Gleich committed May 16, 2009
Showing with 10 additions and 4 deletions.
  1. +6 −4 sparse_to_csr.m
  2. +4 −0 test/test_sparse_to_csr.m
View
@@ -21,15 +21,16 @@
% 2008-04-07: Initial version
% 2008-04-24: Added triple array input
% 2009-05-01: Added ncol output
+% 2009-05-15: Fixed triplet input
-error(nargchk(1, 4, nargin, 'struct'))
+error(nargchk(1, 5, nargin, 'struct'))
retc = nargout>1; reta = nargout>2;
if nargin>1
- n = varargin{3};
if nargin>4, ncol = varargin{4}; end
nzi = A; nzj = varargin{1};
if reta && length(varargin) > 2, nzv = varargin{2}; end
+ if nargin<4, n=max(nzi); else n=varargin{3}; end
nz = length(A);
if length(nzi) ~= length(nzj), error('gaimc:invalidInput',...
'length of nzi (%i) not equal to length of nzj (%i)', nz, ...
@@ -40,9 +41,10 @@
end
if ~isscalar(n), error('gaimc:invalidInput',...
['the 4th input to sparse_to_csr with triple input was not ' ...
- 'a scalar']); end
+ 'a scalar']);
+ end
if nargin < 5, ncol = max(nzj);
- elif ~isscalar(ncol), error('gaimc:invalidInput',...
+ elseif ~isscalar(ncol), error('gaimc:invalidInput',...
['the 5th input to sparse_to_csr with triple input was not ' ...
'a scalar']);
end
@@ -1,4 +1,8 @@
function test_sparse_to_csr
+%% Previous failure
+[ai,aj,av]=find(ones(5));
+sparse_to_csr(ai,aj,av);
+
%% 100 random trials
for t=1:100
A = sprand(100,80,0.01);

0 comments on commit 7f12199

Please sign in to comment.