octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Explanation of Octave operator overloading


From: David Bateman
Subject: Re: Explanation of Octave operator overloading
Date: Thu, 04 May 2006 21:53:22 +0200
User-agent: Thunderbird 1.5 (Windows/20051201)

John Swensen wrote:
Could someone give a quick tutorial on how the operator overloads work
in Octave (and maybe add it as a section in the Da Coda Al Fine section
of the wiki)?

For example, I have defined a new type that derives from
octave_base_value called octave_socket.  The problem is that I want to
be able to compare it to numerical values.  I have already tried simply
overloading the operator< to compare against octave_value.int_value() as
well as just a plain int.
I see there are a bunch of macros called OCTAVE_INSTALL_*_*_*_CMP_OPS
and assume I have to do something with these, but haven't been able to
figure out what.

Thanks.

John Swensen

A good little example is in octave-forge/extra/linear-algebra/ov-re-tri.cc which overloads the assign, ldiv, hermitian and transpose operators for a triangular matrix type. The reason its good is that it is tiny. In particular check the install_tri_ops functions, the functions that are defined immediately above this for the overloaded functions, and finally note that install_tri_ops is called immediately after the type is registered in the replacement chol.cc function. Note that I intend to delete this code in octave-forge now that the code to treat positive definite matrices is in octave itself, so rescuing it and using it as an example in da coda or del segna is probably a good idea. In fact if you are really motivated, rescuing both da coda and del segna, and this code and writing a chapter on oct-files for the octave 3.0 manual might be even better :-)

Regards
David


reply via email to

[Prev in Thread] Current Thread [Next in Thread]