Mercurial > octave
annotate libinterp/corefcn/__dsearchn__.cc @ 20802:8bb38ba1bad6
eliminate return statements after calls to print_usage
* __contourc__.cc, __dispatch__.cc, __dsearchn__.cc, __ichol__.cc,
__lin_interpn__.cc, __qp__.cc, balance.cc, betainc.cc, bsxfun.cc,
colloc.cc, daspk.cc, dasrt.cc, dassl.cc, defaults.cc, det.cc,
dlmread.cc, dot.cc, eig.cc, ellipj.cc, fft.cc, fft2.cc, fftn.cc,
filter.cc, find.cc, gcd.cc, givens.cc, hex2num.cc, inv.cc, lookup.cc,
lu.cc, max.cc, mgorth.cc, ordschur.cc, pinv.cc, profiler.cc, quad.cc,
qz.cc, rcond.cc, schur.cc, str2double.cc:
Eliminate return statements after calls to print_usage.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 04 Dec 2015 12:03:44 -0500 |
parents | 8742e0b1cc49 |
children | f428cbe7576f |
rev | line source |
---|---|
6823 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3 Copyright (C) 2007-2015 David Bateman |
6823 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
6823 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
6823 | 20 |
21 */ | |
22 | |
9786
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
24 #include <config.h> |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
25 #endif |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
26 |
6823 | 27 #include <iostream> |
28 #include <fstream> | |
29 #include <string> | |
30 | |
9786
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
31 #include "lo-math.h" |
6823 | 32 |
19877
12ecb7212b44
move some files without external dependencies from dldfcn to corefcn
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
33 #include "defun.h" |
9786
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
34 #include "error.h" |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
35 #include "oct-obj.h" |
6823 | 36 |
19877
12ecb7212b44
move some files without external dependencies from dldfcn to corefcn
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
37 DEFUN (__dsearchn__, args, , |
12ecb7212b44
move some files without external dependencies from dldfcn to corefcn
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
38 "-*- texinfo -*-\n\ |
12ecb7212b44
move some files without external dependencies from dldfcn to corefcn
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
39 @deftypefn {Built-in Function} {[@var{idx}, @var{d}] =} dsearch (@var{x}, @var{xi})\n\ |
6945 | 40 Undocumented internal function.\n\ |
6823 | 41 @end deftypefn") |
42 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
43 int nargin = args.length (); |
6823 | 44 octave_value_list retval; |
45 | |
46 if (nargin != 2) | |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20667
diff
changeset
|
47 print_usage (); |
6823 | 48 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
49 Matrix x = args(0).matrix_value ().transpose (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
50 Matrix xi = args(1).matrix_value ().transpose (); |
6823 | 51 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
52 if (x.rows () != xi.rows () || x.columns () < 1) |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
53 error ("__dsearch__: number of rows of X and XI must match"); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
54 else |
6823 | 55 { |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
56 octave_idx_type n = x.rows (); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
57 octave_idx_type nx = x.columns (); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
58 octave_idx_type nxi = xi.columns (); |
6823 | 59 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
60 ColumnVector idx (nxi); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
61 double *pidx = idx.fortran_vec (); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
62 ColumnVector dist (nxi); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
63 double *pdist = dist.fortran_vec (); |
6823 | 64 |
65 #define DIST(dd, y, yi, m) \ | |
66 dd = 0.; \ | |
67 for (octave_idx_type k = 0; k < m; k++) \ | |
68 { \ | |
69 double yd = y[k] - yi[k]; \ | |
70 dd += yd * yd; \ | |
71 } \ | |
72 dd = sqrt (dd); | |
73 | |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
74 const double *pxi = xi.fortran_vec (); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
75 for (octave_idx_type i = 0; i < nxi; i++) |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
76 { |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
77 double d0; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
78 const double *px = x.fortran_vec (); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
79 DIST(d0, px, pxi, n); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
80 *pidx = 1.; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
81 for (octave_idx_type j = 1; j < nx; j++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
82 { |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
83 px += n; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
84 double d; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
85 DIST (d, px, pxi, n); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
86 if (d < d0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
87 { |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
88 d0 = d; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
89 *pidx = static_cast<double>(j + 1); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
90 } |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
91 OCTAVE_QUIT; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
92 } |
6823 | 93 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
94 *pdist++ = d0; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
95 pidx++; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
96 pxi += n; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
97 } |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
98 |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
99 retval(1) = dist; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19877
diff
changeset
|
100 retval(0) = idx; |
6823 | 101 } |
102 | |
103 return retval; | |
104 } | |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
105 |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
106 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
107 ## No test needed for internal helper function. |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
108 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
109 */ |