diff --git a/sparse_to_csr.m b/sparse_to_csr.m index 588380d..9538eba 100644 --- a/sparse_to_csr.m +++ b/sparse_to_csr.m @@ -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 diff --git a/test/test_sparse_to_csr.m b/test/test_sparse_to_csr.m index fa0b470..ff4f65c 100644 --- a/test/test_sparse_to_csr.m +++ b/test/test_sparse_to_csr.m @@ -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);