Accessing ComplexMatrix values from octave_value_list

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing ComplexMatrix values from octave_value_list

remigio
Hello,

I am trying to access ComplexMatrix values from octave_value_list
I have written the following code:



and when I run the code I get the error:



In the function  (tested separately which works) the output is of type
ComplexMatrix and is returned the following way:



Anyone know how to solve this problem ?

Thank you in advance,

Remigio



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Accessing ComplexMatrix values from octave_value_list

remigio
I post again with the code :
Hello,

I am trying to access ComplexMatrix values from octave_value_list
I have written the following code:

octave_value_list out = feval("interpolate_complex_modes", argin);
ComplexMatrix psi_int = out(0).complex_matrix_value();

and when I run the code I get the error:

error: octave_base_value::complex_matrix_value(): wrong type argument
'cs-list'

In the function  "interpolate_complex_modes" (tested separately which works)
the output is of type
ComplexMatrix and is returned the following way:

ComplexMatrix  psi_int(psi_dims(1), psi_dims(2));

octave_value_list retval;
retval(0) = octave_value(psi_int);
return octave_value (retval);

Anyone know how to solve this problem ?

Thank you in advance,

Remigio



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Accessing ComplexMatrix values from octave_value_list

Andreas Weber-6
Am 11.01.2018 um 08:59 schrieb remigio:
> octave_value_list out = feval("interpolate_complex_modes", argin);
> ComplexMatrix psi_int = out(0).complex_matrix_value();
>
> and when I run the code I get the error:
>
> error: octave_base_value::complex_matrix_value(): wrong type argument
> 'cs-list'

What is the signature of interpolate_complex_modes? From the error
message I guess it returns more than one value, something like
[foo, bar] = interpolate_complex_mode(...) ?

> In the function  "interpolate_complex_modes" (tested separately which works)
> the output is of type
> ComplexMatrix and is returned the following way:
>
> ComplexMatrix  psi_int(psi_dims(1), psi_dims(2));
>
> octave_value_list retval;
> retval(0) = octave_value(psi_int);
> return octave_value (retval);

So interpolate_complex_modes is not a .m file but in an .oct file?
and you should return a octave_value_list, you can use here

return ovl (psi_int(psi_dims(1), psi_dims(2)));

-- Andy

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Accessing ComplexMatrix values from octave_value_list

remigio
Hello Andy,

I tryed your suggestion and it didn't work, I made a minimum working example
to help understand the problem :
///////////////////////////////////////////////////////////////////////////////////
#include <octave/oct.h>
#include <octave/octave.h>
#include <cmath>

DEFUN_DLD (function1, args, nargout,"function1")
{
ComplexMatrix  psi_int(2, 3);
octave_value_list retval;
retval(0) = octave_value(psi_int);
return octave_value (retval);
}

///////////////////////////////////////////////////////////////////////////////////

#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <cmath>

DEFUN_DLD (function2, args, nargout, "function2")
{

octave_value_list out = feval("function1");
ComplexMatrix psi_int = out(0).complex_matrix_value();

octave_value_list retval;
retval(0) = octave_value(psi_int);
return octave_value (retval);
}

function1 executed in octave works fine and return a 2x3 zero matrix as
expected but function2 which calls function1 and should return the same show
the error message:

error: octave_base_value::complex_matrix_value(): wrong type argument
'cs-list'

I would be gratefull to anyone who can make clear what is wrong with this
code,

Rémi




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Accessing ComplexMatrix values from octave_value_list

siko1056
remigio wrote

> Hello Andy,
>
> I tryed your suggestion and it didn't work, I made a minimum working
> example
> to help understand the problem :
> ///////////////////////////////////////////////////////////////////////////////////
> #include &lt;octave/oct.h&gt;
> #include &lt;octave/octave.h&gt;
> #include
> <cmath>
> DEFUN_DLD (function1, args, nargout,"function1")
> {
> ComplexMatrix  psi_int(2, 3);
> octave_value_list retval;
> retval(0) = octave_value(psi_int);
> return octave_value (retval);
> }
>
> ///////////////////////////////////////////////////////////////////////////////////
>
> #include &lt;octave/oct.h&gt;
> #include &lt;octave/octave.h&gt;
> #include &lt;octave/parse.h&gt;
> #include
> <cmath>
> DEFUN_DLD (function2, args, nargout, "function2")
> {
>
> octave_value_list out = feval("function1");
> ComplexMatrix psi_int = out(0).complex_matrix_value();
>
> octave_value_list retval;
> retval(0) = octave_value(psi_int);
> return octave_value (retval);
> }
>
> function1 executed in octave works fine and return a 2x3 zero matrix as
> expected but function2 which calls function1 and should return the same
> show
> the error message:
>
> error: octave_base_value::complex_matrix_value(): wrong type argument
> 'cs-list'
>
> I would be gratefull to anyone who can make clear what is wrong with this
> code,
>
> Rémi

As Andy says, in function1, `return retval;` is fully sufficient, as
`retval` has already the correct type `octave_value_list`, you do not need
to wrap it again, see why:

What you do is the following (assume that `cs-list` and `octave_value_list`
are the same, which is not 100% true):

    octave_value_list retval;  // Create an empty `octave_value_list ()`
    retval(0) = octave_value(psi_int);  // Now we have `octave_value_list
(octave_value (ComplexMatrix))`
    return octave_value (retval);  // Now we return `octave_value
(octave_value_list (octave_value (ComplexMatrix)))`

This in turn will be wrapped again, because of the definition of DEFUN_DLD:

    octave_value_list (octave_value (octave_value_list (octave_value
(ComplexMatrix))))

Thus now when you unpack this from variable `out` in `function2` is:

    octave_value_list out = feval("function1");
    ComplexMatrix psi_int = out(0).complex_matrix_value();

where

    out(0)  // octave_value (octave_value_list (octave_value
(ComplexMatrix)))

is clearly to me an `octave_value_list`, not an `ComplexMatrix` in the
first level.

HTH,
Kai




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Accessing ComplexMatrix values from octave_value_list

remigio
Thanks Kai,

it is completely clear for me now, I provide a working minimal working
exemple in case it can be of use for somebody:

#include <octave/oct.h>
#include <octave/octave.h>
#include <cmath>

DEFUN_DLD (function1, args, nargout,"function1")
{
ComplexMatrix  psi_int(2, 3);
return octave_value (psi_int);
}


///////////////////////////////////////////////////////////////////////////////////

#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <cmath>

DEFUN_DLD (function2, args, nargout, "function2")
{

octave_value_list out = feval("function1");
ComplexMatrix psi_int = out(0).complex_matrix_value();

return octave_value (psi_int);
}



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave