GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
__pchip_deriv__.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2002-2017 Kai Habel
4 Copyright (C) 2008-2009 Jaroslav Hajek
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
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
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
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include "lo-slatec-proto.h"
29 
30 #include "defun.h"
31 #include "error.h"
32 #include "errwarn.h"
33 #include "ovl.h"
34 #include "utils.h"
35 #include "f77-fcn.h"
36 
37 // Wrapper for SLATEC/PCHIP function DPCHIM to calculate the derivates
38 // for piecewise polynomials.
39 
40 DEFUN (__pchip_deriv__, args, ,
41  doc: /* -*- texinfo -*-
42 @deftypefn {} {} __pchip_deriv__ (@var{x}, @var{y}, @var{dim})
43 Undocumented internal function.
44 @end deftypefn */)
45 {
47  int nargin = args.length ();
48 
49  bool rows = (nargin == 3 && args(2).uint_value () == 2);
50 
51  if (nargin >= 2)
52  {
53  if (args(0).is_single_type () || args(1).is_single_type ())
54  {
55  FloatColumnVector xvec (args(0).float_vector_value ());
56  FloatMatrix ymat (args(1).float_matrix_value ());
57 
58  octave_idx_type nx = xvec.numel ();
59 
60  if (nx < 2)
61  error ("__pchip_deriv__: X must be at least of length 2");
62 
63  octave_idx_type nyr = ymat.rows ();
64  octave_idx_type nyc = ymat.columns ();
65 
66  if (nx != (rows ? nyc : nyr))
67  error ("__pchip_deriv__: X and Y dimension mismatch");
68 
69  FloatMatrix dmat (nyr, nyc);
70 
72  const octave_idx_type incfd = rows ? nyr : 1;
73  volatile const octave_idx_type inc = rows ? 1 : nyr;
74  volatile octave_idx_type k = 0;
75 
76  for (volatile octave_idx_type i = (rows ? nyr : nyc); i > 0; i--)
77  {
78  F77_XFCN (pchim, PCHIM, (nx, xvec.data (),
79  ymat.data () + k * inc,
80  dmat.fortran_vec () + k * inc,
81  incfd, &ierr));
82 
83  k++;
84 
85  if (ierr < 0)
86  error ("__pchip_deriv__: PCHIM failed with ierr = %i", ierr);
87  }
88 
89  retval = dmat;
90  }
91  else
92  {
93  ColumnVector xvec (args(0).vector_value ());
94  Matrix ymat (args(1).matrix_value ());
95 
96  octave_idx_type nx = xvec.numel ();
97 
98  if (nx < 2)
99  error ("__pchip_deriv__: X must be at least of length 2");
100 
101  octave_idx_type nyr = ymat.rows ();
102  octave_idx_type nyc = ymat.columns ();
103 
104  if (nx != (rows ? nyc : nyr))
105  error ("__pchip_deriv__: X and Y dimension mismatch");
106 
107  Matrix dmat (nyr, nyc);
108 
110  const octave_idx_type incfd = rows ? nyr : 1;
111  volatile const octave_idx_type inc = rows ? 1 : nyr;
112  volatile octave_idx_type k = 0;
113 
114  for (volatile octave_idx_type i = (rows ? nyr : nyc); i > 0; i--)
115  {
116  F77_XFCN (dpchim, DPCHIM, (nx, xvec.data (),
117  ymat.data () + k * inc,
118  dmat.fortran_vec () + k * inc,
119  incfd, &ierr));
120  k++;
121 
122  if (ierr < 0)
123  error ("__pchip_deriv__: DPCHIM failed with ierr = %i", ierr);
124  }
125 
126  retval = dmat;
127  }
128  }
129 
130  return retval;
131 }
132 
133 /*
134 ## No test needed for internal helper function.
135 %!assert (1)
136 */
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE const F77_INT F77_INT * ierr
subroutine dpchim(N, X, F, D, INCFD, IERR)
Definition: dpchim.f:2
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
for large enough k
Definition: lu.cc:606
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void error(const char *fmt,...)
Definition: error.cc:570
#define F77_XFCN(f, F, args)
Definition: f77-fcn.h:52
octave_idx_type rows(void) const
Definition: Array.h:401
JNIEnv void * args
Definition: ov-java.cc:67
int nargin
Definition: graphics.cc:10115
const T * data(void) const
Definition: Array.h:582
octave_value retval
Definition: data.cc:6294
Definition: dMatrix.h:37
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE const F77_INT & incfd
subroutine pchim(N, X, F, D, INCFD, IERR)
Definition: pchim.f:2
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
const T * fortran_vec(void) const
Definition: Array.h:584
octave_idx_type columns(void) const
Definition: Array.h:410