text:
# Julia wrapper for header: cvodes.h
# Automatically generated using Clang.jl

function CVodeCreate(lmm::Cint)
    ccall((:CVodeCreate, libsundials_cvodes), CVODEMemPtr, (Cint,), lmm)
end

function CVodeCreate(lmm)
    CVodeCreate(convert(Cint, lmm))
end

function CVodeInit(cvode_mem, f::CVRhsFn, t0::realtype, y0::N_Vector)
    ccall((:CVodeInit, libsundials_cvodes), Cint, (CVODEMemPtr, CVRhsFn, realtype, N_Vector), cvode_mem, f, t0, y0)
end

function CVodeInit(cvode_mem, f, t0::realtype, y0)
    __y0 = convert(NVector, y0)
    CVodeInit(cvode_mem, CVRhsFn_wrapper(f), t0, convert(N_Vector, __y0))
end

function CVodeReInit(cvode_mem, t0::realtype, y0::N_Vector)
    ccall((:CVodeReInit, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, N_Vector), cvode_mem, t0, y0)
end

function CVodeReInit(cvode_mem, t0::realtype, y0)
    __y0 = convert(NVector, y0)
    CVodeReInit(cvode_mem, t0, convert(N_Vector, __y0))
end

function CVodeSStolerances(cvode_mem, reltol::realtype, abstol::realtype)
    ccall((:CVodeSStolerances, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, realtype), cvode_mem, reltol, abstol)
end

function CVodeSVtolerances(cvode_mem, reltol::realtype, abstol::N_Vector)
    ccall((:CVodeSVtolerances, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, N_Vector), cvode_mem, reltol, abstol)
end

function CVodeSVtolerances(cvode_mem, reltol, abstol)
    __abstol = convert(NVector, abstol)
    CVodeSVtolerances(cvode_mem, reltol, convert(N_Vector, __abstol))
end

function CVodeWFtolerances(cvode_mem, efun::CVEwtFn)
    ccall((:CVodeWFtolerances, libsundials_cvodes), Cint, (CVODEMemPtr, CVEwtFn), cvode_mem, efun)
end

function CVodeSetErrHandlerFn(cvode_mem, ehfun::CVErrHandlerFn, eh_data)
    ccall((:CVodeSetErrHandlerFn, libsundials_cvodes), Cint, (CVODEMemPtr, CVErrHandlerFn, Ptr{Cvoid}), cvode_mem, ehfun, eh_data)
end

function CVodeSetErrFile(cvode_mem, errfp)
    ccall((:CVodeSetErrFile, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{FILE}), cvode_mem, errfp)
end

function CVodeSetUserData(cvode_mem, user_data)
    ccall((:CVodeSetUserData, libsundials_cvodes), Cint, (CVODEMemPtr, Any), cvode_mem, user_data)
end

function CVodeSetMaxOrd(cvode_mem, maxord::Cint)
    ccall((:CVodeSetMaxOrd, libsundials_cvodes), Cint, (CVODEMemPtr, Cint), cvode_mem, maxord)
end

function CVodeSetMaxOrd(cvode_mem, maxord)
    CVodeSetMaxOrd(cvode_mem, convert(Cint, maxord))
end

function CVodeSetMaxNumSteps(cvode_mem, mxsteps::Clong)
    ccall((:CVodeSetMaxNumSteps, libsundials_cvodes), Cint, (CVODEMemPtr, Clong), cvode_mem, mxsteps)
end

function CVodeSetMaxNumSteps(cvode_mem, mxsteps)
    CVodeSetMaxNumSteps(cvode_mem, convert(Clong, mxsteps))
end

function CVodeSetMaxHnilWarns(cvode_mem, mxhnil::Cint)
    ccall((:CVodeSetMaxHnilWarns, libsundials_cvodes), Cint, (CVODEMemPtr, Cint), cvode_mem, mxhnil)
end

function CVodeSetMaxHnilWarns(cvode_mem, mxhnil)
    CVodeSetMaxHnilWarns(cvode_mem, convert(Cint, mxhnil))
end

function CVodeSetStabLimDet(cvode_mem, stldet::Cint)
    ccall((:CVodeSetStabLimDet, libsundials_cvodes), Cint, (CVODEMemPtr, Cint), cvode_mem, stldet)
end

function CVodeSetStabLimDet(cvode_mem, stldet)
    CVodeSetStabLimDet(cvode_mem, convert(Cint, stldet))
end

function CVodeSetInitStep(cvode_mem, hin::realtype)
    ccall((:CVodeSetInitStep, libsundials_cvodes), Cint, (CVODEMemPtr, realtype), cvode_mem, hin)
end

function CVodeSetMinStep(cvode_mem, hmin::realtype)
    ccall((:CVodeSetMinStep, libsundials_cvodes), Cint, (CVODEMemPtr, realtype), cvode_mem, hmin)
end

function CVodeSetMaxStep(cvode_mem, hmax::realtype)
    ccall((:CVodeSetMaxStep, libsundials_cvodes), Cint, (CVODEMemPtr, realtype), cvode_mem, hmax)
end

function CVodeSetStopTime(cvode_mem, tstop::realtype)
    ccall((:CVodeSetStopTime, libsundials_cvodes), Cint, (CVODEMemPtr, realtype), cvode_mem, tstop)
end

function CVodeSetMaxErrTestFails(cvode_mem, maxnef::Cint)
    ccall((:CVodeSetMaxErrTestFails, libsundials_cvodes), Cint, (CVODEMemPtr, Cint), cvode_mem, maxnef)
end

function CVodeSetMaxErrTestFails(cvode_mem, maxnef)
    CVodeSetMaxErrTestFails(cvode_mem, convert(Cint, maxnef))
end

function CVodeSetMaxNonlinIters(cvode_mem, maxcor::Cint)
    ccall((:CVodeSetMaxNonlinIters, libsundials_cvodes), Cint, (CVODEMemPtr, Cint), cvode_mem, maxcor)
end

function CVodeSetMaxNonlinIters(cvode_mem, maxcor)
    CVodeSetMaxNonlinIters(cvode_mem, convert(Cint, maxcor))
end

function CVodeSetMaxConvFails(cvode_mem, maxncf::Cint)
    ccall((:CVodeSetMaxConvFails, libsundials_cvodes), Cint, (CVODEMemPtr, Cint), cvode_mem, maxncf)
end

function CVodeSetMaxConvFails(cvode_mem, maxncf)
    CVodeSetMaxConvFails(cvode_mem, convert(Cint, maxncf))
end

function CVodeSetNonlinConvCoef(cvode_mem, nlscoef::realtype)
    ccall((:CVodeSetNonlinConvCoef, libsundials_cvodes), Cint, (CVODEMemPtr, realtype), cvode_mem, nlscoef)
end

function CVodeSetConstraints(cvode_mem, constraints::N_Vector)
    ccall((:CVodeSetConstraints, libsundials_cvodes), Cint, (CVODEMemPtr, N_Vector), cvode_mem, constraints)
end

function CVodeSetConstraints(cvode_mem, constraints)
    __constraints = convert(NVector, constraints)
    CVodeSetConstraints(cvode_mem, convert(N_Vector, __constraints))
end

function CVodeSetNonlinearSolver(cvode_mem, NLS::SUNNonlinearSolver)
    ccall((:CVodeSetNonlinearSolver, libsundials_cvodes), Cint, (CVODEMemPtr, SUNNonlinearSolver), cvode_mem, NLS)
end

function CVodeRootInit(cvode_mem, nrtfn::Cint, g::CVRootFn)
    ccall((:CVodeRootInit, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVRootFn), cvode_mem, nrtfn, g)
end

function CVodeRootInit(cvode_mem, nrtfn, g)
    CVodeRootInit(cvode_mem, convert(Cint, nrtfn), CVRootFn_wrapper(g))
end

function CVodeSetRootDirection(cvode_mem, rootdir)
    ccall((:CVodeSetRootDirection, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Cint}), cvode_mem, rootdir)
end

function CVodeSetNoInactiveRootWarn(cvode_mem)
    ccall((:CVodeSetNoInactiveRootWarn, libsundials_cvodes), Cint, (CVODEMemPtr,), cvode_mem)
end

function CVode(cvode_mem, tout::realtype, yout::N_Vector, tret, itask::Cint)
    ccall((:CVode, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, N_Vector, Ptr{realtype}, Cint), cvode_mem, tout, yout, tret, itask)
end

function CVode(cvode_mem, tout, yout, tret, itask)
    __yout = convert(NVector, yout)
    CVode(cvode_mem, tout, convert(N_Vector, __yout), tret, convert(Cint, itask))
end

function CVodeGetDky(cvode_mem, t::realtype, k::Cint, dky::N_Vector)
    ccall((:CVodeGetDky, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, Cint, N_Vector), cvode_mem, t, k, dky)
end

function CVodeGetDky(cvode_mem, t, k, dky)
    __dky = convert(NVector, dky)
    CVodeGetDky(cvode_mem, t, convert(Cint, k), convert(N_Vector, __dky))
end

function CVodeGetWorkSpace(cvode_mem, lenrw, leniw)
    ccall((:CVodeGetWorkSpace, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}), cvode_mem, lenrw, leniw)
end

function CVodeGetNumSteps(cvode_mem, nsteps)
    ccall((:CVodeGetNumSteps, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nsteps)
end

function CVodeGetNumRhsEvals(cvode_mem, nfevals)
    ccall((:CVodeGetNumRhsEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nfevals)
end

function CVodeGetNumLinSolvSetups(cvode_mem, nlinsetups)
    ccall((:CVodeGetNumLinSolvSetups, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nlinsetups)
end

function CVodeGetNumErrTestFails(cvode_mem, netfails)
    ccall((:CVodeGetNumErrTestFails, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, netfails)
end

function CVodeGetLastOrder(cvode_mem, qlast)
    ccall((:CVodeGetLastOrder, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Cint}), cvode_mem, qlast)
end

function CVodeGetCurrentOrder(cvode_mem, qcur)
    ccall((:CVodeGetCurrentOrder, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Cint}), cvode_mem, qcur)
end

function CVodeGetCurrentGamma(cvode_mem, gamma)
    ccall((:CVodeGetCurrentGamma, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}), cvode_mem, gamma)
end

function CVodeGetNumStabLimOrderReds(cvode_mem, nslred)
    ccall((:CVodeGetNumStabLimOrderReds, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nslred)
end

function CVodeGetActualInitStep(cvode_mem, hinused)
    ccall((:CVodeGetActualInitStep, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}), cvode_mem, hinused)
end

function CVodeGetLastStep(cvode_mem, hlast)
    ccall((:CVodeGetLastStep, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}), cvode_mem, hlast)
end

function CVodeGetCurrentStep(cvode_mem, hcur)
    ccall((:CVodeGetCurrentStep, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}), cvode_mem, hcur)
end

function CVodeGetCurrentState(cvode_mem, y)
    ccall((:CVodeGetCurrentState, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{N_Vector}), cvode_mem, y)
end

function CVodeGetCurrentStateSens(cvode_mem, yS)
    ccall((:CVodeGetCurrentStateSens, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Ptr{N_Vector}}), cvode_mem, yS)
end

function CVodeGetCurrentSensSolveIndex(cvode_mem, index)
    ccall((:CVodeGetCurrentSensSolveIndex, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Cint}), cvode_mem, index)
end

function CVodeGetCurrentTime(cvode_mem, tcur)
    ccall((:CVodeGetCurrentTime, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}), cvode_mem, tcur)
end

function CVodeGetTolScaleFactor(cvode_mem, tolsfac)
    ccall((:CVodeGetTolScaleFactor, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}), cvode_mem, tolsfac)
end

function CVodeGetErrWeights(cvode_mem, eweight::N_Vector)
    ccall((:CVodeGetErrWeights, libsundials_cvodes), Cint, (CVODEMemPtr, N_Vector), cvode_mem, eweight)
end

function CVodeGetErrWeights(cvode_mem, eweight)
    __eweight = convert(NVector, eweight)
    CVodeGetErrWeights(cvode_mem, convert(N_Vector, __eweight))
end

function CVodeGetEstLocalErrors(cvode_mem, ele::N_Vector)
    ccall((:CVodeGetEstLocalErrors, libsundials_cvodes), Cint, (CVODEMemPtr, N_Vector), cvode_mem, ele)
end

function CVodeGetEstLocalErrors(cvode_mem, ele)
    __ele = convert(NVector, ele)
    CVodeGetEstLocalErrors(cvode_mem, convert(N_Vector, __ele))
end

function CVodeGetNumGEvals(cvode_mem, ngevals)
    ccall((:CVodeGetNumGEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, ngevals)
end

function CVodeGetRootInfo(cvode_mem, rootsfound)
    ccall((:CVodeGetRootInfo, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Cint}), cvode_mem, rootsfound)
end

function CVodeGetIntegratorStats(cvode_mem, nsteps, nfevals, nlinsetups, netfails, qlast, qcur, hinused, hlast, hcur, tcur)
    ccall((:CVodeGetIntegratorStats, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}, Ptr{Clong}, Ptr{Clong}, Ptr{Cint}, Ptr{Cint}, Ptr{realtype}, Ptr{realtype}, Ptr{realtype}, Ptr{realtype}), cvode_mem, nsteps, nfevals, nlinsetups, netfails, qlast, qcur, hinused, hlast, hcur, tcur)
end

function CVodeGetNumNonlinSolvIters(cvode_mem, nniters)
    ccall((:CVodeGetNumNonlinSolvIters, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nniters)
end

function CVodeGetNumNonlinSolvConvFails(cvode_mem, nncfails)
    ccall((:CVodeGetNumNonlinSolvConvFails, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nncfails)
end

function CVodeGetNonlinSolvStats(cvode_mem, nniters, nncfails)
    ccall((:CVodeGetNonlinSolvStats, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}), cvode_mem, nniters, nncfails)
end

function CVodeGetReturnFlagName(flag::Clong)
    ccall((:CVodeGetReturnFlagName, libsundials_cvodes), Cstring, (Clong,), flag)
end

function CVodeGetReturnFlagName(flag)
    CVodeGetReturnFlagName(convert(Clong, flag))
end

function CVodeFree(cvode_mem)
    ccall((:CVodeFree, libsundials_cvodes), Cvoid, (Ref{CVODEMemPtr},), cvode_mem)
end

function CVodeQuadInit(cvode_mem, fQ::CVQuadRhsFn, yQ0::N_Vector)
    ccall((:CVodeQuadInit, libsundials_cvodes), Cint, (CVODEMemPtr, CVQuadRhsFn, N_Vector), cvode_mem, fQ, yQ0)
end

function CVodeQuadInit(cvode_mem, fQ, yQ0)
    __yQ0 = convert(NVector, yQ0)
    CVodeQuadInit(cvode_mem, fQ, convert(N_Vector, __yQ0))
end

function CVodeQuadReInit(cvode_mem, yQ0::N_Vector)
    ccall((:CVodeQuadReInit, libsundials_cvodes), Cint, (CVODEMemPtr, N_Vector), cvode_mem, yQ0)
end

function CVodeQuadReInit(cvode_mem, yQ0)
    __yQ0 = convert(NVector, yQ0)
    CVodeQuadReInit(cvode_mem, convert(N_Vector, __yQ0))
end

function CVodeQuadSStolerances(cvode_mem, reltolQ::realtype, abstolQ::realtype)
    ccall((:CVodeQuadSStolerances, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, realtype), cvode_mem, reltolQ, abstolQ)
end

function CVodeQuadSVtolerances(cvode_mem, reltolQ::realtype, abstolQ::N_Vector)
    ccall((:CVodeQuadSVtolerances, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, N_Vector), cvode_mem, reltolQ, abstolQ)
end

function CVodeQuadSVtolerances(cvode_mem, reltolQ, abstolQ)
    __abstolQ = convert(NVector, abstolQ)
    CVodeQuadSVtolerances(cvode_mem, reltolQ, convert(N_Vector, __abstolQ))
end

function CVodeSetQuadErrCon(cvode_mem, errconQ::Cint)
    ccall((:CVodeSetQuadErrCon, libsundials_cvodes), Cint, (CVODEMemPtr, Cint), cvode_mem, errconQ)
end

function CVodeSetQuadErrCon(cvode_mem, errconQ)
    CVodeSetQuadErrCon(cvode_mem, convert(Cint, errconQ))
end

function CVodeGetQuad(cvode_mem, tret, yQout::N_Vector)
    ccall((:CVodeGetQuad, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}, N_Vector), cvode_mem, tret, yQout)
