octave-maintainers
[Top][All Lists]
Advanced

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

improved dispatching to built-in classes


From: Jaroslav Hajek
Subject: improved dispatching to built-in classes
Date: Tue, 12 Jan 2010 13:22:03 +0100

hi all,

the following changeset rewrites some parts of the dispatching
mechanism for built-in classes to make Octave's behavior more
Matlab-compatible:
http://hg.savannah.gnu.org/hgweb/octave/rev/090173f2db40

Previously, in absence of user classes in the argument list, Octave
always used the class of the first argument for dispatching. This is,
however, not what Matlab does - in Matlab, some built-in types are
preferred over others, so in case of multiple arguments the dispatch
type could differ significantly.
To facilitate performance, instead of using the class precedence
table, I extended the existing builtin_type mechanism and implemented
the built-in dispatch computing using a precomputed transition table
(see build_sup_table in symtab.cc), which contains all the transition
rules. I didn't find these rules documented anywhere, so I just
observed them:

1. function_handle is preferred over anything
2. struct and cell are preferred over array types, but not over each other
3. integer types are preferred over other array types
4. anything is preferred over logicals
5. single is preferred over doubles
6. single is preferred over char (why... ?)

maybe something else escaped to me. If yes, we should be able to
simply add more rules. Also, this is from Matlab 2007a, so maybe
someone can update this.
You see that it has some structure, though 6 seems to be ad hoc (no,
double is not preferred over char).
Especially the high priority of cell may be useful for implementing
cell-enabled functions (simply provide an overload that calls
cellfun).

Attached is a Matlab-compatible test script doing various overloaded calls.
With Matlab R2007a, I get:

>> do_test
double
single
single
single
int8
int8
double
char
double
int8
char
uint32
int8
cell
cell
struct
struct
cell
struct
function_handle
function_handle
function_handle
function_handle

with recent Octave, I get:
octave:1> do_test
double
double
double
char
int8
double
double
char
logical
logical
logical
uint32
int8
cell
double
double
int8
cell
struct
double
int8
struct
cell

with the new patches, I get a result identical to Matlab:
octave:2> do_test
double
single
single
single
int8
int8
double
char
double
int8
char
uint32
int8
cell
cell
struct
struct
cell
struct
function_handle
function_handle
function_handle
function_handle

it would be nice to make this somehow a part of the test suite, but
I'm exhausted now, so maybe later unless anyone else does.

comments, suggestions?

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

Attachment: overload_test.tar
Description: Unix tar archive


reply via email to

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