[Top][All Lists]

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

Re: How to access underlying C datatype of octave [u]int{8|16|32|64}NDAr

From: John Swensen
Subject: Re: How to access underlying C datatype of octave [u]int{8|16|32|64}NDArray?
Date: Wed, 21 Mar 2007 14:02:08 -0400
User-agent: Thunderbird 2.0a1 (X11/20060807)

That works fine (e.g. that is how I am doing it), but remember that the fortran_vec is column major, so you might want to do
if your are doing a memcpy() from a C array to the fortran_vec.

Here is a snippet of my code.
uint8NDArray m( dim_vector(settings.width, settings.height));
octave_uint8* tmp = m.fortran_vec();
memcpy( tmp, capturebuffer, settings.height*settings.width );
return octave_value( m.transpose() );
where 'capturebuffer' is a uint8_t array and 'settings' is a struct with camera parameters in it.

Hope this helps.

John Swensen

Benjamin Lindner wrote:
Hello list,

What is the preferred (or best) way to get access to the underlying
C Datatypes of the octave integer Arrays?
I am using an int32NDArray and would like to retrieve a pointer to
int32_t which is the internal datatype. The member functions data() and
fortran_vec() return pointers to the octave_int32 type, which does not
behave like a C integer (which is in my case necessary).

One solution that (at least syntactically) works is to use
reinterpret_cast<>, but it there a more elegant solution?

Imagine C++ Code like:

#include <octave/oct.h>
#include <octave/oct-intytpes.h>

template <class T> int foo( const T* pIN, size_t len_in, T* pOUT ) {
   // do something in here...
   // T must be a built-in C integer type

DEFUN_DLD( foo, args, , "out=foo(in)" ) {
   int32NDArray sigin( args(0).array_value() );
   unsigned int len_sigin = args(0).length();
int32NDArray sigout( dim_vector(len_sigin, 1), 0 ); // IS THIS THE PREFERRED WAY ??
   const int32_t* pIN = reinterpret_cast<const int32_t*>( );
   int32_t* pOUT = reinterpret_cast<int32_t*>( sigout.fortran_vec() );
// call template unsigned int t = foo( pIN, len_sigin, pOUT ); ...

thanks for hints

reply via email to

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