I agree with Toivo's proposal.

Introducing vecnorm() would make code and behavior clearer, and at the same
time avoid the problems with the generic norm() function.
Also, since vecnorm() calls norm(), we only have to care about maintaining
the latter.

cheers.



------------------------------------------
Carlos


On Tue, Mar 4, 2014 at 1:05 PM, Toivo Henningsson <toivo....@gmail.com>wrote:

> I think that this is an unpleasant gotcha right now, when I started
> reading this post I still thought that the matrix norm of a row/column
> vector would reproduce the vector norm.
> Because of multiple dispatch, we go to exceptional lengths in Julia to
> make sure to only overload the same operation on different types, not to
> create functions that do different conceptual operations based on the type.
>
> So I think that the heart of the matter is to settle whether the vector
> norm and matrix norm are the same operation or not. (As long as we are
> talking about row vectors, I still think that they are, right?)
>
> Perhaps it would be enough to leave norm as it is and introduce
>
> vecnorm(x::AbstractVector, args...) = norm(x, args...)
>
> and possible a method that tries to discover a row/column vector disguised
> as a matrix. Or we could just have (something equivalent to)
>
> vecnorm(x::AbstractVector, args...) = norm(x[:], args...)
>
> which would allow you to treat any array as a vector for the purposes of
> norm computation.
>
> On Tuesday, 4 March 2014 09:48:05 UTC+1, Andreas Noack Jensen wrote:
>
>> In master Julia the result is 3. I must have changed that when I
>> reorganised the norm code. I think that 3 is the right answer anyway. In
>> Julia [1 2 3] is a 1x3 matrix, i.e. not a vector. If you want it to behave
>> as a vector, make it a vector. This causes some confusion when coming from
>> MATLAB, but it is only in the transition until you get used to `Vector`s. I
>> also think that having matrix and vector norm in the same function is the
>> natural solution in Julia where so much is about dispatch.
>>
>>
>> 2014-03-04 1:45 GMT+01:00 Miguel Bazdresch <eorl...@gmail.com>:
>>
>>>  In Julia 0.2.1, I get 6.0.
>>>
>>> -- mb
>>>
>>>
>>> On Mon, Mar 3, 2014 at 7:22 PM, Carlos Becker <carlos...@gmail.com>wrote:
>>>
>>>> My mistake there, I meant the L1 norm, re-typed:
>>>>
>>>> -----------------------------
>>>> X= [[1 2 3],[4 5 6]]
>>>>
>>>> # now, X[1,:] is 1x3 array, containing 1 2 3
>>>>
>>>> # but let's peek at its L1-norm:
>>>> norm( X[1,:], 1 )   #  --> we get 3, where I would expect 6 (1+2+3)
>>>> -----------------------------
>>>>
>>>> can you try that on v0.2? I am on 0.3 from upstream.
>>>>
>>>>
>>>> ------------------------------------------
>>>> Carlos
>>>>
>>>>
>>>> On Tue, Mar 4, 2014 at 1:19 AM, Patrick O'Leary 
>>>> <patrick...@gmail.com>wrote:
>>>>
>>>>> This is odd, as I get norm() working just fine with any of a row,
>>>>> column, or vector, and all getting exactly the same result of 3.741...
>>>>> (v0.2.0, on julia.forio.com, since it's quick for me to get to). Note
>>>>> that it will return the L2 norm by default, exactly as MATLAB does.
>>>>> Supplying a second argument with p in it (norm([1 2 3], 1)) will return 
>>>>> the
>>>>> p-norm, exactly like MATLAB.
>>>>>
>>>>>
>>>>> On Monday, March 3, 2014 6:12:53 PM UTC-6, Carlos Becker wrote:
>>>>>>
>>>>>> Hello all,
>>>>>>
>>>>>> today I fought for an hour with a very simple piece of code, of the
>>>>>> kind:
>>>>>>
>>>>>> -----------------------------
>>>>>> X= [[1 2 3],[4 5 6]]
>>>>>>
>>>>>> # now, X[1,:] is 1x3 array, containing 1 2 3
>>>>>>
>>>>>> # but let's peek at its L1-norm:
>>>>>> norm( X[1,:] )   #  --> we get 3, where I would expect 6 (1+2+3)
>>>>>> -----------------------------
>>>>>>
>>>>>> I believe this comes back to the 'how 1xN matrices should be handled'.
>>>>>> The point is that the current behaviour is totally non-intuitive for
>>>>>> someone coming from Matlab,
>>>>>> and having matrix and vector norms in the same function hides this
>>>>>> (in this case) unwanted behavior.
>>>>>>
>>>>>> I am not sure what is the right way to deal with this, but seems like
>>>>>> a hard wall that more than one
>>>>>> will hit when coming from matlab-like backgrounds.
>>>>>>
>>>>>> Cheers.
>>>>>>
>>>>>
>>>>
>>>
>>
>>
>> --
>> Med venlig hilsen
>>
>> Andreas Noack Jensen
>>
>

Reply via email to