changeset 33133:a13cb0eb53a9

maint: Merge stable to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Sun, 03 Mar 2024 10:17:29 +0100
parents 41ac5e288d5a (current diff) 2c8ade2c7491 (diff)
children 9af30a72ca59
files configure.ac libinterp/dldfcn/__ode15__.cc
diffstat 3 files changed, 123 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Sat Mar 02 23:30:57 2024 -0500
+++ b/configure.ac	Sun Mar 03 10:17:29 2024 +0100
@@ -2326,13 +2326,32 @@
   LIBS="$save_LIBS"
 fi
 
+### Check for SUNDIALS core library and header.
+
+if test -n "$SUNDIALS_IDA_LIBS" && test -n "$SUNDIALS_NVECSERIAL_LIBS"; then
+
+  save_CPPFLAGS="$CPPFLAGS"
+  save_LDFLAGS="$LDFLAGS"
+  save_LIBS="$LIBS"
+  LIBS="$SUNDIALS_CORE_LIBS $LIBS"
+  LDFLAGS="$SUNDIALS_CORE_LDFLAGS $LDFLAGS"
+  CPPFLAGS="$SUNDIALS_CORE_CPPFLAGS $CPPFLAGS"
+  OCTAVE_CHECK_LIB(sundials_core, [SUNDIALS core],
+    [SUNDIALS core library not found.],
+    [sundials_core.h sundials/sundials_core.h], [SUNContext_Create],
+    [], [])
+  CPPFLAGS="$save_CPPFLAGS"
+  LDFLAGS="$save_LDFLAGS"
+  LIBS="$save_LIBS"
+fi
+
 ### Check for SUNDIALS library features, some required, some optional.
 
 if test -n "$SUNDIALS_IDA_LIBS" && test -n "$SUNDIALS_NVECSERIAL_LIBS"; then
 
-  CPPFLAGS="$SUNDIALS_IDA_CPPFLAGS $SUNDIALS_NVECSERIAL_CPPFLAGS $KLU_CPPFLAGS $BLAS_CPPFLAGS $CPPFLAGS"
-  LDFLAGS="$SUNDIALS_IDA_LDFLAGS $SUNDIALS_NVECSERIAL_LDFLAGS $KLU_LDFLAGS $BLAS_LDFLAGS $LDFLAGS"
-  LIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_NVECSERIAL_LIBS $KLU_LIBS $BLAS_LIBS $FLIBS $LIBS"
+  CPPFLAGS="$SUNDIALS_IDA_CPPFLAGS $SUNDIALS_NVECSERIAL_CPPFLAGS $SUNDIALS_CORE_CPPFLAGS $KLU_CPPFLAGS $BLAS_CPPFLAGS $CPPFLAGS"
+  LDFLAGS="$SUNDIALS_IDA_LDFLAGS $SUNDIALS_NVECSERIAL_LDFLAGS $SUNDIALS_CORE_LDFLAGS $KLU_LDFLAGS $BLAS_LDFLAGS $LDFLAGS"
+  LIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_NVECSERIAL_LIBS $SUNDIALS_CORE_LIBS $KLU_LIBS $BLAS_LIBS $FLIBS $LIBS"
   if test -z "$warn_sundials_nvecserial" && test -z "$warn_sundials_ida"; then
     dnl Any of the following tests could determine that SUNDIALS is
     dnl incompatible and should be disabled.  In that event, they all populate
@@ -2344,6 +2363,7 @@
       OCTAVE_CHECK_SUNDIALS_COMPATIBLE_API
     fi
     if test -z "$warn_sundials_disabled"; then
+      OCTAVE_CHECK_SUNDIALS_SUNREALTYPE
       OCTAVE_CHECK_SUNDIALS_SIZEOF_REALTYPE
     fi
     if test -z "$warn_sundials_disabled"; then
@@ -2374,9 +2394,9 @@
     AC_DEFINE(HAVE_SUNDIALS, 1, [Define to 1 if SUNDIALS is available.])
 
     ## Options needed to build with SUNDIALS and its dependencies.
