Shouldn't max([])=-inf ?
Matlab seems to follow a rule that iterative reduction operators give appropriate non-empty values to empty inputs. Examples include,
sum([])
prod([])
all([])
any([])
Is it an oversight not to do something similar for min and max?
max([])
For non-empty A and B,
max([A,B])= max(max(A), max(B))
The extension to B=[] should therefore satisfy,
max(A)=max(max(A),max([]))
for any A, which will only be true if we define max([])=-inf.
6 Comments
Time DescendingI believe that would be inconsistent with this -
norm([])
det([])
Wouldn't the identity hold if max([]) returned realmin (of the precision of the input)?
What should max(empty) return if the empty input is of a datatype that doesn't support inf, like int32 for example?
int32(-inf) % == intmin("int32")
max(int32.empty) % should return -2147483648
Perhaps because max is often also used to calculate indices? Even though for the last decades you can use find with more arguments.
Just a minor note: I only understood what you meant by iterative reduction when you showed your example definition at the end. With that in mind, suddently the other outputs also make sense. I can't say I can see a pattern that would explain the results for sum, prod, all, and any, and also explains why max([]) would return an empty answer.
Sign in to participate