Mercurial > hg > octave-lyh
comparison scripts/general/accumarray.m @ 13787:8bb7bdbe9c69
Clarify max/min in accumarray and uniformise its behaviour
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Wed, 02 Nov 2011 00:25:27 -0400 |
parents | 8aaaef4a69aa |
children | 9ab64f063c96 |
comparison
equal
deleted
inserted
replaced
13786:40dab5d70115 | 13787:8bb7bdbe9c69 |
---|---|
38 ## @var{func} function. This should be a function or function handle | 38 ## @var{func} function. This should be a function or function handle |
39 ## that accepts a column vector and returns a scalar. The result of the | 39 ## that accepts a column vector and returns a scalar. The result of the |
40 ## function should not depend on the order of the subscripts. | 40 ## function should not depend on the order of the subscripts. |
41 ## | 41 ## |
42 ## The elements of the returned array that have no subscripts associated | 42 ## The elements of the returned array that have no subscripts associated |
43 ## with them are set to zero. Defining @var{fillval} to some other | 43 ## with them are set to zero. Defining @var{fillval} to some other value |
44 ## value allows these values to be defined. | 44 ## allows these values to be defined. This behaviour changes, however, |
45 ## for certain values of @var{func}. If @var{func} is @code{min} | |
46 ## (respectively, @code{max}) then the result will be filled with the | |
47 ## minimum (respectively, maximum) integer if @var{vals} is of integral | |
48 ## type, logical false (respectively, logical true) if @var{vals} is of | |
49 ## logical type, zero if @var{fillval} is zero and all values are | |
50 ## nonpositive (respectively, nonnegative), and NaN otherwise. | |
45 ## | 51 ## |
46 ## By default @code{accumarray} returns a full matrix. If | 52 ## By default @code{accumarray} returns a full matrix. If |
47 ## @var{issparse} is logically true, then a sparse matrix is returned | 53 ## @var{issparse} is logically true, then a sparse matrix is returned |
48 ## instead. | 54 ## instead. |
49 ## | 55 ## |
246 | 252 |
247 if (isinteger (vals)) | 253 if (isinteger (vals)) |
248 zero = intmax (class (vals)); | 254 zero = intmax (class (vals)); |
249 elseif (islogical (vals)) | 255 elseif (islogical (vals)) |
250 zero = true; | 256 zero = true; |
257 elseif (fillval == 0 && all (vals(:) <= 0)) | |
258 ## This is a common case - fillval is zero, all numbers nonpositive. | |
259 zero = 0; | |
251 else | 260 else |
252 zero = NaN; # Neutral value. | 261 zero = NaN; # Neutral value. |
253 endif | 262 endif |
254 | 263 |
255 if (isempty (sz)) | 264 if (isempty (sz)) |