/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (https://www.swig.org).
 * Version 4.1.1
 *
 * Do not make changes to this file unless you know what you are doing - modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */


#define SWIG_VERSION 0x040101
#define SWIGOCTAVE
#define SWIG_name_d      "letsberational_via_swig"
#define SWIG_name        letsberational_via_swig

#define SWIG_global_name      "cvar"
#define SWIG_op_prefix        "op_"

/* -----------------------------------------------------------------------------
 *  This section contains generic SWIG labels for method/variable
 *  declarations/attributes, and other compiler dependent labels.
 * ----------------------------------------------------------------------------- */

/* template workaround for compilers that cannot correctly implement the C++ standard */
#ifndef SWIGTEMPLATEDISAMBIGUATOR
# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
#  define SWIGTEMPLATEDISAMBIGUATOR template
# elif defined(__HP_aCC)
/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
#  define SWIGTEMPLATEDISAMBIGUATOR template
# else
#  define SWIGTEMPLATEDISAMBIGUATOR
# endif
#endif

/* inline attribute */
#ifndef SWIGINLINE
# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
#   define SWIGINLINE inline
# else
#   define SWIGINLINE
# endif
#endif

/* attribute recognised by some compilers to avoid 'unused' warnings */
#ifndef SWIGUNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define SWIGUNUSED __attribute__ ((__unused__))
#   else
#     define SWIGUNUSED
#   endif
# elif defined(__ICC)
#   define SWIGUNUSED __attribute__ ((__unused__))
# else
#   define SWIGUNUSED
# endif
#endif

#ifndef SWIG_MSC_UNSUPPRESS_4505
# if defined(_MSC_VER)
#   pragma warning(disable : 4505) /* unreferenced local function has been removed */
# endif
#endif

#ifndef SWIGUNUSEDPARM
# ifdef __cplusplus
#   define SWIGUNUSEDPARM(p)
# else
#   define SWIGUNUSEDPARM(p) p SWIGUNUSED
# endif
#endif

/* internal SWIG method */
#ifndef SWIGINTERN
# define SWIGINTERN static SWIGUNUSED
#endif

/* internal inline SWIG method */
#ifndef SWIGINTERNINLINE
# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
#endif

/* exporting methods */
#if defined(__GNUC__)
#  if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#    ifndef GCC_HASCLASSVISIBILITY
#      define GCC_HASCLASSVISIBILITY
#    endif
#  endif
#endif

#ifndef SWIGEXPORT
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
#   if defined(STATIC_LINKED)
#     define SWIGEXPORT
#   else
#     define SWIGEXPORT __declspec(dllexport)
#   endif
# else
#   if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
#     define SWIGEXPORT __attribute__ ((visibility("default")))
#   else
#     define SWIGEXPORT
#   endif
# endif
#endif

/* calling conventions for Windows */
#ifndef SWIGSTDCALL
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
#   define SWIGSTDCALL __stdcall
# else
#   define SWIGSTDCALL
# endif
#endif

/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
# define _CRT_SECURE_NO_DEPRECATE
#endif

/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
# define _SCL_SECURE_NO_DEPRECATE
#endif

/* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */
#if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
# define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
#endif

/* Intel's compiler complains if a variable which was never initialised is
 * cast to void, which is a common idiom which we use to indicate that we
 * are aware a variable isn't used.  So we just silence that warning.
 * See: https://github.com/swig/swig/issues/192 for more discussion.
 */
#ifdef __INTEL_COMPILER
# pragma warning disable 592
#endif

//
// This header includes all C++ headers required for generated Octave wrapper code.
// Using a single header file allows pre-compilation of Octave headers, as follows:
// * Check out this header file:
//     swig -octave -co octheaders.hpp
// * Pre-compile header file into octheaders.hpp.gch:
//     g++ -c ... octheaders.hpp
// * Use pre-compiled header file:
//     g++ -c -include octheaders.hpp ...
//

#if !defined(SWIG_OCTAVE_OCTHEADERS_HPP)
#define SWIG_OCTAVE_OCTHEADERS_HPP

// Required C++ headers
#include <cstdlib>
#include <climits>
#include <iostream>
#include <exception>
#include <functional>
#include <complex>
#include <string>
#include <vector>
#include <map>

// Minimal headers to define Octave version
#include <octave/oct.h>
#include <octave/version.h>

// Macro for enabling features which require Octave version >= major.minor.patch
// - Use (OCTAVE_PATCH_VERSION + 0) to handle both '<digit>' (released) and '<digit>+' (in development) patch numbers
#define SWIG_OCTAVE_PREREQ(major, minor, patch) \
  ( (OCTAVE_MAJOR_VERSION<<16) + (OCTAVE_MINOR_VERSION<<8) + (OCTAVE_PATCH_VERSION + 0) >= ((major)<<16) + ((minor)<<8) + (patch) )

// Reconstruct Octave major, minor, and patch versions for releases prior to 3.8.1
#if !defined(OCTAVE_MAJOR_VERSION)

# if !defined(OCTAVE_API_VERSION_NUMBER)

// Hack to distinguish between Octave 3.8.0, which removed OCTAVE_API_VERSION_NUMBER but did not yet
// introduce OCTAVE_MAJOR_VERSION, and Octave <= 3.2, which did not define OCTAVE_API_VERSION_NUMBER
#  include <octave/ov.h>
#  if defined(octave_ov_h)
#   define OCTAVE_MAJOR_VERSION 3
#   define OCTAVE_MINOR_VERSION 8
#   define OCTAVE_PATCH_VERSION 0
#  else

// Hack to distinguish between Octave 3.2 and earlier versions, before OCTAVE_API_VERSION_NUMBER existed
#   define ComplexLU __ignore
#   include <octave/CmplxLU.h>
#   undef ComplexLU
#   if defined(octave_Complex_LU_h)

// We know only that this version is prior to Octave 3.2, i.e. OCTAVE_API_VERSION_NUMBER < 37
#    define OCTAVE_MAJOR_VERSION 3
#    define OCTAVE_MINOR_VERSION 1
#    define OCTAVE_PATCH_VERSION 99

#   else

// OCTAVE_API_VERSION_NUMBER == 37
#    define OCTAVE_MAJOR_VERSION 3
#    define OCTAVE_MINOR_VERSION 2
#    define OCTAVE_PATCH_VERSION 0

#   endif // defined(octave_Complex_LU_h)

#  endif // defined(octave_ov_h)

// Correlation between Octave API and version numbers extracted from Octave's
// ChangeLogs; version is the *earliest* released Octave with that API number
# elif OCTAVE_API_VERSION_NUMBER >= 48
#  define OCTAVE_MAJOR_VERSION 3
#  define OCTAVE_MINOR_VERSION 6
#  define OCTAVE_PATCH_VERSION 0

# elif OCTAVE_API_VERSION_NUMBER >= 45
#  define OCTAVE_MAJOR_VERSION 3
#  define OCTAVE_MINOR_VERSION 4
#  define OCTAVE_PATCH_VERSION 1

# elif OCTAVE_API_VERSION_NUMBER >= 42
#  define OCTAVE_MAJOR_VERSION 3
#  define OCTAVE_MINOR_VERSION 3
#  define OCTAVE_PATCH_VERSION 54

# elif OCTAVE_API_VERSION_NUMBER >= 41
#  define OCTAVE_MAJOR_VERSION 3
#  define OCTAVE_MINOR_VERSION 3
#  define OCTAVE_PATCH_VERSION 53

# elif OCTAVE_API_VERSION_NUMBER >= 40
#  define OCTAVE_MAJOR_VERSION 3
#  define OCTAVE_MINOR_VERSION 3
#  define OCTAVE_PATCH_VERSION 52

# elif OCTAVE_API_VERSION_NUMBER >= 39
#  define OCTAVE_MAJOR_VERSION 3
#  define OCTAVE_MINOR_VERSION 3
#  define OCTAVE_PATCH_VERSION 51

# else // OCTAVE_API_VERSION_NUMBER == 38
#  define OCTAVE_MAJOR_VERSION 3
#  define OCTAVE_MINOR_VERSION 3
#  define OCTAVE_PATCH_VERSION 50

# endif // !defined(OCTAVE_API_VERSION_NUMBER)

#endif // !defined(OCTAVE_MAJOR_VERSION)

// Required Octave headers
#include <octave/Cell.h>
#include <octave/dynamic-ld.h>
#include <octave/oct-env.h>
#include <octave/oct-map.h>
#include <octave/ov-scalar.h>
#include <octave/ov-fcn-handle.h>
#include <octave/parse.h>
#if SWIG_OCTAVE_PREREQ(4,2,0)
#include <octave/interpreter.h>
#else
#include <octave/toplev.h>
#endif
#include <octave/unwind-prot.h>
#if SWIG_OCTAVE_PREREQ(4,2,0)
#include <octave/call-stack.h>
#endif

#endif // !defined(SWIG_OCTAVE_OCTHEADERS_HPP)

/* -----------------------------------------------------------------------------
 * swigrun.swg
 *
 * This file contains generic C API SWIG runtime support for pointer
 * type checking.
 * ----------------------------------------------------------------------------- */

/* This should only be incremented when either the layout of swig_type_info changes,
   or for whatever reason, the runtime changes incompatibly */
#define SWIG_RUNTIME_VERSION "4"

/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
#ifdef SWIG_TYPE_TABLE
# define SWIG_QUOTE_STRING(x) #x
# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
#else
# define SWIG_TYPE_TABLE_NAME
#endif

/*
  You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for
  creating a static or dynamic library from the SWIG runtime code.
  In 99.9% of the cases, SWIG just needs to declare them as 'static'.

  But only do this if strictly necessary, ie, if you have problems
  with your compiler or suchlike.
*/

#ifndef SWIGRUNTIME
# define SWIGRUNTIME SWIGINTERN
#endif

#ifndef SWIGRUNTIMEINLINE
# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
#endif

/*  Generic buffer size */
#ifndef SWIG_BUFFER_SIZE
# define SWIG_BUFFER_SIZE 1024
#endif

/* Flags for pointer conversions */
#define SWIG_POINTER_DISOWN        0x1
#define SWIG_CAST_NEW_MEMORY       0x2
#define SWIG_POINTER_NO_NULL       0x4
#define SWIG_POINTER_CLEAR         0x8
#define SWIG_POINTER_RELEASE       (SWIG_POINTER_CLEAR | SWIG_POINTER_DISOWN)

/* Flags for new pointer objects */
#define SWIG_POINTER_OWN           0x1


/*
   Flags/methods for returning states.

   The SWIG conversion methods, as ConvertPtr, return an integer
   that tells if the conversion was successful or not. And if not,
   an error code can be returned (see swigerrors.swg for the codes).

   Use the following macros/flags to set or process the returning
   states.

   In old versions of SWIG, code such as the following was usually written:

     if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) {
       // success code
     } else {
       //fail code
     }

   Now you can be more explicit:

    int res = SWIG_ConvertPtr(obj,vptr,ty.flags);
    if (SWIG_IsOK(res)) {
      // success code
    } else {
      // fail code
    }

   which is the same really, but now you can also do

    Type *ptr;
    int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags);
    if (SWIG_IsOK(res)) {
      // success code
      if (SWIG_IsNewObj(res) {
        ...
	delete *ptr;
      } else {
        ...
      }
    } else {
      // fail code
    }

   I.e., now SWIG_ConvertPtr can return new objects and you can
   identify the case and take care of the deallocation. Of course that
   also requires SWIG_ConvertPtr to return new result values, such as

      int SWIG_ConvertPtr(obj, ptr,...) {
        if (<obj is ok>) {
          if (<need new object>) {
            *ptr = <ptr to new allocated object>;
            return SWIG_NEWOBJ;
          } else {
            *ptr = <ptr to old object>;
            return SWIG_OLDOBJ;
          }
        } else {
          return SWIG_BADOBJ;
        }
      }

   Of course, returning the plain '0(success)/-1(fail)' still works, but you can be
   more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the
   SWIG errors code.

   Finally, if the SWIG_CASTRANK_MODE is enabled, the result code
   allows returning the 'cast rank', for example, if you have this

       int food(double)
       int fooi(int);

   and you call

      food(1)   // cast rank '1'  (1 -> 1.0)
      fooi(1)   // cast rank '0'

   just use the SWIG_AddCast()/SWIG_CheckState()
*/

#define SWIG_OK                    (0)
/* Runtime errors are < 0 */
#define SWIG_ERROR                 (-1)
/* Errors in range -1 to -99 are in swigerrors.swg (errors for all languages including those not using the runtime) */
/* Errors in range -100 to -199 are language specific errors defined in *errors.swg */
/* Errors < -200 are generic runtime specific errors */
#define SWIG_ERROR_RELEASE_NOT_OWNED (-200)

#define SWIG_IsOK(r)               (r >= 0)
#define SWIG_ArgError(r)           ((r != SWIG_ERROR) ? r : SWIG_TypeError)

/* The CastRankLimit says how many bits are used for the cast rank */
#define SWIG_CASTRANKLIMIT         (1 << 8)
/* The NewMask denotes the object was created (using new/malloc) */
#define SWIG_NEWOBJMASK            (SWIG_CASTRANKLIMIT  << 1)
/* The TmpMask is for in/out typemaps that use temporal objects */
#define SWIG_TMPOBJMASK            (SWIG_NEWOBJMASK << 1)
/* Simple returning values */
#define SWIG_BADOBJ                (SWIG_ERROR)
#define SWIG_OLDOBJ                (SWIG_OK)
#define SWIG_NEWOBJ                (SWIG_OK | SWIG_NEWOBJMASK)
#define SWIG_TMPOBJ                (SWIG_OK | SWIG_TMPOBJMASK)
/* Check, add and del object mask methods */
#define SWIG_AddNewMask(r)         (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r)
#define SWIG_DelNewMask(r)         (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r)
#define SWIG_IsNewObj(r)           (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK))
#define SWIG_AddTmpMask(r)         (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r)
#define SWIG_DelTmpMask(r)         (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r)
#define SWIG_IsTmpObj(r)           (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK))

/* Cast-Rank Mode */
#if defined(SWIG_CASTRANK_MODE)
#  ifndef SWIG_TypeRank
#    define SWIG_TypeRank             unsigned long
#  endif
#  ifndef SWIG_MAXCASTRANK            /* Default cast allowed */
#    define SWIG_MAXCASTRANK          (2)
#  endif
#  define SWIG_CASTRANKMASK          ((SWIG_CASTRANKLIMIT) -1)
#  define SWIG_CastRank(r)           (r & SWIG_CASTRANKMASK)
SWIGINTERNINLINE int SWIG_AddCast(int r) {
  return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r;
}
SWIGINTERNINLINE int SWIG_CheckState(int r) {
  return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0;
}
#else /* no cast-rank mode */
#  define SWIG_AddCast(r) (r)
#  define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0)
#endif


#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef void *(*swig_converter_func)(void *, int *);
typedef struct swig_type_info *(*swig_dycast_func)(void **);

/* Structure to store information on one type */
typedef struct swig_type_info {
  const char             *name;			/* mangled name of this type */
  const char             *str;			/* human readable name of this type */
  swig_dycast_func        dcast;		/* dynamic cast function down a hierarchy */
  struct swig_cast_info  *cast;			/* linked list of types that can cast into this type */
  void                   *clientdata;		/* language specific type data */
  int                    owndata;		/* flag if the structure owns the clientdata */
} swig_type_info;

/* Structure to store a type and conversion function used for casting */
typedef struct swig_cast_info {
  swig_type_info         *type;			/* pointer to type that is equivalent to this type */
  swig_converter_func     converter;		/* function to cast the void pointers */
  struct swig_cast_info  *next;			/* pointer to next cast in linked list */
  struct swig_cast_info  *prev;			/* pointer to the previous cast */
} swig_cast_info;

/* Structure used to store module information
 * Each module generates one structure like this, and the runtime collects
 * all of these structures and stores them in a circularly linked list.*/
typedef struct swig_module_info {
  swig_type_info         **types;		/* Array of pointers to swig_type_info structures that are in this module */
  size_t                 size;		        /* Number of types in this module */
  struct swig_module_info *next;		/* Pointer to next element in circularly linked list */
  swig_type_info         **type_initial;	/* Array of initially generated type structures */
  swig_cast_info         **cast_initial;	/* Array of initially generated casting structures */
  void                    *clientdata;		/* Language specific module data */
} swig_module_info;

/*
  Compare two type names skipping the space characters, therefore
  "char*" == "char *" and "Class<int>" == "Class<int >", etc.

  Return 0 when the two name types are equivalent, as in
  strncmp, but skipping ' '.
*/
SWIGRUNTIME int
SWIG_TypeNameComp(const char *f1, const char *l1,
		  const char *f2, const char *l2) {
  for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
    while ((*f1 == ' ') && (f1 != l1)) ++f1;
    while ((*f2 == ' ') && (f2 != l2)) ++f2;
    if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1;
  }
  return (int)((l1 - f1) - (l2 - f2));
}

