help-octave
[Top][All Lists]
Advanced

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

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


From: Zoltán Szabó
Subject: Re: Return std::complex<float> as octave_value from oct.
Date: Mon, 18 Jul 2016 17:14:41 +0100

Hi,

So I could do this with FloatComplex but here is a strange one. For small arrays, everything is fine, but if I create a huge array, I get segmentation fault:

Like with this size, exactly when it executes this line:
FloatComplex fcomplex[1329456];

Any idea what I can check?

Thanks,
Zoltan



2016-07-15 19:35 GMT+01:00 Mike Miller <address@hidden>:
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


reply via email to

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