Mercurial > octave-nkf
annotate libinterp/corefcn/__pchip_deriv__.cc @ 19908:5261186f1b00
__pchip_deriv__.cc: Stop variable might be clobbered by 'longjmp' warning.
* __pchip_deriv__.cc: Declare loop index i to be volatile.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 27 Feb 2015 15:53:42 -0800 |
parents | 4ae2987c5f66 |
children | a9574e3c6e9e |
rev | line source |
---|---|
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1 /* |
5837 | 2 |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18639
diff
changeset
|
3 Copyright (C) 2002-2015 Kai Habel |
11523 | 4 Copyright (C) 2008-2009 Jaroslav Hajek |
5837 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5837 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5837 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
28 #include "defun.h" |
5837 | 29 #include "error.h" |
30 #include "gripes.h" | |
31 #include "oct-obj.h" | |
32 #include "utils.h" | |
33 #include "f77-fcn.h" | |
34 | |
5838 | 35 extern "C" |
36 { | |
6242 | 37 F77_RET_T |
11518 | 38 F77_FUNC (dpchim, DPCHIM) (const octave_idx_type& n, const double *x, |
39 const double *f, double *d, | |
40 const octave_idx_type &incfd, | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
41 octave_idx_type *ierr); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
42 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
43 F77_RET_T |
11518 | 44 F77_FUNC (pchim, PCHIM) (const octave_idx_type& n, const float *x, |
45 const float *f, float *d, | |
46 const octave_idx_type& incfd, | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
47 octave_idx_type *ierr); |
5837 | 48 } |
49 | |
6945 | 50 // Wrapper for SLATEC/PCHIP function DPCHIM to calculate the derivates |
51 // for piecewise polynomials. | |
52 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
53 DEFUN (__pchip_deriv__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
54 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
55 @deftypefn {Built-in Function} {} __pchip_deriv__ (@var{x}, @var{y}, @var{dim})\n\ |
6945 | 56 Undocumented internal function.\n\ |
5837 | 57 @end deftypefn") |
58 { | |
59 octave_value retval; | |
5838 | 60 const int nargin = args.length (); |
5837 | 61 |
18111
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
62 bool rows = (nargin == 3 && args(2).uint_value () == 2); |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
63 |
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
64 if (nargin >= 2) |
5837 | 65 { |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
66 if (args(0).is_single_type () || args(1).is_single_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
67 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
68 FloatColumnVector xvec (args(0).float_vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
69 FloatMatrix ymat (args(1).float_matrix_value ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
70 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
71 octave_idx_type nx = xvec.length (); |
14462
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
72 |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
73 if (nx < 2) |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
74 { |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
75 error ("__pchip_deriv__: X must be at least of length 2"); |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
76 return retval; |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
77 } |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
78 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
79 octave_idx_type nyr = ymat.rows (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
80 octave_idx_type nyc = ymat.columns (); |
5838 | 81 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
82 if (nx != (rows ? nyc : nyr)) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
83 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
84 error ("__pchip_deriv__: X and Y dimension mismatch"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
85 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
86 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
87 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
88 FloatMatrix dmat (nyr, nyc); |
5837 | 89 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
90 octave_idx_type ierr; |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
91 const octave_idx_type incfd = rows ? nyr : 1; |
19821
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
92 volatile const octave_idx_type inc = rows ? 1 : nyr; |
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
93 volatile octave_idx_type k = 0; |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
94 |
19908
5261186f1b00
__pchip_deriv__.cc: Stop variable might be clobbered by 'longjmp' warning.
Rik <rik@octave.org>
parents:
19821
diff
changeset
|
95 for (volatile octave_idx_type i = (rows ? nyr : nyc); i > 0; i--) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
96 { |
18637
e7369c43ebe0
Fix segmentation fault for interp2 and pchip method (bug #41838).
Stefan Mahr <dac922@gmx.de>
parents:
17787
diff
changeset
|
97 F77_XFCN (pchim, PCHIM, (nx, xvec.data (), |
19821
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
98 ymat.data () + k * inc, |
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
99 dmat.fortran_vec () + k * inc, |
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
100 incfd, &ierr)); |
5837 | 101 |
19821
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
102 k++; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
103 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
104 if (ierr < 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
105 { |
19814
fc789d4e362e
don't suppress stack trace in error message from __pchip_deriv__
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
106 error ("__pchip_deriv__: PCHIM failed with ierr = %i", ierr); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
107 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
108 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
109 } |
5837 | 110 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
111 retval = dmat; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
112 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
113 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
114 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
115 ColumnVector xvec (args(0).vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
116 Matrix ymat (args(1).matrix_value ()); |
5837 | 117 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
118 octave_idx_type nx = xvec.length (); |
14462
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
119 |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
120 if (nx < 2) |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
121 { |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
122 error ("__pchip_deriv__: X must be at least of length 2"); |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
123 return retval; |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
124 } |
af552038cc52
Fix segfault in pchip when input array is too small (bug #35835).
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
125 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
126 octave_idx_type nyr = ymat.rows (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
127 octave_idx_type nyc = ymat.columns (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
128 |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
129 if (nx != (rows ? nyc : nyr)) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
130 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
131 error ("__pchip_deriv__: X and Y dimension mismatch"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
132 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
133 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
134 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
135 Matrix dmat (nyr, nyc); |
5837 | 136 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
137 octave_idx_type ierr; |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
138 const octave_idx_type incfd = rows ? nyr : 1; |
19821
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
139 volatile const octave_idx_type inc = rows ? 1 : nyr; |
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
140 volatile octave_idx_type k = 0; |
8712
010e15c7be9a
support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
141 |
19908
5261186f1b00
__pchip_deriv__.cc: Stop variable might be clobbered by 'longjmp' warning.
Rik <rik@octave.org>
parents:
19821
diff
changeset
|
142 for (volatile octave_idx_type i = (rows ? nyr : nyc); i > 0; i--) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
143 { |
18637
e7369c43ebe0
Fix segmentation fault for interp2 and pchip method (bug #41838).
Stefan Mahr <dac922@gmx.de>
parents:
17787
diff
changeset
|
144 F77_XFCN (dpchim, DPCHIM, (nx, xvec.data (), |
19821
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
145 ymat.data () + k * inc, |
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
146 dmat.fortran_vec () + k * inc, |
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
147 incfd, &ierr)); |
4ae2987c5f66
avoid variable possibly clobbered by longjmp warning from GCC
John W. Eaton <jwe@octave.org>
parents:
19814
diff
changeset
|
148 k++; |
5838 | 149 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
150 if (ierr < 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
151 { |
19814
fc789d4e362e
don't suppress stack trace in error message from __pchip_deriv__
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
152 error ("__pchip_deriv__: DPCHIM failed with ierr = %i", ierr); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
153 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
154 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
155 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
156 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
157 retval = dmat; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
8713
diff
changeset
|
158 } |
5837 | 159 } |
160 | |
161 return retval; | |
162 } | |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
163 |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
164 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
165 ## 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
|
166 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
167 */ |