help-octave
[Top][All Lists]
Advanced

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

fortran_vec() vs data() - very first element is lost


From: Patrick Boettcher
Subject: fortran_vec() vs data() - very first element is lost
Date: Mon, 24 Oct 2016 16:07:18 +0200

Hi list,

I'm still working in an .oct-file to get in and out complex and
double matrices.

I noticed something strange which makes me wonder whether I really got
it correctly:

I read here 

  
https://www.gnu.org/software/octave/doc/v4.0.1/Matrices-and-Arrays-in-Oct_002dFiles.html

that I should use the method fortran_vec() to get to the raw-buffer.

It seems I'm using it correctly to fill data into a matrix returned by
my oct-function. However, when using this method to access the data of
a matrix given to my function as an argument the very first element
contains garbage:

Example code:

Here's my c++ oct-code

  DEFUN_DLD(test_matrix, args, nargout, "")
  {
    auto fdata = args(0).complex_matrix_value().fortran_vec();
    auto data = args(0).complex_matrix_value().data(); 
    auto matrix = args(0).complex_matrix_value();

    octave_stdout << fdata[0] << " " << fdata[1]<< "\n";
    octave_stdout << data[0] << " " << data[1]<< "\n";
    octave_stdout << matrix(0) << " " << matrix(1)<< "\n";

    return octave_value();
  }

Here is my octave-code:

  A = [ 1.5 + 2.5*i, 3.5 + 4.5*i ]
  test_matrix(A)

Octave's output:

  A =

     1.5000 + 2.5000i   3.5000 + 4.5000i

  (0,2.5) (3.5,4.5)
  (1.5,2.5) (3.5,4.5)
  (1.5,2.5) (3.5,4.5)

The first line says: (0,2.5) whereas 1.5 instead of 0 is expected.
Using the data()-method works fine (second line). I'm seeing the same
with normal double matrices.

When injecting data into octave I'm using fortran_vec() to get access
to the raw-buffer. Displaying the matrix in octave shows the first
element to be correctly set.

Is this expected? Am I doing something wrong?

--
Patrick.




reply via email to

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