octave-maintainers
[Top][All Lists]
Advanced

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

Re: Ignorance


From: Robert T. Short
Subject: Re: Ignorance
Date: Tue, 06 Mar 2012 11:25:32 -0800
User-agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

On 03/06/2012 09:52 AM, Jordi Gutiérrez Hermoso wrote:
On 6 March 2012 12:46, Robert T. Short<address@hidden>  wrote:
On 03/05/2012 07:34 PM, John W. Eaton wrote:
On  5-Mar-2012, Robert T. Short wrote:

| I don't know the dimensions or the direction a-priori.  The obvious
| answer is 1:N followed by a repmat but there are so many cute little
| octave tricks that I was hoping there was something really clever.

Given

   x = 1:4;
   y = ones (3, 1);
   z = ones (3, 4);

here are the ways I can think of:

   Repmat:

     repmat (x, [3,1])

   Kron:

     kron (x, y)

   Indexing:

     x(y,:)

   Outer product:

     y * x

   Broadcasting:

     z .* x

Are there any others?

jwe


Excellent.  The kind of thing I was looking for was the indexing solution.
  Using kron, outer product, sums, broadcasting involve computation so I
would rather not use them for something like this.  Thanks for the tips.
tic-tock them... You may be surprised at which one is fastest.

Also, I'm expecting that this is an intermediate step for a latter
computation, which is why I suggested broadcasting, which does the
latter computation without explicitly doing something as useless as
copying data around.

- Jordi G. H.


I will do some performance comparisons for my own edification - I based my statements on some comments in the manual about indexing vs. things like a*ones(x,y). The indexing thing worked out slick as a whistle though and really was the right solution to my problem.

I did understand what you meant about using broadcasting. However, I am working on a little problem that does not lend itself to array computations, similar to (and based on) the Bessel function thing I have been so wound up about. Basically my problem really requires that I compute each element of an array individually, so building like-dimensioned arrays of arguments seems a pretty sensible way to go. I will submit the results on the forge list when I get done and you can pick me apart then. :-[

I really do like the broadcasting thing. The problem is that octave is moving way ahead of MATLAB and it is becoming increasingly more difficult to provide compatibility unless I dumb down my scripts. Mind you, that is a good problem to have.

Bob


reply via email to

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