octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Opinions for linspace behavior


From: Carnë Draug
Subject: Re: Opinions for linspace behavior
Date: Wed, 26 Aug 2015 22:11:35 +0100

On 26 August 2015 at 21:39, rik <address@hidden> wrote:
> All,
>
> While fixing bug #45820 (https://savannah.gnu.org/bugs/?45820) I found that
> Octave implements a superset of Matlab's linspace behavior.  For linspace
> (A, B, N), Matlab only accepts scalars while Octave will also accept row or
> column vectors.  The current behavior is to transform everything into a
> column vector and then expand.  For example,
>
> linspace ([1 2], 3, 5)
> ans =
>
>    1.0000   1.5000   2.0000   2.5000   3.0000
>    2.0000   2.2500   2.5000   2.7500   3.0000
>
> This goes against my intuition.  I would expect that a row vector would be
> expanded "down" to increase the number of rows while a column vector would
> be expanded "right" to increase the number of columns.  I've created a
> patch that does this and the results are shown below.
>
> octave:2> linspace ([1 2], 3, 5)
> ans =
>
>    1.0000   2.0000
>    1.5000   2.2500
>    2.0000   2.5000
>    2.5000   2.7500
>    3.0000   3.0000
>
> octave:3> linspace ([1 2]', 3, 5)
> ans =
>
>    1.0000   1.5000   2.0000   2.5000   3.0000
>    2.0000   2.2500   2.5000   2.7500   3.0000
>
> What are people's opinions about this change?  Is anyone actually using
> this feature of Octave in their code?

I actually wanted to do this a couple of weeks ago.  At the time I assumed
it was done for Matlab compatibility so I just permuted it.  +1 for your
patch.

However, suppose some code which gets an arbitrary number of base values
in a row vector (so each new vector is a column vector).  When this program
gets a single base value, linspace() will suddenly return a single row
vector instead of the expected single column vector.  So we'd have to add an
extra option to specify dimension.  I'm not sure if it's worthy the extra
complication.  Specially since the function documentation is pretty explicit
on returning row vectors.

Carnë



reply via email to

[Prev in Thread] Current Thread [Next in Thread]