help-octave
[Top][All Lists]
Advanced

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

Re: Passing diagonal matrix to an *.oct function


From: José Luis García Pallero
Subject: Re: Passing diagonal matrix to an *.oct function
Date: Fri, 6 Mar 2009 11:30:04 +0100

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 <address@hidden>
On Fri, Mar 6, 2009 at 10:48 AM, José Luis García Pallero
<address@hidden> 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
address@hidden
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************

reply via email to

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