-    SUNDIALS_XCPPFLAGS="$SUNDIALS_IDA_CPPFLAGS $SUNDIALS_SUNLINSOLKLU_CPPFLAGS $SUNDIALS_NVECSERIAL_CPPFLAGS $KLU_CPPFLAGS"
-    SUNDIALS_XLDFLAGS="$SUNDIALS_IDA_LDFLAGS $SUNDIALS_SUNLINSOLKLU_LDFLAGS $SUNDIALS_NVECSERIAL_LDFLAGS $KLU_LDFLAGS"
-    SUNDIALS_XLIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_SUNLINSOLKLU_LIBS $SUNDIALS_NVECSERIAL_LIBS $KLU_LIBS"
+    SUNDIALS_XCPPFLAGS="$SUNDIALS_IDA_CPPFLAGS $SUNDIALS_SUNLINSOLKLU_CPPFLAGS $SUNDIALS_NVECSERIAL_CPPFLAGS $SUNDIALS_CORE_CPPFLAGS $KLU_CPPFLAGS"
+    SUNDIALS_XLDFLAGS="$SUNDIALS_IDA_LDFLAGS $SUNDIALS_SUNLINSOLKLU_LDFLAGS $SUNDIALS_NVECSERIAL_LDFLAGS $SUNDIALS_CORE_LDFLAGS $KLU_LDFLAGS"
+    SUNDIALS_XLIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_SUNLINSOLKLU_LIBS $SUNDIALS_NVECSERIAL_LIBS $SUNDIALS_CORE_LIBS $KLU_LIBS"
   else
     SUNDIALS_IDA_CPPFLAGS=
     SUNDIALS_IDA_LDFLAGS=
@@ -2387,6 +2407,9 @@
     SUNDIALS_NVECSERIAL_CPPFLAGS=
     SUNDIALS_NVECSERIAL_LDFLAGS=
     SUNDIALS_NVECSERIAL_LIBS=
+    SUNDIALS_CORE_CPPFLAGS=
+    SUNDIALS_CORE_LDFLAGS=
+    SUNDIALS_CORE_LIBS=
     SUNDIALS_XCPPFLAGS=
     SUNDIALS_XLDFLAGS=
     SUNDIALS_XLIBS=
@@ -3335,6 +3358,9 @@
   SPQR LDFLAGS:                  $SPQR_LDFLAGS
   SPQR libraries:                $SPQR_LIBS
   SuiteSparse config libraries:  $SUITESPARSECONFIG_LIBS
+  SUNDIALS core CPPFLAGS:        $SUNDIALS_CORE_CPPFLAGS
+  SUNDIALS core LDFLAGS:         $SUNDIALS_CORE_LDFLAGS
+  SUNDIALS core libraries:       $SUNDIALS_CORE_LIBS
   SUNDIALS IDA CPPFLAGS:         $SUNDIALS_IDA_CPPFLAGS
   SUNDIALS IDA LDFLAGS:          $SUNDIALS_IDA_LDFLAGS
   SUNDIALS IDA libraries:        $SUNDIALS_IDA_LIBS
--- a/libinterp/dldfcn/__ode15__.cc	Sat Mar 02 23:30:57 2024 -0500
+++ b/libinterp/dldfcn/__ode15__.cc	Sun Mar 03 10:17:29 2024 +0100
@@ -121,7 +121,7 @@
 #    endif
 #  endif
 
-static inline realtype *
+static inline OCTAVE_SUNREALTYPE *
 nv_data_s (N_Vector& v)
 {
 #  if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
@@ -147,26 +147,27 @@
   typedef
   ColumnVector (*DAERHSFuncIDA) (const ColumnVector& x,
                                  const ColumnVector& xdot,
-                                 realtype t, const octave_value& idaf);
+                                 OCTAVE_SUNREALTYPE t,
+                                 const octave_value& idaf);
 
   typedef
   Matrix (*DAEJacFuncDense) (const ColumnVector& x,
-                             const ColumnVector& xdot, realtype t,
-                             realtype cj, const octave_value& idaj);
+                             const ColumnVector& xdot, OCTAVE_SUNREALTYPE t,
+                             OCTAVE_SUNREALTYPE cj, const octave_value& idaj);
 
   typedef
   SparseMatrix (*DAEJacFuncSparse) (const ColumnVector& x,
                                     const ColumnVector& xdot,
-                                    realtype t, realtype cj,
+                                    OCTAVE_SUNREALTYPE t, OCTAVE_SUNREALTYPE cj,
                                     const octave_value& idaj);
 
   typedef
   Matrix (*DAEJacCellDense) (Matrix *dfdy, Matrix *dfdyp,
-                             realtype cj);
+                             OCTAVE_SUNREALTYPE cj);
 
   typedef
   SparseMatrix (*DAEJacCellSparse) (SparseMatrix *dfdy,
-                                    SparseMatrix *dfdyp, realtype cj);
+                                    SparseMatrix *dfdyp, OCTAVE_SUNREALTYPE cj);
 
   //Default
   IDA ()