/*
  Check type equivalence in a name list like <name1>|<name2>|...
  Return 0 if equal, -1 if nb < tb, 1 if nb > tb
*/
SWIGRUNTIME int
SWIG_TypeCmp(const char *nb, const char *tb) {
  int equiv = 1;
  const char* te = tb + strlen(tb);
  const char* ne = nb;
  while (equiv != 0 && *ne) {
    for (nb = ne; *ne; ++ne) {
      if (*ne == '|') break;
    }
    equiv = SWIG_TypeNameComp(nb, ne, tb, te);
    if (*ne) ++ne;
  }
  return equiv;
}

/*
  Check type equivalence in a name list like <name1>|<name2>|...
  Return 0 if not equal, 1 if equal
*/
SWIGRUNTIME int
SWIG_TypeEquiv(const char *nb, const char *tb) {
  return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0;
}

/*
  Check the typename
*/
SWIGRUNTIME swig_cast_info *
SWIG_TypeCheck(const char *c, swig_type_info *ty) {
  if (ty) {
    swig_cast_info *iter = ty->cast;
    while (iter) {
      if (strcmp(iter->type->name, c) == 0) {
        if (iter == ty->cast)
          return iter;
        /* Move iter to the top of the linked list */
        iter->prev->next = iter->next;
        if (iter->next)
          iter->next->prev = iter->prev;
        iter->next = ty->cast;
        iter->prev = 0;
        if (ty->cast) ty->cast->prev = iter;
        ty->cast = iter;
        return iter;
      }
      iter = iter->next;
    }
  }
  return 0;
}

/*
  Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison
*/
SWIGRUNTIME swig_cast_info *
SWIG_TypeCheckStruct(const swig_type_info *from, swig_type_info *ty) {
  if (ty) {
    swig_cast_info *iter = ty->cast;
    while (iter) {
      if (iter->type == from) {
        if (iter == ty->cast)
          return iter;
        /* Move iter to the top of the linked list */
        iter->prev->next = iter->next;
        if (iter->next)
          iter->next->prev = iter->prev;
        iter->next = ty->cast;
        iter->prev = 0;
        if (ty->cast) ty->cast->prev = iter;
        ty->cast = iter;
        return iter;
      }
      iter = iter->next;
    }
  }
  return 0;
}

/*
  Cast a pointer up an inheritance hierarchy
*/
SWIGRUNTIMEINLINE void *
SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) {
  return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory);
}

/*
   Dynamic pointer casting. Down an inheritance hierarchy
*/
SWIGRUNTIME swig_type_info *
SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
  swig_type_info *lastty = ty;
  if (!ty || !ty->dcast) return ty;
  while (ty && (ty->dcast)) {
    ty = (*ty->dcast)(ptr);
    if (ty) lastty = ty;
  }
  return lastty;
}

/*
  Return the name associated with this type
*/
SWIGRUNTIMEINLINE const char *
SWIG_TypeName(const swig_type_info *ty) {
  return ty->name;
}

/*
  Return the pretty name associated with this type,
  that is an unmangled type name in a form presentable to the user.
*/
SWIGRUNTIME const char *
SWIG_TypePrettyName(const swig_type_info *type) {
  /* The "str" field contains the equivalent pretty names of the
     type, separated by vertical-bar characters.  Choose the last
     name. It should be the most specific; a fully resolved name
     but not necessarily with default template parameters expanded. */
  if (!type) return NULL;
  if (type->str != NULL) {
    const char *last_name = type->str;
    const char *s;
    for (s = type->str; *s; s++)
      if (*s == '|') last_name = s+1;
    return last_name;
  }
  else
    return type->name;
}

/*
   Set the clientdata field for a type
*/
SWIGRUNTIME void
SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
  swig_cast_info *cast = ti->cast;
  /* if (ti->clientdata == clientdata) return; */
  ti->clientdata = clientdata;

  while (cast) {
    if (!cast->converter) {
      swig_type_info *tc = cast->type;
      if (!tc->clientdata) {
	SWIG_TypeClientData(tc, clientdata);
      }
    }
    cast = cast->next;
  }
}
SWIGRUNTIME void
SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) {
  SWIG_TypeClientData(ti, clientdata);
  ti->owndata = 1;
}

/*
  Search for a swig_type_info structure only by mangled name
  Search is a O(log #types)

  We start searching at module start, and finish searching when start == end.
  Note: if start == end at the beginning of the function, we go all the way around
  the circular list.
*/
SWIGRUNTIME swig_type_info *
SWIG_MangledTypeQueryModule(swig_module_info *start,
                            swig_module_info *end,
		            const char *name) {
  swig_module_info *iter = start;
  do {
    if (iter->size) {
      size_t l = 0;
      size_t r = iter->size - 1;
      do {
	/* since l+r >= 0, we can (>> 1) instead (/ 2) */
	size_t i = (l + r) >> 1;
	const char *iname = iter->types[i]->name;
	if (iname) {
	  int compare = strcmp(name, iname);
	  if (compare == 0) {
	    return iter->types[i];
	  } else if (compare < 0) {
	    if (i) {
	      r = i - 1;
	    } else {
	      break;
	    }
	  } else if (compare > 0) {
	    l = i + 1;
	  }
	} else {
	  break; /* should never happen */
	}
      } while (l <= r);
    }
    iter = iter->next;
  } while (iter != end);
  return 0;
}

/*
  Search for a swig_type_info structure for either a mangled name or a human readable name.
  It first searches the mangled names of the types, which is a O(log #types)
  If a type is not found it then searches the human readable names, which is O(#types).

  We start searching at module start, and finish searching when start == end.
  Note: if start == end at the beginning of the function, we go all the way around
  the circular list.
*/
SWIGRUNTIME swig_type_info *
SWIG_TypeQueryModule(swig_module_info *start,
                     swig_module_info *end,
		     const char *name) {
  /* STEP 1: Search the name field using binary search */
  swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
  if (ret) {
    return ret;
  } else {
    /* STEP 2: If the type hasn't been found, do a complete search
       of the str field (the human readable name) */
    swig_module_info *iter = start;
    do {
      size_t i = 0;
      for (; i < iter->size; ++i) {
	if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
	  return iter->types[i];
      }
      iter = iter->next;
    } while (iter != end);
  }

  /* neither found a match */
  return 0;
}

/*
   Pack binary data into a string
*/
SWIGRUNTIME char *
SWIG_PackData(char *c, void *ptr, size_t sz) {
  static const char hex[17] = "0123456789abcdef";
  const unsigned char *u = (unsigned char *) ptr;
  const unsigned char *eu =  u + sz;
  for (; u != eu; ++u) {
    unsigned char uu = *u;
    *(c++) = hex[(uu & 0xf0) >> 4];
    *(c++) = hex[uu & 0xf];
  }
  return c;
}

/*
   Unpack binary data from a string
*/
SWIGRUNTIME const char *
SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
  unsigned char *u = (unsigned char *) ptr;
  const unsigned char *eu = u + sz;
  for (; u != eu; ++u) {
    char d = *(c++);
    unsigned char uu;
    if ((d >= '0') && (d <= '9'))
      uu = (unsigned char)((d - '0') << 4);
    else if ((d >= 'a') && (d <= 'f'))
      uu = (unsigned char)((d - ('a'-10)) << 4);
    else
      return (char *) 0;
    d = *(c++);
    if ((d >= '0') && (d <= '9'))
      uu |= (unsigned char)(d - '0');
    else if ((d >= 'a') && (d <= 'f'))
      uu |= (unsigned char)(d - ('a'-10));
    else
      return (char *) 0;
    *u = uu;
  }
  return c;
}

/*
   Pack 'void *' into a string buffer.
*/
SWIGRUNTIME char *
SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
  char *r = buff;
  if ((2*sizeof(void *) + 2) > bsz) return 0;
  *(r++) = '_';
  r = SWIG_PackData(r,&ptr,sizeof(void *));
  if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
  strcpy(r,name);
  return buff;
}

SWIGRUNTIME const char *
SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
  if (*c != '_') {
    if (strcmp(c,"NULL") == 0) {
      *ptr = (void *) 0;
      return name;
    } else {
      return 0;
    }
  }
  return SWIG_UnpackData(++c,ptr,sizeof(void *));
}

SWIGRUNTIME char *
SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
  char *r = buff;
  size_t lname = (name ? strlen(name) : 0);
  if ((2*sz + 2 + lname) > bsz) return 0;
  *(r++) = '_';
  r = SWIG_PackData(r,ptr,sz);
  if (lname) {
    strncpy(r,name,lname+1);
  } else {
    *r = 0;
  }
  return buff;
}

SWIGRUNTIME const char *
SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
  if (*c != '_') {
    if (strcmp(c,"NULL") == 0) {
      memset(ptr,0,sz);
      return name;
    } else {
      return 0;
    }
  }
  return SWIG_UnpackData(++c,ptr,sz);
}

#ifdef __cplusplus
}
#endif

/* SWIG Errors applicable to all language modules, values are reserved from -1 to -99 */
#define  SWIG_UnknownError    	   -1
#define  SWIG_IOError        	   -2
#define  SWIG_RuntimeError   	   -3
#define  SWIG_IndexError     	   -4
#define  SWIG_TypeError      	   -5
#define  SWIG_DivisionByZero 	   -6
#define  SWIG_OverflowError  	   -7
#define  SWIG_SyntaxError    	   -8
#define  SWIG_ValueError     	   -9
#define  SWIG_SystemError    	   -10
#define  SWIG_AttributeError 	   -11
#define  SWIG_MemoryError    	   -12
#define  SWIG_NullReferenceError   -13


#if !SWIG_OCTAVE_PREREQ(3,2,0)
#define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, FS ## cname, args, nargout, doc)
#else
#define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, G ## cname, args, nargout, doc)
#endif

SWIGRUNTIME bool SWIG_check_num_args(const char *func_name, int num_args, int max_args, int min_args, int varargs) {
  if (num_args > max_args && !varargs)
    error("function %s takes at most %i arguments", func_name, max_args);
  else if (num_args < min_args)
    error("function %s requires at least %i arguments", func_name, min_args);
  else
    return true;
  return false;
}

SWIGRUNTIME octave_value_list *SWIG_Octave_AppendOutput(octave_value_list *ovl, const octave_value &ov) {
  ovl->append(ov);
  return ovl;
}

SWIGRUNTIME octave_value SWIG_ErrorType(int code) {
  switch (code) {
  case SWIG_MemoryError:
    return "SWIG_MemoryError";
  case SWIG_IOError:
    return "SWIG_IOError";
  case SWIG_RuntimeError:
    return "SWIG_RuntimeError";
  case SWIG_IndexError:
    return "SWIG_IndexError";
  case SWIG_TypeError:
    return "SWIG_TypeError";
  case SWIG_DivisionByZero:
    return "SWIG_DivisionByZero";
  case SWIG_OverflowError:
    return "SWIG_OverflowError";
  case SWIG_SyntaxError:
    return "SWIG_SyntaxError";
  case SWIG_ValueError:
    return "SWIG_ValueError";
  case SWIG_SystemError:
    return "SWIG_SystemError";
  case SWIG_AttributeError:
    return "SWIG_AttributeError";
  }
  return "SWIG unknown error";
}

SWIGRUNTIME octave_value SWIG_Error(int code, const char *msg) {
  octave_value type(SWIG_ErrorType(code));
  std::string r = msg;
  r += " (" + type.string_value() + ")";
  error("%s", r.c_str());
  return octave_value(r);
}

#define SWIG_fail                                       goto fail

#define SWIG_Octave_ConvertPtr(obj, pptr, type, flags)  SWIG_Octave_ConvertPtrAndOwn(obj, pptr, type, flags, 0)
#define SWIG_ConvertPtr(obj, pptr, type, flags)         SWIG_Octave_ConvertPtr(obj, pptr, type, flags)
#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own)  SWIG_Octave_ConvertPtrAndOwn(obj, pptr, type, flags, own)
#define SWIG_ConvertPtr(obj, pptr, type, flags)         SWIG_Octave_ConvertPtr(obj, pptr, type, flags)
#define SWIG_NewPointerObj(ptr, type, flags)            SWIG_Octave_NewPointerObj(ptr, type, flags)
#define swig_owntype                                    int

#define SWIG_ConvertPacked(obj, ptr, sz, ty)            SWIG_Octave_ConvertPacked(obj, ptr, sz, ty)
#define SWIG_NewPackedObj(ptr, sz, type)                SWIG_Octave_NewPackedObj(ptr, sz, type)

#define SWIG_ConvertFunctionPtr(obj, pptr, type)        SWIG_ConvertPtr(obj, pptr, type, 0)
#define SWIG_NewFunctionPtrObj(ptr, type)               SWIG_NewPointerObj(ptr, type, 0)

#define SWIG_ConvertMember(obj, ptr, sz, ty)            SWIG_Octave_ConvertPacked(obj, ptr, sz, ty)
#define SWIG_NewMemberObj(ptr, sz, type)                SWIG_Octave_NewPackedObj(ptr, sz, type)

#define SWIG_GetModule(clientdata) SWIG_Octave_GetModule(clientdata)
#define SWIG_SetModule(clientdata, pointer) SWIG_Octave_SetModule(clientdata,pointer);
#define SWIG_MODULE_CLIENTDATA_TYPE void*

#define Octave_Error_Occurred() 0
#define SWIG_Octave_AddErrorMsg(msg) {;}

SWIGRUNTIME swig_module_info *SWIG_Octave_GetModule(void *clientdata);
SWIGRUNTIME void SWIG_Octave_SetModule(void *clientdata, swig_module_info *pointer);

// For backward compatibility only
#define SWIG_POINTER_EXCEPTION  0
#define SWIG_arg_fail(arg)      0

// Runtime API implementation

typedef octave_value_list(*octave_func) (const octave_value_list &, int);
class octave_swig_type;

namespace Swig {

#ifdef SWIG_DIRECTORS

  class Director;

  typedef std::map < void *, Director * > rtdir_map;
  SWIGINTERN rtdir_map* get_rtdir_map();
  SWIGINTERNINLINE void set_rtdir(void *vptr, Director *d);
  SWIGINTERNINLINE void erase_rtdir(void *vptr);
  SWIGINTERNINLINE Director *get_rtdir(void *vptr);

  SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d);
  SWIGRUNTIME octave_swig_type *swig_director_get_self(Director *d);
  SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self);

#endif

  SWIGRUNTIME octave_base_value *swig_value_ref(octave_swig_type *ost);
  SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov);
  SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov);
}

#ifdef SWIG_DIRECTORS
SWIGRUNTIME void swig_acquire_ownership(void *vptr);
SWIGRUNTIME void swig_acquire_ownership_array(void *vptr);
SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
#endif

  struct swig_octave_member {
    const char *name;
    octave_func method;
    octave_func get_method;
    octave_func set_method;
    int flags;			// 1 static, 2 global
    const char *doc;
    bool is_static() const {
      return flags &1;
    } bool is_global() const {
      return flags &2;
    }
  };

  struct swig_octave_class {
    const char *name;
    swig_type_info **type;
    int director;
    octave_func constructor;
    const char *constructor_doc;
    octave_func destructor;
    const swig_octave_member *members;
    const char **base_names;
    const swig_type_info **base;
  };

