An option we considered and discarded was to introduce a Dim immutable, i.e.,
min(A, Dim(2))
That would not have the performance disadvantage of a keyword argument.
--Tim
On Monday, May 05, 2014 11:24:28 AM Stefan Karpinski wrote:
> The thing I had proposed was
>
> min(A,1) => smallest value of A or 1, whichever is smaller
> min(A,1, dim=()) => same shape as A, clamped above at 1
> min(A,1, dim=1) => the minimum of each column or 1 as a row matrix
> min(A,1, dim=2) => the minimum of each row or 1 as a column matrix
>
>
> Efficient implementation is a bit tricky, but the usage I think is pretty
> clear.
>
> On Mon, May 5, 2014 at 11:03 AM, Toivo Henningsson
<[email protected]>wrote:
> > I think there's too much ambiguity here to get away with overloading both
> > in the same function like this.
> > Say that I have an array A and I want to clamp all elements so that they
> >
> > are no larger than 1:
> > A_clamped = min(A, 1)
> >
> > But it's equally reasonable to want to use
> >
> > A_col_minima = minimum(A, 1)
> >
> > to get the minimum over each row. There needs to be some way do
> > distinguish a 1 that is a dimension from a 1 that is the scalar value 1,
> > be
> > it different function names, a keyword argument, or something else. I
> > still
> > think it's too bad that keyword arguments can't be used when low overhead
> > is needed (or maybe they can, sometimes?)
> > A less drastic solution would be to rename maximum to something like
> > maxover that would at least indicate that you are maximizing over
> > something (dimensions).
> > (Or we could maximum to max_ as a pun on the fact that maximizing over a
> > dimension is typically typed as e.g. max_i A_i in latex :)
> >
> > On Monday, 5 May 2014 16:22:28 UTC+2, Tomas Lycken wrote:
> >> After thinking another few moments about it, I think the confusion might
> >> be lifted slightly with some clever use of dispatch. Consider if we'd do
> >> something like this:
> >>
> >> max(itr) # returns the largest element in the collection
> >> max(a,b,c...) = max([a,b,c...])
> >>
> >> max{N}(A,dims::NTuple{N}) # compute maximum element along dimensions
> >> max(A,dim::Integer) = max(A, (dim,))
> >> max(a::Number, b::Integer) = max([a,b]) # there's probably a more
> >> efficient way to do this, to avoid the array allocation
> >>
> >> Since the last one is more specific than the second to last, there is no
> >> longer a conflict between max(A,2) to calculate the maximum of each row
> >> of
> >> a matrix, and max(a,2) to get the largest value out of a and the integer
> >> 2.
> >> There might of course be use cases I've forgotten about, but to me this
> >> seems to cover most of the use cases and still avoid having to remember
> >> two
> >> different function names. (I tried to take a look at methods(max) to see
> >> if
> >> I could find a reason for this not already being the way things were, but
> >> I ran into trouble... <https://github.com/JuliaLang/julia/issues/6755>)
> >>
> >> // T
> >>
> >> On Monday, May 5, 2014 3:55:42 PM UTC+2, Stefan Karpinski wrote:
> >>> Honestly, I've always been dissatisfied with this solution and would
> >>> have preferred the keyword-argument solution that I proposed back when
> >>> we
> >>> were discussing this. Having lived with the maximum thing for a while
> >>> and
> >>> seen others encounter it, I'm no less dissatisfied. I still type max
> >>> when I
> >>> need maximum almost every time.
> >>>
> >>> > On May 5, 2014, at 9:36 AM, Billou Bielour <[email protected]>
> >>>
> >>> wrote:
> >>> > I'm not saying that the help is not clear, or that the behavior is
> >>>
> >>> surprising, but only that there no information in the words "max" and
> >>> "maximum" that allows you to guess or remember their behaviors. I mean
> >>> one
> >>> is just the abbreviation of the other.
> >>>
> >>> > For example if I tell you I have two functions, "ceil" and "ceiling",
> >>>
> >>> can you guess what is the difference between the two ?