end

function CVodeGetQuad(cvode_mem, tret, yQout)
    __yQout = convert(NVector, yQout)
    CVodeGetQuad(cvode_mem, tret, convert(N_Vector, yQout))
end

function CVodeGetQuadDky(cvode_mem, t::realtype, k::Cint, dky::N_Vector)
    ccall((:CVodeGetQuadDky, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, Cint, N_Vector), cvode_mem, t, k, dky)
end

function CVodeGetQuadDky(cvode_mem, t, k, dky)
    __dky = convert(NVector, dky)
    CVodeGetQuadDky(cvode_mem, t, convert(Cint, k), convert(N_Vector, __dky))
end

function CVodeGetQuadNumRhsEvals(cvode_mem, nfQevals)
    ccall((:CVodeGetQuadNumRhsEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nfQevals)
end

function CVodeGetQuadNumErrTestFails(cvode_mem, nQetfails)
    ccall((:CVodeGetQuadNumErrTestFails, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nQetfails)
end

function CVodeGetQuadErrWeights(cvode_mem, eQweight::N_Vector)
    ccall((:CVodeGetQuadErrWeights, libsundials_cvodes), Cint, (CVODEMemPtr, N_Vector), cvode_mem, eQweight)
end

function CVodeGetQuadErrWeights(cvode_mem, eQweight)
    __eQweight = convert(NVector, eQweight)
    CVodeGetQuadErrWeights(cvode_mem, convert(N_Vector, __eQweight))
end

function CVodeGetQuadStats(cvode_mem, nfQevals, nQetfails)
    ccall((:CVodeGetQuadStats, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}), cvode_mem, nfQevals, nQetfails)
end

function CVodeQuadFree(cvode_mem)
    ccall((:CVodeQuadFree, libsundials_cvodes), Cvoid, (CVODEMemPtr,), cvode_mem)
end

function CVodeSensInit(cvode_mem, Ns::Cint, ism::Cint, fS::CVSensRhsFn, yS0)
    ccall((:CVodeSensInit, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Cint, CVSensRhsFn, Ptr{N_Vector}), cvode_mem, Ns, ism, fS, yS0)
end

function CVodeSensInit(cvode_mem, Ns, ism, fS, yS0)
    CVodeSensInit(cvode_mem, convert(Cint, Ns), convert(Cint, ism), fS, yS0)
end

function CVodeSensInit1(cvode_mem, Ns::Cint, ism::Cint, fS1::CVSensRhs1Fn, yS0)
    ccall((:CVodeSensInit1, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Cint, CVSensRhs1Fn, Ptr{N_Vector}), cvode_mem, Ns, ism, fS1, yS0)
end

function CVodeSensInit1(cvode_mem, Ns, ism, fS1, yS0)
    CVodeSensInit1(cvode_mem, convert(Cint, Ns), convert(Cint, ism), fS1, yS0)
end

function CVodeSensReInit(cvode_mem, ism::Cint, yS0)
    ccall((:CVodeSensReInit, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Ptr{N_Vector}), cvode_mem, ism, yS0)
end

function CVodeSensReInit(cvode_mem, ism, yS0)
    CVodeSensReInit(cvode_mem, convert(Cint, ism), yS0)
end

function CVodeSensSStolerances(cvode_mem, reltolS::realtype, abstolS)
    ccall((:CVodeSensSStolerances, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, Ptr{realtype}), cvode_mem, reltolS, abstolS)
end

function CVodeSensSVtolerances(cvode_mem, reltolS::realtype, abstolS)
    ccall((:CVodeSensSVtolerances, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, Ptr{N_Vector}), cvode_mem, reltolS, abstolS)
end

function CVodeSensEEtolerances(cvode_mem)
    ccall((:CVodeSensEEtolerances, libsundials_cvodes), Cint, (CVODEMemPtr,), cvode_mem)
end

function CVodeSetSensDQMethod(cvode_mem, DQtype::Cint, DQrhomax::realtype)
    ccall((:CVodeSetSensDQMethod, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, realtype), cvode_mem, DQtype, DQrhomax)
end

function CVodeSetSensDQMethod(cvode_mem, DQtype, DQrhomax)
    CVodeSetSensDQMethod(cvode_mem, convert(Cint, DQtype), DQrhomax)
end

function CVodeSetSensErrCon(cvode_mem, errconS::Cint)
    ccall((:CVodeSetSensErrCon, libsundials_cvodes), Cint, (CVODEMemPtr, Cint), cvode_mem, errconS)
end

function CVodeSetSensErrCon(cvode_mem, errconS)
    CVodeSetSensErrCon(cvode_mem, convert(Cint, errconS))
end

function CVodeSetSensMaxNonlinIters(cvode_mem, maxcorS::Cint)
    ccall((:CVodeSetSensMaxNonlinIters, libsundials_cvodes), Cint, (CVODEMemPtr, Cint), cvode_mem, maxcorS)
end

function CVodeSetSensMaxNonlinIters(cvode_mem, maxcorS)
    CVodeSetSensMaxNonlinIters(cvode_mem, convert(Cint, maxcorS))
end

function CVodeSetSensParams(cvode_mem, p, pbar, plist)
    ccall((:CVodeSetSensParams, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}, Ptr{realtype}, Ptr{Cint}), cvode_mem, p, pbar, plist)
end

function CVodeSetNonlinearSolverSensSim(cvode_mem, NLS::SUNNonlinearSolver)
    ccall((:CVodeSetNonlinearSolverSensSim, libsundials_cvodes), Cint, (CVODEMemPtr, SUNNonlinearSolver), cvode_mem, NLS)
end

function CVodeSetNonlinearSolverSensStg(cvode_mem, NLS::SUNNonlinearSolver)
    ccall((:CVodeSetNonlinearSolverSensStg, libsundials_cvodes), Cint, (CVODEMemPtr, SUNNonlinearSolver), cvode_mem, NLS)
end

function CVodeSetNonlinearSolverSensStg1(cvode_mem, NLS::SUNNonlinearSolver)
    ccall((:CVodeSetNonlinearSolverSensStg1, libsundials_cvodes), Cint, (CVODEMemPtr, SUNNonlinearSolver), cvode_mem, NLS)
end

function CVodeSensToggleOff(cvode_mem)
    ccall((:CVodeSensToggleOff, libsundials_cvodes), Cint, (CVODEMemPtr,), cvode_mem)
end

function CVodeGetSens(cvode_mem, tret, ySout)
    ccall((:CVodeGetSens, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}, Ptr{N_Vector}), cvode_mem, tret, ySout)
end

function CVodeGetSens1(cvode_mem, tret, is::Cint, ySout::N_Vector)
    ccall((:CVodeGetSens1, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}, Cint, N_Vector), cvode_mem, tret, is, ySout)
end

function CVodeGetSens1(cvode_mem, tret, is, ySout)
    __ySout = convert(NVector, ySout)
    CVodeGetSens1(cvode_mem, tret, convert(Cint, is), convert(N_Vector, __ySout))
end

function CVodeGetSensDky(cvode_mem, t::realtype, k::Cint, dkyA)
    ccall((:CVodeGetSensDky, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, Cint, Ptr{N_Vector}), cvode_mem, t, k, dkyA)
end

function CVodeGetSensDky(cvode_mem, t, k, dkyA)
    CVodeGetSensDky(cvode_mem, t, convert(Cint, k), dkyA)
end

function CVodeGetSensDky1(cvode_mem, t::realtype, k::Cint, is::Cint, dky::N_Vector)
    ccall((:CVodeGetSensDky1, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, Cint, Cint, N_Vector), cvode_mem, t, k, is, dky)
end

function CVodeGetSensDky1(cvode_mem, t, k, is, dky)
    __dky = convert(NVector, dky)
    CVodeGetSensDky1(cvode_mem, t, convert(Cint, k), convert(Cint, is), convert(N_Vector, __dky))
end

