From help-octave-request at bevo dot che dot wisc dot edu Wed Dec 18 22:58:42 2002 Subject: Re: A bit puzzled... From: Paul Kienzle To: "Albert F. Niessner" , Paul Kienzle Cc: Octave Help Date: Wed, 18 Dec 2002 23:55:06 -0500 ----- Original Message ----- From: "Albert F. Niessner" To: "Paul Kienzle" Cc: "Octave Help" Sent: Wednesday, December 18, 2002 3:19 PM Subject: A bit puzzled... > > Thanks for your responses to my posts, but your replies have me a bit > puzzled. > > In one of them > (http://www.octave.org/mailing-lists/help-octave/2002/1164), you wrote: > "The data is not actually copied until you do A.fortran_vec() to access > the data for modification." > > However, in the other > (http://www.octave.org/mailing-lists/help-octave/2002/1163) you wrote: > "If the operation is not in place, or if you need a working vector, > allocate it beforehand: > > octave_value_list retval; > const Matrix A(args(0).matrix_value()); > const Matrix B(args(1).matrix_value()); > Matrix C(A.rows(),B.columns()); > F77_FUNC(f,F)(A.data(),B.data(),C.fortran_vec()); > retval(0) = C; > return retval;" > > But, if the data is being copied at the C.fortran_vec() routine, then > retval(0) = C cannot possibly contain the answer. I should have said that C.fortran_vec() checks the reference count for the data in matrix C, and if it is greater than 1, allocates new data for C, copies the values from the old data to the new data and decrements the reference count in the old data. C.fortran_vec() does not return a copy of the data --- it returns the real data but with the assurance that no other matrix is referencing it. That way when you change the data directly, you can be sure that no matrices other than C are affected. Does this help? Paul Kienzle pkienzle at users dot sf dot net ------------------------------------------------------------- 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 -------------------------------------------------------------