[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Accessing ComplexMatrix values from octave_value_list
From: |
siko1056 |
Subject: |
Re: Accessing ComplexMatrix values from octave_value_list |
Date: |
Thu, 11 Jan 2018 05:38:05 -0700 (MST) |
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 <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
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