Passing diagonal matrix to an *.oct function

José Luis García Pallero jgpallero at gmail.com
Fri Mar 6 04:30:04 CST 2009


Your method:

const octave_diag_matrix& dmref = dynamic_cast<const octave_diag_matrix&>
(args(0).get_rep ());
DiagMatrix a = dmref.diag_matrix_value ();

fails at compile time. The error is:

error: expected initializer before ‘&’ token
error: ‘dmref’ was not declared in this scope

I can work with a trick. I can pass a column vector to my function instead a
diagonal matrix and initialize the DiagMatrix in the oct function:

DiagMatrix a(args(0).column_vector_value());

Can I think that this method produces a waste of memory because the original
array is duplicated?

I suppose that diag_matrix_value_method() must be added, as matrix_value(),
column_vector_value(), etc. They can return an error in situatios of
conflict, like Matrix a=args(0).colum_vector_value(), for example.

Thanks

2009/3/6 Jaroslav Hajek <highegg at gmail.com>

> On Fri, Mar 6, 2009 at 10:48 AM, José Luis García Pallero
> <jgpallero at gmail.com> wrote:
> > Hi,
> > I'm trying to pass a diagonal matrix to an c++ function, but I don't know
> > the method for conversion from the octave_value class. I've tried with
> > DiagMatrix a=args(0).diagmatrix_value(), .diagonal_matrix_value(),
> > .matrix_value(), but all fails. Wich is the correct form?
> > Thanks
> >
>
> Since the support is still kind of experimental, there's no such
> method in octave_value interface. What you need is to dynamic_cast the
> reference to the proper subclass and query that:
>
> const octave_diag_matrix& dmref = dynamic_cast<const
> octave_diag_matrix&> (args(0).get_rep ());
> DiagMatrix a = dmref.diag_matrix_value ();
>
> Admittedly, it's clumsy (CAST_CONV_ARG macro helps a little). Maybe
> these methods should be added? What should they return for other
> values? Should they just fail?
>
> cheers
>
> --
> RNDr. Jaroslav Hajek
> computing expert & GNU Octave developer
> Aeronautical Research and Test Institute (VZLU)
> Prague, Czech Republic
> url: www.highegg.matfyz.cz
>



-- 
*****************************************
José Luis García Pallero
jgpallero at gmail.com
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www-old.cae.wisc.edu/pipermail/help-octave/attachments/20090306/3a35d008/attachment.html 


More information about the Help-octave mailing list