@@ -179,7 +180,7 @@
   { }
 
 
-  IDA (realtype t, ColumnVector y, ColumnVector yp,
+  IDA (OCTAVE_SUNREALTYPE t, ColumnVector y, ColumnVector yp,
        const octave_value& ida_fcn, DAERHSFuncIDA daefun)
     : m_t0 (t), m_y0 (y), m_yp0 (yp), m_havejac (false), m_havejacfcn (false),
       m_havejacsparse (false), m_mem (nullptr), m_num (), m_ida_fcn (ida_fcn),
@@ -268,21 +269,21 @@
   set_up (const ColumnVector& y);
 
   void
-  set_tolerance (ColumnVector& abstol, realtype reltol);
+  set_tolerance (ColumnVector& abstol, OCTAVE_SUNREALTYPE reltol);
 
   void
-  set_tolerance (realtype abstol, realtype reltol);
+  set_tolerance (OCTAVE_SUNREALTYPE abstol, OCTAVE_SUNREALTYPE reltol);
 
   static int
-  resfun (realtype t, N_Vector yy, N_Vector yyp,
+  resfun (OCTAVE_SUNREALTYPE t, N_Vector yy, N_Vector yyp,
           N_Vector rr, void *user_data);
 
   void
-  resfun_impl (realtype t, N_Vector& yy,
+  resfun_impl (OCTAVE_SUNREALTYPE t, N_Vector& yy,
                N_Vector& yyp, N_Vector& rr);
   static int
-  jacdense (realtype t, realtype cj, N_Vector yy, N_Vector yyp,
-            N_Vector, SUNMatrix JJ, void *user_data, N_Vector,
+  jacdense (OCTAVE_SUNREALTYPE t, OCTAVE_SUNREALTYPE cj, N_Vector yy,
+            N_Vector yyp, N_Vector, SUNMatrix JJ, void *user_data, N_Vector,
             N_Vector, N_Vector)
   {
     IDA *self = static_cast <IDA *> (user_data);
@@ -291,13 +292,13 @@
   }
 
   void
-  jacdense_impl (realtype t, realtype cj,
+  jacdense_impl (OCTAVE_SUNREALTYPE t, OCTAVE_SUNREALTYPE cj,
                  N_Vector& yy, N_Vector& yyp, SUNMatrix& JJ);
 
 #  if defined (HAVE_SUNDIALS_SUNLINSOL_KLU)
   static int
-  jacsparse (realtype t, realtype cj, N_Vector yy, N_Vector yyp,
-             N_Vector, SUNMatrix Jac, void *user_data, N_Vector,
+  jacsparse (OCTAVE_SUNREALTYPE t, OCTAVE_SUNREALTYPE cj, N_Vector yy,
+             N_Vector yyp, N_Vector, SUNMatrix Jac, void *user_data, N_Vector,
              N_Vector, N_Vector)
   {
     IDA *self = static_cast <IDA *> (user_data);
@@ -306,17 +307,17 @@
   }
 
   void
-  jacsparse_impl (realtype t, realtype cj,
+  jacsparse_impl (OCTAVE_SUNREALTYPE t, OCTAVE_SUNREALTYPE cj,
                   N_Vector& yy, N_Vector& yyp, SUNMatrix& Jac);
 #  endif
 
-  void set_maxstep (realtype maxstep);
+  void set_maxstep (OCTAVE_SUNREALTYPE maxstep);
 
-  void set_initialstep (realtype initialstep);
+  void set_initialstep (OCTAVE_SUNREALTYPE initialstep);
 
   bool
   interpolate (octave_idx_type& cont, Matrix& output, ColumnVector& tout,
-               int refine, realtype tend, bool haveoutputfcn,
+               int refine, OCTAVE_SUNREALTYPE tend, bool haveoutputfcn,
                bool haveoutputsel, const octave_value& output_fcn,
                ColumnVector& outputsel, bool haveeventfunction,
                const octave_value& event_fcn, ColumnVector& te,
@@ -327,17 +328,18 @@
 
   bool
   outputfun (const octave_value& output_fcn, bool haveoutputsel,
-             const ColumnVector& output, realtype tout, realtype tend,
-             ColumnVector& outputsel, const std::string& flag);
+             const ColumnVector& output, OCTAVE_SUNREALTYPE tout,
+             OCTAVE_SUNREALTYPE tend, ColumnVector& outputsel,
+             const std::string& flag);
 
 
   bool
   event (const octave_value& event_fcn,
          ColumnVector& te, Matrix& ye, ColumnVector& ie,
-         realtype tsol, const ColumnVector& y, const std::string& flag,
-         const ColumnVector& yp, ColumnVector& oldval,
+         OCTAVE_SUNREALTYPE tsol, const ColumnVector& y,
+         const std::string& flag, const ColumnVector& yp, ColumnVector& oldval,
          ColumnVector& oldisterminal, ColumnVector& olddir,
-         octave_idx_type cont, octave_idx_type& temp, realtype told,
+         octave_idx_type cont, octave_idx_type& temp, OCTAVE_SUNREALTYPE told,
          ColumnVector& yold,
          const octave_idx_type num_event_args);
 
@@ -356,7 +358,7 @@
 
 private:
 
-  realtype m_t0;
+  OCTAVE_SUNREALTYPE m_t0;
   ColumnVector m_y0;
   ColumnVector m_yp0;
   bool m_havejac;
@@ -383,7 +385,7 @@
 };
 
 int
-IDA::resfun (realtype t, N_Vector yy, N_Vector yyp, N_Vector rr,
+IDA::resfun (OCTAVE_SUNREALTYPE t, N_Vector yy, N_Vector yyp, N_Vector rr,
              void *user_data)
 {
   IDA *self = static_cast <IDA *> (user_data);
@@ -392,7 +394,7 @@
 }
 
 void
-IDA::resfun_impl (realtype t, N_Vector& yy,
+IDA::resfun_impl (OCTAVE_SUNREALTYPE t, N_Vector& yy,
                   N_Vector& yyp, N_Vector& rr)
 {
   ColumnVector y = IDA::NVecToCol (yy, m_num);
@@ -401,7 +403,7 @@
 
   ColumnVector res = (*m_fcn) (y, yp, t, m_ida_fcn);
 
-  realtype *puntrr = nv_data_s (rr);
+  OCTAVE_SUNREALTYPE *puntrr = nv_data_s (rr);
 
   for (octave_idx_type i = 0; i < m_num; i++)
     puntrr[i] = res(i);
@@ -476,7 +478,7 @@
 }
 
 void
-IDA::jacdense_impl (realtype t, realtype cj,
+IDA::jacdense_impl (OCTAVE_SUNREALTYPE t, OCTAVE_SUNREALTYPE cj,
                     N_Vector& yy, N_Vector& yyp, SUNMatrix& JJ)
 
 {
@@ -501,8 +503,8 @@
 
 #  if defined (HAVE_SUNDIALS_SUNLINSOL_KLU)
 void
-IDA::jacsparse_impl (realtype t, realtype cj, N_Vector& yy, N_Vector& yyp,
-                     SUNMatrix& Jac)
+IDA::jacsparse_impl (OCTAVE_SUNREALTYPE t, OCTAVE_SUNREALTYPE cj, N_Vector& yy,
+                     N_Vector& yyp, SUNMatrix& Jac)
 
 {
   ColumnVector y = NVecToCol (yy, m_num);
@@ -550,7 +552,7 @@
 IDA::NVecToCol (N_Vector& v, octave_f77_int_type n)
 {
   ColumnVector data (n);
-  realtype *punt = nv_data_s (v);
+  OCTAVE_SUNREALTYPE *punt = nv_data_s (v);
 
   for (octave_f77_int_type i = 0; i < n; i++)
     data(i) = punt[i];
@@ -563,7 +565,7 @@
 {
   N_Vector v = N_VNew_Serial (n OCTAVE_SUNCONTEXT);
 
-  realtype *punt = nv_data_s (v);
+  OCTAVE_SUNREALTYPE *punt = nv_data_s (v);
 
   for (octave_f77_int_type i = 0; i < n; i++)
     punt[i] = data(i);
@@ -585,7 +587,10 @@
 {
   m_num = to_f77_int (m_y0.numel ());
 #  if defined (HAVE_SUNDIALS_SUNCONTEXT)
-  if (SUNContext_Create (nullptr, &m_sunContext) < 0)
+#    if ! defined (SUN_COMM_NULL)
+#      define SUN_COMM_NULL nullptr
+#    endif
+  if (SUNContext_Create (SUN_COMM_NULL, &m_sunContext) < 0)
     error ("__ode15__: unable to create context for SUNDIALS");
   m_mem = IDACreate (m_sunContext);
 #  else
@@ -606,7 +611,7 @@
 }
 
 void
-IDA::set_tolerance (ColumnVector& abstol, realtype reltol)
+IDA::set_tolerance (ColumnVector& abstol, OCTAVE_SUNREALTYPE reltol)
 {
   N_Vector abs_tol = ColToNVec (abstol, m_num);
   octave::unwind_action act ([&abs_tol] () { N_VDestroy_Serial (abs_tol); });
@@ -616,7 +621,7 @@
 }
 
 void
-IDA::set_tolerance (realtype abstol, realtype reltol)
+IDA::set_tolerance (OCTAVE_SUNREALTYPE abstol, OCTAVE_SUNREALTYPE reltol)
 {
   if (IDASStolerances (m_mem, reltol, abstol) != 0)
     error ("IDA: Tolerance not set");
@@ -640,8 +645,8 @@
   std::string string = "";
   ColumnVector yold = y;
 
-  realtype tsol = tspan(0);
-  realtype tend = tspan(numt-1);
+  OCTAVE_SUNREALTYPE tsol = tspan(0);
+  OCTAVE_SUNREALTYPE tend = tspan(numt-1);
 
   N_Vector yyp = ColToNVec (yp, m_num);
   N_Vector yy = ColToNVec (y, m_num);
@@ -796,12 +801,12 @@
 
 bool
 IDA::event (const octave_value& event_fcn,
-            ColumnVector& te, Matrix& ye, ColumnVector& ie, realtype tsol,
-            const ColumnVector& y, const std::string& flag,
-            const ColumnVector& yp, ColumnVector& oldval,
-            ColumnVector& oldisterminal, ColumnVector& olddir,
-            octave_idx_type cont, octave_idx_type& temp, realtype told,
-            ColumnVector& yold,
+            ColumnVector& te, Matrix& ye, ColumnVector& ie,
+            OCTAVE_SUNREALTYPE tsol, const ColumnVector& y,
+            const std::string& flag, const ColumnVector& yp,
+            ColumnVector& oldval, ColumnVector& oldisterminal,
+            ColumnVector& olddir, octave_idx_type cont, octave_idx_type& temp,
+            OCTAVE_SUNREALTYPE told, ColumnVector& yold,
             const octave_idx_type num_event_args)
 {
   bool status = false;
@@ -911,7 +916,7 @@
 
 bool
 IDA::interpolate (octave_idx_type& cont, Matrix& output, ColumnVector& tout,
-                  int refine, realtype tend, bool haveoutputfcn,
+                  int refine, OCTAVE_SUNREALTYPE tend, bool haveoutputfcn,
                   bool haveoutputsel, const octave_value& output_fcn,
                   ColumnVector& outputsel, bool haveeventfunction,
                   const octave_value& event_fcn, ColumnVector& te,
@@ -920,7 +925,7 @@
                   octave_idx_type& temp, ColumnVector& yold,
                   const octave_idx_type num_event_args)
 {
-  realtype h = 0, tcur = 0;
+  OCTAVE_SUNREALTYPE h = 0, tcur = 0;
   bool status = false;
 
   N_Vector dky = N_VNew_Serial (m_num OCTAVE_SUNCONTEXT);
@@ -940,9 +945,9 @@
   if (IDAGetCurrentTime (m_mem, &tcur) != 0)
     error ("IDA failed to return the current time");
 
-  realtype tin = tcur - h;
+  OCTAVE_SUNREALTYPE tin = tcur - h;
 
-  realtype step = h / refine;
+  OCTAVE_SUNREALTYPE step = h / refine;
 
   for (octave_idx_type i = 1;
        i < refine && tin + step * i < tend && status == 0;
@@ -981,8 +986,8 @@
 
 bool
 IDA::outputfun (const octave_value& output_fcn, bool haveoutputsel,
-                const ColumnVector& yout, realtype tsol,
-                realtype tend, ColumnVector& outputsel,
+                const ColumnVector& yout, OCTAVE_SUNREALTYPE tsol,
+                OCTAVE_SUNREALTYPE tend, ColumnVector& outputsel,
                 const std::string& flag)
 {
   bool status = false;
@@ -1029,14 +1034,14 @@
 }
 
 void
-IDA::set_maxstep (realtype maxstep)
+IDA::set_maxstep (OCTAVE_SUNREALTYPE maxstep)
 {
   if (IDASetMaxStep (m_mem, maxstep) != 0)
     error ("IDA: Max Step not set");
 }
 
 void
-IDA::set_initialstep (realtype initialstep)
+IDA::set_initialstep (OCTAVE_SUNREALTYPE initialstep)
 {
   if (IDASetInitStep (m_mem, initialstep) != 0)
     error ("IDA: Initial Step not set");
@@ -1148,7 +1153,7 @@
 do_ode15 (const octave_value& ida_fcn,
           const ColumnVector& tspan,
           const octave_idx_type numt,
-          const realtype t0,
+          const OCTAVE_SUNREALTYPE t0,
           const ColumnVector& y0,
           const ColumnVector& yp0,
           const octave_scalar_map& options,
@@ -1206,7 +1211,7 @@
   dae.initialize ();
 
   // Set tolerances
-  realtype rel_tol = options.getfield ("RelTol").double_value ();
+  OCTAVE_SUNREALTYPE rel_tol = options.getfield ("RelTol").double_value ();
 
   bool haveabstolvec = options.getfield ("haveabstolvec").bool_value ();
 
@@ -1218,20 +1223,20 @@
     }
   else
     {
-      realtype abs_tol = options.getfield ("AbsTol").double_value ();
+      OCTAVE_SUNREALTYPE abs_tol = options.getfield ("AbsTol").double_value ();
 
       dae.set_tolerance (abs_tol, rel_tol);
     }
 
   //Set max step
-  realtype maxstep = options.getfield ("MaxStep").double_value ();
+  OCTAVE_SUNREALTYPE maxstep = options.getfield ("MaxStep").double_value ();
 
   dae.set_maxstep (maxstep);
 
   //Set initial step
   if (! options.getfield ("InitialStep").isempty ())
     {
-      realtype initialstep = options.getfield ("InitialStep").double_value ();
+      OCTAVE_SUNREALTYPE initialstep = options.getfield ("InitialStep").double_value ();
 
       dae.set_initialstep (initialstep);
     }
@@ -1316,7 +1321,7 @@
 
   octave_idx_type numt = tspan.numel ();
 
-  realtype t0 = tspan(0);
+  OCTAVE_SUNREALTYPE t0 = tspan(0);
 
   if (numt < 2)
     error ("__ode15__: TRANGE must contain at least 2 elements");
--- a/m4/acinclude.m4	Sat Mar 02 23:30:57 2024 -0500
+++ b/m4/acinclude.m4	Sun Mar 03 10:17:29 2024 +0100
@@ -2333,6 +2333,31 @@
   fi
 ])
 dnl
+dnl Check whether SUNDIALS IDA uses sunrealtype.
+dnl
+AC_DEFUN([OCTAVE_CHECK_SUNDIALS_SUNREALTYPE], [
+  AC_CACHE_CHECK([whether SUNDIALS IDA uses sunrealtype],
+    [octave_cv_sundials_has_sunrealtype],
+    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        #if defined (HAVE_IDA_IDA_H)
+        #  include <ida/ida.h>
+        #endif
+        ]], [[
+        sunrealtype test;
+      ]])],
+      octave_cv_sundials_has_sunrealtype=yes,
+      octave_cv_sundials_has_sunrealtype=no)
+  ])
+  if test $octave_cv_sundials_has_sunrealtype = no; then
+    OCTAVE_SUNREALTYPE=realtype
+  else
+    OCTAVE_SUNREALTYPE=sunrealtype
+  fi
+  AC_SUBST(OCTAVE_SUNREALTYPE)
+  AC_DEFINE_UNQUOTED(OCTAVE_SUNREALTYPE, [$OCTAVE_SUNREALTYPE],
+    [Define to the type used for real numbers by SUNDIALS.])
+])
+dnl
 dnl Check whether SUNDIALS IDA library is configured with double
 dnl precision realtype.
 dnl
@@ -2345,7 +2370,7 @@
         #endif
         #include <assert.h>
         ]], [[
-        static_assert (sizeof (realtype) == sizeof (double),
+        static_assert (sizeof (OCTAVE_SUNREALTYPE) == sizeof (double),
                        "SUNDIALS is not configured for double precision");
       ]])],
       octave_cv_sundials_realtype_is_double=yes,