# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1320207927 14400 # Node ID 8bb7bdbe9c6928f46ce26fed0a869d099e4915fb # Parent 40dab5d70115a69d78946efced40f52f3daa1da2 Clarify max/min in accumarray and uniformise its behaviour diff --git a/scripts/general/accumarray.m b/scripts/general/accumarray.m --- a/scripts/general/accumarray.m +++ b/scripts/general/accumarray.m @@ -40,8 +40,14 @@ ## function should not depend on the order of the subscripts. ## ## The elements of the returned array that have no subscripts associated -## with them are set to zero. Defining @var{fillval} to some other -## value allows these values to be defined. +## with them are set to zero. Defining @var{fillval} to some other value +## allows these values to be defined. This behaviour changes, however, +## for certain values of @var{func}. If @var{func} is @code{min} +## (respectively, @code{max}) then the result will be filled with the +## minimum (respectively, maximum) integer if @var{vals} is of integral +## type, logical false (respectively, logical true) if @var{vals} is of +## logical type, zero if @var{fillval} is zero and all values are +## nonpositive (respectively, nonnegative), and NaN otherwise. ## ## By default @code{accumarray} returns a full matrix. If ## @var{issparse} is logically true, then a sparse matrix is returned @@ -248,6 +254,9 @@ zero = intmax (class (vals)); elseif (islogical (vals)) zero = true; + elseif (fillval == 0 && all (vals(:) <= 0)) + ## This is a common case - fillval is zero, all numbers nonpositive. + zero = 0; else zero = NaN; # Neutral value. endif