|
From: | Robert T. Short |
Subject: | Re: Correct behavior of common_size()? |
Date: | Wed, 14 Mar 2012 13:57:01 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux i686; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 |
On 03/14/2012 10:20 AM, Jordi GutiƩrrez Hermoso wrote:
Hmmm. It seems to me that common_size is something that one should use when broadcasting really doesn't apply. An example is my current fanaticism - Bessel functions. The bessel{j,y,i,k} routine will take a column vector of orders and a row vector of arguments and create a table. Each element of the table needs to be computed individually though since convergence properties and the algorithm itself is likely to vary considerably from element to element. All of my current problems fall into this situation.On 14 March 2012 12:59, Robert T. Short<address@hidden> wrote:When I include an empty vector in common_size() I get, for example, octave> [ec,x,y,z]=common_size([],1,[1 2 3]) ec = 1 x = [](0x0) y = 1 z = 1 2 3 In other words, I get an error because the empty matrix can't be sized to match the other elements. I wonder if this is the correct behavior, though.It seems to me that common_size should be a special case of broadcasting arrays to a common shape. Accordingly, the broadcasting rules do not apply to dimensions of size zero, only size one. Ben was asking a while ago for a function like common_size that applied all of the broadcasting rules. I was hesitant to encourage that development, because one of the objectives of broadcasting is to not actually fill your RAM with useless copies of the same data (not to mention the time it takes to do so). Perhaps it's nevertheless useful to extend common_size to do all of the broadcasting. - Jordi G. H.
I guess, more succinctly, using common_size is a convenient way of allowing non-vectorizable functions to return vectors and/or matrices.
BTW, attached is a function that might be what Ben was asking for. It is a generalization of common_size in that it will do what the bessel function routines do - create tables from vectors of compatible dimensions in very much the same way as broadcasting. If there is any community interest you are welcome to it. The only thing I ask in return is for someone to think of a better name for the function.
Bob
tablify.m
Description: Text document
[Prev in Thread] | Current Thread | [Next in Thread] |