#if SWIG_OCTAVE_PREREQ(4,4,0)
  // in Octave 4.4 behaviour of octave_builtin() appears to have changed and 'self' argument is no longer passed
  // to function (maybe because this is now a 'method'??) so need to create our own octave_function subclass
#define SWIG_OCTAVE_BOUND_FUNC(func, args) octave_value(new octave_swig_bound_func(func, args))
  class octave_swig_bound_func : public octave_function {
  public:

    octave_swig_bound_func(void) : octave_function(), method(0), first_args()
      { }

    octave_swig_bound_func(octave_function* _method, octave_value_list _first_args)
      : octave_function("", ""), method(_method), first_args(_first_args)
      { }

    octave_swig_bound_func(const octave_swig_bound_func& f) = delete;

    octave_swig_bound_func& operator= (const octave_swig_bound_func& f) = delete;

    ~octave_swig_bound_func(void) = default;

    bool is_function(void) const { return true; }

    octave_function* function_value(bool = false) { return this; }

#if SWIG_OCTAVE_PREREQ(6,0,0)
    octave_value_list call(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) {
      return execute(tw,nargout,args);
    }
#endif
#if SWIG_OCTAVE_PREREQ(6,0,0)
    octave_value_list execute(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) {
#else
    octave_value_list call(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) {
#endif
      octave_value_list all_args;
      all_args.append(first_args);
      all_args.append(args);
      return method->call(tw, nargout, all_args);
    }

    octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx) {
      octave_value_list ovl = subsref(ops, idx, 1);
      return ovl.length() ? ovl(0) : octave_value();
    }

    octave_value_list subsref(const std::string &ops, const std::list < octave_value_list > &idx, int nargout) {
      assert(ops.size() > 0);
      assert(ops.size() == idx.size());
      if (ops != "(")
        error("invalid function call");
      octave::tree_evaluator& tw = octave::interpreter::the_interpreter()->get_evaluator();
      return call(tw, nargout, *idx.begin());
    }

  protected:

    octave_function* method;
    octave_value_list first_args;

    std::set<std::string> dispatch_classes;

  };
#else
#define SWIG_OCTAVE_BOUND_FUNC(func, args) octave_value(func)
#endif

  // octave_swig_type plays the role of both the shadow class and the class 
  // representation within Octave, since there is no support for classes.
  //
  // These should really be decoupled, with the class support added to Octave
  // and the shadow class given by an m-file script. That would dramatically 
  // reduce the runtime complexity, and be more in line w/ other modules.

  class octave_swig_type:public octave_base_value {
    struct cpp_ptr {
      void *ptr;
      bool destroyed;
      cpp_ptr(void *_ptr):ptr(_ptr), destroyed(false) {
      }};
    typedef std::pair < const swig_type_info *, cpp_ptr > type_ptr_pair;

    mutable swig_module_info *module;

    const swig_type_info *construct_type;	// type of special type object
    std::vector < type_ptr_pair > types;	// our c++ base classes
    int thisown; // whether we call c++ destructors when we die

    typedef std::pair < const swig_octave_member *, octave_value > member_value_pair;
    typedef std::map < std::string, member_value_pair > member_map;
    member_map members;
    bool always_static;

    const swig_octave_member *find_member(const swig_type_info *type, const std::string &name) {
      if (!type->clientdata)
	return 0;
      swig_octave_class *c = (swig_octave_class *) type->clientdata;
      const swig_octave_member *m;
      for (m = c->members; m->name; ++m)
	if (m->name == name)
	  return m;
      for (int j = 0; c->base_names[j]; ++j) {
	if (!c->base[j]) {
	  if (!module)
	    module = SWIG_GetModule(0);
	  assert(module);
	  c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]);
	}
	if (!c->base[j])
	  return 0;
	if ((m = find_member(c->base[j], name)))
	  return m;
      }
      return 0;
    }

    member_value_pair *find_member(const std::string &name, bool insert_if_not_found) {
      member_map::iterator it = members.find(name);
      if (it != members.end())
	return &it->second;
      const swig_octave_member *m;
      for (unsigned int j = 0; j < types.size(); ++j)
	if ((m = find_member(types[j].first, name)))
	  return &members.insert(std::make_pair(name, std::make_pair(m, octave_value()))).first->second;
      if (!insert_if_not_found)
	return 0;
      return &members[name];
    }

    const swig_type_info *find_base(const std::string &name, const swig_type_info *base) {
      if (!base) {
	for (unsigned int j = 0; j < types.size(); ++j) {
	  assert(types[j].first->clientdata);
	  swig_octave_class *cj = (swig_octave_class *) types[j].first->clientdata;
	  if (cj->name == name)
	    return types[j].first;
	}
	return 0;
      }
      assert(base->clientdata);
      swig_octave_class *c = (swig_octave_class *) base->clientdata;
      for (int j = 0; c->base_names[j]; ++j) {
	if (!c->base[j]) {
	  if (!module)
	    module = SWIG_GetModule(0);
	  assert(module);
	  c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]);
	}
	if (!c->base[j])
	  return 0;
	assert(c->base[j]->clientdata);
	swig_octave_class *cj = (swig_octave_class *) c->base[j]->clientdata;
	if (cj->name == name)
	  return c->base[j];
      }
      return 0;
    }

    void load_members(const swig_octave_class* c,member_map& out) const {
      for (const swig_octave_member *m = c->members; m->name; ++m) {
	if (out.find(m->name) == out.end())
	  out.insert(std::make_pair(m->name, std::make_pair(m, octave_value())));
      }
      for (int j = 0; c->base_names[j]; ++j) {
	if (!c->base[j]) {
	  if (!module)
	    module = SWIG_GetModule(0);
	  assert(module);
	  c->base[j] = SWIG_MangledTypeQueryModule(module, module, c->base_names[j]);
	}
	if (!c->base[j])
	  continue;
	assert(c->base[j]->clientdata);
	const swig_octave_class *cj =
	  (const swig_octave_class *) c->base[j]->clientdata;
	load_members(cj,out);
      }
    }

    void load_members(member_map& out) const {
      out=members;
      for (unsigned int j = 0; j < types.size(); ++j)
	if (types[j].first->clientdata)
	  load_members((const swig_octave_class *) types[j].first->clientdata, out);
    }

    octave_value_list member_invoke(member_value_pair *m, const octave_value_list &args, int nargout) {
      if (m->second.is_defined())
	return m->second.subsref("(", std::list < octave_value_list > (1, args), nargout);
      else if (m->first && m->first->method)
	return m->first->method(args, nargout);
      error("member not defined or not invocable");
      return octave_value_list();
    }

    bool dispatch_unary_op(const std::string &symbol, octave_value &ret) const {
      octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
      member_value_pair *m = nc_this->find_member(symbol, false);
      if (!m || m->first->is_static() || m->first->is_global())
	return false;
      octave_value_list args;
      args.append(nc_this->as_value());
      octave_value_list argout(nc_this->member_invoke(m, args, 1));
      if (argout.length() < 1)
	return false;
      ret = argout(0);
      return true;
    }

    bool dispatch_binary_op(const std::string &symbol, const octave_base_value &rhs, octave_value &ret) const {
      octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
      member_value_pair *m = nc_this->find_member(symbol, false);
      if (!m || m->first->is_static() || m->first->is_global())
	return false;
      octave_value_list args;
      args.append(nc_this->as_value());
      args.append(make_value_hack(rhs));
      octave_value_list argout(nc_this->member_invoke(m, args, 1));
      if (argout.length() < 1)
	return false;
      ret = argout(0);
      return true;
    }

    bool dispatch_index_op(const std::string &symbol, const octave_value_list &rhs, octave_value_list &ret) const {
      octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
      member_value_pair *m = nc_this->find_member(symbol, false);
      if (!m || m->first->is_static() || m->first->is_global())
	return false;
      octave_value_list args;
      args.append(nc_this->as_value());
      args.append(rhs);
      octave_value_list argout(nc_this->member_invoke(m, args, 1));
      if (argout.length() >= 1)
	ret = argout(0);
      return true;
    }

    octave_value_list member_deref(member_value_pair *m, const octave_value_list &args) {
      if (m->second.is_defined()) {
        if (m->second.is_function() || m->second.is_function_handle()) {
          return SWIG_OCTAVE_BOUND_FUNC(m->second.function_value(), args);
        } else {
          return m->second;
        }
      } else if (m->first) {
	if (m->first->get_method)
	  return m->first->get_method(args, 1);
	else if (m->first->method)
          return SWIG_OCTAVE_BOUND_FUNC(new octave_builtin(m->first->method), args);
      }
      error("undefined member");
      return octave_value_list();
    }

    static octave_value make_value_hack(const octave_base_value &x) {
      ((octave_swig_type &) x).count++;
      return octave_value((octave_base_value *) &x);
    }

    octave_swig_type(const octave_swig_type &x);
    octave_swig_type &operator=(const octave_swig_type &rhs);
  public:

    octave_swig_type(void *_ptr = 0, const swig_type_info *_type = 0, int _own = 0,
		     bool _always_static = false)
      :	module(0), construct_type(_ptr ? 0 : _type), thisown(_own), 
      always_static(_always_static) {
      if (_type || _ptr)
	types.push_back(std::make_pair(_type, _ptr));
#ifdef SWIG_DIRECTORS
      if (_ptr) {
	Swig::Director *d = Swig::get_rtdir(_ptr);
	if (d)
	  Swig::swig_director_set_self(d, this);
      }
#endif
    }

    ~octave_swig_type() {
      if (thisown) {
	++count;
	for (unsigned int j = 0; j < types.size(); ++j) {
	  if (!types[j].first || !types[j].first->clientdata)
	    continue;
	  swig_octave_class *c = (swig_octave_class *) types[j].first->clientdata;
	  if (c->destructor && !types[j].second.destroyed && types[j].second.ptr) {
	    c->destructor(as_value(), 0);
	  }
	}
      }
#ifdef SWIG_DIRECTORS
      for (unsigned int j = 0; j < types.size(); ++j)
	Swig::erase_rtdir(types[j].second.ptr);
#endif
    }

    dim_vector dims(void) const {
      octave_value out;
      if (!dispatch_unary_op("__dims__", out))
        return dim_vector(1,1);

      // Return value should be cell or matrix of integers
#if SWIG_OCTAVE_PREREQ(4,4,0)
      if (out.iscell()) {
#else
      if (out.is_cell()) {
#endif
        const Cell & c=out.cell_value();
        int ndim = c.rows();
        if (ndim==1 && c.columns()!=1) ndim = c.columns();

        dim_vector d;
        d.resize(ndim < 2 ? 2 : ndim);
        d(0) = d(1) = 1;

        // Fill in dim_vector 
        for (int k=0;k<ndim;k++) {
          const octave_value& obj = c(k);
#if SWIG_OCTAVE_PREREQ(6,0,0)
          try {
            d.elem(k) = obj.int_value();
          }
          catch (octave::execution_exception& oee) {
            // __dims__ should return a cell filled with integers
            return dim_vector(1,1);
          }
#else
          d.elem(k) = obj.int_value();
          
          // __dims__ should return a cell filled with integers
          if (error_state) return dim_vector(1,1);
#endif
        }
        return d;
#if SWIG_OCTAVE_PREREQ(4,4,0)
      } else if (out.is_matrix_type() || out.isnumeric() ) {
#else
      } else if (out.is_matrix_type() || out.is_numeric_type() ) {
#endif
        if (out.rows()==1 || out.columns()==1) {
#if SWIG_OCTAVE_PREREQ(6,0,0)
           Array<int> a;
           try {
             a = out.int_vector_value();
           }
           catch (octave::execution_exception& oee) {
             return dim_vector(1,1);
           }
#else
           Array<int> a = out.int_vector_value();
           if (error_state) return dim_vector(1,1);
#endif
           dim_vector d;
           d.resize(a.numel() < 2 ? 2 : a.numel());
           d(0) = d(1) = 1;
           for (int k=0;k<a.numel();k++) {
              d.elem(k) = a(k);
           }
           return d;
        } else {
          return dim_vector(1,1);
        }
      } else {
        return dim_vector(1,1);
      }
    }

    octave_value as_value() {
      ++count;
      return Swig::swig_value_ref(this);
    }

    void incref() {
      ++count;
    }

    void decref() {
      if (!--count)
	delete this;
    }

    size_t swig_this() const {
      if (!types.size())
	return (size_t) this;
      return (size_t) types[0].second.ptr;
    }
    const char* help_text() const {
      if (!types.size())
	return 0;
      if (!types[0].first->clientdata)
	return 0;
      swig_octave_class *c = (swig_octave_class *) types[0].first->clientdata;
      return c->constructor_doc;
    }

    std::string swig_type_name() const {
      // * need some way to manually name subclasses.
      // * eg optional first arg to subclass(), or named_subclass()
      std::string ret;
      for (unsigned int j = 0; j < types.size(); ++j) {
	if (j)
	  ret += "_";
	if (types[j].first->clientdata) {
	  swig_octave_class *c = (swig_octave_class *) types[j].first->clientdata;
	  ret += c->name;
	} else
	  ret += types[j].first->name;
      }
      return ret;
    }

    void merge(octave_swig_type &rhs) {
      rhs.thisown = 0;
      for (unsigned int j = 0; j < rhs.types.size(); ++j) {
	assert(!rhs.types[j].second.destroyed);
#ifdef SWIG_DIRECTORS
	Swig::Director *d = Swig::get_rtdir(rhs.types[j].second.ptr);
	if (d)
	  Swig::swig_director_set_self(d, this);
#endif
      }
      types.insert(types.end(), rhs.types.begin(), rhs.types.end());
      members.insert(rhs.members.begin(), rhs.members.end());
#if SWIG_OCTAVE_PREREQ(4,4,0)
      assign(rhs.swig_type_name(), rhs.as_value());
#else
      rhs.types.clear();
      rhs.members.clear();
#endif
    }

    typedef member_map::const_iterator swig_member_const_iterator;
    swig_member_const_iterator swig_members_begin() { return members.begin(); }
    swig_member_const_iterator swig_members_end() { return members.end(); }

    int cast(void **vptr, swig_type_info *type, int *own, int flags) {
      int res = SWIG_ERROR;
      int clear_pointer = 0;

      if (own)
	*own = 0;
      if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !thisown) {
	return SWIG_ERROR_RELEASE_NOT_OWNED;
      } else {
	if (own)
	  *own = *own | thisown;
	if (flags & SWIG_POINTER_DISOWN) {
	  thisown = 0;
	}
	if (flags & SWIG_POINTER_CLEAR) {
	  clear_pointer = 1;
	}
      }

      if (!type && types.size()) {
	if (vptr) {
          *vptr = types[0].second.ptr;
	  if (clear_pointer)
	    types[0].second.ptr = 0;
        }
        return SWIG_OK;
      }
      for (unsigned int j = 0; j < types.size(); ++j)
	if (type == types[j].first) {
	  if (vptr) {
            *vptr = types[j].second.ptr;
	    if (clear_pointer)
	      types[j].second.ptr = 0;
	  }
          return SWIG_OK;
        }
      for (unsigned int j = 0; j < types.size(); ++j) {
	swig_cast_info *tc = SWIG_TypeCheck(types[j].first->name, type);
	if (!tc)
	  continue;
	if (vptr) {
	  int newmemory = 0;
	  *vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory);
	  if (newmemory == SWIG_CAST_NEW_MEMORY) {
	    assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
	    if (own)
	      *own = *own | SWIG_CAST_NEW_MEMORY;
	  }
	  if (clear_pointer)
	    types[j].second.ptr = 0;
        }
        res = SWIG_OK;
        break;
      }
      return res;
    }

    bool is_owned() const {
      return thisown;
    }

#ifdef SWIG_DIRECTORS
    void director_destroyed(Swig::Director *d) {
      bool found = false;
      for (unsigned int j = 0; j < types.size(); ++j) {
	Swig::Director *dj = Swig::get_rtdir(types[j].second.ptr);
	if (dj == d) {
	  types[j].second.destroyed = true;
	  found = true;
	}
      }
      assert(found);
    }
