[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A question about programming using dynamically linked function
From: |
Paul Thomas |
Subject: |
Re: A question about programming using dynamically linked function |
Date: |
Wed, 02 Jun 2004 15:38:33 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225 |
Find below a slightly different approach to David's. Like David the
Array<T> function fortran_vec() is used to point to the first member in
the complexMatrix. However, my example uses the C++ standard library
complex, rather than the octave Complex. I have commented out a
transpose that operates directly on the complex matrices and replaced it
in the next line with the same operation using complex pointers.
Best regards
Paul T
#include <octave/oct.h>
#include <octave/quit.h>
#include <complex>
typedef std::complex<double> dComplex;
DEFUN_DLD (complexdemo, args, ,
"Demonstrate fortran_vec for complex \n\n\
transpose_of_x=complexdemo(x) \n") {
if ( args.length() != 1 ) {
error("this version of matrixdemo omly takes one argument");
return octave_value( 0 );
}
ComplexMatrix xin1( args(0).complex_matrix_value() );
int ir = xin1.rows();
int ic = xin1.cols();
ComplexMatrix xout1(ic,ir);
dComplex *pin1 = xin1.fortran_vec();
dComplex *pout1 = xout1.fortran_vec();
for (int ir1 = 0 ; ir1 < ir ; ir1++)
for (int ic1 = 0 ; ic1 < ic ; ic1++) {
// xout1(ic1,ir1) = xin1(ir1,ic1); //transpose using
Matrices
pout1[ic1 + ir1*ic] = pin1[ir1 + ic1*ir]; //transpose using
pointers
}
return octave_value( xout1 );
}
address@hidden wrote:
Hi
I am writing dynamically linked functions. In my function, I
need to copy the data from a complex matrix (in octave_value
type) to a double buffer. I was wondering if there is a way to
find a pointer to the real data in the complex matrix (in
octave_value type), so that I can use memcpy to copy it to my
own buffer. The similar function can be found in MATLAB which
is mxGetPr. Does Octave have similar functions like mxGetPr?
Thanks a lot!
Jia
__
Friends are angels
sent down to earth
to have good days and
to help us find our way...
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------