From sources-request at octave dot org Thu Apr 13 13:53:53 2006 Subject: OVER / over(arrayX,arrayY, at func) / : function implemented. From: Muthiah Annamalai To: octave src Cc: David dot Bateman at motorola dot com Date: Thu, 13 Apr 2006 11:40:04 -0700 (PDT) --0-564094898-1144953604=:37385 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Content-Id: Content-Disposition: inline Hello there, I have a implementation of OVER function [over(arrayX,arrayY, at func)] with some test cases. Please have a look, and see if its good enough to make the Octave source tree. I hope Im not reinventing the wheel. Thanks Muthu Annamalai __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --0-564094898-1144953604=:37385 Content-Type: text/plain; name="over.cpp" Content-Description: 1267139252-over.cpp Content-Disposition: inline; filename="over.cpp" /* * (C) 2006,April, Muthiah Annamalai, FSF. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Include Octave header files */ #include #include #include #include #include #include #include #include/* for feval */ #include #include #include #include using namespace std; /* * is_vector finds out if the given matrix value, * is indeed a vector or not. Returns true or false. * * PRECONDITION: Assume args is a valid octave_value * */ static bool is_vector(octave_value args) { bool rval=false; /* See if its a Vector */ if(args.is_matrix_type()&& !args.is_char_matrix()) { Matrix m=args.matrix_value(); if(m.cols()==1 || m.rows()==1) rval=true; } return rval; } /* *PRECONDITION: Assume the user has called is_vector() function, and has got 'true' value. * *POSTCONDITION: New object is created & deployed. */ static ColumnVector get_vector(octave_value args) { ColumnVector c; Matrix m=args.matrix_value(); if(m.cols()==1 || m.rows()==1) { if(m.cols()==1) c=m.column(0); else { /* row vector convert to column */ RowVector rv=m.row(0); c=rv.transpose(); } } return c; } /* * fcn_handle is what I want. * it has a reference to a octave_function */ /* * ISSUES: * * Can we take X or Y as a scalar iff the other one is a vector? Yes. * If we only take the names of functions using the at FUNC_NAME notation, * we will be restricted to taking only names of loaded functions. Yes. * So how do we make a deal? * */ DEFUN_DLD(over,args,, "function over(VecX,VecY,opt:function)"\ "Return a MxN matrix with f(x,y) evaluated at x,y position"\ "for each x,y in VecX,VecY respectively"\ "If not function is provided, use '*' as default operation"\ "Function can be provided using at FUNCTION_NAME "\ "as a string. Both are compatible") { int m=0,n=0,aLength=0; ColumnVector cv[2]; bool function_present=false; octave_function *func=NULL; /* hope to use commutativity of the operators someday */ bool is_commutative=false; aLength=args.length(); if(aLength < 2) { std::cout<<"Error Invoking over();"<=3 && (args(2).is_function_handle() /* ||args(2).is_string() */)) { function_present=true; is_commutative=false; func=args(2).function_value(); #if 0 std::cout<<"Function Found"<name()<name()<<" must return atleast one value, on invocation"<