#endif

    void assign(const std::string &name, const octave_value &ov) {
      members[name] = std::make_pair((const swig_octave_member *) 0, ov);
    }

    void assign(const std::string &name, const swig_octave_member *m) {
      members[name] = std::make_pair(m, octave_value());
    }

    octave_base_value *clone() const {
      // pass-by-value is probably not desired, and is harder;
      // requires calling copy constructors of contained types etc.
      assert(0);
      *(int *) 0 = 0;
      return 0;
    }

    octave_base_value *empty_clone() const {
      return new octave_swig_type();
    }

    bool is_defined() const {
      return true;
    }

#if SWIG_OCTAVE_PREREQ(6,0,0)
    virtual bool isstruct() const {
#else
    virtual bool is_map() const {
#endif
      return true;
    }

    virtual octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx) {
      octave_value_list ovl = subsref(ops, idx, 1);
      return ovl.length()? ovl(0) : octave_value();
    }

    virtual octave_value_list subsref(const std::string &ops, const std::list < octave_value_list > &idx, int nargout) {
      assert(ops.size() > 0);
      assert(ops.size() == idx.size());

      std::list < octave_value_list >::const_iterator idx_it = idx.begin();
      int skip = 0;
      octave_value_list sub_ovl;

      // constructor invocation
      if (ops[skip] == '(' && construct_type) {
	assert(construct_type->clientdata);
	swig_octave_class *c = (swig_octave_class *) construct_type->clientdata;
	if (!c->constructor) {
	  error("cannot create instance");
	  return octave_value_list();
	}
	octave_value_list args;
	if (c->director)
	  args.append(Swig::swig_value_ref(new octave_swig_type(this, 0, 0)));
	args.append(*idx_it++);
	++skip;
	sub_ovl = c->constructor(args, nargout);
      }
      // member dereference or invocation
      else if (ops[skip] == '.') {
	std::string subname;
	const swig_type_info *base = 0;	// eg, a.base.base_cpp_mem
	for (;;) {
	  octave_value_list subname_ovl(*idx_it++);
	  ++skip;
	  assert(subname_ovl.length() == 1 && subname_ovl(0).is_string());
	  subname = subname_ovl(0).string_value();

	  const swig_type_info *next_base = find_base(subname, base);
	  if (!next_base || skip >= (int) ops.size() || ops[skip] != '.')
	    break;
	  base = next_base;
	}

	member_value_pair tmp, *m = &tmp;
	if (!base || !(m->first = find_member(base, subname)))
	  m = find_member(subname, false);
	if (!m) {
	  error("member not found");
	  return octave_value_list();
	}

	octave_value_list args;
	if (!always_static &&
	    (!m->first || (!m->first->is_static() && !m->first->is_global())))
	  args.append(as_value());
	if (skip < (int) ops.size() && ops[skip] == '(' && 
	    ((m->first && m->first->method) || m->second.is_function() || 
	     m->second.is_function_handle())) {
	  args.append(*idx_it++);
	  ++skip;
	  sub_ovl = member_invoke(m, args, nargout);
	} else {
	  sub_ovl = member_deref(m, args);
	}
      }
      // index operator
      else {
	if (ops[skip] == '(' || ops[skip] == '{') {
	  const char *op_name = ops[skip] == '(' ? "__paren__" : "__brace__";
	  octave_value_list args;
	  args.append(*idx_it++);
	  ++skip;
	  if (!dispatch_index_op(op_name, args, sub_ovl)) {
	    error("error evaluating index operator");
	    return octave_value_list();
	  }
	} else {
	  error("unsupported subsref");
	  return octave_value_list();
	}
      }

      if (skip >= (int) ops.size())
	return sub_ovl;
      if (sub_ovl.length() < 1) {
	error("bad subs ref");
	return octave_value_list();
      }
      return sub_ovl(0).next_subsref(nargout, ops, idx, skip);
    }

    octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs) {
      assert(ops.size() > 0);
      assert(ops.size() == idx.size());

      std::list < octave_value_list >::const_iterator idx_it = idx.begin();
      int skip = 0;

      if (ops.size() > 1) {
	std::list < octave_value_list >::const_iterator last = idx.end();
	--last;
	std::list < octave_value_list > next_idx(idx.begin(), last);
	octave_value next_ov = subsref(ops.substr(0, ops.size() - 1), next_idx);
	next_ov.subsasgn(ops.substr(ops.size() - 1), std::list < octave_value_list > (1, *last), rhs);
      }

      else if (ops[skip] == '(' || ops[skip] == '{') {
	const char *op_name = ops[skip] == '(' ? "__paren_asgn__" : "__brace_asgn__";
	member_value_pair *m = find_member(op_name, false);
	if (m) {
	  octave_value_list args;
	  args.append(as_value());
	  args.append(*idx_it);
	  args.append(rhs);
	  member_invoke(m, args, 1);
	} else
	  error("%s member not found", op_name);
      }

      else if (ops[skip] == '.') {
	octave_value_list subname_ovl(*idx_it++);
	++skip;
	assert(subname_ovl.length() == 1 &&subname_ovl(0).is_string());
	std::string subname = subname_ovl(0).string_value();

	member_value_pair *m = find_member(subname, true);
	if (!m->first || !m->first->set_method) {
	  m->first = 0;
	  m->second = rhs;
	} else if (m->first->set_method) {
	  octave_value_list args;
	  if (!m->first->is_static() && !m->first->is_global())
	    args.append(as_value());
	  args.append(rhs);
	  m->first->set_method(args, 1);
	} else
	  error("member not assignable");
      } else
	error("unsupported subsasgn");

      return as_value();
    }

#if SWIG_OCTAVE_PREREQ(4,4,0)
    virtual bool isobject() const {
#else
    virtual bool is_object() const {
#endif
      return true;
    }

    virtual bool is_string() const {
      octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
      return !!nc_this->find_member("__str__", false);
    }

    virtual std::string string_value(bool force = false) const {
      octave_value ret;
      if (!dispatch_unary_op("__str__", ret)) {
        error("__str__ method not defined");
        return std::string();
      }
      if (!ret.is_string()) {
	error("__str__ method did not return a string");
	return std::string();
      }
      return ret.string_value();
    }

    virtual double scalar_value(bool frc_str_conv = false) const {
      octave_value ret;
      if (!dispatch_unary_op("__float__", ret)) {
        error("__float__ method not defined");
      }
      return ret.scalar_value();
    }

#if SWIG_OCTAVE_PREREQ(4,2,0)
    virtual octave_value as_double(void) const {
      octave_value ret;
      if (!dispatch_unary_op("__float__", ret)) {
        error("__float__ method not defined");
      }
      return ret.as_double();
    }

    virtual octave_value as_single(void) const {
      octave_value ret;
      if (!dispatch_unary_op("__float__", ret)) {
        error("__float__ method not defined");
      }
      return ret.as_single();
    }
#endif

#if SWIG_OCTAVE_PREREQ(3,8,0)
    virtual octave_value map(octave_base_value::unary_mapper_t umap) const {
      const std::string opname = std::string("__") + octave_base_value::get_umap_name(umap) + std::string("__");
      octave_value ret;
      if (!dispatch_unary_op(opname, ret)) {
        error("%s", (opname + std::string(" method not found")).c_str());
        return octave_value();
      }
      return ret;
    }
#endif

#if SWIG_OCTAVE_PREREQ(3,3,52)
    virtual octave_map map_value() const {
      return octave_map();
    }
#else
    virtual Octave_map map_value() const {
      return Octave_map();
    }
#endif

    virtual string_vector map_keys() const {
      member_map tmp;
      load_members(tmp);

      string_vector keys(tmp.size());
      int k = 0;
      for (member_map::iterator it = tmp.begin(); it != tmp.end(); ++it)
	keys(k++) = it->first;

      return keys;
    }

    virtual bool save_ascii (std::ostream& os) {
      return true;
    }

    virtual bool load_ascii (std::istream& is) {
      return true;
    }

    virtual bool save_binary (std::ostream& os, bool& save_as_floats) {
      return true;
    }

    virtual bool load_binary (std::istream& is, bool swap, 
#if SWIG_OCTAVE_PREREQ(6,0,0)
			      octave::mach_info::float_format fmt) {
#else
                             oct_mach_info::float_format fmt) {
#endif
      return true;
    }

#if defined (HAVE_HDF5)
# if SWIG_OCTAVE_PREREQ(4,0,0)
    virtual bool
      save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) {
      return true;
    }

    virtual bool
      load_hdf5 (octave_hdf5_id loc_id, const char *name, bool have_h5giterate_bug) {
      return true;
    }
# else
    virtual bool
      save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) {
      return true;
    }

    virtual bool
      load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) {
      return true;
    }
# endif
#endif

    virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const {
      return string_value();
    }

    virtual octave_value convert_to_str_internal(bool pad, bool force, char type) const {
      return string_value();
    }

    static bool dispatch_global_op(const std::string &symbol, const octave_value_list &args, octave_value &ret) {
      // we assume that SWIG_op_prefix-prefixed functions are installed in global namespace
      // (rather than any module namespace).

      octave_function *fcn = is_valid_function(symbol, std::string(), false);
      if (!fcn)
	return false;
#if SWIG_OCTAVE_PREREQ(4,4,0)
      octave::tree_evaluator& tw = octave::interpreter::the_interpreter()->get_evaluator();
      octave_value_list retval = fcn->call(tw, 1, args);
      if (retval.length() == 1)
        ret = retval(0);
#else
      ret = fcn->do_multi_index_op(1, args)(0);
#endif
      return true;
    }

    static octave_value dispatch_unary_op(const octave_base_value &x, const char *op_name) {
      octave_swig_type *ost = Swig::swig_value_deref(x);
      assert(ost);

      octave_value ret;
      if (ost->dispatch_unary_op(std::string("__") + op_name + std::string("__"), ret))
	return ret;
      std::string symbol = SWIG_op_prefix + ost->swig_type_name() + "_" + op_name;
      octave_value_list args;
      args.append(make_value_hack(x));
      if (dispatch_global_op(symbol, args, ret))
	return ret;

      error("could not dispatch unary operator");
      return octave_value();
    }

    static octave_value dispatch_binary_op(const octave_base_value &lhs, const octave_base_value &rhs, const char *op_name) {
      octave_swig_type *lhs_ost = Swig::swig_value_deref(lhs);
      octave_swig_type *rhs_ost = Swig::swig_value_deref(rhs);

      octave_value ret;
      if (lhs_ost && lhs_ost->dispatch_binary_op(std::string("__") + op_name + std::string("__"), rhs, ret))
	return ret;
      if (rhs_ost) {
        if (strlen(op_name) == 2  && (op_name[1] == 't' || op_name[1] == 'e')) {
          if (op_name[0] == 'l' && rhs_ost->dispatch_binary_op(std::string("__g") + op_name[1] + std::string("__"), lhs, ret))
            return ret;
          if (op_name[0] == 'g' && rhs_ost->dispatch_binary_op(std::string("__l") + op_name[1] + std::string("__"), lhs, ret))
            return ret;
        }
        if (rhs_ost->dispatch_binary_op(std::string("__r") + op_name + std::string("__"), lhs, ret))
          return ret;
      }

      std::string symbol;
      octave_value_list args;
      args.append(make_value_hack(lhs));
      args.append(make_value_hack(rhs));

      symbol = SWIG_op_prefix;
      symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name();
      symbol += "_";
      symbol += op_name;
      symbol += "_";
      symbol += rhs_ost ? rhs_ost->swig_type_name() : rhs.type_name();
      if (dispatch_global_op(symbol, args, ret))
	return ret;

      symbol = SWIG_op_prefix;
      symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name();
      symbol += "_";
      symbol += op_name;
      symbol += "_";
      symbol += "any";
      if (dispatch_global_op(symbol, args, ret))
	return ret;

      symbol = SWIG_op_prefix;
      symbol += "any";
      symbol += "_";
      symbol += op_name;
      symbol += "_";
      symbol += rhs_ost ? rhs_ost->swig_type_name() : rhs.type_name();
      if (dispatch_global_op(symbol, args, ret))
	return ret;

      error("could not dispatch binary operator");
      return octave_value();
    }

#if SWIG_OCTAVE_PREREQ(4,0,0)
    void print(std::ostream &os, bool pr_as_read_syntax = false)
#else
    void print(std::ostream &os, bool pr_as_read_syntax = false) const
#endif
    {
      if (is_string()) {
	os << string_value();
	return;
      }

      member_map tmp;
      load_members(tmp);

      indent(os);
      os << "{"; newline(os);
      increment_indent_level();
      for (unsigned int j = 0; j < types.size(); ++j) {
        indent(os);
	if (types[j].first->clientdata) {
	  const swig_octave_class *c = (const swig_octave_class *) types[j].first->clientdata;
	  os << c->name << ", ptr = " << types[j].second.ptr; newline(os);
	} else {
	  os << types[j].first->name << ", ptr = " << types[j].second.ptr; newline(os);
	}
      }
      for (member_map::const_iterator it = tmp.begin(); it != tmp.end(); ++it) {
        indent(os);
	if (it->second.first) {
	  const char *objtype = it->second.first->method ? "method" : "variable";
	  const char *modifier = (it->second.first->flags &1) ? "static " : (it->second.first->flags &2) ? "global " : "";
	  os << it->second.first->name << " (" << modifier << objtype << ")"; newline(os);
	  assert(it->second.first->name == it->first);
	} else {
	  os << it->first; newline(os);
	}
      }
      decrement_indent_level();
      indent(os);
      os << "}"; newline(os);
    }
  };

  // Octave tries hard to preserve pass-by-value semantics. Eg, assignments
  // will call clone() via make_unique() if there is more than one outstanding 
  // reference to the lhs, and forces the clone's reference count to 1 
  // (so you can't just increment your own count and return this).
  //
  // One way to fix this (without modifying Octave) is to add a level of
  // indirection such that clone copies ref-counted pointer and we keep 
  // pass-by-ref semantics (which are more natural/expected for C++ bindings).
  //
  // Supporting both pass-by-{ref,value} and toggling via %feature/option 
  // might be nice.

  class octave_swig_ref:public octave_base_value {
    octave_swig_type *ptr;
  public:
    octave_swig_ref(octave_swig_type *_ptr = 0)
      :ptr(_ptr)
      {
        // Ensure type_id() is set correctly
        if (t_id == -1) {
          t_id = octave_swig_ref::static_type_id();
        }
      }

    ~octave_swig_ref()
      { if (ptr) ptr->decref(); }

    octave_swig_type *get_ptr() const
      { return ptr; }

    octave_base_value *clone() const
      { if (ptr) ptr->incref(); return new octave_swig_ref(ptr); }

    octave_base_value *empty_clone() const
      { return new octave_swig_ref(0); }

    dim_vector dims(void) const 
      { return ptr->dims(); }

    bool is_defined() const
      { return ptr->is_defined(); }

#if SWIG_OCTAVE_PREREQ(6,0,0)
    virtual bool isstruct() const
      { return ptr->isstruct(); }
#else
    virtual bool is_map() const 
      { return ptr->is_map(); }
#endif

    virtual octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx) 
      { return ptr->subsref(ops, idx); }

    virtual octave_value_list subsref(const std::string &ops, const std::list < octave_value_list > &idx, int nargout)
      { return ptr->subsref(ops, idx, nargout); }

    octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs)
      { return ptr->subsasgn(ops, idx, rhs); }

#if SWIG_OCTAVE_PREREQ(4,4,0)
    virtual bool isobject() const
      { return ptr->isobject(); }
#else
    virtual bool is_object() const 
      { return ptr->is_object(); }
#endif

    virtual bool is_string() const 
      { return ptr->is_string(); }

    virtual std::string string_value(bool force = false) const 
      { return ptr->string_value(force); }

    virtual double scalar_value(bool frc_str_conv = false) const
      { return ptr->scalar_value(frc_str_conv); }

#if SWIG_OCTAVE_PREREQ(4,2,0)
    virtual octave_value as_double(void) const
      { return ptr->as_double(); }

    virtual octave_value as_single(void) const
      { return ptr->as_single(); }
