[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Moving code from octaveforge to octave [Was: polyderiv problem?]
From: 
John W. Eaton 
Subject: 
Re: Moving code from octaveforge to octave [Was: polyderiv problem?] 
Date: 
Thu, 10 Feb 2005 10:00:42 0500 
On 9Feb2005, Michael Creel <address@hidden> wrote:
 On Wednesday 09 February 2005 16:50, David Bateman wrote:
 > The only
 > remaining patch to consider is Mvops2.1.31.patch that allows the
 > extension of ./, .*, etc to allow Matrix by vector arguments.

 I sent this message to David, but I meant to send it to all, so here it is:

 This is a behavior that I have found very useful in languages like Gauss and
 Ox.
Do these languages have special syntax for these operations?
Although it has been discussed before, and I have probably even
suggested implementing it in the past, I now hesitate to overload
operators like .* for this purpose because (as David mentioned) it
means that a dimensioning error can lead to bad results with no
warning. As another example, you might mean to multiply elements of
M1 by elements of M2, but M2 accidentally becomes a vector, so
suddenly you are scaling columns instead of seeing an error about
nonconforming operands. That seems bad to me. But it would be
useful to have this capability implemented efficiently, even if we do
not have special operators for it.
 Maybe it would be possible to allow it only for matrices and vectors, but
 not NDArrays?
There is probably some way to generalize to Nd arrays when the
dimension of one operand is one less than the dimension of the other.
 Or maybe a function would do the job. I attach a quck hack for
 consideration. Michael
 m_x_v.m
 function result = m_x_v(m,v)
 if !ismatrix(m)
 error("m_x_v: first arg must be a matrix");
 endif
 if !isvector(v)
 error("m_x_v: second arg must be a vector");
 endif

 [rm, cm] = size(m);
 [rv, cv] = size(v);

 if (rm == rv)
 v = kron(v, ones(1,cm));
 result = m .* v;
 elseif (cm == cv)
 v = kron(v, ones(rm, 1));
 result = m .* v;
 else
 error("m_x_v: dimension of vector must match one of the
dimensions of the matr
 ix");
 endif
 endfunction
This kind of approach will work, but it will use a lot of memory, so
it would be better to do this in a builtin function where we could
use loops and not sacrifice speed or memory efficiency.
jwe
 Moving code from octaveforge to octave [Was: polyderiv problem?], David Bateman, 2005/02/09
 Re: Moving code from octaveforge to octave [Was: polyderiv problem?], David Bateman, 2005/02/09
 Re: Moving code from octaveforge to octave [Was: polyderiv problem?], Paul Kienzle, 2005/02/09
 Re: Moving code from octaveforge to octave [Was: polyderiv problem?], David Bateman, 2005/02/10
 Re: Moving code from octaveforge to octave [Was: polyderiv problem?], David Bateman, 2005/02/10
 Re: Moving code from octaveforge to octave [Was: polyderiv problem?], Paul Kienzle, 2005/02/10
 Re: Moving code from octaveforge to octave [Was: polyderiv problem?], David Bateman, 2005/02/10
 Re: Moving code from octaveforge to octave [Was: polyderiv problem?], John W. Eaton, 2005/02/10
 Re: Moving code from octaveforge to octave [Was: polyderiv problem?], Geordie McBain, 2005/02/11
 Re: Moving code from octaveforge to octave [Was: polyderiv problem?], David Bateman, 2005/02/23