octave-maintainers
[Top][All Lists]
Advanced

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

Re: Help with [] for defined types


From: Andy Adler
Subject: Re: Help with [] for defined types
Date: Mon, 2 Aug 2004 14:51:59 -0400 (EDT)

David,

Thanks for your help with this stuff. I still have some questions.

On Wed, 28 Jul 2004, David Bateman wrote:

> To get a reasonable speed the concatenation function precalcuates the
> size of the return type and then dimensions the return value before
> inserting the data into it. As the functions in pt-mat.cc
> (tree_matrix::rvalue) and data.cc (do_cat) know nothing of the types
> its concatenations (it hands that role off to do_catop), it uses a
> resize of the octave_value itself. For this reason you have to define
> in make_sparse.h something like
>
> #ifdef HAVE_OCTAVE_CONCAT
> octave_value
> octave_sparse::resize (const dim_vector& dv) const
> {
>   if (dv.length() > 2)
>     {
>       error ("Can not resize sparse matrix to NDArray");
>       return octave_value ();
>     }
>   SuperMatrix retval (*this);
>
>   // Do the magic needed to change the number of rows and columns while
>   // leaving the elements of retval alone //
>
>   return new octave_sparse (retval);
> }
> #endif

I've done this, and it seems to be being called twice, the first time
with dv=[0,0] and the second time with the right output size, but

echo 's=sparse(diag([1,3],1)); p=[s,s]' | octave -qfH
DEBUG:sparse( void)
installing sparse type at type-id = 40
install sm_sm
DEBUG:sparse - matrix_to_sparse
DEBUG:sparse( SuperMatrix A)
DEBUG:sparse_resize                  <--- calls sparse([1;2],[2;3],[1;3],0,0)
DEBUG:sparse - assemble_sparse
error: sparse row index out of range  <-- error because rows,cols= 0,0
DEBUG:sparse( SuperMatrix A)
DEBUG:sparse_resize                  <--- calls sparse([],[],[],3,6)
DEBUG:sparse( SuperMatrix A)
DEBUG:sparse destructor
DEBUG:sparse destructor
error: evaluating assignment expression near line 1, column 28

I don't understand why octave_sparse::resize is being called twice here
Am I missing something?

> You'll also need to register the concat functions. For the galois field type
> I used macros, and these modified for your use might look like
>
> #ifdef HAVE_OCTAVE_CONCAT
> #define DEFCATOP_SPARSE_FN(name, t1, t2, f) \
>   CATOPDECL (name, a1, a2)         \
>   { \
>     CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
>     return new octave_sparse (f (v1.t1 ## _value (), v2.t2 ## _value (), 
> ra_idx)); \
>   }
>
> #define INSTALL_SPARSE_CATOP(t1, t2, f) INSTALL_CATOP(t1, t2, f)
> #else
> #define DEFCATOP_SPARSE_FN(name, t1, t2, f)
> #define INSTALL_SPARSE_CATOP(t1, t2, f)
> #endif
>
> You should then add
>
> DEFCATOP_SPARSE_FN (sm_sm, sparse, sparse, concat)
 ...
> INSTALL_SPARSE_CATOP (octave_sparse, octave_sparse, sm_sm);
 ...
>
> to sparse_ops.cc.

I've implemented these, but they don't seem to be being called.
Definitely, octave_sparse concat (const octave_sparse& ra,
                      const octave_sparse& rb, const Array<int>& ra_idx);
is not called.

Also, I'm not sure I understand what ra_idx is and how I'm supposed to
interpret it.

Thanks for all the help.

--
Andy Adler





reply via email to

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