#endif

#if SWIG_OCTAVE_PREREQ(3,8,0)
    virtual octave_value map(octave_base_value::unary_mapper_t umap) const
      { return ptr->map(umap); }
#endif

#if SWIG_OCTAVE_PREREQ(3,3,52)
    virtual octave_map map_value() const
      { return ptr->map_value(); }
#else
    virtual Octave_map map_value() const
      { return ptr->map_value(); }
#endif

    virtual string_vector map_keys() const
      { return ptr->map_keys(); }

    virtual bool save_ascii (std::ostream& os)
      { return ptr->save_ascii(os); }

    virtual bool load_ascii (std::istream& is)
      { return ptr->load_ascii(is); }

    virtual bool save_binary (std::ostream& os, bool& save_as_floats)
      { return ptr->save_binary(os, save_as_floats); }

    virtual bool load_binary (std::istream& is, bool swap, 
#if SWIG_OCTAVE_PREREQ(6,0,0)
			      octave::mach_info::float_format fmt)
#else
                             oct_mach_info::float_format fmt)
#endif
      { return ptr->load_binary(is, swap, fmt); }

#if defined (HAVE_HDF5)
# if SWIG_OCTAVE_PREREQ(4,0,0)
    virtual bool
      save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats)
      { return ptr->save_hdf5(loc_id, name, save_as_floats); }

    virtual bool
      load_hdf5 (octave_hdf5_id loc_id, const char *name, bool have_h5giterate_bug)
      { return ptr->load_hdf5(loc_id, name, have_h5giterate_bug); }
# else
    virtual bool
      save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats)
      { return ptr->save_hdf5(loc_id, name, save_as_floats); }

    virtual bool
      load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug)
      { return ptr->load_hdf5(loc_id, name, have_h5giterate_bug); }
# endif
#endif

    virtual octave_value convert_to_str(bool pad = false, bool force = false, char type = '"') const
      { return ptr->convert_to_str(pad, force, type); }

    virtual octave_value convert_to_str_internal(bool pad, bool force, char type) const
      { return ptr->convert_to_str_internal(pad, force, type); }

#if SWIG_OCTAVE_PREREQ(4,0,0)
    void print(std::ostream &os, bool pr_as_read_syntax = false)
#else
    void print(std::ostream &os, bool pr_as_read_syntax = false) const
#endif
      { return ptr->print(os, pr_as_read_syntax); }

#if SWIG_OCTAVE_PREREQ(4,4,0)
      static void set_type_id(int type_id) { t_id=type_id; }
#endif

    virtual type_conv_info numeric_conversion_function(void) const {
      return octave_base_value::type_conv_info (default_numeric_conversion_function,
                                                octave_scalar::static_type_id ());
    }

  private:
    static octave_base_value *default_numeric_conversion_function (const octave_base_value& a) {
      const octave_swig_ref& v = dynamic_cast<const octave_swig_ref&>(a);
      return new octave_scalar(v.scalar_value());
    }

#if !SWIG_OCTAVE_PREREQ(4,0,0)
    DECLARE_OCTAVE_ALLOCATOR;
#endif
    DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;
  };
#if !SWIG_OCTAVE_PREREQ(4,0,0)
  DEFINE_OCTAVE_ALLOCATOR(octave_swig_ref);
#endif
  DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_ref, "swig_ref", "swig_ref");

  class octave_swig_packed:public octave_base_value {
    swig_type_info *type;
    std::vector < char > buf;
  public:

    octave_swig_packed(swig_type_info *_type = 0, const void *_buf = 0, size_t _buf_len = 0)
      :	type(_type), buf((const char*)_buf, (const char*)_buf + _buf_len)
      {
        // Ensure type_id() is set correctly
        if (t_id == -1) {
          t_id = octave_swig_packed::static_type_id();
        }
      }

    bool copy(swig_type_info *outtype, void *ptr, size_t sz) const {
      if (outtype && outtype != type)
	return false;
      assert(sz <= buf.size());
      std::copy(buf.begin(), buf.begin()+sz, (char*)ptr);
      return true;
    }

    octave_base_value *clone() const {
      return new octave_swig_packed(*this);
    }

    octave_base_value *empty_clone() const {
      return new octave_swig_packed();
    }

    bool is_defined() const {
      return true;
    }

#if SWIG_OCTAVE_PREREQ(4,0,0)
    void print(std::ostream &os, bool pr_as_read_syntax = false)
#else
    void print(std::ostream &os, bool pr_as_read_syntax = false) const
#endif
    {
      indent(os);
      os << "swig packed type: name = " << (type ? type->name : std::string()) << ", len = " << buf.size(); newline(os);
    }


    virtual bool save_ascii (std::ostream& os) {
      return true;
    }

    virtual bool load_ascii (std::istream& is) {
      return true;
    }

    virtual bool save_binary (std::ostream& os, bool& save_as_floats) {
      return true;
    }

    virtual bool load_binary (std::istream& is, bool swap, 
#if SWIG_OCTAVE_PREREQ(6,0,0)
			      octave::mach_info::float_format fmt) {
#else
                             oct_mach_info::float_format fmt) {
#endif
      return true;
    }

#if defined (HAVE_HDF5)
# if SWIG_OCTAVE_PREREQ(4,0,0)
    virtual bool
      save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) {
      return true;
    }

    virtual bool
      load_hdf5 (octave_hdf5_id loc_id, const char *name, bool have_h5giterate_bug) {
      return true;
    }
# else
    virtual bool
      save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) {
      return true;
    }

    virtual bool
      load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug) {
      return true;
    }
# endif
#endif

#if SWIG_OCTAVE_PREREQ(4,4,0)
    static void set_type_id(int type_id) { t_id=type_id; }
#endif

  private:
#if !SWIG_OCTAVE_PREREQ(4,0,0)
    DECLARE_OCTAVE_ALLOCATOR;
#endif
    DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;
  };
#if !SWIG_OCTAVE_PREREQ(4,0,0)
  DEFINE_OCTAVE_ALLOCATOR(octave_swig_packed);
#endif
  DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_packed, "swig_packed", "swig_packed");

  SWIGRUNTIME octave_value_list octave_set_immutable(const octave_value_list &args, int nargout) {
    error("attempt to set immutable member variable");
    return octave_value_list();
  }

  struct octave_value_ref {
    const octave_value_list &ovl;
    int j;

    octave_value_ref(const octave_value_list &_ovl, int _j)
      :ovl(_ovl), j(_j) { }

    operator  octave_value() const {
      return ovl(j);
    }

    octave_value operator*() const {
      return ovl(j);
    }
  };


namespace Swig {

  SWIGRUNTIME octave_base_value *swig_value_ref(octave_swig_type *ost) {
    return new octave_swig_ref(ost);
  }

  SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov) {
    if (
#if SWIG_OCTAVE_PREREQ(4,4,0)
      ov.iscell()
#else
      ov.is_cell()
#endif
      && ov.rows() == 1 && ov.columns() == 1)
      ov = ov.cell_value()(0);
    return swig_value_deref(*ov.internal_rep());
  }

  SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov) {
    if (ov.type_id() != octave_swig_ref::static_type_id())
      return 0;
    const octave_swig_ref *osr = static_cast < const octave_swig_ref *>(&ov);
    return osr->get_ptr();
  }

}


