On 5/23/06, John W. Eaton <address@hidden> wrote:
On 23-May-2006, Keith Goodman wrote:
| While porting a m-file to an oct-file I got stuck on the line
|
| y = x'*(x > 0);
|
| where x is Nx1.
|
| How do I port x>0?
|
| I figured out how not to do it all by myself:
|
| #include <oct.h>
| DEFUN_DLD(abc, args, nargout,"y = x'*(x > 0) where x is Nx1")
| {
| octave_value retval;
| Matrix x = args(0).matrix_value();
| retval = x.transpose() * (x > 0);
| return retval;
| }
|
| $ mkoctfile abc.cc
| abc.cc: In function 'octave_value_list Fabc(const octave_value_list&, int)':
| abc.cc:6: error: ambiguous overload for 'operator>' in 'x > 0'
#include <oct.h>
DEFUN_DLD(abc, args, nargout,"y = x'*(x > 0) where x is Nx1")
{
octave_value retval;
Matrix x = args(0).matrix_value();
retval = x.transpose() * mx_el_gt (x, 0);
return retval;
}
If your next question is "Where is this documented?" the only answer I
has is that the internals of Octave are not well documented, so use
the Source, Luke. Then you'll probably say, "I could have looked all
day/week/month/year/decade and not found this function!" and I'd have
to say, "Me too, when is someone going to document this mess?"
Thank you. Thank you. Thank you. You are the documentation!
I think the best way to start is with a table that translates m-file
commands into oct-file commands.
The first column is the m-file command; the second column is the
corresponding oct-file command; maybe a third column for comments.
One table could be for matrix manipulation:
x > 2
mx_el_gt (x, 2)
x'
x.transpose()
any(~isfinite(x))
x.any_element_is_inf_or_nan()
abs(x)
x.abs()
y = [x; z]
x.stack(z)
inv(x)
x.inverse()
x*y
x*y
x.*y
product(x, y)
x./y
quotient(x,y)
x(1:2,5:6)
x.extract(0,4,1,5)
randn(3,4)
octave_rand::distribution("normal")
octrandn = octave_rand::matrix(3,4)
sumsq(x)
x.sumsq()
x(3)
x(2)
sum(x,1)
x.sum(0)
sum(x,2)
x.sum(1)
size(x,1)
x.rows()
size(x,2)
x.cols()