[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: oct file: slower than expected using fortran_vec
From: |
John W. Eaton |
Subject: |
Re: oct file: slower than expected using fortran_vec |
Date: |
Mon, 16 May 2011 13:24:23 -0400 |
On 16-May-2011, Seb Astien wrote:
| It is a bit faster the second time, but it does not explain the gap
| between the two:
| The bigger the matrix, the bigger the gap between built-in function
| and the oct one.
| I suspect a copying taking it place somehwere.
Yes, because when you write
NDArray A = args(0).array_value ();
you grab a second reference to the underlying array data. Then when
you do
const double *p = A.fortran_vec ();
you are forcing a copy. The const on the LHS is not what determines
whether or not the const version of Array::fortran_vec is selected
over the non-const version. That selection is based on whether the
method is called on a const object.
If you want to avoid the copy, then you should write
const NDArray A = args(0).array_value ();
const double *p = A.fortran_vec ();
or
NDArray A = args(0).array_value (); // could also declare A to be const
const double *p = A.data ();
In the latter case, it does not matter whether A is const; no copy is
ever made with the Array::data method.
jwe
Re: oct file: slower than expected using fortran_vec, Jordi GutiƩrrez Hermoso, 2011/05/16