|
From: | Zoltán Szabó |
Subject: | Re: Return std::complex<float> as octave_value from oct. |
Date: | Mon, 18 Jul 2016 17:14:41 +0100 |
On Fri, Jul 15, 2016 at 17:00:07 +0100, Zoltán Szabó wrote:
> Hi,
>
> I have an oct module where I have a std::complex<float> as a result of some
> c++ function.
> What is the best way to return it as an octave_value to octave? I tried to
> create a ComplexNDArray but I could not figure out how to do it properly.
>
> My result variable basically an array of complex numbers, so like:
> [24.000000 + 0.000000i, 0.809017 + -5.567582i]
>
> So if needed I can create a different type of variable than complex<float>
> from the oct module.
If it's a 1-dimensional array of std::complex<float>, you can do
something like
size_t len = // the size of your array
FloatComplexRowVector v (len);
for (i = 0; i < len; i++)
v(i) = a[i];
return ovl (v);
If the function you are calling allows you to pass in a pointer to an
array to be filled, then maybe you'll want to create the Octave array
object first, and pass in a pointer to its raw data with the data()
method to avoid the extra copy.
HTH,
--
mike
[Prev in Thread] | Current Thread | [Next in Thread] |