[Top][All Lists]

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

Re: Help with [] for defined types

From: Paul Kienzle
Subject: Re: Help with [] for defined types
Date: Wed, 7 Jul 2004 21:37:39 -0400

On Jul 5, 2004, at 10:50 AM, David Bateman wrote:

According to Andy Adler <address@hidden> (on 07/05/04):
OK, I understand why it is so hard now.

For stuff like your galois field types, which inherit from NDMatrix,
they don't need to add to the conversion table in data.cc. However,
doing this with sparse would need to add a new row and column.
I suppose it would be (after testing with Matlab)

          //       re   cx   ch c  spre spcx
          // --------------------
          // re   |re   cx   ch X  spre spcx
          // cx   |cx   cx   X  X  spcx spcx
          // ch   |ch   X    ch X   X    X
          // cell |X    X    X  c   X    X
             spre  spre spcx X  X   spre spcx
             spcx  spcx spcx X  X   spcx spcx
          // (X means incompatible).

This appears to be a significant pain right now. I think I've
decided to leave it for the moment (after all, the functions
sphcat and spvcat exist)


Galois inherits from octave_base_value, but even if it did inherit
from octave_base_matrix, the way Fcat is written wouldn't be compatiable.
It is hard-coded for real and complex arrays, cell arrays and character

In any case I'd suggest if there is no crossover to the Fcat function
between "spre and spcx" and "re and cx" as you suggest it would be
better to treat the compatiablity with Fcat by writing a function
spcat and overloading it using dispatch. You should probably do the
same to horzcat and vertcat at the same time. The only case that
might cause problems is if for instance you wanted to concatenate
sparse and full matrices like "cat(sparse(...), rand(...))"

dispatch could be extended so that it searches the entire
argument list for the given type.   0.0I wouldn't want to try
to support a specific list of types since octave makes
heavy use of dynamic interpretation of the argument list.

I don't want to create a type hierarchy like matlab, perl, etc.,
but what do we do when someone uses:

        cat(sparse(), full(), galois())

In this case, obviously it is galois, but somehow 3rd party
types would need to negotiate what to use.  Not very pretty.

Also not pretty is defining pairwise ops between types from
different packages.

In any case the function Fcat doesn't get you the "[]" operator which
is defined in tree_matrix::rvalue in pt-mat.cc, and there is no way to
overload. The correct solution would be to create a function lookup
like BINOP, but perhaps called CATOP, which takes a dim argument as
well as the two arbitrary args.

For efficiency you want to walk the whole arg list to []
and determine the final type and dimensions before
building anything.

The tricky bit again is to decide what type to assign
when two different user types are being used
simultaneously.  I guess that's a problem for the
user type installer to deal with.

Paul Kienzle

reply via email to

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