function CVodeGetSensNumRhsEvals(cvode_mem, nfSevals)
    ccall((:CVodeGetSensNumRhsEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nfSevals)
end

function CVodeGetNumRhsEvalsSens(cvode_mem, nfevalsS)
    ccall((:CVodeGetNumRhsEvalsSens, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nfevalsS)
end

function CVodeGetSensNumErrTestFails(cvode_mem, nSetfails)
    ccall((:CVodeGetSensNumErrTestFails, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nSetfails)
end

function CVodeGetSensNumLinSolvSetups(cvode_mem, nlinsetupsS)
    ccall((:CVodeGetSensNumLinSolvSetups, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nlinsetupsS)
end

function CVodeGetSensErrWeights(cvode_mem, eSweight)
    ccall((:CVodeGetSensErrWeights, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{N_Vector}), cvode_mem, eSweight)
end

function CVodeGetSensStats(cvode_mem, nfSevals, nfevalsS, nSetfails, nlinsetupsS)
    ccall((:CVodeGetSensStats, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}, Ptr{Clong}, Ptr{Clong}), cvode_mem, nfSevals, nfevalsS, nSetfails, nlinsetupsS)
end

function CVodeGetSensNumNonlinSolvIters(cvode_mem, nSniters)
    ccall((:CVodeGetSensNumNonlinSolvIters, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nSniters)
end

function CVodeGetSensNumNonlinSolvConvFails(cvode_mem, nSncfails)
    ccall((:CVodeGetSensNumNonlinSolvConvFails, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nSncfails)
end

function CVodeGetStgrSensNumNonlinSolvIters(cvode_mem, nSTGR1niters)
    ccall((:CVodeGetStgrSensNumNonlinSolvIters, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nSTGR1niters)
end

function CVodeGetStgrSensNumNonlinSolvConvFails(cvode_mem, nSTGR1ncfails)
    ccall((:CVodeGetStgrSensNumNonlinSolvConvFails, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nSTGR1ncfails)
end

function CVodeGetSensNonlinSolvStats(cvode_mem, nSniters, nSncfails)
    ccall((:CVodeGetSensNonlinSolvStats, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}), cvode_mem, nSniters, nSncfails)
end

function CVodeSensFree(cvode_mem)
    ccall((:CVodeSensFree, libsundials_cvodes), Cvoid, (CVODEMemPtr,), cvode_mem)
end

function CVodeQuadSensInit(cvode_mem, fQS::CVQuadSensRhsFn, yQS0)
    ccall((:CVodeQuadSensInit, libsundials_cvodes), Cint, (CVODEMemPtr, CVQuadSensRhsFn, Ptr{N_Vector}), cvode_mem, fQS, yQS0)
end

function CVodeQuadSensReInit(cvode_mem, yQS0)
    ccall((:CVodeQuadSensReInit, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{N_Vector}), cvode_mem, yQS0)
end

function CVodeQuadSensSStolerances(cvode_mem, reltolQS::realtype, abstolQS)
    ccall((:CVodeQuadSensSStolerances, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, Ptr{realtype}), cvode_mem, reltolQS, abstolQS)
end

function CVodeQuadSensSVtolerances(cvode_mem, reltolQS::realtype, abstolQS)
    ccall((:CVodeQuadSensSVtolerances, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, Ptr{N_Vector}), cvode_mem, reltolQS, abstolQS)
end

function CVodeQuadSensEEtolerances(cvode_mem)
    ccall((:CVodeQuadSensEEtolerances, libsundials_cvodes), Cint, (CVODEMemPtr,), cvode_mem)
end

function CVodeSetQuadSensErrCon(cvode_mem, errconQS::Cint)
    ccall((:CVodeSetQuadSensErrCon, libsundials_cvodes), Cint, (CVODEMemPtr, Cint), cvode_mem, errconQS)
end

function CVodeSetQuadSensErrCon(cvode_mem, errconQS)
    CVodeSetQuadSensErrCon(cvode_mem, convert(Cint, errconQS))
end

function CVodeGetQuadSens(cvode_mem, tret, yQSout)
    ccall((:CVodeGetQuadSens, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}, Ptr{N_Vector}), cvode_mem, tret, yQSout)
end

function CVodeGetQuadSens1(cvode_mem, tret, is::Cint, yQSout::N_Vector)
    ccall((:CVodeGetQuadSens1, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{realtype}, Cint, N_Vector), cvode_mem, tret, is, yQSout)
end

function CVodeGetQuadSens1(cvode_mem, tret, is, yQSout)
    __yQSout = convert(NVector, yQSout)
    CVodeGetQuadSens1(cvode_mem, tret, convert(Cint, is), convert(N_Vector, yQSout))
end

function CVodeGetQuadSensDky(cvode_mem, t::realtype, k::Cint, dkyQS_all)
    ccall((:CVodeGetQuadSensDky, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, Cint, Ptr{N_Vector}), cvode_mem, t, k, dkyQS_all)
end

function CVodeGetQuadSensDky(cvode_mem, t, k, dkyQS_all)
    CVodeGetQuadSensDky(cvode_mem, t, convert(Cint, k), dkyQS_all)
end

function CVodeGetQuadSensDky1(cvode_mem, t::realtype, k::Cint, is::Cint, dkyQS::N_Vector)
    ccall((:CVodeGetQuadSensDky1, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, Cint, Cint, N_Vector), cvode_mem, t, k, is, dkyQS)
end

function CVodeGetQuadSensDky1(cvode_mem, t, k, is, dkyQS)
    __dkyQS = convert(NVector, dkyQS)
    CVodeGetQuadSensDky1(cvode_mem, t, convert(Cint, k), convert(Cint, is), convert(N_Vector, __dkyQS))
end

function CVodeGetQuadSensNumRhsEvals(cvode_mem, nfQSevals)
    ccall((:CVodeGetQuadSensNumRhsEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nfQSevals)
end

function CVodeGetQuadSensNumErrTestFails(cvode_mem, nQSetfails)
    ccall((:CVodeGetQuadSensNumErrTestFails, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nQSetfails)
end

function CVodeGetQuadSensErrWeights(cvode_mem, eQSweight)
    ccall((:CVodeGetQuadSensErrWeights, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{N_Vector}), cvode_mem, eQSweight)
end

function CVodeGetQuadSensStats(cvode_mem, nfQSevals, nQSetfails)
    ccall((:CVodeGetQuadSensStats, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}), cvode_mem, nfQSevals, nQSetfails)
end

function CVodeQuadSensFree(cvode_mem)
    ccall((:CVodeQuadSensFree, libsundials_cvodes), Cvoid, (CVODEMemPtr,), cvode_mem)
end

function CVodeAdjInit(cvode_mem, steps::Clong, interp::Cint)
    ccall((:CVodeAdjInit, libsundials_cvodes), Cint, (CVODEMemPtr, Clong, Cint), cvode_mem, steps, interp)
end

function CVodeAdjInit(cvode_mem, steps, interp)
    CVodeAdjInit(cvode_mem, convert(Clong, steps), convert(Cint, interp))
end

function CVodeAdjReInit(cvode_mem)
    ccall((:CVodeAdjReInit, libsundials_cvodes), Cint, (CVODEMemPtr,), cvode_mem)
end

function CVodeAdjFree(cvode_mem)
    ccall((:CVodeAdjFree, libsundials_cvodes), Cvoid, (CVODEMemPtr,), cvode_mem)
end

function CVodeCreateB(cvode_mem, lmmB::Cint, which)
    ccall((:CVodeCreateB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Ptr{Cint}), cvode_mem, lmmB, which)
end

function CVodeCreateB(cvode_mem, lmmB, which)
    CVodeCreateB(cvode_mem, convert(Cint, lmmB), which)
end

function CVodeInitB(cvode_mem, which::Cint, fB::CVRhsFnB, tB0::realtype, yB0::N_Vector)
    ccall((:CVodeInitB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVRhsFnB, realtype, N_Vector), cvode_mem, which, fB, tB0, yB0)
end

function CVodeInitB(cvode_mem, which, fB, tB0, yB0)
    __yB0 = convert(NVector, yB0)
    CVodeInitB(cvode_mem, convert(Cint, which), fB, tB0, convert(N_Vector, __yB0))
end

function CVodeInitBS(cvode_mem, which::Cint, fBs::CVRhsFnBS, tB0::realtype, yB0::N_Vector)
    ccall((:CVodeInitBS, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVRhsFnBS, realtype, N_Vector), cvode_mem, which, fBs, tB0, yB0)
end

function CVodeInitBS(cvode_mem, which, fBs, tB0, yB0)
    __yB0 = convert(NVector, yB0)
    CVodeInitBS(cvode_mem, convert(Cint, which), fBs, tB0, convert(N_Vector, __yB0))
end

function CVodeReInitB(cvode_mem, which::Cint, tB0::realtype, yB0::N_Vector)
    ccall((:CVodeReInitB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, realtype, N_Vector), cvode_mem, which, tB0, yB0)
end

function CVodeReInitB(cvode_mem, which, tB0, yB0)
    __yB0 = convert(NVector, yB0)
    CVodeReInitB(cvode_mem, convert(Cint, which), tB0, convert(N_Vector, __yB0))
end

function CVodeSStolerancesB(cvode_mem, which::Cint, reltolB::realtype, abstolB::realtype)
    ccall((:CVodeSStolerancesB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, realtype, realtype), cvode_mem, which, reltolB, abstolB)
end

function CVodeSStolerancesB(cvode_mem, which, reltolB, abstolB)
    CVodeSStolerancesB(cvode_mem, convert(Cint, which), reltolB, abstolB)
end

function CVodeSVtolerancesB(cvode_mem, which::Cint, reltolB::realtype, abstolB::N_Vector)
    ccall((:CVodeSVtolerancesB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, realtype, N_Vector), cvode_mem, which, reltolB, abstolB)
end

function CVodeSVtolerancesB(cvode_mem, which, reltolB, abstolB)
    __abstolB = convert(NVector, abstolB)
    CVodeSVtolerancesB(cvode_mem, convert(Cint, which), reltolB, convert(N_Vector, __abstolB))
end

function CVodeQuadInitB(cvode_mem, which::Cint, fQB::CVQuadRhsFnB, yQB0::N_Vector)
    ccall((:CVodeQuadInitB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVQuadRhsFnB, N_Vector), cvode_mem, which, fQB, yQB0)
end

function CVodeQuadInitB(cvode_mem, which, fQB, yQB0)
    __yQB0 = convert(NVector, yQB0)
    CVodeQuadInitB(cvode_mem, convert(Cint, which), fQB, convert(N_Vector, __yQB0))
end

function CVodeQuadInitBS(cvode_mem, which::Cint, fQBs::CVQuadRhsFnBS, yQB0::N_Vector)
    ccall((:CVodeQuadInitBS, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVQuadRhsFnBS, N_Vector), cvode_mem, which, fQBs, yQB0)
end

function CVodeQuadInitBS(cvode_mem, which, fQBs, yQB0)
    __yQB0 = convert(NVector, yQB0)
    CVodeQuadInitBS(cvode_mem, convert(Cint, which), fQBs, convert(N_Vector, __yQB0))
end

function CVodeQuadReInitB(cvode_mem, which::Cint, yQB0::N_Vector)
    ccall((:CVodeQuadReInitB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, N_Vector), cvode_mem, which, yQB0)
end

function CVodeQuadReInitB(cvode_mem, which, yQB0)
    __yQB0 = convert(NVector, yQB0)
    CVodeQuadReInitB(cvode_mem, convert(Cint, which), convert(N_Vector, __yQB0))
end

function CVodeQuadSStolerancesB(cvode_mem, which::Cint, reltolQB::realtype, abstolQB::realtype)
    ccall((:CVodeQuadSStolerancesB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, realtype, realtype), cvode_mem, which, reltolQB, abstolQB)
end

function CVodeQuadSStolerancesB(cvode_mem, which, reltolQB, abstolQB)
    CVodeQuadSStolerancesB(cvode_mem, convert(Cint, which), reltolQB, abstolQB)
end

function CVodeQuadSVtolerancesB(cvode_mem, which::Cint, reltolQB::realtype, abstolQB::N_Vector)
    ccall((:CVodeQuadSVtolerancesB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, realtype, N_Vector), cvode_mem, which, reltolQB, abstolQB)
end

function CVodeQuadSVtolerancesB(cvode_mem, which, reltolQB, abstolQB)
    __abstolQB = convert(NVector, abstolQB)
    CVodeQuadSVtolerancesB(cvode_mem, convert(Cint, which), reltolQB, convert(N_Vector, __abstolQB))
end

function CVodeF(cvode_mem, tout::realtype, yout::N_Vector, tret, itask::Cint, ncheckPtr)
    ccall((:CVodeF, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, N_Vector, Ptr{realtype}, Cint, Ptr{Cint}), cvode_mem, tout, yout, tret, itask, ncheckPtr)
end

function CVodeF(cvode_mem, tout, yout, tret, itask, ncheckPtr)
    __yout = convert(NVector, yout)
    CVodeF(cvode_mem, tout, convert(N_Vector, __yout), tret, convert(Cint, itask), ncheckPtr)
end

function CVodeB(cvode_mem, tBout::realtype, itaskB::Cint)
    ccall((:CVodeB, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, Cint), cvode_mem, tBout, itaskB)
end

function CVodeB(cvode_mem, tBout, itaskB)
    CVodeB(cvode_mem, tBout, convert(Cint, itaskB))
end

function CVodeSetAdjNoSensi(cvode_mem)
    ccall((:CVodeSetAdjNoSensi, libsundials_cvodes), Cint, (CVODEMemPtr,), cvode_mem)
end

function CVodeSetUserDataB(cvode_mem, which::Cint, user_dataB)
    ccall((:CVodeSetUserDataB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Any), cvode_mem, which, user_dataB)
end

function CVodeSetUserDataB(cvode_mem, which, user_dataB)
    CVodeSetUserDataB(cvode_mem, convert(Cint, which), user_dataB)
end

function CVodeSetMaxOrdB(cvode_mem, which::Cint, maxordB::Cint)
    ccall((:CVodeSetMaxOrdB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Cint), cvode_mem, which, maxordB)
end

function CVodeSetMaxOrdB(cvode_mem, which, maxordB)
    CVodeSetMaxOrdB(cvode_mem, convert(Cint, which), convert(Cint, maxordB))
end

function CVodeSetMaxNumStepsB(cvode_mem, which::Cint, mxstepsB::Clong)
    ccall((:CVodeSetMaxNumStepsB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Clong), cvode_mem, which, mxstepsB)
end

function CVodeSetMaxNumStepsB(cvode_mem, whichs, mxstepsB)
    CVodeSetMaxNumStepsB(cvode_mem, convert(Cint, which), convert(Clong, mxstepsB))
end

function CVodeSetStabLimDetB(cvode_mem, which::Cint, stldetB::Cint)
    ccall((:CVodeSetStabLimDetB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Cint), cvode_mem, which, stldetB)
end

function CVodeSetStabLimDetB(cvode_mem, which, stldetB)
    CVodeSetStabLimDetB(cvode_mem, convert(Cint, which), convert(Cint, stldetB))
end

function CVodeSetInitStepB(cvode_mem, which::Cint, hinB::realtype)
    ccall((:CVodeSetInitStepB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, realtype), cvode_mem, which, hinB)
end

function CVodeSetInitStepB(cvode_mem, which, hinB)
    CVodeSetInitStepB(cvode_mem, convert(Cint, which), hinB)
end

function CVodeSetMinStepB(cvode_mem, which::Cint, hminB::realtype)
    ccall((:CVodeSetMinStepB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, realtype), cvode_mem, which, hminB)
end

function CVodeSetMinStepB(cvode_mem, which, hminB)
    CVodeSetMinStepB(cvode_mem, convert(Cint, which), hminB)
end

function CVodeSetMaxStepB(cvode_mem, which::Cint, hmaxB::realtype)
    ccall((:CVodeSetMaxStepB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, realtype), cvode_mem, which, hmaxB)
end

function CVodeSetMaxStepB(cvode_mem, which, hmaxB)
    CVodeSetMaxStepB(cvode_mem, convert(Cint, which), hmaxB)
end

function CVodeSetConstraintsB(cvode_mem, which::Cint, constraintsB::N_Vector)
    ccall((:CVodeSetConstraintsB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, N_Vector), cvode_mem, which, constraintsB)
end

function CVodeSetConstraintsB(cvode_mem, which, constraintsB)
    __constraintsB = convert(NVector, constraintsB)
    CVodeSetConstraintsB(cvode_mem, convert(Cint, which), convert(N_Vector, __constraintsB))
end

function CVodeSetQuadErrConB(cvode_mem, which::Cint, errconQB::Cint)
    ccall((:CVodeSetQuadErrConB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Cint), cvode_mem, which, errconQB)
end

function CVodeSetQuadErrConB(cvode_mem, which, errconQB)
    CVodeSetQuadErrConB(cvode_mem, convert(Cint, which), convert(Cint, errconQB))
end

function CVodeSetNonlinearSolverB(cvode_mem, which::Cint, NLS::SUNNonlinearSolver)
    ccall((:CVodeSetNonlinearSolverB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, SUNNonlinearSolver), cvode_mem, which, NLS)
end

function CVodeSetNonlinearSolverB(cvode_mem, which, NLS)
    CVodeSetNonlinearSolverB(cvode_mem, convert(Cint, which), NLS)
end

function CVodeGetB(cvode_mem, which::Cint, tBret, yB::N_Vector)
    ccall((:CVodeGetB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Ptr{realtype}, N_Vector), cvode_mem, which, tBret, yB)
end

function CVodeGetB(cvode_mem, which, tBret, yB)
    __yB = convert(NVector, yB)
    CVodeGetB(cvode_mem, convert(Cint, which), tBret, convert(N_Vector, __yB))
end

function CVodeGetQuadB(cvode_mem, which::Cint, tBret, qB::N_Vector)
    ccall((:CVodeGetQuadB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Ptr{realtype}, N_Vector), cvode_mem, which, tBret, qB)
end

function CVodeGetQuadB(cvode_mem, which, tBret, qB)
    __qB = convert(NVector, qB)
    CVodeGetQuadB(cvode_mem, convert(Cint, which), tBret, convert(N_Vector, __qB))
end

function CVodeGetAdjCVodeBmem(cvode_mem, which::Cint)
    ccall((:CVodeGetAdjCVodeBmem, libsundials_cvodes), Ptr{Cvoid}, (CVODEMemPtr, Cint), cvode_mem, which)
end

function CVodeGetAdjCVodeBmem(cvode_mem, which)
    CVodeGetAdjCVodeBmem(cvode_mem, convert(Cint, which))
end

function CVodeGetAdjY(cvode_mem, t::realtype, y::N_Vector)
    ccall((:CVodeGetAdjY, libsundials_cvodes), Cint, (CVODEMemPtr, realtype, N_Vector), cvode_mem, t, y)
end

function CVodeGetAdjY(cvode_mem, t, y)
    __y = convert(NVector, y)
    CVodeGetAdjY(cvode_mem, t, convert(N_Vector, __y))
end

function CVodeGetAdjCheckPointsInfo(cvode_mem, ckpnt)
    ccall((:CVodeGetAdjCheckPointsInfo, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{CVadjCheckPointRec}), cvode_mem, ckpnt)
end

function CVodeGetAdjDataPointHermite(cvode_mem, which::Cint, t, y::N_Vector, yd::N_Vector)
    ccall((:CVodeGetAdjDataPointHermite, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Ptr{realtype}, N_Vector, N_Vector), cvode_mem, which, t, y, yd)
end

function CVodeGetAdjDataPointHermite(cvode_mem, which, t, y, yd)
    __y = convert(NVector, y)
    __yd = convert(NVector, yd)
    CVodeGetAdjDataPointHermite(cvode_mem, convert(Cint, which), t, convert(N_Vector, __y), convert(N_Vector, __yd))
end

function CVodeGetAdjDataPointPolynomial(cvode_mem, which::Cint, t, order, y::N_Vector)
    ccall((:CVodeGetAdjDataPointPolynomial, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, Ptr{realtype}, Ptr{Cint}, N_Vector), cvode_mem, which, t, order, y)
end

function CVodeGetAdjDataPointPolynomial(cvode_mem, which, t, order, y)
    __y = convert(NVector, y)
    CVodeGetAdjDataPointPolynomial(cvode_mem, convert(Cint, which), t, order, convert(N_Vector, __y))
end

function CVodeGetAdjCurrentCheckPoint(cvode_mem, addr)
    ccall((:CVodeGetAdjCurrentCheckPoint, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Ptr{Cvoid}}), cvode_mem, addr)
end
# Julia wrapper for header: cvodes_bandpre.h
# Automatically generated using Clang.jl

function CVBandPrecInit(cvode_mem, N::sunindextype, mu::sunindextype, ml::sunindextype)
    ccall((:CVBandPrecInit, libsundials_cvodes), Cint, (CVODEMemPtr, sunindextype, sunindextype, sunindextype), cvode_mem, N, mu, ml)
end

function CVBandPrecGetWorkSpace(cvode_mem, lenrwLS, leniwLS)
    ccall((:CVBandPrecGetWorkSpace, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}), cvode_mem, lenrwLS, leniwLS)
end

function CVBandPrecGetNumRhsEvals(cvode_mem, nfevalsBP)
    ccall((:CVBandPrecGetNumRhsEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nfevalsBP)
end

function CVBandPrecInitB(cvode_mem, which::Cint, nB::sunindextype, muB::sunindextype, mlB::sunindextype)
    ccall((:CVBandPrecInitB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, sunindextype, sunindextype, sunindextype), cvode_mem, which, nB, muB, mlB)
end

function CVBandPrecInitB(cvode_mem, which, nB::sunindextype, muB::sunindextype, mlB::sunindextype)
    CVBandPrecInitB(cvode_mem, convert(Cint, which), nB, muB, mlB)
end
# Julia wrapper for header: cvodes_bbdpre.h
# Automatically generated using Clang.jl

function CVBBDPrecInit(cvode_mem, Nlocal::sunindextype, mudq::sunindextype, mldq::sunindextype, mukeep::sunindextype, mlkeep::sunindextype, dqrely::realtype, gloc::CVLocalFn, cfn::CVCommFn)
    ccall((:CVBBDPrecInit, libsundials_cvodes), Cint, (CVODEMemPtr, sunindextype, sunindextype, sunindextype, sunindextype, sunindextype, realtype, CVLocalFn, CVCommFn), cvode_mem, Nlocal, mudq, mldq, mukeep, mlkeep, dqrely, gloc, cfn)
end

function CVBBDPrecReInit(cvode_mem, mudq::sunindextype, mldq::sunindextype, dqrely::realtype)
    ccall((:CVBBDPrecReInit, libsundials_cvodes), Cint, (CVODEMemPtr, sunindextype, sunindextype, realtype), cvode_mem, mudq, mldq, dqrely)
end

function CVBBDPrecGetWorkSpace(cvode_mem, lenrwBBDP, leniwBBDP)
    ccall((:CVBBDPrecGetWorkSpace, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}), cvode_mem, lenrwBBDP, leniwBBDP)
end

function CVBBDPrecGetNumGfnEvals(cvode_mem, ngevalsBBDP)
    ccall((:CVBBDPrecGetNumGfnEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, ngevalsBBDP)
end

function CVBBDPrecInitB(cvode_mem, which::Cint, NlocalB::sunindextype, mudqB::sunindextype, mldqB::sunindextype, mukeepB::sunindextype, mlkeepB::sunindextype, dqrelyB::realtype, glocB::CVLocalFnB, cfnB::CVCommFnB)
    ccall((:CVBBDPrecInitB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, sunindextype, sunindextype, sunindextype, sunindextype, sunindextype, realtype, CVLocalFnB, CVCommFnB), cvode_mem, which, NlocalB, mudqB, mldqB, mukeepB, mlkeepB, dqrelyB, glocB, cfnB)
end

function CVBBDPrecInitB(cvode_mem, which, NlocalB::sunindextype, mudqB::sunindextype, mldqB::sunindextype, mukeepB::sunindextype, mlkeepB::sunindextype, dqrelyB::realtype, glocB::CVLocalFnB, cfnB::CVCommFnB)
    CVBBDPrecInitB(cvode_mem, convert(Cint, which), NlocalB, mudqB, mldqB, mukeepB, mlkeepB, dqrelyB, glocB, cfnB)
end

function CVBBDPrecReInitB(cvode_mem, which::Cint, mudqB::sunindextype, mldqB::sunindextype, dqrelyB::realtype)
    ccall((:CVBBDPrecReInitB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, sunindextype, sunindextype, realtype), cvode_mem, which, mudqB, mldqB, dqrelyB)
end

function CVBBDPrecReInitB(cvode_mem, which, mudqB::sunindextype, mldqB::sunindextype, dqrelyB::realtype)
    CVBBDPrecReInitB(cvode_mem, convert(Cint, which), mudqB, mldqB, dqrelyB)
end
# Julia wrapper for header: cvodes_diag.h
# Automatically generated using Clang.jl

function CVDiag(cvode_mem)
    ccall((:CVDiag, libsundials_cvodes), Cint, (CVODEMemPtr,), cvode_mem)
end

function CVDiagGetWorkSpace(cvode_mem, lenrwLS, leniwLS)
    ccall((:CVDiagGetWorkSpace, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}), cvode_mem, lenrwLS, leniwLS)
end

function CVDiagGetNumRhsEvals(cvode_mem, nfevalsLS)
    ccall((:CVDiagGetNumRhsEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nfevalsLS)
end

function CVDiagGetLastFlag(cvode_mem, flag)
    ccall((:CVDiagGetLastFlag, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, flag)
end

function CVDiagGetReturnFlagName(flag::Clong)
    ccall((:CVDiagGetReturnFlagName, libsundials_cvodes), Cstring, (Clong,), flag)
end

function CVDiagGetReturnFlagName(flag)
    CVDiagGetReturnFlagName(convert(Clong, flag))
end

function CVDiagB(cvode_mem, which::Cint)
    ccall((:CVDiagB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint), cvode_mem, which)
end

function CVDiagB(cvode_mem, which)
    CVDiagB(cvode_mem, convert(Cint, which))
end
# Julia wrapper for header: cvodes_direct.h
# Automatically generated using Clang.jl

function CVDlsSetLinearSolver(cvode_mem, LS::SUNLinearSolver, A::SUNMatrix)
    ccall((:CVDlsSetLinearSolver, libsundials_cvodes), Cint, (CVODEMemPtr, SUNLinearSolver, SUNMatrix), cvode_mem, LS, A)
end

function CVDlsSetJacFn(cvode_mem, jac::CVDlsJacFn)
    ccall((:CVDlsSetJacFn, libsundials_cvodes), Cint, (CVODEMemPtr, CVDlsJacFn), cvode_mem, jac)
end

function CVDlsGetWorkSpace(cvode_mem, lenrwLS, leniwLS)
    ccall((:CVDlsGetWorkSpace, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}), cvode_mem, lenrwLS, leniwLS)
end

function CVDlsGetNumJacEvals(cvode_mem, njevals)
    ccall((:CVDlsGetNumJacEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, njevals)
end

function CVDlsGetNumRhsEvals(cvode_mem, nfevalsLS)
    ccall((:CVDlsGetNumRhsEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nfevalsLS)
end

function CVDlsGetLastFlag(cvode_mem, flag)
    ccall((:CVDlsGetLastFlag, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, flag)
end

function CVDlsGetReturnFlagName(flag::Clong)
    ccall((:CVDlsGetReturnFlagName, libsundials_cvodes), Cstring, (Clong,), flag)
end

function CVDlsGetReturnFlagName(flag)
    CVDlsGetReturnFlagName(convert(Clong, flag))
end

function CVDlsSetLinearSolverB(cvode_mem, which::Cint, LS::SUNLinearSolver, A::SUNMatrix)
    ccall((:CVDlsSetLinearSolverB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, SUNLinearSolver, SUNMatrix), cvode_mem, which, LS, A)
end

function CVDlsSetLinearSolverB(cvode_mem, which, LS::SUNLinearSolver, A::SUNMatrix)
    CVDlsSetLinearSolverB(cvode_mem, convert(Cint, which), LS, A)
end

function CVDlsSetJacFnB(cvode_mem, which::Cint, jacB::CVDlsJacFnB)
    ccall((:CVDlsSetJacFnB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVDlsJacFnB), cvode_mem, which, jacB)
end

function CVDlsSetJacFnB(cvode_mem, which, jacB::CVDlsJacFnB)
    CVDlsSetJacFnB(cvode_mem, convert(Cint, which), jacB)
end

function CVDlsSetJacFnBS(cvode_mem, which::Cint, jacBS::CVDlsJacFnBS)
    ccall((:CVDlsSetJacFnBS, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVDlsJacFnBS), cvode_mem, which, jacBS)
end

function CVDlsSetJacFnBS(cvode_mem, which, jacBS::CVDlsJacFnBS)
    CVDlsSetJacFnBS(cvode_mem, convert(Cint, which), jacBS)
end
# Julia wrapper for header: cvodes_ls.h
# Automatically generated using Clang.jl

function CVodeSetLinearSolver(cvode_mem, LS::SUNLinearSolver, A::SUNMatrix)
    ccall((:CVodeSetLinearSolver, libsundials_cvodes), Cint, (CVODEMemPtr, SUNLinearSolver, SUNMatrix), cvode_mem, LS, A)
end

function CVodeSetJacFn(cvode_mem, jac::CVLsJacFn)
    ccall((:CVodeSetJacFn, libsundials_cvodes), Cint, (CVODEMemPtr, CVLsJacFn), cvode_mem, jac)
end

function CVodeSetMaxStepsBetweenJac(cvode_mem, msbj::Clong)
    ccall((:CVodeSetMaxStepsBetweenJac, libsundials_cvodes), Cint, (CVODEMemPtr, Clong), cvode_mem, msbj)
end

function CVodeSetMaxStepsBetweenJac(cvode_mem, msbj)
    CVodeSetMaxStepsBetweenJac(cvode_mem, convert(Clong, msbj))
end

function CVodeSetEpsLin(cvode_mem, eplifac::realtype)
    ccall((:CVodeSetEpsLin, libsundials_cvodes), Cint, (CVODEMemPtr, realtype), cvode_mem, eplifac)
end

function CVodeSetPreconditioner(cvode_mem, pset::CVLsPrecSetupFn, psolve::CVLsPrecSolveFn)
    ccall((:CVodeSetPreconditioner, libsundials_cvodes), Cint, (CVODEMemPtr, CVLsPrecSetupFn, CVLsPrecSolveFn), cvode_mem, pset, psolve)
end

function CVodeSetJacTimes(cvode_mem, jtsetup::CVLsJacTimesSetupFn, jtimes::CVLsJacTimesVecFn)
    ccall((:CVodeSetJacTimes, libsundials_cvodes), Cint, (CVODEMemPtr, CVLsJacTimesSetupFn, CVLsJacTimesVecFn), cvode_mem, jtsetup, jtimes)
end

function CVodeSetLinSysFn(cvode_mem, linsys::CVLsLinSysFn)
    ccall((:CVodeSetLinSysFn, libsundials_cvodes), Cint, (CVODEMemPtr, CVLsLinSysFn), cvode_mem, linsys)
end

function CVodeGetLinWorkSpace(cvode_mem, lenrwLS, leniwLS)
    ccall((:CVodeGetLinWorkSpace, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}), cvode_mem, lenrwLS, leniwLS)
end

function CVodeGetNumJacEvals(cvode_mem, njevals)
    ccall((:CVodeGetNumJacEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, njevals)
end

function CVodeGetNumPrecEvals(cvode_mem, npevals)
    ccall((:CVodeGetNumPrecEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, npevals)
end

function CVodeGetNumPrecSolves(cvode_mem, npsolves)
    ccall((:CVodeGetNumPrecSolves, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, npsolves)
end

function CVodeGetNumLinIters(cvode_mem, nliters)
    ccall((:CVodeGetNumLinIters, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nliters)
end

function CVodeGetNumLinConvFails(cvode_mem, nlcfails)
    ccall((:CVodeGetNumLinConvFails, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nlcfails)
end

function CVodeGetNumJTSetupEvals(cvode_mem, njtsetups)
    ccall((:CVodeGetNumJTSetupEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, njtsetups)
end

function CVodeGetNumJtimesEvals(cvode_mem, njvevals)
    ccall((:CVodeGetNumJtimesEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, njvevals)
end

function CVodeGetNumLinRhsEvals(cvode_mem, nfevalsLS)
    ccall((:CVodeGetNumLinRhsEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nfevalsLS)
end

function CVodeGetLastLinFlag(cvode_mem, flag)
    ccall((:CVodeGetLastLinFlag, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, flag)
end

function CVodeGetLinReturnFlagName(flag::Clong)
    ccall((:CVodeGetLinReturnFlagName, libsundials_cvodes), Cstring, (Clong,), flag)
end

function CVodeGetLinReturnFlagName(flag)
    CVodeGetLinReturnFlagName(convert(Clong, flag))
end

function CVodeSetLinearSolverB(cvode_mem, which::Cint, LS::SUNLinearSolver, A::SUNMatrix)
    ccall((:CVodeSetLinearSolverB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, SUNLinearSolver, SUNMatrix), cvode_mem, which, LS, A)
end

function CVodeSetLinearSolverB(cvode_mem, which, LS::SUNLinearSolver, A::SUNMatrix)
    CVodeSetLinearSolverB(cvode_mem, convert(Cint, which), LS, A)
end

function CVodeSetJacFnB(cvode_mem, which::Cint, jacB::CVLsJacFnB)
    ccall((:CVodeSetJacFnB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVLsJacFnB), cvode_mem, which, jacB)
end

function CVodeSetJacFnB(cvode_mem, which, jacB::CVLsJacFnB)
    CVodeSetJacFnB(cvode_mem, convert(Cint, which), jacB)
end

function CVodeSetJacFnBS(cvode_mem, which::Cint, jacBS::CVLsJacFnBS)
    ccall((:CVodeSetJacFnBS, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVLsJacFnBS), cvode_mem, which, jacBS)
end

function CVodeSetJacFnBS(cvode_mem, which, jacBS::CVLsJacFnBS)
    CVodeSetJacFnBS(cvode_mem, convert(Cint, which), jacBS)
end

function CVodeSetEpsLinB(cvode_mem, which::Cint, eplifacB::realtype)
    ccall((:CVodeSetEpsLinB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, realtype), cvode_mem, which, eplifacB)
end

function CVodeSetEpsLinB(cvode_mem, which, eplifacB::realtype)
    CVodeSetEpsLinB(cvode_mem, convert(Cint, which), eplifacB)
end

function CVodeSetPreconditionerB(cvode_mem, which::Cint, psetB::CVLsPrecSetupFnB, psolveB::CVLsPrecSolveFnB)
    ccall((:CVodeSetPreconditionerB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVLsPrecSetupFnB, CVLsPrecSolveFnB), cvode_mem, which, psetB, psolveB)
end

function CVodeSetPreconditionerB(cvode_mem, which, psetB::CVLsPrecSetupFnB, psolveB::CVLsPrecSolveFnB)
    CVodeSetPreconditionerB(cvode_mem, convert(Cint, which), psetB, psolveB)
end

function CVodeSetPreconditionerBS(cvode_mem, which::Cint, psetBS::CVLsPrecSetupFnBS, psolveBS::CVLsPrecSolveFnBS)
    ccall((:CVodeSetPreconditionerBS, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVLsPrecSetupFnBS, CVLsPrecSolveFnBS), cvode_mem, which, psetBS, psolveBS)
end

function CVodeSetPreconditionerBS(cvode_mem, which, psetBS::CVLsPrecSetupFnBS, psolveBS::CVLsPrecSolveFnBS)
    CVodeSetPreconditionerBS(cvode_mem, convert(Cint, which), psetBS, psolveBS)
end

function CVodeSetJacTimesB(cvode_mem, which::Cint, jtsetupB::CVLsJacTimesSetupFnB, jtimesB::CVLsJacTimesVecFnB)
    ccall((:CVodeSetJacTimesB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVLsJacTimesSetupFnB, CVLsJacTimesVecFnB), cvode_mem, which, jtsetupB, jtimesB)
end

function CVodeSetJacTimesB(cvode_mem, which, jtsetupB::CVLsJacTimesSetupFnB, jtimesB::CVLsJacTimesVecFnB)
    CVodeSetJacTimesB(cvode_mem, convert(Cint, which), jtsetupB, jtimesB)
end

function CVodeSetJacTimesBS(cvode_mem, which::Cint, jtsetupBS::CVLsJacTimesSetupFnBS, jtimesBS::CVLsJacTimesVecFnBS)
    ccall((:CVodeSetJacTimesBS, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVLsJacTimesSetupFnBS, CVLsJacTimesVecFnBS), cvode_mem, which, jtsetupBS, jtimesBS)
end

function CVodeSetJacTimesBS(cvode_mem, which, jtsetupBS::CVLsJacTimesSetupFnBS, jtimesBS::CVLsJacTimesVecFnBS)
    CVodeSetJacTimesBS(cvode_mem, convert(Cint, which), jtsetupBS, jtimesBS)
end

function CVodeSetLinSysFnB(cvode_mem, which::Cint, linsys::CVLsLinSysFnB)
    ccall((:CVodeSetLinSysFnB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVLsLinSysFnB), cvode_mem, which, linsys)
end

function CVodeSetLinSysFnB(cvode_mem, which, linsys::CVLsLinSysFnB)
    CVodeSetLinSysFnB(cvode_mem, convert(Cint, which), linsys)
end

function CVodeSetLinSysFnBS(cvode_mem, which::Cint, linsys::CVLsLinSysFnBS)
    ccall((:CVodeSetLinSysFnBS, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVLsLinSysFnBS), cvode_mem, which, linsys)
end

function CVodeSetLinSysFnBS(cvode_mem, which, linsys::CVLsLinSysFnBS)
    CVodeSetLinSysFnBS(cvode_mem, convert(Cint, which), linsys)
end
# Julia wrapper for header: cvodes_spils.h
# Automatically generated using Clang.jl

function CVSpilsSetLinearSolver(cvode_mem, LS::SUNLinearSolver)
    ccall((:CVSpilsSetLinearSolver, libsundials_cvodes), Cint, (CVODEMemPtr, SUNLinearSolver), cvode_mem, LS)
end

function CVSpilsSetEpsLin(cvode_mem, eplifac::realtype)
    ccall((:CVSpilsSetEpsLin, libsundials_cvodes), Cint, (CVODEMemPtr, realtype), cvode_mem, eplifac)
end

function CVSpilsSetPreconditioner(cvode_mem, pset::CVSpilsPrecSetupFn, psolve::CVSpilsPrecSolveFn)
    ccall((:CVSpilsSetPreconditioner, libsundials_cvodes), Cint, (CVODEMemPtr, CVSpilsPrecSetupFn, CVSpilsPrecSolveFn), cvode_mem, pset, psolve)
end

function CVSpilsSetJacTimes(cvode_mem, jtsetup::CVSpilsJacTimesSetupFn, jtimes::CVSpilsJacTimesVecFn)
    ccall((:CVSpilsSetJacTimes, libsundials_cvodes), Cint, (CVODEMemPtr, CVSpilsJacTimesSetupFn, CVSpilsJacTimesVecFn), cvode_mem, jtsetup, jtimes)
end

function CVSpilsGetWorkSpace(cvode_mem, lenrwLS, leniwLS)
    ccall((:CVSpilsGetWorkSpace, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}, Ptr{Clong}), cvode_mem, lenrwLS, leniwLS)
end

function CVSpilsGetNumPrecEvals(cvode_mem, npevals)
    ccall((:CVSpilsGetNumPrecEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, npevals)
end

function CVSpilsGetNumPrecSolves(cvode_mem, npsolves)
    ccall((:CVSpilsGetNumPrecSolves, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, npsolves)
end

function CVSpilsGetNumLinIters(cvode_mem, nliters)
    ccall((:CVSpilsGetNumLinIters, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nliters)
end

function CVSpilsGetNumConvFails(cvode_mem, nlcfails)
    ccall((:CVSpilsGetNumConvFails, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nlcfails)
end

function CVSpilsGetNumJTSetupEvals(cvode_mem, njtsetups)
    ccall((:CVSpilsGetNumJTSetupEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, njtsetups)
end

function CVSpilsGetNumJtimesEvals(cvode_mem, njvevals)
    ccall((:CVSpilsGetNumJtimesEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, njvevals)
end

function CVSpilsGetNumRhsEvals(cvode_mem, nfevalsLS)
    ccall((:CVSpilsGetNumRhsEvals, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, nfevalsLS)
end

function CVSpilsGetLastFlag(cvode_mem, flag)
    ccall((:CVSpilsGetLastFlag, libsundials_cvodes), Cint, (CVODEMemPtr, Ptr{Clong}), cvode_mem, flag)
end

function CVSpilsGetReturnFlagName(flag)
    ccall((:CVSpilsGetReturnFlagName, libsundials_cvodes), Cstring, (Clong,), flag)
end

function CVSpilsSetLinearSolverB(cvode_mem, which::Cint, LS::SUNLinearSolver)
    ccall((:CVSpilsSetLinearSolverB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, SUNLinearSolver), cvode_mem, which, LS)
end

function CVSpilsSetLinearSolverB(cvode_mem, which, LS::SUNLinearSolver)
    CVSpilsSetLinearSolverB(cvode_mem, convert(Cint, which), LS)
end

function CVSpilsSetEpsLinB(cvode_mem, which::Cint, eplifacB::realtype)
    ccall((:CVSpilsSetEpsLinB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, realtype), cvode_mem, which, eplifacB)
end

function CVSpilsSetEpsLinB(cvode_mem, which, eplifacB::realtype)
    CVSpilsSetEpsLinB(cvode_mem, convert(Cint, which), eplifacB)
end

function CVSpilsSetPreconditionerB(cvode_mem, which::Cint, psetB::CVSpilsPrecSetupFnB, psolveB::CVSpilsPrecSolveFnB)
    ccall((:CVSpilsSetPreconditionerB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVSpilsPrecSetupFnB, CVSpilsPrecSolveFnB), cvode_mem, which, psetB, psolveB)
end

function CVSpilsSetPreconditionerB(cvode_mem, which, psetB, psolveB)
    CVSpilsSetPreconditionerB(cvode_mem, convert(Cint, which), psetB, psolveB)
end

function CVSpilsSetPreconditionerBS(cvode_mem, which::Cint, psetBS::CVSpilsPrecSetupFnBS, psolveBS::CVSpilsPrecSolveFnBS)
    ccall((:CVSpilsSetPreconditionerBS, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVSpilsPrecSetupFnBS, CVSpilsPrecSolveFnBS), cvode_mem, which, psetBS, psolveBS)
end

function CVSpilsSetPreconditionerBS(cvode_mem, which, psetBS::CVSpilsPrecSetupFnBS, psolveBS::CVSpilsPrecSolveFnBS)
    CVSpilsSetPreconditionerBS(cvode_mem, convert(Cint, which), psetBS, psolveBS)
end

function CVSpilsSetJacTimesB(cvode_mem, which::Cint, jtsetupB::CVSpilsJacTimesSetupFnB, jtimesB::CVSpilsJacTimesVecFnB)
    ccall((:CVSpilsSetJacTimesB, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVSpilsJacTimesSetupFnB, CVSpilsJacTimesVecFnB), cvode_mem, which, jtsetupB, jtimesB)
end

function CVSpilsSetJacTimesB(cvode_mem, which, jtsetupB::CVSpilsJacTimesSetupFnB, jtimesB::CVSpilsJacTimesVecFnB)
    CVSpilsSetJacTimesB(cvode_mem, convert(Cint, which), jtsetupB, jtimesB)
end

function CVSpilsSetJacTimesBS(cvode_mem, which::Cint, jtsetupBS::CVSpilsJacTimesSetupFnBS, jtimesBS::CVSpilsJacTimesVecFnBS)
    ccall((:CVSpilsSetJacTimesBS, libsundials_cvodes), Cint, (CVODEMemPtr, Cint, CVSpilsJacTimesSetupFnBS, CVSpilsJacTimesVecFnBS), cvode_mem, which, jtsetupBS, jtimesBS)
end

function CVSpilsSetJacTimesBS(cvode_mem, which, jtsetupBS::CVSpilsJacTimesSetupFnBS, jtimesBS::CVSpilsJacTimesVecFnBS)
    CVSpilsSetJacTimesBS(cvode_mem, convert(Cint, which), jtsetupBS, jtimesBS)
end


text:
This is the JLL package corresponding to the `ReSHOP.jl` Julia package.

The Julia code is based on the one produced by `BinaryBuilder.jl` and has been manually edited.

ext: jl


text:
using AbstractTrees
using Random
using ProgressMeter: Progress

const AT = AbstractTrees

struct StructTree{X}
    x::X
end

is_expand(x) = true
is_expand(::AbstractArray) = false
is_expand(::AbstractDict) = false
is_expand(::AbstractRNG) = false
is_expand(::Progress) = false
is_expand(::Function) = false
is_expand(::UnionAll) = false
is_expand(::DataType) = false

function AT.children(t::StructTree{X}) where {X}
    if is_expand(t.x)
        Tuple(f => StructTree(getfield(t.x, f)) for f in fieldnames(X))
    else
        ()
    end
end

AT.children(t::Pair{Symbol,<:StructTree}) = children(last(t))

AT.printnode(io::IO, t::StructTree{T}) where {T} = print(io, T.name)
AT.printnode(io::IO, t::StructTree{<:Union{Number,Symbol}}) = print(io, t.x)
AT.printnode(io::IO, t::StructTree{UnionAll}) = print(io, t.x)
AT.printnode(io::IO, t::StructTree{<:AbstractArray}) = summary(io, t.x)

function AT.printnode(io::IO, t::Pair{Symbol,<:StructTree})
    print(io, first(t), " => ")
    AT.printnode(io, last(t))
end

function AT.printnode(io::IO, t::StructTree{String})
    s = t.x
    i = findfirst('\n', s)
    if isnothing(i)
        if length(s) > 79
            print(io, "\"$(s[1:79])...\"")
        else
            print(io, "\"$s\"")
        end
    else
        if i > 79
            print(io, "\"$(s[1:79])...\"")
        else
            print(io, "\"$(s[1:i-1])...\"")
        end
    end
end

AT.printnode(io::IO, t::Pair{Symbol,<:StructTree{<:Tuple}}) = print(io, first(t))


text:
using Random
using Plots
using StatsBase
using Distributions

function simulate_game(number_of_players::Int, number_of_steps::Int)
    local leader = 1
    local alive = ones(Int16, number_of_players)
    for i in 1:number_of_steps::Int
        if rand() < 0.5
            if sum(alive) == 0
                return(0)
            end
            alive[leader] = 0
            leader += 1
        end
    end
    return(sum(alive))
end

num_simulations = 10000
num_people = 16
num_steps = 18
num_survivors = Array{Int16}(undef, num_simulations)
time_per_simulation = Array{Float32}(undef, num_simulations)
p = Binomial(18, 0.5)
for i in 1:num_simulations::Int
    #stats = @timed num_survivors[i] = simulate_game(num_people, num_steps)
    stats = @timed num_survivors[i] = max(16 - sum(rand(18) .< 0.5), 0)
    #stats = @timed num_survivors = max(16 - rand(p), 0)
    time_per_simulation[i] = stats.time*10^9
end

describe(time_per_simulation)
display(histogram(time_per_simulation))


text:
import Distributions

const Dists = Distributions

struct Integral{F,M}
    f::F
    μ::M
end

∫(μ) = ∫(identity, μ)
∫(f, μ) = Integral(f, μ)

∫(::typeof(identity), ::Dists.Distribution) = 1.0

∫(Dists.Normal()) do x
    x^2
end


text:
module FESpacesInterfacesTests

using FillArrays
using Test
using Gridap.Arrays
using Gridap.Fields
using Gridap.TensorValues
using Gridap.ReferenceFEs
using Gridap.Geometry
using Gridap.FESpaces
using Gridap.CellData
using LinearAlgebra

order = 1
domain =(0,1,0,1)
partition = (3,3)
model = CartesianDiscreteModel(domain,partition)
reffe = ReferenceFE(lagrangian,Float64,order)
V = FESpace(model,reffe,dirichlet_tags=["tag_1","tag_6"])
test_fe_space(V)

vh = FEFunction(V,rand(num_free_dofs(V)))
@test isa(vh,FEFunction)
test_fe_function(vh)

dv = get_fe_basis(V)
du = get_trial_fe_basis(V)

trian_Γ = SkeletonTriangulation(model)
x_Γ = get_cell_points(trian_Γ)

@test isa(dv.minus(x_Γ)[1],ArrayBlock)
@test isa(du.plus(x_Γ)[1],ArrayBlock)
@test isa(∇(dv).plus(x_Γ)[1],ArrayBlock)
@test isa(∇(du).minus(x_Γ)[1],ArrayBlock)

cellids = [1,3,5,2]
cell_vals = get_cell_dof_values(vh,cellids)
@test cell_vals == get_cell_dof_values(vh)[cellids]

cellidsL = cellids
cellidsR = [2,4,3,1]
cellidsS = SkeletonPair(cellidsL,cellidsR)
cell_vals = get_cell_dof_values(vh,cellidsS)
@test isa(cell_vals[1],ArrayBlock)

zh = zero(V)
@test isa(zh,FEFunction)
@test has_constraints(V) == false

cellids = [1,3,5,2]
@test get_cell_dof_ids(V,cellids) == [[-1, 1, 4, 5], [2, 3, 6, 7], [5, 6, 9, 10], [1, 2, 5, 6]]

cellidsL = cellids
cellidsR = [2,4,3,1]
cellidsS = SkeletonPair(cellidsL,cellidsR)
@test isa(get_cell_dof_ids(V,cellidsS)[1],ArrayBlock)
@test get_cell_dof_ids(V,cellidsS)[1][1] == [-1, 1, 4, 5]
@test get_cell_dof_ids(V,cellidsS)[1][2] == [1, 2, 5, 6]

cell_constr = get_cell_constraints(V)
@test cell_constr == [Matrix(I,4,4) for cell in 1:num_cells(model)]

cell_constr = get_cell_constraints(V,cellids)
@test cell_constr == [Matrix(I,4,4) for cell in 1:length(cellids)]

@test get_cell_isconstrained(V,cellids) == Fill(false,length(cellids))

cell_constr = get_cell_constraints(V,cellidsS)
@test isa(cell_constr[1],ArrayBlock)

du = get_trial_fe_basis(V)
du_data = get_data(du)
@test size(du_data[1]) == (1,4)

@test get_cell_isconstrained(V,cellidsS) == Fill(false,length(cellids))

cellmat = [rand(4,4) for cell in 1:num_cells(model)]
cellvec = [rand(4) for cell in 1:num_cells(model)]
cellmatvec = pair_arrays(cellmat,cellvec)
cellids = IdentityVector(num_cells(model))
matdata = (cellmat,cellids,cellids)
vecdata = (cellvec,cellids)
matvecdata = (cellmatvec,cellids,cellids)

@test cellmat === attach_constraints_rows(V,cellmat,cellids)
@test cellmat === attach_constraints_cols(V,cellmat,cellids)
test_fe_space(V,matvecdata,matdata,vecdata)

end # module


text:
using OVERTVerify
using LazySets
using Dates

controller_type = ARGS[1] # pass from command line, e.g. "small"
controller = "nnet_files/jmlr/single_pendulum_$(controller_type)_controller.nnet"
println("Controller: ", controller)
query = OvertQuery(
	SinglePendulum,    # problem
	controller,        # network file
	Id(),              # last layer activation layer Id()=linear, or ReLU()=relu
	"MIP",             # query solver, "MIP" or "ReluPlex"
	25,                # ntime
	0.1,               # dt
	-1,                # N_overt
	)

input_set = Hyperrectangle(low=[1., 0.], high=[1.2, 0.2])
concretization_intervals = Int.(ones(query.ntime))
t1 = Dates.time()
concrete_state_sets, symbolic_state_sets, concrete_meas_sets, symbolic_meas_sets = symbolic_reachability_with_concretization(query, input_set, concretization_intervals)
t2 = Dates.time()
dt = (t2-t1)
print("elapsed time= $(dt) seconds")

# we want to check the intersection with the avoid set: x_1 <= -.2167
avoid_set = [HalfSpace([1., 0.], -0.2167)] # 1*x_1 + 0*x_2 <= -.2167  --> x_1 <= -.2167

t1 = time()
safe, violations = check_avoid_set_intersection(symbolic_state_sets, input_set, avoid_set)
dt_check = time() - t1

using JLD2
JLD2.@save "src/examples/jmlr/data/single_pendulum_reachability_$(controller_type)_controller_data_1step.jld2" query input_set concretization_intervals concrete_state_sets concrete_meas_sets symbolic_state_sets symbolic_meas_sets dt controller avoid_set safe violations dt_check


text:
using CSV, DataFrames, DecisionTree, Distributions, Gurobi, JuMP, LightGraphs, Parameters, SparseArrays, Statistics, ArgParse
cd("~/code")

include("oracles/shortest_path_oracle.jl")
include("solver/util.jl")
include("solver/sgd.jl")
include("solver/reformulation.jl")
include("solver/random_forests_po.jl")
include("solver/validation_set.jl")
include("experiments/replication_functions.jl")

# Fix parameters
p_features = 20 #try: 10, 20
grid_dim = 5
num_trials = 30 #30 #50
n_test = 1000

num_lambda = 10
lambda_max = 100
lambda_min_ratio = 10.0^(-8)
holdout_percent = 0.25
regularization = :lasso
different_validation_losses = false

n_train_vec = [100] #[100; 1000]
polykernel_degree_vec = [1; 2; 4; 6; 8] #also tried: [1; 4; 8; 12; 16; 20]
polykernel_noise_half_width_vec = [0.5]

# random seed
rng_seed = 5352 #for comparison

# Run experiment and get results: save separate dataframes based on runs with parameters above
# Note that Gurobi enviornments are set within this function call
expt_results = shortest_path_multiple_replications(rng_seed, num_trials, grid_dim,
    n_train_vec, n_test,
    p_features, polykernel_degree_vec, polykernel_noise_half_width_vec;
    num_lambda = num_lambda, lambda_max = lambda_max, lambda_min_ratio = lambda_min_ratio,
    holdout_percent = holdout_percent, regularization = regularization,
    different_validation_losses = different_validation_losses)

#save respective dataframe
csv_string = "shortest_path_100n_20p.csv"
CSV.write(csv_string, expt_results)

max_stars_repo_name: katerinagiannoutsou/dso-coding-project

max_issues_repo_name: katerinagiannoutsou/dso-coding-project

max_forks_repo_name: katerinagiannoutsou/dso-coding-project


text:
function reshape3d(x::CuArray, dim::Int)
    # dim == 0 && return (1, length(x), 1)
    dim1, dim2, dim3 = 1, size(x,dim), 1
    for i = 1:dim-1
        dim1 *= size(x, i)
    end
    for i = dim+1:ndims(x)
        dim3 *= size(x, i)
    end
    reshape(x, dim1, dim2, dim3)
end

doc"""
    mean(x, dim::Int)

Computes the average over the given dimension.
"""
function Base.mean(x::Var, dim::Int)
    if dim == ndims(x)
        y = mean_batch(x.data, x.batchdims)
        batchdims = ones(Int, length(x.batchdims))
    else
        y = mean(x.data, dim)
        batchdims = x.batchdims
    end
    Var(y, batchdims, mean, (x,dim))
end

function mean_batch2{T,N}(x::Array{T,N}, batchdims::Vector{Int})
    front = Base.front(size(x))
    n = prod(front)
    y = T[]

    cumdim = 0
    for i = 1:length(batchdims)
        p = pointer(x, n*cumdim+1)
        subx = unsafe_wrap(Array, p, (front...,batchdims[i]))

        m = mean(subx, N)
        append!(y, m)
        cumdim += batchdims[i]
    end
    reshape(y, front..., length(batchdims))
end

function addgrad!(y::Var, ::typeof(mean), x::Var, dim::Int)
    isvoid(x.grad) || ∇mean!(y.grad, x.grad, dim)
end

function ∇mean!{T}(gy::Array{T}, gx::Array{T}, dim::Int)
    g = broadcast(+, x.grad, y.grad)
    broadcast(/, gx, g, size(gx,dim))
end


text:
using SafeTestsets, Test

@safetestset "Values at origin" begin include("origin.jl") end
@safetestset "Orientation" begin include("orientation.jl") end
@safetestset "Field values compared with symbolic results" begin include("field_values.jl") end
@safetestset "Divergence in Polynomial Roots" begin include("roots.jl") end
@safetestset "LG(p = 0, m = 0, x, y, z, t) == G(x, y, z, t)" begin include("gauss.jl") end
@safetestset "Comparison to Symbolic Values" begin include("field_values.jl") end


text:
abstract type AbstractStrideArray{S,D,T,N,C,B,R,X,O} <: DenseArray{T,N} end
abstract type AbstractPtrStrideArray{S,D,T,N,C,B,R,X,O} <: AbstractStrideArray{S,D,T,N,C,B,R,X,O} end
const AbstractStrideVector{S,D,T,C,B,R,X,O} = AbstractStrideArray{S,D,T,1,C,B,R,X,O}
const AbstractStrideMatrix{S,D,T,C,B,R,X,O} = AbstractStrideArray{S,D,T,2,C,B,R,X,O}

struct PtrArray{S,D,T,N,C,B,R,X,O} <: AbstractPtrStrideArray{S,D,T,N,C,B,R,X,O}
  ptr::StridedPointer{T,N,C,B,R,X,O}
  size::S
end
@inline function PtrArray(ptr::StridedPointer{T,N,C,B,R,X,O}, size::S, ::Val{D}) where {S,D,T,N,C,B,R,X,O}
  PtrArray{S,D,T,N,C,B,R,X,O}(ptr, size)
end
struct BitPtrArray{S,D,N,C,B,R,X,O} <: AbstractPtrStrideArray{S,D,Bit,N,C,B,R,X,O}
  ptr::StridedBitPointer{N,C,B,R,X,O}
  size::S
end
@inline function PtrArray(ptr::StridedBitPointer{N,C,B,R,X,O}, size::S, ::Val{D}) where {S,D,N,C,B,R,X,O}
  BitPtrArray{S,D,N,C,B,R,X,O}(ptr, size)
end

const PtrVector{S,D,T,C,B,R,X,O} = PtrArray{S,D,T,1,C,B,R,X,O}
const PtrMatrix{S,D,T,C,B,R,X,O} = PtrArray{S,D,T,2,C,B,R,X,O}

@inline PtrArray(A::AbstractArray) = PtrArray(stridedpointer(A), size(A), val_dense_dims(A))

@inline LayoutPointers.stridedpointer(A::AbstractPtrStrideArray) = getfield(A, :ptr)
@inline Base.pointer(A::AbstractStrideArray) = pointer(stridedpointer(A))
@inline Base.unsafe_convert(::Type{Ptr{T}}, A::AbstractStrideArray) where {T} = Base.unsafe_convert(Ptr{T}, pointer(A))
@inline Base.elsize(::AbstractStrideArray{<:Any,<:Any,T}) where {T} = sizeof(T)

@inline ArrayInterface.size(A::AbstractPtrStrideArray) = getfield(A, :size)
@inline LayoutPointers.bytestrides(A::AbstractPtrStrideArray) = bytestrides(getfield(A, :ptr))
ArrayInterface.device(::AbstractStrideArray) = ArrayInterface.CPUPointer()

ArrayInterface.contiguous_axis(::Type{<:AbstractStrideArray{S,D,T,N,C}}) where {S,D,T,N,C} = StaticInt{C}()
ArrayInterface.contiguous_batch_size(::Type{<:AbstractStrideArray{S,D,T,N,C,B}}) where {S,D,T,N,C,B} = ArrayInterface.StaticInt{B}()

static_expr(N::Int) = Expr(:call, Expr(:curly, :StaticInt, N))
static_expr(b::Bool) = Expr(:call, b ? :True : :False)
@generated function ArrayInterface.stride_rank(::Type{<:AbstractStrideArray{S,D,T,N,C,B,R}}) where {S,D,T,N,C,B,R}
  t = Expr(:tuple)
  for r ∈ R
    push!(t.args, static_expr(r::Int))
  end
  t
end
@generated function ArrayInterface.dense_dims(::Type{<:AbstractStrideArray{S,D}}) where {S,D}
  t = Expr(:tuple)
  for d ∈ D
    push!(t.args, static_expr(d::Bool))
  end
  t
end

# @inline bytestride(A, n) = LayoutPointers.bytestrides(A)[n]

function onetupleexpr(N::Int)
  t = Expr(:tuple);
  for n in 1:N
    push!(t.args, :(One()))
  end
  Expr(:block, Expr(:meta,:inline), t)
end
@generated onetuple(::Val{N}) where {N} = onetupleexpr(N)

@inline function default_strideindex(s::Tuple{Vararg{Integer,N}}, o::Tuple{Vararg{Integer,N}}) where {N}
  StrideIndex{N,ntuple(identity,Val(N)),1}(s, o)
end
@inline function default_stridedpointer(ptr::Ptr{T}, x::X) where {T, N, X <: Tuple{Vararg{Integer,N}}}
  stridedpointer(ptr, default_strideindex(x, onetuple(Val(N))))
end
@inline function default_zerobased_stridedpointer(ptr::Ptr{T}, x::X) where {T, N, X <: Tuple{Vararg{Integer,N}}}
  stridedpointer(ptr, default_strideindex(x, LayoutPointers.zerotuple(Val(N))))
end

@inline function ptrarray0(ptr::Ptr{T}, s::Tuple{Vararg{Integer,N}}, x::Tuple{Vararg{Integer,N}}, ::Val{D}) where {T,N,D}
  PtrArray(default_zerobased_stridedpointer(ptr, x), s, Val{D}())
end
@inline function PtrArray(ptr::Ptr{T}, s::Tuple{Vararg{Integer,N}}, x::Tuple{Vararg{Integer,N}}, ::Val{D}) where {T,N,D}
  PtrArray(default_stridedpointer(ptr, x), s, Val{D}())
end

@inline LayoutPointers.zero_offsets(A::AbstractPtrStrideArray{S,D}) where {S,D} = PtrArray(LayoutPointers.zero_offsets(stridedpointer(A)), size(A), Val{D}())

function ptrarray_densestride_quote(::Type{T}, N, stridedpointer_offsets) where {T}
  last_sx = :s_0
  q = Expr(:block, Expr(:meta,:inline), Expr(:(=), last_sx, static_sizeof(T)))
  t = Expr(:tuple); d = Expr(:tuple);
  n = 0
  while true
    n += 1
    push!(t.args, last_sx)
    push!(d.args, true)
    n == N && break
    new_sx = Symbol(:s_,n)
    push!(q.args, Expr(:(=), new_sx, Expr(:call, *, last_sx, Expr(:call, GlobalRef(Core,:getfield), :s, n, false))))
    last_sx = new_sx
  end
  push!(q.args, :(PtrArray($stridedpointer_offsets(ptr, $t), s, Val{$d}())))
  q
end
@generated function PtrArray(ptr::Ptr{T}, s::Tuple{Vararg{Integer,N}}) where {T,N}
  ptrarray_densestride_quote(T, N, :default_stridedpointer)
end
@generated function ptrarray0(ptr::Ptr{T}, s::Tuple{Vararg{Integer,N}}) where {T,N}
  ptrarray_densestride_quote(T, N, :default_zerobased_stridedpointer)
end

intlog2(N::I) where {I <: Integer} = (8sizeof(I) - one(I) - leading_zeros(N)) % I
intlog2(::Type{T}) where {T} = intlog2(static_sizeof(T))
@generated intlog2(::StaticInt{N}) where {N} = Expr(:call, Expr(:curly, :StaticInt, intlog2(N)))

@inline function ArrayInterface.strides(A::PtrArray{S,D,T,N}) where {S,D,T,N}
  map(Base.Fix2(>>>,intlog2(static_sizeof(T))), bytestrides(A))
end

@inline Base.size(A::AbstractStrideArray) = map(Int, size(A))
@inline Base.strides(A::AbstractStrideArray) = map(Int, strides(A))

@inline create_axis(s, ::Zero) = CloseOpen(s)
@inline create_axis(s, ::One) = Base.OneTo(unsigned(s))
@inline create_axis(::StaticInt{N}, ::One) where {N} = One():StaticInt{N}()
@inline create_axis(s, o) = CloseOpen(o, s+o)

@inline ArrayInterface.axes(A::AbstractStrideArray) = map(create_axis, size(A), offsets(A))
@inline Base.axes(A::AbstractStrideArray) = axes(A)

@inline ArrayInterface.offsets(A::PtrArray) = offsets(getfield(A, :ptr))
@inline ArrayInterface.static_length(A::AbstractStrideArray) = ArrayInterface.reduce_tup(*, size(A))

# type stable, because index known at compile time
@inline type_stable_select(t::NTuple, ::StaticInt{N}) where {N} = getfield(t, N, false)
@inline type_stable_select(t::Tuple, ::StaticInt{N}) where {N} = getfield(t, N, false)
# type stable, because tuple is homogenous
@inline type_stable_select(t::NTuple, i::Integer) = getfield(t, i, false)
# make the tuple homogenous before indexing
@inline type_stable_select(t::Tuple, i::Integer) = getfield(map(Int, t), i, false)

@inline ArrayInterface._axes(A::AbstractStrideArray{S,D,T,N}, i::Integer) where {S,D,T,N} = __axes(A, i)
@inline ArrayInterface._axes(A::AbstractStrideArray{S,D,T,N}, i::Int) where {S,D,T,N} = __axes(A, i)
@inline ArrayInterface._axes(A::AbstractStrideArray{S,D,T,N}, ::StaticInt{I}) where {S,D,T,N,I} = __axes(A, StaticInt{I}())

@inline function __axes(A::AbstractStrideArray{S,D,T,N}, i::Integer) where {S,D,T,N}
  if i ≤ N
    o = type_stable_select(offsets(A), i)
    s = type_stable_select(size(A), i)
    return create_axis(s, o)
  else
    return One():One()
  end
end
@inline Base.axes(A::AbstractStrideArray, i::Integer) = axes(A, i)

@inline function ArrayInterface.size(A::AbstractStrideVector, i::Integer)
  d = Int(length(A))
  ifelse(isone(i), d, one(d))
end
@inline ArrayInterface.size(A::AbstractStrideVector, ::StaticInt{N}) where {N} = One()
@inline ArrayInterface.size(A::AbstractStrideVector, ::StaticInt{1}) = length(A)
@inline ArrayInterface.size(A::AbstractStrideArray, ::StaticInt{N}) where {N} = size(A)[N]
@inline ArrayInterface.size(A::AbstractStrideArray, i::Integer) = type_stable_select(size(A), i)
@inline Base.size(A::AbstractStrideArray, i::Integer) = size(A, i)

# Base.IndexStyle(::Type{<:AbstractStrideArray}) = IndexCartesian()
# Base.IndexStyle(::Type{<:AbstractStrideVector{<:Any,<:Any,<:Any,1}}) = IndexLinear()
@generated function Base.IndexStyle(::Type{<:AbstractStrideArray{S,D,T,N,C,B,R}}) where {S,D,T,N,C,B,R}
  # if is column major || is a transposed contiguous vector
  if all(D) && ((isone(C) && R === ntuple(identity, Val(N))) || (C === 2 && R === (2,1) && S <: Tuple{One,Integer}))
    :(IndexLinear())
  else
    :(IndexCartesian())
  end
end

@inline LayoutPointers.preserve_buffer(A::PtrArray) = nothing

@generated function pload(p::Ptr{T}) where {T}
  if Base.allocatedinline(T)
    Expr(:block, Expr(:meta,:inline), :(unsafe_load(p)))
  else
    Expr(:block, Expr(:meta,:inline), :(ccall(:jl_value_ptr, Ref{$T}, (Ptr{Cvoid},), unsafe_load(Base.unsafe_convert(Ptr{Ptr{Cvoid}}, p)))))
  end
end
@generated function pstore!(p::Ptr{T}, v::T) where {T}
  if Base.allocatedinline(T)
    Expr(:block, Expr(:meta,:inline), :(unsafe_store!(p, v); return nothing))
  else
    Expr(:block, Expr(:meta,:inline), :(unsafe_store!(Base.unsafe_convert(Ptr{Ptr{Cvoid}}, p), Base.pointer_from_objref(v)); return nothing))
  end
end
@inline pstore!(p::Ptr{T}, v) where {T} = pstore!(p, convert(T, v))

function rank2sortperm(R)
  map(R) do r
    sum(map(≥(r),R))
  end
end
# @generated function _offset_ptr(ptr::AbstractStridedPointer{T,N,C,B,R}, i::Tuple{Vararg{Integer,NI}}) where {T,N,C,B,R,NI}
#   if N ≠ NI
#     if (N > NI) & (NI ≠ 1)
#       throw(ArgumentError("If the dimension of the array exceeds the dimension of the index, then the index should be linear/one dimensional."))
#     end
#     # use only the first index. Supports, for example `x[i,1,1,1,1]` when `x` is a vector, or `A[i]` where `A` is an array with dim > 1.
#     return Expr(:block, Expr(:meta,:inline), :(pointer(ptr) + (first(i)-1)*$(static_sizeof(T))))
#   end
#   sp = rank2sortperm(R)
#   q = Expr(:block, Expr(:meta,:inline), :(p = pointer(ptr)), :(o = LayoutPointers.offsets(ptr)), :(x = strides(ptr)))
#   gf = GlobalRef(Core,:getfield)
#   for n ∈ 1:N
#     j = findfirst(==(n),sp)::Int
#     index = Expr(:call, gf, :i, j, false)
#     offst = Expr(:call, gf, :o, j, false)
#     strid = Expr(:call, gf, :x, j, false)
#     push!(q.args, :(p += ($index - $offst)*$strid))
#   end
#   q
# end
@generated function _offset_ptr(ptr::AbstractStridedPointer{T,N,C,B,R}, i::Tuple{Vararg{Integer,NI}}) where {T,N,C,B,R,NI}
  ptr_expr = :(pointer(ptr))
  T === Bit && (ptr_expr = :(reinterpret(Ptr{UInt8}, $ptr_expr)))
  N == 0 && return Expr(:block, Expr(:meta,:inline), ptr_expr)
  if N ≠ NI
    if (N > NI) & (NI ≠ 1)
      throw(ArgumentError("If the dimension of the array exceeds the dimension of the index, then the index should be linear/one dimensional."))
    end
    # use only the first index. Supports, for example `x[i,1,1,1,1]` when `x` is a vector, or `A[i]` where `A` is an array with dim > 1.
    return Expr(:block, Expr(:meta,:inline), :($ptr_expr + (first(i)-1)*$(static_sizeof(T))))
  end
  sp = rank2sortperm(R)
  q = Expr(:block, Expr(:meta,:inline), :(p = $ptr_expr), :(o = offsets(ptr)), :(x = strides(ptr)))
  for n ∈ 1:N
    j = findfirst(==(n),sp)::Int
    index = Expr(:call, getfield, :i, j, false)
    offst = Expr(:call, getfield, :o, j, false)
    strid = Expr(:call, getfield, :x, j, false)
    if T ≢ Bit
      push!(q.args, :(p += ($index - $offst)*$strid))
    else
      push!(q.args, :(p += (($index - $offst)>>>3)*$strid))
    end
  end
  q
end
# @inline _offset_ptr(ptr::AbstractStridedPointer{T,N,C,B,R,X,NTuple{N,Zero}}, i::Tuple{Vararg{Integer,NI}}) where {T,N,C,B,R,NI,X} = __offset_ptr(ptr,i)
# @inline function _offset_ptr(ptr::AbstractStridedPointer{T,N,C,B,R}, i::Tuple{Vararg{Integer,NI}}) where {T,N,C,B,R,NI}
#   __offset_ptr(LayoutPointers.center(ptr), i)
# end

@inline function Base.getindex(A::BitPtrArray{S,D,N,C}, i::Vararg{Integer,N}) where {S,D,N,C}
  fi = getfield(i, C) - getfield(offsets(A), C)
  u = pload(_offset_ptr(stridedpointer(A), i))
  (u >>> (fi & 7)) % Bool
end
@inline function Base.getindex(A::BitPtrArray{S,D,N,C}, i::Integer) where {S,D,N,C}
  j = i - oneunit(i)
  u = pload(reinterpret(Ptr{UInt8}, pointer(A)) + (j >>> 3))
  (u >>> (j & 7)) % Bool
end
# Base.@propagate_inbounds function Base.getindex(A::AbstractStrideArray, i::Vararg{Any,K}) where {K}
# end
Base.@propagate_inbounds function Base.getindex(A::AbstractStrideArray, i::Vararg{Integer,K}) where {K}
  b = preserve_buffer(A)
  GC.@preserve b begin
    PtrArray(A)[i...]
  end
end
Base.@propagate_inbounds function Base.setindex!(A::AbstractStrideArray, v, i::Vararg{Integer,K}) where {K}
  b = preserve_buffer(A)
  GC.@preserve b begin
    PtrArray(A)[i...] = v
  end
end
# Base.@propagate_inbounds Base.getindex(A::AbstractStrideVector, i::Int, j::Int) = A[i]
@inline function Base.getindex(A::PtrArray, i::Vararg{Integer})
  @boundscheck checkbounds(A, i...)
  pload(_offset_ptr(stridedpointer(A), i))
end
# @inline function Base.getindex(A::AbstractStrideArray, i::Vararg{Integer,K}) where {K}
#   b = preserve_buffer(A)
#   P = PtrArray(A)
#   GC.@preserve b begin
#     @boundscheck checkbounds(P, i...)
#     pload(_offset_ptr(stridedpointer(P), i))
#   end
# end
@inline function Base.setindex!(A::PtrArray, v, i::Vararg{Integer,K}) where {K}
  @boundscheck checkbounds(A, i...)
  pstore!(_offset_ptr(stridedpointer(A), i), v)
  v
end
# @inline function Base.setindex!(A::AbstractStrideArray, v, i::Vararg{Integer,K}) where {K}
#   b = preserve_buffer(A)
#   P = PtrArray(A)
#   GC.@preserve b begin
#     @boundscheck checkbounds(P, i...)
#     pstore!(_offset_ptr(stridedpointer(A), i), v)
#   end
#   v
# end
@inline function Base.getindex(A::PtrArray{S,D,T}, i::Integer) where {S,D,T}
  @boundscheck checkbounds(A, i)
  pload(pointer(A) + (i-oneunit(i))*static_sizeof(T))
end
# @inline function Base.getindex(A::AbstractStrideArray{S,D,T}, i::Integer) where {S,D,T}
#   b = preserve_buffer(A)
#   P = PtrArray(A)
#   GC.@preserve b begin
#     @boundscheck checkbounds(P, i)
#     pload(pointer(A) + (i-oneunit(i))*static_sizeof(T))
#   end
# end
@inline function Base.setindex!(A::PtrArray{S,D,T}, v, i::Integer) where {S,D,T}
  @boundscheck checkbounds(A, i)
  pstore!(pointer(A) + (i-oneunit(i))*static_sizeof(T), v)
  v
end
# @inline function Base.setindex!(A::AbstractStrideArray{S,D,T}, v, i::Integer) where {S,D,T}
#   b = preserve_buffer(A)
#   P = PtrArray(A)
#   GC.@preserve b begin
#     @boundscheck checkbounds(P, i)
#     pstore!(pointer(A) + (i-oneunit(i))*static_sizeof(T), v)
#   end
#   v
# end

@inline function Base.getindex(A::PtrVector{S,D,T}, i::Integer) where {S,D,T}
  @boundscheck checkbounds(A, i)
  pload(pointer(A) + (i-oneunit(i))*only(LayoutPointers.bytestrides(A)))
end
# @inline function Base.getindex(A::AbstractStrideVector{S,D,T}, i::Integer) where {S,D,T}
#   b = preserve_buffer(A)
#   P = PtrArray(A)
#   GC.@preserve b begin
#     @boundscheck checkbounds(P, i)
#     pload(pointer(A) + (i-oneunit(i))*only(LayoutPointers.bytestrides(A)))
#   end
# end
@inline function Base.setindex!(A::PtrVector{S,D,T}, v, i::Integer) where {S,D,T}
  @boundscheck checkbounds(A, i)
  pstore!(pointer(A) + (i-oneunit(i))*only(LayoutPointers.bytestrides(A)), v)
  v
end
# @inline function Base.setindex!(A::AbstractStrideVector{S,D,T}, v, i::Integer) where {S,D,T}
#   b = preserve_buffer(A)
#   P = PtrArray(A)
#   GC.@preserve b begin
#     @boundscheck checkbounds(P, i)
#     pstore!(pointer(A) + (i-oneunit(i))*only(LayoutPointers.bytestrides(A)), v)
#   end
#   v
# end

@inline LayoutPointers.bytestrideindex(A::AbstractStrideArray{T}) where {T} = StrideIndex(stridedpointer(A))

_scale(::False, x, _, __) = x
@inline function _scale(::True, x, num, denom)
  cmp = Static.gt(num, denom)
  numerator = IfElse.ifelse(cmp, num, denom)
  denominator = IfElse.ifelse(cmp, denom, num)
  frac = numerator ÷ denominator
  IfElse.ifelse(cmp, x * frac, x ÷ frac)
end

@inline function Base.reinterpret(::Type{Tnew}, A::PtrArray{S,D,Told,N}) where {Tnew,Told,S,D,N}
  sz = let szt_old = static_sizeof(Told), szt_new = static_sizeof(Tnew)
    map(_scale, contiguous_axis_indicator(A), size(A), ntuple(_ -> szt_old, Val(N)), ntuple(_ -> szt_new, Val(N)))
  end
  sp = reinterpret(Tnew, stridedpointer(A))
  PtrArray(sp, sz, Val{D}())
end

@generated function Base.reinterpret(::typeof(reshape), ::Type{Tnew}, A::PtrArray{S,D,Told,N,C,B,R}) where {S,D,Told,Tnew,N,C,B,R}
  sz_old = sizeof(Told)
  sz_new = sizeof(Tnew)
  Nnew = ifelse(sz_old == sz_new, N, ifelse(sz_old < sz_new, N - 1, N + 1))
  Bnew = ((B ≤ 0) | (sz_old == sz_new)) ? B : ((sz_old*B) ÷ sz_new)
  # sz_old < sz_new && push!(q.args, :(@assert size_A[$C] == $(sz_new ÷ sz_old)))
  if sz_old == sz_new
    size_expr = :size_A
    bx_expr = :bx
    offs_expr = :offs
    Rnew = R
    Cnew = C
    Dnew = D
    Nnew = N
  else
    @assert 1 ≤ C ≤ N
    size_expr = Expr(:tuple)
    bx_expr = Expr(:tuple)
    offs_expr = Expr(:tuple)
    Rnew = Expr(:tuple)
    Dnew = Expr(:tuple)
    for n ∈ 1:N
      sz_n = Expr(:call, GlobalRef(Core,:getfield), :size_A, n, false)
      bx_n = Expr(:call, GlobalRef(Core,:getfield), :bx, n, false)
      of_n = Expr(:call, GlobalRef(Core,:getfield), :offs, n, false)
      if n ≠ C
        push!(size_expr.args, sz_n)
        push!(bx_expr.args, bx_n)
        push!(offs_expr.args, of_n)
        push!(Dnew.args, D[n])
        r = R[n]
        r = if sz_old > sz_new
          r += r > C
        elseif sz_old < sz_new
          r -= r > C
        end
        push!(Rnew.args, r)
      elseif sz_old > sz_new
        si = :(StaticInt{$(sz_old ÷ sz_new)}())
        push!(size_expr.args, si, sz_n)
        push!(bx_expr.args, Expr(:call, :÷, bx_n, si), bx_n)
        push!(offs_expr.args, :(One()), of_n)
        push!(Dnew.args, true, D[n])
        push!(Rnew.args, 1, 1+R[n])
        Cnew = C
      else
        # si = :(StaticInt{$(sz_new ÷ sz_old)}())
        # push!(size_expr.args, Expr(:call, :÷, sz_n, si))
        # push!(bx_expr.args, Expr(:call, :*, sz_n, si))
        R2ind = findfirst(==(2), R)
        Cnew = if R2ind === nothing
          0
        elseif D[R2ind]
          R2ind-1
        else
          0
        end
      end
    end
  end
  quote
    $(Expr(:meta,:inline))
    sp = stridedpointer(A)
    bx = LayoutPointers.bytestrides(sp)
    size_A = size(A)
    offs = offsets(sp)
    si = StrideIndex{$Nnew,$Rnew,$Cnew}($bx_expr, $offs_expr)
    sp = stridedpointer(reinterpret(Ptr{$Tnew}, pointer(sp)), si, StaticInt{$Bnew}())
    PtrArray(sp, $size_expr, Val{$Dnew}())
  end
end
@inline Base.reinterpret(::Type{T}, A::AbstractStrideArray) where {T} = StrideArray(reinterpret(T, PtrArray(A)), preserve_buffer(A))
@inline Base.reinterpret(::typeof(reshape), ::Type{T}, A::AbstractStrideArray) where {T} = StrideArray(reinterpret(reshape, T, PtrArray(A)), preserve_buffer(A))


text:
"
    Truncate a given state using svd
"
@with_kw struct SvdCut <: Algorithm
    trscheme = notrunc()
end

changebonds(state::Union{FiniteMPS{T},MPSComoving{T}},alg::SvdCut) where T = changebonds!(copy(state),alg);
function changebonds!(state::Union{FiniteMPS{T},MPSComoving{T}},alg::SvdCut) where T
    newstate = copy(state);

    for i in length(state)-1:-1:1
        (U,S,V) = tsvd(state.CR[i],trunc=alg.trscheme,alg=TensorKit.SVD());

        state.AC[i] = (state.AL[i]*U,complex(S));
        state.AC[i+1] = (complex(S),_permute_front(V*_permute_tail(state.AR[i+1])));
    end

    return state
end

changebonds(state::InfiniteMPO,alg::SvdCut) = convert(InfiniteMPO,changebonds(convert(InfiniteMPS,state),alg));
changebonds(state::MPOMultiline,alg::SvdCut) = convert(MPOMultiline,changebonds(convert(MPSMultiline,state),alg))
changebonds(state::MPSMultiline,alg::SvdCut) = Multiline(map(x->changebonds(x,alg),state.data))
function changebonds(state::InfiniteMPS,alg::SvdCut)
    copied = copy(state.AL);

    for i in 1:length(state)

        (U,state.CR[i],V) = tsvd(state.CR[i],trunc=alg.trscheme,alg=TensorKit.SVD());
        copied[i] = copied[i]*U
        copied[i+1] = _permute_front(U'*_permute_tail(copied[i+1]))
    end

    InfiniteMPS(copied,state.CR[end]);
end

changebonds(state,H,alg::SvdCut,envs=environments(state,H)) = (changebonds(state,alg),envs)


text:
module ROCdbg

using CEnum

include("librocdbg_common.jl")
include("librocdbg_enums.jl")
include("librocdbg_types.jl")
include("librocdbg_api.jl")

end #module


text:
# ------------ Factor ------------ #

@inline function (ctx::SimulateContext)(fn::typeof(factor), arg)
    ctx.score += arg
    return arg
end


text:
### A Pluto.jl notebook ###
# v0.12.17

using Markdown
using InteractiveUtils

# ╔═╡ b26a3f0c-448e-11eb-1cf0-25438afc670d
using Plots

# ╔═╡ 98aeef06-44a5-11eb-1095-adc7773fd362
using LinearAlgebra

# ╔═╡ 9e6d6934-448e-11eb-21f3-69467bda2410
function lineAngle(slope1, slope2)
    a = slope2 - slope1
    b = 1.0 + (slope2*slope1)
    c = abs(a / b)
    d = atan(c)
    return d
end

# ╔═╡ c3fb3d48-448e-11eb-3dff-6fccd893312c
function lineZero(m, b)
    # find root of the passed line
    x = (-b)/m
    y = 0
    return [x, y]
end

# ╔═╡ c3fbc362-448e-11eb-36b3-a5c2694955da
function findFunc(point1, point2)
    # find the linear function that fits two points, returns m, b
    a = point2[2] - point1[2]
    b = point2[1] - point1[1]
    c = (point2[1] * point1[2]) - (point1[1] * point2[2])
    m = a/b
    d = c/b
    return [m, d]
end

# ╔═╡ c3fc5fd4-448e-11eb-2347-9ddee5b2cc8a
function pFunc(m)
    # find the function perpindicular to passed function flope
    if m != 0.0
        mperp = -1.0/m
    end
    if m == 0
        mperp = 0.0
    end

    return mperp
end

# ╔═╡ c40b9c4c-448e-11eb-1cbc-45324d95420d
function newB(m, point)
    # find the y-intersection that the function point pair pass through
    a = m*point[1]
    b = point[2] - a
    return b
end

# ╔═╡ c41174be-448e-11eb-334d-f97165d225d0
"""Find the distance between points p1 = [x, y] and p2"""
function dist(p1, p2)
    # find the distance between two points
    p = p1-p2
    d = norm(p)
    return d
end

# ╔═╡ c418c974-448e-11eb-01b9-8167c73c6e24
"""Find intersection point between lines of form [slope, intercept]"""
function inter(mb1, mb2)
    # find line intersection point between two lines
    a = mb2[2] - mb1[2]
    b = mb1[1] - mb2[1]

    if b==0
        return 0, mb1[2]
    end

    x = a / b
    y = (mb1[1] * x) + mb1[2]
    return [x, y]
end

# ╔═╡ c41eb1ec-448e-11eb-288d-eb4fecc22f89
"""Find the distance between a line [slope, intercept] and a point [x, y],
where the slope of the line is an angle in degrees."""
function distpointline(line, point)
    s = tan(deg2rad(line[1]))
    p = pFunc(s)
    perp_line = [p, newB(p, point)]
    # now find intersection of the two lines, where lp is not an angle but usual slope
    lp = (s, line[2])
    # find line intersection point
    intersection = inter(perp_line, lp)
    # determine distance and return
    d = dist(point, intersection)
    return d
end

# ╔═╡ c425aa88-448e-11eb-067f-132bc8887e8a
"""Takes the target lineslope angle, and the given rule step angle,
    and returns the two lines that intersect at the target line at the step angle
"""
function mappingOptions(target_line_angle, step_angle)
    # construct base step angle slopes
    b = tan(deg2rad(step_angle + target_line_angle))
    b2 = tan(deg2rad(target_line_angle - step_angle))
    lines = [b, b2]
    return lines
end

# ╔═╡ 2b64bd10-448f-11eb-361c-1798fccb5fde
# plot the visited points
function plotOrbit(X_m, visitedPoints, points_to_plot, orbit_color)
    x = -800:800
    plot(x, zeros(1601), color="black", xlims=(-20,20), ylims=(-20, 20))

    # now plot lines composing X_m
    @simd for k in X_m
        # define y coordinates
        m = k[1]
        m = tan(deg2rad(m))
        b = k[2]
        plot!(x, (x*m).+b, color="black")
    end

    # now plot the orbit
    tx = []
    for i in visitedPoints[points_to_plot[1]+1:points_to_plot[2]+1]
        push!(tx, i[1])
    end
    ty = []
    for i in visitedPoints[points_to_plot[1]+1:points_to_plot[2]+1]
        push!(ty, i[2])
    end
    # plot
    plot!(tx, ty, color=orbit_color, label="Orbit")
end

# ╔═╡ ef6fb954-448e-11eb-0915-299e31bffd95
"""
The following code takes an n-rule, and plots the path it generates
    in the specified space X_m.  If the n-rule map converges to a periodic orbit
    within num_iter iterations, the program will return the period.
    Inputs:
    X_m: input a list of m tuples, where m is the number of lines plus the x axis, so
        X_m is of form [(slope1, intercept1), (slope2, intercept2), ...] for line slope and intercept
        where line slope is an angle in degrees.  Further, we require that len(X_m) >= 2
    n-rule: takes a list of n length three tuples of form
        [(angle1, orientation1, distance1), (angle2, orientation2, distance2), ...]
        where each angle parameter is between 0 and 90, orientation is either 1 or 0, and distance
        is a positive integer from 1 to m inclusive (dealing with m+1 lines as add the x axis).  If angle=90, orientation can be either 0 or 1 with no change
        of map behavior
    num_iter: number of times to iterate the map
    points_to_plot: an interval [start_point, end_point] that determines the interval of iterations
        of the map to be plotted.
    start_point: list of length 2 [x, y] specifying the x and y coordinates of the point from which to
        begin iteration
    orbit_color: the color of the orbit plot, default is red.
"""
function nRuleMap(X_m, nrule, num_iter, points_to_plot, start_point, orbit_color="red")
    currPoint = start_point
    visitedPoints = [start_point]
    n = length(nrule)
    m = length(X_m) # m-1 as we include x-axis as a line

    # begin iteration
    for i in 1:num_iter
        # get rule information
        rulenum = (i%n) + 1
        currRule = nrule[rulenum]
        step_ang = currRule[1]
        o = currRule[2]
        d = currRule[3]

        # order liens via distance and choose line at specified distance
        lineIndx = 1
        lineDistOrdering = []
        for j in X_m
            d_j = distpointline(j, currPoint)
            push!(lineDistOrdering, d_j)
        end

        # add distance from x axis
        xdist = abs(currPoint[2])
        push!(lineDistOrdering, xdist)

        @simd for j in 1:d-1
            # we must find the index of the line in X_m
            # with the dth closest line, so set all other lines
            # to the max distance
            minIndx = argmin(lineDistOrdering)
            lineDistOrdering[minIndx] = Inf
        end

        # now determine the index of the line to map to
        lineIndx = argmin(lineDistOrdering)
        # now if index is m+1, then it is the x axis, as we added that to the end
        if lineIndx == m+1
            mappingLine1 = [0, 0]
            mappingLine2 = [0, 0]
		else
			mappingLine1 = X_m[lineIndx]
			s = tan(deg2rad(mappingLine1[1]))
			mappingLine2 = (s, mappingLine1[2])
		end

		# upon picking a line, determine two possible step lines via mapping angles
		# and pick one given the orientation
		possibleLines = mappingOptions(mappingLine1[1], step_ang)
		iterationLineSlope = possibleLines[o+1]

		# generate the line to find the next point in iteration
		iterationLine = [iterationLineSlope, newB(iterationLineSlope, currPoint)]

		# determine the next point in the orbit and add to visited points
		nextPoint = inter(iterationLine, mappingLine2)
		currPoint = nextPoint
		push!(visitedPoints, currPoint)
	end

	## Now we plot the lines composing X_m and the iterations of the map
	# first plot the x axis. We plot lines on fairly wide axis
    plotOrbit(X_m, visitedPoints, points_to_plot, orbit_color)
end

# ╔═╡ 0e77beee-449b-11eb-39dd-6f2a6335dee0
"""
A symbolic implementation of n-rule maps. The function symbolicnrulemap takes an n-rule, and plots the path it generates in the specified space X_m.  If the n-rule map converges to a periodic orbit within num_iter iterations, the program will return the period.
Inputs:
X_m: input a list of m tuples, where m is the number of lines plus the x axis, so
	X_m is of form [(slope1, intercept1), (slope2, intercept2), ...] for line slope 	and intercept where line slope is an angle in degrees.  Further, we require that 	len(X_m) >= 2.  The function is designed so that the index in the list X_m is the symbol value of the corresponding line, and m+1 index is the symbol value of the x-axis.
n-rule: takes a list of n length three tuples of form
	[(angle1, orientation1, distance1), (angle2, orientation2, distance2), ...]
	where each angle parameter is between 0 and 90, orientation is either 1 or 0, and distance is a positive integer from 1 to m+1 inclusive.  If angle=90, orientation can be either 0 or 1 with no change of map behavior
num_iter: number of times to iterate the map
points_to_plot: an interval [start_point, end_point] that determines the interval of iterations
	of the map to be plotted.
start_point: list of length 2 [x, y] specifying the x and y coordinates of the point from which to
	begin iteration
orbit_color: the color of the orbit plot, default is red.
"""
function symbolicnRuleMap(X_m, nrule, num_iter, points_to_plot, start_point, orbit_color="red")

	currPoint = start_point
    visitedPoints = Array{Float64,1}[start_point]
    n = length(nrule)
    m = length(X_m) # m-1 as we include x-axis as a line

    # begin iteration
    for i in 1:num_iter
        # get rule information
        rulenum = (i%n) + 1
        currRule = nrule[rulenum]
        step_ang = currRule[1]
        o = currRule[2]
        d = currRule[3]

        # determine line
        if d == m+1
            mappingLine1 = [0.0, 0.0]
            mappingLine2 = [0.0, 0.0]
		else
			mappingLine1 = X_m[d]
			s = tan(deg2rad(mappingLine1[1]))
			mappingLine2 = (s, mappingLine1[2])
		end

		# upon picking a line, determine two possible step lines via mapping angles
		# and pick one given the orientation
		possibleLines = mappingOptions(mappingLine1[1], step_ang)
		iterationLineSlope = possibleLines[o+1]

		# generate the line to find the next point in iteration
		iterationLine = [iterationLineSlope, newB(iterationLineSlope, currPoint)]

		# determine the next point in the orbit and add to visited points
		nextPoint = inter(iterationLine, mappingLine2)
		currPoint = nextPoint
		push!(visitedPoints, currPoint)
	end

	## Now we plot the lines composing X_m and the iterations of the map
	# first plot the x axis. We plot lines on fairly wide axis
    plotOrbit(X_m, visitedPoints, points_to_plot, orbit_color)
end

# ╔═╡ Cell order:
# ╠═b26a3f0c-448e-11eb-1cf0-25438afc670d
# ╠═98aeef06-44a5-11eb-1095-adc7773fd362
# ╠═9e6d6934-448e-11eb-21f3-69467bda2410
# ╠═c3fb3d48-448e-11eb-3dff-6fccd893312c
# ╠═c3fbc362-448e-11eb-36b3-a5c2694955da
# ╠═c3fc5fd4-448e-11eb-2347-9ddee5b2cc8a
# ╠═c40b9c4c-448e-11eb-1cbc-45324d95420d
# ╠═c41174be-448e-11eb-334d-f97165d225d0
# ╠═c418c974-448e-11eb-01b9-8167c73c6e24
# ╠═c41eb1ec-448e-11eb-288d-eb4fecc22f89
# ╠═c425aa88-448e-11eb-067f-132bc8887e8a
# ╠═2b64bd10-448f-11eb-361c-1798fccb5fde
# ╠═ef6fb954-448e-11eb-0915-299e31bffd95
# ╠═0e77beee-449b-11eb-39dd-6f2a6335dee0