help-octave
[Top][All Lists]
Advanced

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

Re: Fast copy of buffer data into a matrix


From: John Swensen
Subject: Re: Fast copy of buffer data into a matrix
Date: Fri, 09 Feb 2007 11:01:56 -0500
User-agent: Thunderbird 2.0a1 (X11/20060807)

David Bateman wrote:
John Swensen wrote:
FYI, here is how I ended up copying a unsigned char buffer into a Matrix of type uint8. It ended up taking about 50% of the time of doing it element by element.

static Matrix m1(settings.width, settings.height);
static uint8NDArray m = octave_value(m1).uint8_array_value();
static octave_uint8* tmp = m.fortran_vec();
memcpy( tmp, capturebuffer, settings.height*settings.width );
return octave_value(m.transpose());
Shouldn't that be

static unit8NDArray m (dim_vector(settings.width, settings.height));
static octave_uint8* tmp = m.fortran_vec();
memcpy( tmp, capturebuffer, settings.height*settings.width );
return octave_value(m.transpose());

You might be able to do away with the transpose as well, as the
transpose means that there is a second copy of m in memory at the same
time. However, for it to be efficient, it would have to be some sort of
blocked algorithm so that cache limitations are taken into account..

D.

Is there a difference between:
1) static unit8NDArray m (dim_vector(settings.width, settings.height));
and
2) static uint8NDArray m = octave_value(m1).uint8_array_value();
?
Both of them seem to work. Also, I have to do the transpose because the data from the camera is in row major form and octave is column major (or the other way around, I always get confused).

John


reply via email to

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