From maintainers-request at octave dot org Wed Feb 9 11:25:39 2005 Subject: Re: Moving code from octave-forge to octave [Was: polyderiv problem?] From: Michael Creel To: maintainers at octave dot org Cc: Paul Kienzle , Joe Koski Date: Wed, 09 Feb 2005 17:56:11 +0100 --Boundary_(ID_VbnQ2y9JaPwoLDrrK3LOCA) Content-type: text/plain; charset=iso-8859-1 Content-disposition: inline On Wednesday 09 February 2005 16:50, David Bateman wrote: > I looked at the patches directory of octave-forge and it seems that all > of the patches here, except one are either already included in the main > part of octave or superseded by other changes to octave. The only > remaining patch to consider is M-v-ops-2.1.31.patch that allows the > extension of ./, .*, etc to allow Matrix by vector arguments. Its not > clear how this ports to NDArrays, since in fact the NDArray > generalization means that singleton dimensions in one of the args should > force the matrix to be duplicated allow that dimension of the other arg. > > Do we want to do that? In any case, matlab doesn't support this > behavior, and it might hid some dimensioning errors from the since > something like "randn(N,1)+randn(1,N)" would create an N-by-N matrix... > It is clear however, that the existing patch is of no use as a basis for > this as it is against an octave version prior to the introduction of > NDArrays. So all of the patches in octave-forge might be dumped... > > Regards > David 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. Maybe it would be possible to allow it only for matrices and vectors, but not NDArrays? Or maybe a function would do the job. I attach a quck hack for consideration. Michael m_x_v.m --Boundary_(ID_VbnQ2y9JaPwoLDrrK3LOCA) Content-type: text/octave; charset=iso-8859-1; name=m_x_v.m Content-disposition: attachment; filename=m_x_v.m Content-transfer-encoding: 7BIT 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 --Boundary_(ID_VbnQ2y9JaPwoLDrrK3LOCA)--