|
From: | Shai Ayal |
Subject: | Re: basic DLD help? |
Date: | Thu, 14 Jul 2005 15:23:35 +0300 |
User-agent: | Mozilla Thunderbird 1.0 (X11/20041206) |
Thanks everyone, it works now Shai Paul Kienzle wrote:
Octave doesn't allow in-place modification of arrays. Instead you need to make a copy and return it.Use: octave_value_list retval; RowVector y(args(0).vector_value()); double *py = y.fortran_vec(); ... retval(0) = y; return retval; - Paul On Jul 14, 2005, at 6:22 AM, Shai Ayal wrote:Ah, but what if I do want to change the data ? Shai John W. Eaton wrote:On 13-Jul-2005, David Bateman wrote: | Even better would be | | const RowVector y(args(0).vector_value()); | const double *py = y.fortran_vec();| | since as you say fortran_vec calls make_unique except when "const", and | since you aren't altering the data past to the function, in this manner | you avoid a copy.Still better would be const RowVector y(args(0).vector_value()); const double *py = y.data(); because if you are only asking for read-only access, you can use the const data() method and avoid the call to make_unique(). As I recall, the reason for having different names (fortran_vec and data) was because it was not possible to overload on const in early C++ dialects. Now that it is possible, I suppose we could use just one name instead of two. jwe
-- Shai Ayal, Ph.D. Head of Research BioControl Medical BCM 3 Geron St. Yehud 56100 ISRAEL Tel: + 972 3 6322 126 ext 223 Fax: + 972 3 6322 125 email: address@hidden ------------------------------------------------------------- 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 -------------------------------------------------------------
[Prev in Thread] | Current Thread | [Next in Thread] |