[Top][All Lists]

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

Re: Return std::complex<float> as octave_value from oct.

From: Mike Miller
Subject: Re: Return std::complex<float> as octave_value from oct.
Date: Fri, 15 Jul 2016 11:35:29 -0700
User-agent: Mutt/1.6.0 (2016-04-01)

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.



reply via email to

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