#define swig_unary_op(name) \
SWIGRUNTIME octave_value swig_unary_op_##name(const octave_base_value &x) { \
  return octave_swig_type::dispatch_unary_op(x,#name); \
}
#define swig_binary_op(name) \
SWIGRUNTIME octave_value swig_binary_op_##name(const octave_base_value&lhs,const octave_base_value &rhs) { \
  return octave_swig_type::dispatch_binary_op(lhs,rhs,#name); \
}
#if SWIG_OCTAVE_PREREQ(4,4,0)
#define swigreg_unary_op(name) \
if (!octave_value_typeinfo::lookup_unary_op(octave_value::op_##name,tid)) \
typeinfo.register_unary_op(octave_value::op_##name,tid,swig_unary_op_##name);
#else
#define swigreg_unary_op(name) \
if (!octave_value_typeinfo::lookup_unary_op(octave_value::op_##name,tid)) \
octave_value_typeinfo::register_unary_op(octave_value::op_##name,tid,swig_unary_op_##name);
#endif
#if SWIG_OCTAVE_PREREQ(4,4,0)
#define swigreg_binary_op(name) \
if (!octave_value_typeinfo::lookup_binary_op(octave_value::op_##name,tid1,tid2)) \
typeinfo.register_binary_op(octave_value::op_##name,tid1,tid2,swig_binary_op_##name);
#else
#define swigreg_binary_op(name) \
if (!octave_value_typeinfo::lookup_binary_op(octave_value::op_##name,tid1,tid2)) \
octave_value_typeinfo::register_binary_op(octave_value::op_##name,tid1,tid2,swig_binary_op_##name);
#endif

  swig_unary_op(not);
  swig_unary_op(uplus);
  swig_unary_op(uminus);
  swig_unary_op(transpose);
  swig_unary_op(hermitian);
  swig_unary_op(incr);
  swig_unary_op(decr);

  swig_binary_op(add);
  swig_binary_op(sub);
  swig_binary_op(mul);
  swig_binary_op(div);
  swig_binary_op(pow);
  swig_binary_op(ldiv);
#if !SWIG_OCTAVE_PREREQ(4,2,0)
  swig_binary_op(lshift);
  swig_binary_op(rshift);
#endif
  swig_binary_op(lt);
  swig_binary_op(le);
  swig_binary_op(eq);
  swig_binary_op(ge);
  swig_binary_op(gt);
  swig_binary_op(ne);
  swig_binary_op(el_mul);
  swig_binary_op(el_div);
  swig_binary_op(el_pow);
  swig_binary_op(el_ldiv);
  swig_binary_op(el_and);
  swig_binary_op(el_or);

  SWIGRUNTIME void SWIG_InstallUnaryOps(int tid) {
#if SWIG_OCTAVE_PREREQ(4,4,0)
    octave::type_info& typeinfo = octave::interpreter::the_interpreter()->get_type_info();
#endif
    swigreg_unary_op(not);
    swigreg_unary_op(uplus);
    swigreg_unary_op(uminus);
    swigreg_unary_op(transpose);
    swigreg_unary_op(hermitian);
    swigreg_unary_op(incr);
    swigreg_unary_op(decr);
  }
  SWIGRUNTIME void SWIG_InstallBinaryOps(int tid1, int tid2) {
#if SWIG_OCTAVE_PREREQ(4,4,0)
    octave::type_info& typeinfo = octave::interpreter::the_interpreter()->get_type_info();
#endif
    swigreg_binary_op(add);
    swigreg_binary_op(sub);
    swigreg_binary_op(mul);
    swigreg_binary_op(div);
    swigreg_binary_op(pow);
    swigreg_binary_op(ldiv);
#if !SWIG_OCTAVE_PREREQ(4,2,0)
    swigreg_binary_op(lshift);
    swigreg_binary_op(rshift);
#endif
    swigreg_binary_op(lt);
    swigreg_binary_op(le);
    swigreg_binary_op(eq);
    swigreg_binary_op(ge);
    swigreg_binary_op(gt);
    swigreg_binary_op(ne);
    swigreg_binary_op(el_mul);
    swigreg_binary_op(el_div);
    swigreg_binary_op(el_pow);
    swigreg_binary_op(el_ldiv);
    swigreg_binary_op(el_and);
    swigreg_binary_op(el_or);
  }
  SWIGRUNTIME void SWIG_InstallOps(int tid) {
    // here we assume that tid are conseq integers increasing from zero, and 
    // that our tid is the last one. might be better to have explicit string 
    // list of types we should bind to, and use lookup_type to resolve their tid.

    SWIG_InstallUnaryOps(tid);
    SWIG_InstallBinaryOps(tid, tid);
    for (int j = 0; j < tid; ++j) {
      SWIG_InstallBinaryOps(j, tid);
      SWIG_InstallBinaryOps(tid, j);
    }
  }

SWIGRUNTIME octave_value SWIG_Octave_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
  int own = (flags &SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;

  if (ptr) {
#ifdef SWIG_DIRECTORS
    Swig::Director *d = Swig::get_rtdir(ptr);
    if (d && Swig::swig_director_get_self(d))
      return Swig::swig_director_get_self(d)->as_value();
#endif
    return Swig::swig_value_ref(new octave_swig_type(ptr, type, own));
  }
  return octave_value(Matrix()); // null matrix
}

SWIGRUNTIME int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void **ptr, swig_type_info *type, int flags, int *own) {
    if (
#if SWIG_OCTAVE_PREREQ(4,4,0)
      ov.iscell()
#else
      ov.is_cell()
#endif
      && ov.rows() == 1 && ov.columns() == 1)
    ov = ov.cell_value()(0);
  if (!ov.is_defined() ||
      (ov.is_matrix_type() && ov.rows() == 0 && ov.columns() == 0) ) {
    if (ptr)
      *ptr = 0;
    return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
  }
  if (ov.type_id() != octave_swig_ref::static_type_id())
    return SWIG_ERROR;
  octave_swig_ref *osr = static_cast < octave_swig_ref *>(ov.internal_rep());
  octave_swig_type *ost = osr->get_ptr();
  return ost->cast(ptr, type, own, flags);
}

SWIGRUNTIME octave_value SWIG_Octave_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
  return new octave_swig_packed(type, (char *) ptr, sz);
}

SWIGRUNTIME int SWIG_Octave_ConvertPacked(const octave_value &ov, void *ptr, size_t sz, swig_type_info *type) {
  if (!ov.is_defined())
    return SWIG_ERROR;
  if (ov.type_id() != octave_swig_packed::static_type_id())
    return SWIG_ERROR;
  octave_swig_packed *ost = static_cast < octave_swig_packed *>(ov.internal_rep());
  return ost->copy(type, (char *) ptr, sz) ? SWIG_OK : SWIG_ERROR;
}

SWIGRUNTIMEINLINE void SWIG_Octave_SetConstant(octave_swig_type *module_ns, const std::string &name, const octave_value &ov) {
  module_ns->assign(name, ov);
}

SWIGRUNTIMEINLINE octave_value SWIG_Octave_GetGlobalValue(std::string name) {
#if SWIG_OCTAVE_PREREQ(6,0,0)
  octave::interpreter *interp = octave::interpreter::the_interpreter ();
  return interp->global_varval(name);
#else
#if SWIG_OCTAVE_PREREQ(4,4,0)
  octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table();
  return symtab.global_varval(name);
#else
  return get_global_value(name, true);
#endif
#endif
}

SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value& value) {
#if SWIG_OCTAVE_PREREQ(6,0,0)
  octave::interpreter *interp = octave::interpreter::the_interpreter ();
  interp->global_assign(name, value);
#elif SWIG_OCTAVE_PREREQ(4,4,0)
  octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table();
  symtab.global_assign(name, value);
#else
  set_global_value(name, value);
#endif
}

SWIGRUNTIME void SWIG_Octave_LinkGlobalValue(std::string name) {
#if SWIG_OCTAVE_PREREQ(4,4,0)
  octave::symbol_scope symscope = octave::interpreter::the_interpreter()->get_current_scope();
#if SWIG_OCTAVE_PREREQ(6,0,0)
  octave::interpreter *interp = octave::interpreter::the_interpreter ();
  interp->assign(name, interp->global_varval(name));
// Updated on 2023-11-06 according to https://github.com/swig/swig/pull/2512/files
#if SWIG_OCTAVE_PREREQ(8,0,0)
  std::shared_ptr<octave::stack_frame> stackFrame = interp->get_evaluator().get_current_stack_frame();
#else
  octave::tree_evaluator& tree_eval = interp->get_evaluator();
  octave::call_stack& callStack = tree_eval.get_call_stack();
  std::shared_ptr<octave::stack_frame> stackFrame = callStack.get_current_stack_frame();
#endif
  octave::symbol_record sym=symscope.lookup_symbol(name);
  stackFrame->mark_global(sym);
#else
  octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table();
  symscope.assign(name, symtab.global_varval(name));
  symscope.mark_global(name);
#endif
#else
#if !SWIG_OCTAVE_PREREQ(3,2,0)
  link_to_global_variable(curr_sym_tab->lookup(name, true));
#else
#if !SWIG_OCTAVE_PREREQ(3,8,0)
  symbol_table::varref(name);
#endif
  symbol_table::mark_global(name);
#endif
#endif
}

SWIGRUNTIME swig_module_info *SWIG_Octave_GetModule(void *clientdata) {
  octave_value ov = SWIG_Octave_GetGlobalValue("__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION);
  if (!ov.is_defined() ||
      ov.type_id() != octave_swig_packed::static_type_id())
    return 0;
  const octave_swig_packed* osp = 
    static_cast < const octave_swig_packed *> (ov.internal_rep());
  swig_module_info *pointer = 0;
  osp->copy(0, &pointer, sizeof(swig_module_info *));
  return pointer;
}

SWIGRUNTIME void SWIG_Octave_SetModule(void *clientdata, swig_module_info *pointer) {
  octave_value ov = new octave_swig_packed(0, &pointer, sizeof(swig_module_info *));
  SWIG_Octave_SetGlobalValue("__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION, ov);
}


SWIGINTERN void SWIG_Octave_Raise(const octave_value &obj, const char *type) {
  if (obj.is_string())
    error("%s", obj.string_value().c_str());
  else
    error("C++ side threw an exception of type %s", type);
}



#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) 

#define SWIG_contract_assert(expr, msg) do { if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } } while (0) 



/* -------- TYPES TABLE (BEGIN) -------- */

#define SWIGTYPE_p_char swig_types[0]
static swig_type_info *swig_types[2];
static swig_module_info swig_module = {swig_types, 1, 0, 0, 0, 0};
#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)

/* -------- TYPES TABLE (END) -------- */


#ifdef __cplusplus
#include <utility>
/* SwigValueWrapper is described in swig.swg */
template<typename T> class SwigValueWrapper {
  struct SwigSmartPointer {
    T *ptr;
    SwigSmartPointer(T *p) : ptr(p) { }
    ~SwigSmartPointer() { delete ptr; }
    SwigSmartPointer& operator=(SwigSmartPointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
    void reset(T *p) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = p; }
  } pointer;
  SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
  SwigValueWrapper(const SwigValueWrapper<T>& rhs);
public:
  SwigValueWrapper() : pointer(0) { }
  SwigValueWrapper& operator=(const T& t) { SwigSmartPointer tmp(new T(t)); pointer = tmp; return *this; }
#if __cplusplus >=201103L
  SwigValueWrapper& operator=(T&& t) { SwigSmartPointer tmp(new T(std::move(t))); pointer = tmp; return *this; }
  operator T&&() const { return std::move(*pointer.ptr); }
#else
  operator T&() const { return *pointer.ptr; }
#endif
  T *operator&() const { return pointer.ptr; }
  static void reset(SwigValueWrapper& t, T *p) { t.pointer.reset(p); }
};

/*
 * SwigValueInit() is a generic initialisation solution as the following approach:
 * 
 *       T c_result = T();
 * 
 * doesn't compile for all types for example:
 * 
 *       unsigned int c_result = unsigned int();
 */
template <typename T> T SwigValueInit() {
  return T();
}

#if __cplusplus >=201103L
# define SWIG_STD_MOVE(OBJ) std::move(OBJ)
#else
# define SWIG_STD_MOVE(OBJ) OBJ
#endif

#endif


#define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) 
#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) 


#include <stdexcept>


#ifdef HAVE_SYS_SELECT_H
# undef HAVE_SYS_SELECT_H
#endif /* !HAVE_SYS_SELECT_H */
#include "lets_be_rational.h"


  SWIGINTERN int SWIG_AsVal_double (const octave_value& ov, double* val)
    {
      if (!ov.is_scalar_type())
	return SWIG_TypeError;
      if (ov.is_complex_scalar())
	return SWIG_TypeError;
      if (val)
	*val = ov.double_value();
      return SWIG_OK;
    }


  SWIGINTERNINLINE octave_value SWIG_From_double    (double value)
    {    
      return octave_value(value);
    }


SWIGINTERN swig_type_info*
SWIG_pchar_descriptor(void)
{
  static int init = 0;
  static swig_type_info* info = 0;
  if (!init) {
    info = SWIG_TypeQuery("_p_char");
    init = 1;
  }
  return info;
}


SWIGINTERNINLINE octave_value
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
  return std::string(carray,carray+size);
}


SWIGINTERNINLINE octave_value 
SWIG_FromCharPtr(const char *cptr)
{ 
  return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0));
}


  SWIGINTERNINLINE octave_value SWIG_From_long    (long value)
    {    
      return octave_value(value);
    }


SWIGINTERNINLINE octave_value
SWIG_From_int  (int value)
{    
  return SWIG_From_long  (value);
}

 namespace { inline const char* skip_path(const char* file_name) { return (const char*)std::max((uintptr_t)file_name, std::max((uintptr_t)strrchr(file_name, '/'), (uintptr_t)strrchr(file_name, '\\')) + 1); } } 

#ifdef HAVE_SYS_SELECT_H
//#error ERROR
#endif /* !HAVE_SYS_SELECT_H */


SWIG_DEFUN( Black, _wrap_Black, std::string() ) {
  double arg1 ;
  double arg2 ;
  double arg3 ;
  double arg4 ;
  double arg5 ;
  double val1 ;
  int ecode1 = 0 ;
  double val2 ;
  int ecode2 = 0 ;
  double val3 ;
  int ecode3 = 0 ;
  double val4 ;
  int ecode4 = 0 ;
  double val5 ;
  int ecode5 = 0 ;
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("Black",args.length(),5,5,0)) {
      SWIG_fail;
    }
    ecode1 = SWIG_AsVal_double(args(0), &val1);
    if (!SWIG_IsOK(ecode1)) {
      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "Black" "', argument " "1"" of type '" "double""'");
    } 
    arg1 = static_cast< double >(val1);
    ecode2 = SWIG_AsVal_double(args(1), &val2);
    if (!SWIG_IsOK(ecode2)) {
      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Black" "', argument " "2"" of type '" "double""'");
    } 
    arg2 = static_cast< double >(val2);
    ecode3 = SWIG_AsVal_double(args(2), &val3);
    if (!SWIG_IsOK(ecode3)) {
      SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Black" "', argument " "3"" of type '" "double""'");
    } 
    arg3 = static_cast< double >(val3);
    ecode4 = SWIG_AsVal_double(args(3), &val4);
    if (!SWIG_IsOK(ecode4)) {
      SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "Black" "', argument " "4"" of type '" "double""'");
    } 
    arg4 = static_cast< double >(val4);
    ecode5 = SWIG_AsVal_double(args(4), &val5);
    if (!SWIG_IsOK(ecode5)) {
      SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "Black" "', argument " "5"" of type '" "double""'");
    } 
    arg5 = static_cast< double >(val5);
    result = (double)Black(arg1,arg2,arg3,arg4,arg5);
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( NormalisedBlack, _wrap_NormalisedBlack, std::string() ) {
  double arg1 ;
  double arg2 ;
  double arg3 ;
  double val1 ;
  int ecode1 = 0 ;
  double val2 ;
  int ecode2 = 0 ;
  double val3 ;
  int ecode3 = 0 ;
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("NormalisedBlack",args.length(),3,3,0)) {
      SWIG_fail;
    }
    ecode1 = SWIG_AsVal_double(args(0), &val1);
    if (!SWIG_IsOK(ecode1)) {
      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "NormalisedBlack" "', argument " "1"" of type '" "double""'");
    } 
    arg1 = static_cast< double >(val1);
    ecode2 = SWIG_AsVal_double(args(1), &val2);
    if (!SWIG_IsOK(ecode2)) {
      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "NormalisedBlack" "', argument " "2"" of type '" "double""'");
    } 
    arg2 = static_cast< double >(val2);
    ecode3 = SWIG_AsVal_double(args(2), &val3);
    if (!SWIG_IsOK(ecode3)) {
      SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "NormalisedBlack" "', argument " "3"" of type '" "double""'");
    } 
    arg3 = static_cast< double >(val3);
    result = (double)NormalisedBlack(arg1,arg2,arg3);
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( ImpliedBlackVolatility, _wrap_ImpliedBlackVolatility, std::string() ) {
  double arg1 ;
  double arg2 ;
  double arg3 ;
  double arg4 ;
  double arg5 ;
  double val1 ;
  int ecode1 = 0 ;
  double val2 ;
  int ecode2 = 0 ;
  double val3 ;
  int ecode3 = 0 ;
  double val4 ;
  int ecode4 = 0 ;
  double val5 ;
  int ecode5 = 0 ;
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("ImpliedBlackVolatility",args.length(),5,5,0)) {
      SWIG_fail;
    }
    ecode1 = SWIG_AsVal_double(args(0), &val1);
    if (!SWIG_IsOK(ecode1)) {
      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "ImpliedBlackVolatility" "', argument " "1"" of type '" "double""'");
    } 
    arg1 = static_cast< double >(val1);
    ecode2 = SWIG_AsVal_double(args(1), &val2);
    if (!SWIG_IsOK(ecode2)) {
      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "ImpliedBlackVolatility" "', argument " "2"" of type '" "double""'");
    } 
    arg2 = static_cast< double >(val2);
    ecode3 = SWIG_AsVal_double(args(2), &val3);
    if (!SWIG_IsOK(ecode3)) {
      SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "ImpliedBlackVolatility" "', argument " "3"" of type '" "double""'");
    } 
    arg3 = static_cast< double >(val3);
    ecode4 = SWIG_AsVal_double(args(3), &val4);
    if (!SWIG_IsOK(ecode4)) {
      SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "ImpliedBlackVolatility" "', argument " "4"" of type '" "double""'");
    } 
    arg4 = static_cast< double >(val4);
    ecode5 = SWIG_AsVal_double(args(4), &val5);
    if (!SWIG_IsOK(ecode5)) {
      SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "ImpliedBlackVolatility" "', argument " "5"" of type '" "double""'");
    } 
    arg5 = static_cast< double >(val5);
    result = (double)ImpliedBlackVolatility(arg1,arg2,arg3,arg4,arg5);
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( NormalisedImpliedBlackVolatility, _wrap_NormalisedImpliedBlackVolatility, std::string() ) {
  double arg1 ;
  double arg2 ;
  double arg3 ;
  double val1 ;
  int ecode1 = 0 ;
  double val2 ;
  int ecode2 = 0 ;
  double val3 ;
  int ecode3 = 0 ;
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("NormalisedImpliedBlackVolatility",args.length(),3,3,0)) {
      SWIG_fail;
    }
    ecode1 = SWIG_AsVal_double(args(0), &val1);
    if (!SWIG_IsOK(ecode1)) {
      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "NormalisedImpliedBlackVolatility" "', argument " "1"" of type '" "double""'");
    } 
    arg1 = static_cast< double >(val1);
    ecode2 = SWIG_AsVal_double(args(1), &val2);
    if (!SWIG_IsOK(ecode2)) {
      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "NormalisedImpliedBlackVolatility" "', argument " "2"" of type '" "double""'");
    } 
    arg2 = static_cast< double >(val2);
    ecode3 = SWIG_AsVal_double(args(2), &val3);
    if (!SWIG_IsOK(ecode3)) {
      SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "NormalisedImpliedBlackVolatility" "', argument " "3"" of type '" "double""'");
    } 
    arg3 = static_cast< double >(val3);
    result = (double)NormalisedImpliedBlackVolatility(arg1,arg2,arg3);
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( ComplementaryNormalisedBlack, _wrap_ComplementaryNormalisedBlack, std::string() ) {
  double arg1 ;
  double arg2 ;
  double val1 ;
  int ecode1 = 0 ;
  double val2 ;
  int ecode2 = 0 ;
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("ComplementaryNormalisedBlack",args.length(),2,2,0)) {
      SWIG_fail;
    }
    ecode1 = SWIG_AsVal_double(args(0), &val1);
    if (!SWIG_IsOK(ecode1)) {
      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "ComplementaryNormalisedBlack" "', argument " "1"" of type '" "double""'");
    } 
    arg1 = static_cast< double >(val1);
    ecode2 = SWIG_AsVal_double(args(1), &val2);
    if (!SWIG_IsOK(ecode2)) {
      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "ComplementaryNormalisedBlack" "', argument " "2"" of type '" "double""'");
    } 
    arg2 = static_cast< double >(val2);
    result = (double)ComplementaryNormalisedBlack(arg1,arg2);
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( Vega, _wrap_Vega, std::string() ) {
  double arg1 ;
  double arg2 ;
  double arg3 ;
  double arg4 ;
  double val1 ;
  int ecode1 = 0 ;
  double val2 ;
  int ecode2 = 0 ;
  double val3 ;
  int ecode3 = 0 ;
  double val4 ;
  int ecode4 = 0 ;
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("Vega",args.length(),4,4,0)) {
      SWIG_fail;
    }
    ecode1 = SWIG_AsVal_double(args(0), &val1);
    if (!SWIG_IsOK(ecode1)) {
      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "Vega" "', argument " "1"" of type '" "double""'");
    } 
    arg1 = static_cast< double >(val1);
    ecode2 = SWIG_AsVal_double(args(1), &val2);
    if (!SWIG_IsOK(ecode2)) {
      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Vega" "', argument " "2"" of type '" "double""'");
    } 
    arg2 = static_cast< double >(val2);
    ecode3 = SWIG_AsVal_double(args(2), &val3);
    if (!SWIG_IsOK(ecode3)) {
      SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Vega" "', argument " "3"" of type '" "double""'");
    } 
    arg3 = static_cast< double >(val3);
    ecode4 = SWIG_AsVal_double(args(3), &val4);
    if (!SWIG_IsOK(ecode4)) {
      SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "Vega" "', argument " "4"" of type '" "double""'");
    } 
    arg4 = static_cast< double >(val4);
    result = (double)Vega(arg1,arg2,arg3,arg4);
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( NormalisedVega, _wrap_NormalisedVega, std::string() ) {
  double arg1 ;
  double arg2 ;
  double val1 ;
  int ecode1 = 0 ;
  double val2 ;
  int ecode2 = 0 ;
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("NormalisedVega",args.length(),2,2,0)) {
      SWIG_fail;
    }
    ecode1 = SWIG_AsVal_double(args(0), &val1);
    if (!SWIG_IsOK(ecode1)) {
      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "NormalisedVega" "', argument " "1"" of type '" "double""'");
    } 
    arg1 = static_cast< double >(val1);
    ecode2 = SWIG_AsVal_double(args(1), &val2);
    if (!SWIG_IsOK(ecode2)) {
      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "NormalisedVega" "', argument " "2"" of type '" "double""'");
    } 
    arg2 = static_cast< double >(val2);
    result = (double)NormalisedVega(arg1,arg2);
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( Volga, _wrap_Volga, std::string() ) {
  double arg1 ;
  double arg2 ;
  double arg3 ;
  double arg4 ;
  double val1 ;
  int ecode1 = 0 ;
  double val2 ;
  int ecode2 = 0 ;
  double val3 ;
  int ecode3 = 0 ;
  double val4 ;
  int ecode4 = 0 ;
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("Volga",args.length(),4,4,0)) {
      SWIG_fail;
    }
    ecode1 = SWIG_AsVal_double(args(0), &val1);
    if (!SWIG_IsOK(ecode1)) {
      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "Volga" "', argument " "1"" of type '" "double""'");
    } 
    arg1 = static_cast< double >(val1);
    ecode2 = SWIG_AsVal_double(args(1), &val2);
    if (!SWIG_IsOK(ecode2)) {
      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Volga" "', argument " "2"" of type '" "double""'");
    } 
    arg2 = static_cast< double >(val2);
    ecode3 = SWIG_AsVal_double(args(2), &val3);
    if (!SWIG_IsOK(ecode3)) {
      SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Volga" "', argument " "3"" of type '" "double""'");
    } 
    arg3 = static_cast< double >(val3);
    ecode4 = SWIG_AsVal_double(args(3), &val4);
    if (!SWIG_IsOK(ecode4)) {
      SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "Volga" "', argument " "4"" of type '" "double""'");
    } 
    arg4 = static_cast< double >(val4);
    result = (double)Volga(arg1,arg2,arg3,arg4);
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( NormalisedVolga, _wrap_NormalisedVolga, std::string() ) {
  double arg1 ;
  double arg2 ;
  double val1 ;
  int ecode1 = 0 ;
  double val2 ;
  int ecode2 = 0 ;
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("NormalisedVolga",args.length(),2,2,0)) {
      SWIG_fail;
    }
    ecode1 = SWIG_AsVal_double(args(0), &val1);
    if (!SWIG_IsOK(ecode1)) {
      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "NormalisedVolga" "', argument " "1"" of type '" "double""'");
    } 
    arg1 = static_cast< double >(val1);
    ecode2 = SWIG_AsVal_double(args(1), &val2);
    if (!SWIG_IsOK(ecode2)) {
      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "NormalisedVolga" "', argument " "2"" of type '" "double""'");
    } 
    arg2 = static_cast< double >(val2);
    result = (double)NormalisedVolga(arg1,arg2);
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( BlackAccuracyFactor, _wrap_BlackAccuracyFactor, std::string() ) {
  double arg1 ;
  double arg2 ;
  double arg3 ;
  double val1 ;
  int ecode1 = 0 ;
  double val2 ;
  int ecode2 = 0 ;
  double val3 ;
  int ecode3 = 0 ;
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("BlackAccuracyFactor",args.length(),3,3,0)) {
      SWIG_fail;
    }
    ecode1 = SWIG_AsVal_double(args(0), &val1);
    if (!SWIG_IsOK(ecode1)) {
      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "BlackAccuracyFactor" "', argument " "1"" of type '" "double""'");
    } 
    arg1 = static_cast< double >(val1);
    ecode2 = SWIG_AsVal_double(args(1), &val2);
    if (!SWIG_IsOK(ecode2)) {
      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "BlackAccuracyFactor" "', argument " "2"" of type '" "double""'");
    } 
    arg2 = static_cast< double >(val2);
    ecode3 = SWIG_AsVal_double(args(2), &val3);
    if (!SWIG_IsOK(ecode3)) {
      SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "BlackAccuracyFactor" "', argument " "3"" of type '" "double""'");
    } 
    arg3 = static_cast< double >(val3);
    result = (double)BlackAccuracyFactor(arg1,arg2,arg3);
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( ImpliedVolatilityAttainableAccuracy, _wrap_ImpliedVolatilityAttainableAccuracy, std::string() ) {
  double arg1 ;
  double arg2 ;
  double arg3 ;
  double val1 ;
  int ecode1 = 0 ;
  double val2 ;
  int ecode2 = 0 ;
  double val3 ;
  int ecode3 = 0 ;
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("ImpliedVolatilityAttainableAccuracy",args.length(),3,3,0)) {
      SWIG_fail;
    }
    ecode1 = SWIG_AsVal_double(args(0), &val1);
    if (!SWIG_IsOK(ecode1)) {
      SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "ImpliedVolatilityAttainableAccuracy" "', argument " "1"" of type '" "double""'");
    } 
    arg1 = static_cast< double >(val1);
    ecode2 = SWIG_AsVal_double(args(1), &val2);
    if (!SWIG_IsOK(ecode2)) {
      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "ImpliedVolatilityAttainableAccuracy" "', argument " "2"" of type '" "double""'");
    } 
    arg2 = static_cast< double >(val2);
    ecode3 = SWIG_AsVal_double(args(2), &val3);
    if (!SWIG_IsOK(ecode3)) {
      SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "ImpliedVolatilityAttainableAccuracy" "', argument " "3"" of type '" "double""'");
    } 
    arg3 = static_cast< double >(val3);
    result = (double)ImpliedVolatilityAttainableAccuracy(arg1,arg2,arg3);
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( DblEpsilon, _wrap_DblEpsilon, std::string() ) {
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("DblEpsilon",args.length(),0,0,0)) {
      SWIG_fail;
    }
    result = (double)DblEpsilon();
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( DblMin, _wrap_DblMin, std::string() ) {
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("DblMin",args.length(),0,0,0)) {
      SWIG_fail;
    }
    result = (double)DblMin();
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( DblMax, _wrap_DblMax, std::string() ) {
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  double result;
  
  try {
    if (!SWIG_check_num_args("DblMax",args.length(),0,0,0)) {
      SWIG_fail;
    }
    result = (double)DblMax();
    _outv = SWIG_From_double(static_cast< double >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( CPUName, _wrap_CPUName, std::string() ) {
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  char *result = 0 ;
  
  try {
    if (!SWIG_check_num_args("CPUName",args.length(),0,0,0)) {
      SWIG_fail;
    }
    result = (char *)CPUName();
    _outv = SWIG_FromCharPtr((const char *)result);
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}


SWIG_DEFUN( Revision, _wrap_Revision, std::string() ) {
  octave_value_list _out;
  octave_value_list *_outp=&_out;
  octave_value _outv;
  int result;
  
  try {
    if (!SWIG_check_num_args("Revision",args.length(),0,0,0)) {
      SWIG_fail;
    }
    result = (int)Revision();
    _outv = SWIG_From_int(static_cast< int >(result));
    if (_outv.is_defined()) _outp = SWIG_Octave_AppendOutput(_outp, _outv);
    return _out;
  fail:
    return octave_value_list();
  }
  catch(...) {
    throw;
  }
}



static const struct swig_octave_member swig_globals[] = {
{"Black",_wrap_Black,0,0,2,0},
{"NormalisedBlack",_wrap_NormalisedBlack,0,0,2,0},
{"ImpliedBlackVolatility",_wrap_ImpliedBlackVolatility,0,0,2,0},
{"NormalisedImpliedBlackVolatility",_wrap_NormalisedImpliedBlackVolatility,0,0,2,0},
{"ComplementaryNormalisedBlack",_wrap_ComplementaryNormalisedBlack,0,0,2,0},
{"Vega",_wrap_Vega,0,0,2,0},
{"NormalisedVega",_wrap_NormalisedVega,0,0,2,0},
{"Volga",_wrap_Volga,0,0,2,0},
{"NormalisedVolga",_wrap_NormalisedVolga,0,0,2,0},
{"BlackAccuracyFactor",_wrap_BlackAccuracyFactor,0,0,2,0},
{"ImpliedVolatilityAttainableAccuracy",_wrap_ImpliedVolatilityAttainableAccuracy,0,0,2,0},
{"DblEpsilon",_wrap_DblEpsilon,0,0,2,0},
{"DblMin",_wrap_DblMin,0,0,2,0},
{"DblMax",_wrap_DblMax,0,0,2,0},
{"CPUName",_wrap_CPUName,0,0,2,0},
{"Revision",_wrap_Revision,0,0,2,0},
{0,0,0,0,0,0}
};

/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */

static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0};

static swig_type_info *swig_type_initial[] = {
  &_swigt__p_char,
};

static swig_cast_info _swigc__p_char[] = {  {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}};

static swig_cast_info *swig_cast_initial[] = {
  _swigc__p_char,
};


/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */

/* -----------------------------------------------------------------------------
 * Type initialization:
 * This problem is tough by the requirement that no dynamic
 * memory is used. Also, since swig_type_info structures store pointers to
 * swig_cast_info structures and swig_cast_info structures store pointers back
 * to swig_type_info structures, we need some lookup code at initialization.
 * The idea is that swig generates all the structures that are needed.
 * The runtime then collects these partially filled structures.
 * The SWIG_InitializeModule function takes these initial arrays out of
 * swig_module, and does all the lookup, filling in the swig_module.types
 * array with the correct data and linking the correct swig_cast_info
 * structures together.
 *
 * The generated swig_type_info structures are assigned statically to an initial
 * array. We just loop through that array, and handle each type individually.
 * First we lookup if this type has been already loaded, and if so, use the
 * loaded structure instead of the generated one. Then we have to fill in the
 * cast linked list. The cast data is initially stored in something like a
 * two-dimensional array. Each row corresponds to a type (there are the same
 * number of rows as there are in the swig_type_initial array). Each entry in
 * a column is one of the swig_cast_info structures for that type.
 * The cast_initial array is actually an array of arrays, because each row has
 * a variable number of columns. So to actually build the cast linked list,
 * we find the array of casts associated with the type, and loop through it
 * adding the casts to the list. The one last trick we need to do is making
 * sure the type pointer in the swig_cast_info struct is correct.
 *
 * First off, we lookup the cast->type name to see if it is already loaded.
 * There are three cases to handle:
 *  1) If the cast->type has already been loaded AND the type we are adding
 *     casting info to has not been loaded (it is in this module), THEN we
 *     replace the cast->type pointer with the type pointer that has already
 *     been loaded.
 *  2) If BOTH types (the one we are adding casting info to, and the
 *     cast->type) are loaded, THEN the cast info has already been loaded by
 *     the previous module so we just ignore it.
 *  3) Finally, if cast->type has not already been loaded, then we add that
 *     swig_cast_info to the linked list (because the cast->type) pointer will
 *     be correct.
 * ----------------------------------------------------------------------------- */

#ifdef __cplusplus
extern "C" {
#if 0
} /* c-mode */
#endif
#endif

#if 0
#define SWIGRUNTIME_DEBUG
#endif

#ifndef SWIG_INIT_CLIENT_DATA_TYPE
#define SWIG_INIT_CLIENT_DATA_TYPE void *
#endif

SWIGRUNTIME void
SWIG_InitializeModule(SWIG_INIT_CLIENT_DATA_TYPE clientdata) {
  size_t i;
  swig_module_info *module_head, *iter;
  int init;

  /* check to see if the circular list has been setup, if not, set it up */
  if (swig_module.next==0) {
    /* Initialize the swig_module */
    swig_module.type_initial = swig_type_initial;
    swig_module.cast_initial = swig_cast_initial;
    swig_module.next = &swig_module;
    init = 1;
  } else {
    init = 0;
  }

  /* Try and load any already created modules */
  module_head = SWIG_GetModule(clientdata);
  if (!module_head) {
    /* This is the first module loaded for this interpreter */
    /* so set the swig module into the interpreter */
    SWIG_SetModule(clientdata, &swig_module);
  } else {
    /* the interpreter has loaded a SWIG module, but has it loaded this one? */
    iter=module_head;
    do {
      if (iter==&swig_module) {
        /* Our module is already in the list, so there's nothing more to do. */
        return;
      }
      iter=iter->next;
    } while (iter!= module_head);

    /* otherwise we must add our module into the list */
    swig_module.next = module_head->next;
    module_head->next = &swig_module;
  }

  /* When multiple interpreters are used, a module could have already been initialized in
     a different interpreter, but not yet have a pointer in this interpreter.
     In this case, we do not want to continue adding types... everything should be
     set up already */
  if (init == 0) return;

  /* Now work on filling in swig_module.types */
#ifdef SWIGRUNTIME_DEBUG
  printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size);
#endif
  for (i = 0; i < swig_module.size; ++i) {
    swig_type_info *type = 0;
    swig_type_info *ret;
    swig_cast_info *cast;

#ifdef SWIGRUNTIME_DEBUG
    printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
#endif

    /* if there is another module already loaded */
    if (swig_module.next != &swig_module) {
      type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
    }
    if (type) {
      /* Overwrite clientdata field */
#ifdef SWIGRUNTIME_DEBUG
      printf("SWIG_InitializeModule: found type %s\n", type->name);
#endif
      if (swig_module.type_initial[i]->clientdata) {
	type->clientdata = swig_module.type_initial[i]->clientdata;
#ifdef SWIGRUNTIME_DEBUG
      printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name);
#endif
      }
    } else {
      type = swig_module.type_initial[i];
    }

    /* Insert casting types */
    cast = swig_module.cast_initial[i];
    while (cast->type) {

      /* Don't need to add information already in the list */
      ret = 0;
#ifdef SWIGRUNTIME_DEBUG
      printf("SWIG_InitializeModule: look cast %s\n", cast->type->name);
#endif
      if (swig_module.next != &swig_module) {
        ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
#ifdef SWIGRUNTIME_DEBUG
	if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name);
#endif
      }
      if (ret) {
	if (type == swig_module.type_initial[i]) {
#ifdef SWIGRUNTIME_DEBUG
	  printf("SWIG_InitializeModule: skip old type %s\n", ret->name);
#endif
	  cast->type = ret;
	  ret = 0;
	} else {
	  /* Check for casting already in the list */
	  swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type);
#ifdef SWIGRUNTIME_DEBUG
	  if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name);
#endif
	  if (!ocast) ret = 0;
	}
      }

      if (!ret) {
#ifdef SWIGRUNTIME_DEBUG
	printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name);
#endif
        if (type->cast) {
          type->cast->prev = cast;
          cast->next = type->cast;
        }
        type->cast = cast;
      }
      cast++;
    }
    /* Set entry in modules->types array equal to the type */
    swig_module.types[i] = type;
  }
  swig_module.types[i] = 0;

