1,072
edits
m (Update total number of instances) |
(→Files) |
||
(24 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
== Introduction == | == Introduction == | ||
Some functions | Some Octave functions return more than one value. For example, the LU factorization can return L and U, but also P, Q, and R. In C++ these functions return an octave_value_list object which is a row vector of return values. The first element in the vector (element 0) contains the leftmost return argument. For return arguments L,U,P the indices would be 0,1,2. | ||
However, unless the octave_value_list has been pre-declared to the correct size, growing the row vector by indexing into a non-existent position forces the array to grow. Thus, the straightforward and very clear coding strategy of | |||
==== Example 1 : | <pre> | ||
retval(0) = L; | |||
retval(1) = U; | |||
retval(2) = P; | |||
</pre> | |||
turns out to be an inefficient implementation. For this reason, current Octave code always writes this in reverse as | |||
<pre> | |||
retval(2) = P; | |||
retval(1) = U; | |||
retval(0) = L; | |||
</pre> | |||
The first indexing operation resizes the row vector and is done only once, but the disadvantage is that this code is more difficult to match with the function's behavior. | |||
As an alternative, there is the ovl() function where the name stands for Octave Value List. This function grows the vector just once and allows the arguments to be presented in their natural order. In this case, the example code could be written as | |||
<pre> | |||
retval = ovl (L, U, P); | |||
</pre> | |||
The principal work for this sprint topic is to convert the C++ code to use the ovl() function where possible. In general, this means collapsing multiple assignment statements to a single assignment. Keeping in mind that line length should be limited to 80 characters, this may mean appropriately breaking the line and indenting the following lines. In some cases, the declaration of "octave_value_list retval" may no longer be necessary and a direct "return ovl (...)" will be possible. In that case, the code can be further simplified by eliminating the retval variable entirely from the function. | |||
==== Example 1 : Remove List and retval declaration (colloc() from colloc.cc) ==== | |||
{| | {| | ||
!Before !! After | !Before !! After | ||
Line 22: | Line 46: | ||
|} | |} | ||
==== Example 2 : | ==== Example 2 : ovl() extending over multiple lines ==== | ||
{| | {| | ||
!Before !! After | !Before !! After | ||
Line 55: | Line 79: | ||
== Detailed Instructions == | == Detailed Instructions == | ||
The list of files which contain | The list of files which contain a possible instance where ovl() could be used is shown in the Files section of this page. The actual instances, including line numbers, are shown in the Instances section. To avoid duplication, sign up for a particular file by editing the Files section of this wiki page and replacing '???' with your name. When you have edited a file you should verify that everything is okay by executing | ||
<pre> | <pre> | ||
Line 71: | Line 95: | ||
Total: 61 | Total: 61 | ||
Fixed: | Fixed: 61 | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 77: | Line 101: | ||
|- | |- | ||
| | | Jose || <strike> corefcn/__dsearchn__.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/__ilu__.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/__qp__.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/balance.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/besselj.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/colloc.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/daspk.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/dasrt.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/dassl.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/data.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/debug.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/det.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/dirfns.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/eig.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/ellipj.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/file-io.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/filter.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/find.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/getgrent.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/getpwent.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/givens.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/graphics.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/help.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/hess.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/inv.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/lsode.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/lu.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/luinc.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/max.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/mgorth.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/oct-stream.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/octave-link.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/ordschur.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/profiler.cc </strike> | ||
|- | |- | ||
| | | Jose || <strike> corefcn/quad.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/quadcc.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/qz.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/regexp.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/schur.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/spparms.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/sqrtm.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/svd.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/symtab.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/syscalls.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/time.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/toplev.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> corefcn/urlwrite.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/__eigs__.cc </strike> | ||
|- | |- | ||
| | | Andy || <strike> dldfcn/__fltk_uigetfile__.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/__glpk__.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/__magick_read__.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/__voronoi__.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/amd.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/audioread.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/ccolamd.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/chol.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/colamd.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/convhulln.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/dmperm.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/qr.cc </strike> | ||
|- | |- | ||
| | | Rik || <strike> dldfcn/symbfact.cc </strike> | ||
|- | |- | ||
Line 553: | Line 577: | ||
dldfcn/__eigs__.cc:521 | dldfcn/__eigs__.cc:521 | ||
dldfcn/__eigs__.cc:567 | dldfcn/__eigs__.cc:567 | ||
dldfcn/__fltk_uigetfile__.cc:129 | dldfcn/__fltk_uigetfile__.cc:129 Andy: I think this is a case where using ovl makes no sense | ||
dldfcn/__fltk_uigetfile__.cc:131 | dldfcn/__fltk_uigetfile__.cc:131 Andy: I think this is a case where using ovl makes no sense | ||
dldfcn/__glpk__.cc:632 | dldfcn/__glpk__.cc:632 | ||
dldfcn/__magick_read__.cc:279 | dldfcn/__magick_read__.cc:279 |
edits