#ifdef SWIGRUNTIME_DEBUG
  printf("**** SWIG_InitializeModule: Cast List ******\n");
  for (i = 0; i < swig_module.size; ++i) {
    int j = 0;
    swig_cast_info *cast = swig_module.cast_initial[i];
    printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
    while (cast->type) {
      printf("SWIG_InitializeModule: cast type %s\n", cast->type->name);
      cast++;
      ++j;
    }
  printf("---- Total casts: %d\n",j);
  }
  printf("**** SWIG_InitializeModule: Cast List ******\n");
#endif
}

/* This function will propagate the clientdata field of type to
* any new swig_type_info structures that have been added into the list
* of equivalent types.  It is like calling
* SWIG_TypeClientData(type, clientdata) a second time.
*/
SWIGRUNTIME void
SWIG_PropagateClientData(void) {
  size_t i;
  swig_cast_info *equiv;
  static int init_run = 0;

  if (init_run) return;
  init_run = 1;

  for (i = 0; i < swig_module.size; i++) {
    if (swig_module.types[i]->clientdata) {
      equiv = swig_module.types[i]->cast;
      while (equiv) {
        if (!equiv->converter) {
          if (equiv->type && !equiv->type->clientdata)
            SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);
        }
        equiv = equiv->next;
      }
    }
  }
}

#ifdef __cplusplus
#if 0
{ /* c-mode */
#endif
}
#endif



static bool SWIG_init_user(octave_swig_type* module_ns);

SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) {
  bool retn = false;
  {
#if SWIG_OCTAVE_PREREQ(6,0,0)
#elif SWIG_OCTAVE_PREREQ(4,2,0)
    octave::unwind_protect frame;
    frame.protect_var(discard_error_messages);          discard_error_messages = true;
    frame.protect_var(discard_warning_messages);        discard_warning_messages = true;
#elif SWIG_OCTAVE_PREREQ(3,3,50)
    unwind_protect frame;
    frame.protect_var(error_state);                     error_state = 0;
    frame.protect_var(warning_state);                   warning_state = 0;
    frame.protect_var(discard_error_messages);          discard_error_messages = true;
    frame.protect_var(discard_warning_messages);        discard_warning_messages = true;
#else
    unwind_protect::begin_frame("SWIG_Octave_LoadModule");
    unwind_protect_int(error_state);                    error_state = 0;
    unwind_protect_int(warning_state);                  warning_state = 0;
    unwind_protect_bool(discard_error_messages);        discard_error_messages = true;
    unwind_protect_bool(discard_warning_messages);      discard_warning_messages = true;
#endif
#if SWIG_OCTAVE_PREREQ(4,2,0)
    try {
#if SWIG_OCTAVE_PREREQ(4,4,0)
      octave::feval(name, octave_value_list(), 0);
#else
      feval(name, octave_value_list(), 0);
#endif
      retn = true;
    } catch (octave::execution_exception&) { }
#else
    feval(name, octave_value_list(), 0);
    retn = (error_state == 0);
#endif
#if !SWIG_OCTAVE_PREREQ(3,3,50)
    unwind_protect::run_frame("SWIG_Octave_LoadModule");
#endif
  }
  if (!retn) {
    error(SWIG_name_d ": could not load module `%s'", name.c_str());
  }
  return retn;
}

SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::string name) {
  bool retn = false;
  {
#if SWIG_OCTAVE_PREREQ(6,0,0)
#elif SWIG_OCTAVE_PREREQ(4,2,0)
    octave::unwind_protect frame;
    frame.protect_var(discard_error_messages);          discard_error_messages = true;
    frame.protect_var(discard_warning_messages);        discard_warning_messages = true;
#elif SWIG_OCTAVE_PREREQ(3,3,50)
    unwind_protect frame;
    frame.protect_var(error_state);                     error_state = 0;
    frame.protect_var(warning_state);                   warning_state = 0;
    frame.protect_var(discard_error_messages);          discard_error_messages = true;
    frame.protect_var(discard_warning_messages);        discard_warning_messages = true;
#else
    unwind_protect::begin_frame("SWIG_Octave_InstallFunction");
    unwind_protect_int(error_state);                    error_state = 0;
    unwind_protect_int(warning_state);                  warning_state = 0;
    unwind_protect_bool(discard_error_messages);        discard_error_messages = true;
    unwind_protect_bool(discard_warning_messages);      discard_warning_messages = true;
#endif
    octave_value_list args;
    args.append(name);
    args.append(octloadfcn->fcn_file_name());
#if SWIG_OCTAVE_PREREQ(4,2,0)
    try {
#if SWIG_OCTAVE_PREREQ(4,4,0)
      octave::feval("autoload", args, 0);
#else
      feval("autoload", args, 0);
#endif
      retn = true;
    } catch (octave::execution_exception&) { }
#else
    feval("autoload", args, 0);
    retn = (error_state == 0);
#endif
#if !SWIG_OCTAVE_PREREQ(3,3,50)
    unwind_protect::run_frame("SWIG_Octave_InstallFunction");
#endif
  }
  if (!retn) {
    error(SWIG_name_d ": could not load function `%s'", name.c_str());
  }
  return retn;
}

static const char *const subclass_usage = "-*- texinfo -*- \n\
@deftypefn {Loadable Function} {} subclass()\n\
@deftypefnx{Loadable Function} {} subclass(@var{swigclass}, @var{name}, @var{fcn}, @dots{})\n\
Subclass a C++ class from within Octave, and provide implementations of its virtual methods.\n\
\n\
See the SWIG manual for usage examples.\n\
@end deftypefn";

DEFUN_DLD( subclass, args, nargout, subclass_usage ) {
  octave_swig_type *top = new octave_swig_type;
  for (int j = 0; j < args.length(); ++j) {
    if (args(j).type_id() == octave_swig_ref::static_type_id()) {
      octave_swig_ref *osr = static_cast < octave_swig_ref *>(args(j).internal_rep());
      octave_swig_type *ost = osr->get_ptr();
      if (!ost->is_owned()) {
        error("subclass: cannot subclass object not constructed on octave side");
        return octave_value_list();
      }
      top->merge(*ost);
    } else if (args(j).is_function_handle()) {
      top->assign(args(j).fcn_handle_value()->fcn_name(), args(j));
    } else if (args(j).is_string()) {
      if (j + 1 >= args.length()) {
        error("subclass: member assignments must be of string,value form");
        return octave_value_list();
      }
      top->assign(args(j).string_value(), args(j + 1));
      ++j;
    } else {
      error("subclass: invalid arguments to subclass()");
      return octave_value_list();
    }
  }
  return octave_value(Swig::swig_value_ref(top));
}

static const char *const swig_type_usage = "-*- texinfo -*- \n\
@deftypefn {Loadable Function} {} swig_type(@var{swigref})\n\
Return the underlying C/C++ type name of a SWIG-wrapped object.\n\
@end deftypefn";

DEFUN_DLD( swig_type, args, nargout, swig_type_usage ) {
  if (args.length() != 1) {
    error("swig_type: must be called with only a single object");
    return octave_value_list();
  }
  octave_swig_type *ost = Swig::swig_value_deref(args(0));
  if (!ost) {
    error("swig_type: object is not a swig_ref");
    return octave_value_list();
  }
  return octave_value(ost->swig_type_name());
}

static const char *const swig_typequery_usage = "-*- texinfo -*- \n\
@deftypefn {Loadable Function} {} swig_typequery(@var{string})\n\
Return @var{string} if it is a recognised SWIG-wrapped C/C++ type name;\n\
otherwise return `<unknown>'.\n\
@end deftypefn";

DEFUN_DLD( swig_typequery, args, nargout, swig_typequery_usage ) {
  if (args.length() != 1 || !args(0).is_string()) {
    error("swig_typequery: must be called with single string argument");
    return octave_value_list();
  }
  swig_module_info *module = SWIG_GetModule(0);
  swig_type_info *type = SWIG_TypeQueryModule(module, module, args(0).string_value().c_str());
  if (!type)
    return octave_value("<unknown>");
  return octave_value(type->name);
}

static const char *const swig_this_usage = "-*- texinfo -*- \n\
@deftypefn {Loadable Function} {} swig_this(@var{swigref})\n\
Return the underlying C/C++ pointer of a SWIG-wrapped object.\n\
@end deftypefn";

DEFUN_DLD( swig_this, args, nargout, swig_this_usage ) {
  if (args.length() != 1) {
    error("swig_this: must be called with only a single object");
    return octave_value_list();
  }
  if (args(0).is_matrix_type() && args(0).rows() == 0 && args(0).columns() == 0)
    return octave_value(octave_uint64(0));
  octave_swig_type *ost = Swig::swig_value_deref(args(0));
  if (!ost) {
    error("swig_this: object is not a swig_ref");
    return octave_value_list();
  }
  return octave_value(octave_uint64((unsigned long long) ost->swig_this()));
}

static const char *const swig_octave_prereq_usage = "-*- texinfo -*- \n\
@deftypefn {Loadable Function} {} swig_octave_prereq(@var{major}, @var{minor}, @var{patch})\n\
Return true if the version of Octave is at least @var{major}.@var{minor}.@var{patch}.\n\
@end deftypefn";

DEFUN_DLD( swig_octave_prereq, args, nargout, swig_octave_prereq_usage ) {
  if (args.length() != 3) {
    error("swig_octave_prereq: must be called with 3 arguments");
    return octave_value_list();
  }
  const int major = args(0).int_value();
  const int minor = args(1).int_value();
  const int patch = args(2).int_value();
  const bool prereq = SWIG_OCTAVE_PREREQ(major, minor, patch);
  return octave_value(prereq);
}

static const char *const swig_exit_usage = "-*- texinfo -*- \n\
@deftypefn {Loadable Function} {} swig_exit([@var{exit_status}])\n\
Exit Octave without performing any memory cleanup.\n\
@end deftypefn";

DEFUN_DLD( swig_exit, args, nargout, swig_exit_usage ) {
  if (args.length() > 1) {
    error("swig_exit: must be called with at most one arguments");
    return octave_value_list();
  }
  int exit_status = 0;
  if (args.length() == 1) {
    exit_status = args(0).int_value();
  }
  ::_Exit(exit_status);
  return octave_value();
}

static const char *const SWIG_name_usage = "-*- texinfo -*- \n\
@deftypefn {Loadable Module} {} " SWIG_name_d "\n\
Loads the SWIG-generated module `" SWIG_name_d "'.\n\
@end deftypefn";

DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) {

  static octave_swig_type* module_ns = 0;

  // workaround to prevent octave seg-faulting on exit: set Octave exit function
  // octave_exit to _Exit, which exits immediately without trying to cleanup memory.
  // definitely affected version 3.2.*, not sure about 3.3.*, seems to be fixed in
  // version 3.4.*, reappeared in 4.2.*, hack not possible in 4.4.* or later due to
  // removal of octave_exit, so turn on for all versions between 3.2.*. and 4.4.*.
  // can be turned off with macro definition.
#ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK
#if !SWIG_OCTAVE_PREREQ(4,4,0)
#if SWIG_OCTAVE_PREREQ(3,2,0)
  octave_exit = ::_Exit;
#endif
#endif
#endif

  // check for no input and output args
  if (args.length() != 0 || nargout != 0) {
    print_usage();
    return octave_value_list();
  }

  // create module on first function call
  if (!module_ns) {

    // workaround bug in octave where installing global variable of custom type and then
    // exiting without explicitly clearing the variable causes octave to segfault.
#if SWIG_OCTAVE_PREREQ(3,2,0)
    octave_value_list eval_args;
    eval_args.append("base");
    eval_args.append("function __swig_atexit__; "
                     "  if mislocked() "
                     "    clear -all; "
                     "  else "
                     "    mlock(); "
                     "  endif; "
                     "endfunction; "
                     "__swig_atexit__; "
                     "atexit(\"__swig_atexit__\", false); "
                     "atexit(\"__swig_atexit__\")");
#if SWIG_OCTAVE_PREREQ(4,4,0)
    octave::feval("evalin", eval_args, 0);
#else
    feval("evalin", eval_args, 0);
#endif
#endif

#if SWIG_OCTAVE_PREREQ(4,4,0)
    {
      octave::type_info& typeinfo = octave::interpreter::the_interpreter()->get_type_info();
      string_vector types = typeinfo.installed_type_names();
      bool register_octave_swig_ref = true;
      bool register_octave_swig_packed = true;
      for (int i = 0; i < types.numel(); ++i) {
        if (types(i) == octave_swig_ref::static_type_name()) {
          register_octave_swig_ref = false;
          octave_swig_ref::set_type_id(i);
        }
        if (types(i) == octave_swig_packed::static_type_name()) {
          register_octave_swig_packed = false;
	  octave_swig_packed::set_type_id(i);
        }
      }
      if (register_octave_swig_ref) {
        octave_swig_ref::register_type();
      }
      if (register_octave_swig_packed) {
        octave_swig_packed::register_type();
      }
    }
#else
    octave_swig_ref::register_type();
    octave_swig_packed::register_type();
#endif
    SWIG_InitializeModule(0);
    SWIG_PropagateClientData();

// Updated on 2023-11-06 according to https://github.com/swig/swig/pull/2512/files
#if SWIG_OCTAVE_PREREQ(8,0,0)
    octave::tree_evaluator& tree_eval = octave::interpreter::the_interpreter()->get_evaluator();
    octave_function *me = tree_eval.current_function();
#elif SWIG_OCTAVE_PREREQ(6,0,0)
    octave::tree_evaluator& tree_eval = octave::interpreter::the_interpreter()->get_evaluator();
    octave::call_stack& stack = tree_eval.get_call_stack();
    octave_function *me = stack.current_function();
#elif SWIG_OCTAVE_PREREQ(4,4,0)
    octave::call_stack& stack = octave::interpreter::the_interpreter()->get_call_stack();
    octave_function *me = stack.current();
#else
    octave_function *me = octave_call_stack::current();
#endif

    if (!SWIG_Octave_InstallFunction(me, "subclass")) {
      return octave_value_list();
    }
    if (!SWIG_Octave_InstallFunction(me, "swig_type")) {
      return octave_value_list();
    }
    if (!SWIG_Octave_InstallFunction(me, "swig_typequery")) {
      return octave_value_list();
    }
    if (!SWIG_Octave_InstallFunction(me, "swig_this")) {
      return octave_value_list();
    }
    if (!SWIG_Octave_InstallFunction(me, "swig_octave_prereq")) {
      return octave_value_list();
    }
    if (!SWIG_Octave_InstallFunction(me, "swig_exit")) {
      return octave_value_list();
    }

    octave_swig_type* cvar_ns=0;
    if (std::string(SWIG_global_name) != ".") {
      cvar_ns=new octave_swig_type;
      for (int j=0;swig_globals[j].name;++j)
        if (swig_globals[j].get_method)
          cvar_ns->assign(swig_globals[j].name,&swig_globals[j]);
    }

    module_ns=new octave_swig_type(0, 0, 0, true);
    if (std::string(SWIG_global_name) != ".") {
      module_ns->assign(SWIG_global_name,Swig::swig_value_ref(cvar_ns));
    }
    else {
      for (int j=0;swig_globals[j].name;++j)
        if (swig_globals[j].get_method)
          module_ns->assign(swig_globals[j].name,&swig_globals[j]);
    }
    for (int j=0;swig_globals[j].name;++j)
      if (swig_globals[j].method)
        module_ns->assign(swig_globals[j].name,&swig_globals[j]);

    // * need better solution here; swig_type -> octave_class mapping is
    // * really n-to-1, in some cases such as template partial spec, etc.
    // * see failing tests.
    for (int j=0;swig_types[j];++j)
      if (swig_types[j]->clientdata) {
        swig_octave_class* c=(swig_octave_class*)swig_types[j]->clientdata;
        module_ns->assign(c->name,
                        Swig::swig_value_ref
                        (new octave_swig_type(0,swig_types[j])));
      }

    if (!SWIG_init_user(module_ns)) {
      delete module_ns;
      module_ns=0;
      return octave_value_list();
    }

    SWIG_InstallOps(octave_swig_ref::static_type_id());

    octave_swig_type::swig_member_const_iterator mb;
    for (mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb) {
      if (mb->second.first && mb->second.first->method) {
        if (!SWIG_Octave_InstallFunction(me, mb->first)) {
          return octave_value_list();
        }
      }
    }

#if SWIG_OCTAVE_PREREQ(4,4,0)
    octave::interpreter::the_interpreter()->mlock();
#elif SWIG_OCTAVE_PREREQ(3,2,0)
    mlock();
#else
    mlock(me->name());
#endif

  }

  octave_swig_type::swig_member_const_iterator mb;
  for (mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb) {
    if (mb->second.second.is_defined()) {
      SWIG_Octave_SetGlobalValue(mb->first, mb->second.second);
      SWIG_Octave_LinkGlobalValue(mb->first);
    }
  }

  SWIG_Octave_SetGlobalValue(SWIG_name_d, module_ns->as_value());
  SWIG_Octave_LinkGlobalValue(SWIG_name_d);

  return octave_value_list();

}


static bool SWIG_init_user(octave_swig_type* module_ns)
{
#ifdef SWIGOCTAVE
#if SWIG_VERSION < 0x040101
#error "AT LEAST SWIG VERSION 4.1.1 IS REQUIRED!"
#endif
#if SWIG_OCTAVE_PREREQ(8,0,0)
  std::string oct_file = octave::interpreter::the_interpreter()->get_evaluator().current_function()->fcn_file_name();
#elif SWIG_OCTAVE_PREREQ(6,0,0)
  std::string oct_file = octave::interpreter::the_interpreter()->get_evaluator().get_call_stack().current_function()->fcn_file_name();
#elif SWIG_OCTAVE_PREREQ(4,4,0)
  std::string oct_file = octave::interpreter::the_interpreter()->get_call_stack().current()->fcn_file_name();
#else
  std::string oct_file = octave_call_stack::current()->fcn_file_name();
#endif
  oct_file = skip_path(oct_file.c_str());
  if (module_ns->swig_members_begin() != module_ns->swig_members_end()) {
#endif
    
    // Common to all target languages (e.g., PYTHON and OCTAVE).
    printf("\nLoaded dynamic load library %s revision %d [%d bit %s running on %s] compiled with %s on %s from %s .\n\n", DLLName(), Revision(), Bitness(), BuildConfiguration(), CPUName(), CompilerVersion(), BuildDate(), DLLDirectory());
    fflush(stdout);
    
#ifdef SWIGOCTAVE
    printf("Registered the following functions for autoloading from %s by Octave:\n\n",oct_file.c_str());
    for (octave_swig_type::swig_member_const_iterator mb = module_ns->swig_members_begin(); mb != module_ns->swig_members_end(); ++mb)
    if (mb->second.first && mb->second.first->method && mb->second.first->name)
    printf("\t%s()\n",mb->second.first->name);
    printf("\n");
  } else
  printf("\nNothing to be (auto-)loaded from %s.\n\n",oct_file.c_str());
#endif
  
  
  return true;
}

