⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optim_private_checkbounds.c

📁 ASUFIT-Matlab-全局拟合程序
💻 C
字号:
/*
 * MATLAB Compiler: 2.0.1
 * Date: Tue May 08 21:28:22 2001
 * Arguments: "-B" "sgl" "-m" "-W" "mainhg" "-L" "C" "asufit.m" "absfun.m"
 * "absfunfree.m" "absfunshift.m" "absfunwidth.m" "dispfit.m" "dispfitdisp.m"
 * "dispfitfree.m" "dispfitwidth.m" "seqmodfree.m" "spcfun.m" "spcfun1.m"
 * "atamult.m" "aprecon.m" 
 */
#include "optim_private_checkbounds.h"

/*
 * The function "Moptim_private_checkbounds" is the implementation version of
 * the "optim/private/checkbounds" M-function from file
 * "C:\MATLABR11\toolbox\optim\private\checkbounds.m" (lines 1-62). It contains
 * the actual compiled code for that M-function. It is a static function and
 * must only be called from one of the interface functions, appearing below.
 */
/*
 * function [x,lb,ub,msg] = checkbounds(xin,lbin,ubin,nvars)
 */
static mxArray * Moptim_private_checkbounds(mxArray * * lb,
                                            mxArray * * ub,
                                            mxArray * * msg,
                                            int nargout_,
                                            mxArray * xin,
                                            mxArray * lbin,
                                            mxArray * ubin,
                                            mxArray * nvars) {
    mxArray * x = mclGetUninitializedArray();
    mxArray * ans = mclInitializeAns();
    mxArray * count = mclGetUninitializedArray();
    mxArray * len = mclGetUninitializedArray();
    mxArray * lenlb = mclGetUninitializedArray();
    mxArray * lenub = mclGetUninitializedArray();
    mxArray * lenx = mclGetUninitializedArray();
    mclValidateInputs(
      "optim/private/checkbounds", 4, &xin, &lbin, &ubin, &nvars);
    mclCopyArray(&xin);
    /*
     * %CHECKBOUNDS Move the initial point within the (valid) bounds.
     * %   [X,LB,UB,X,FLAG] = CHECKBOUNDS(X0,LB,UB,nvars) 
     * %   checks that the upper and lower
     * %   bounds are valid (LB <= UB) and the same length as X (pad with -inf/inf
     * %   if necessary); warn if too long.  Also make LB and UB vectors if not 
     * %   already.
     * %   Finally, inf in LB or -inf in UB throws an error.
     * 
     * %   Copyright (c) 1990-98 by The MathWorks, Inc.
     * %   $Revision: 1.2 $  $Date: 1998/08/17 19:42:04 $
     * %   Mary Ann Branch 5-1-98
     * 
     * msg = [];
     */
    mlfAssign(msg, mclCreateEmptyArray());
    /*
     * % Turn into column vectors
     * lb = lbin(:); 
     */
    mlfAssign(lb, mlfIndexRef(lbin, "(?)", mlfCreateColonIndex()));
    /*
     * ub = ubin(:); 
     */
    mlfAssign(ub, mlfIndexRef(ubin, "(?)", mlfCreateColonIndex()));
    /*
     * xin = xin(:);
     */
    mlfAssign(&xin, mlfIndexRef(xin, "(?)", mlfCreateColonIndex()));
    /*
     * 
     * lenlb = length(lb);
     */
    mlfAssign(&lenlb, mlfLength(*lb));
    /*
     * lenub = length(ub);
     */
    mlfAssign(&lenub, mlfLength(*ub));
    /*
     * lenx = length(xin);
     */
    mlfAssign(&lenx, mlfLength(xin));
    /*
     * 
     * % Check maximum length
     * if lenlb > nvars
     */
    if (mlfTobool(mlfGt(lenlb, nvars))) {
        /*
         * warning('Length of lower bounds is > length(x); ignoring extra bounds');
         */
        mclAssignAns(
          &ans,
          mlfWarning(
            NULL,
            mxCreateString(
              "Length of lower bounds is > length(x); ignoring extra bounds")));
        /*
         * lb = lb(1:nvars);   
         */
        mlfAssign(
          lb, mlfIndexRef(*lb, "(?)", mlfColon(mlfScalar(1.0), nvars, NULL)));
        /*
         * lenlb = nvars;
         */
        mlfAssign(&lenlb, nvars);
    /*
     * elseif lenlb < nvars
     */
    } else if (mlfTobool(mlfLt(lenlb, nvars))) {
        /*
         * lb = [lb; -inf*ones(nvars-lenlb,1)];
         */
        mlfAssign(
          lb,
          mlfVertcat(
            mlfHorzcat(*lb, NULL),
            mlfHorzcat(
              mlfMtimes(
                mlfUminus(mlfInf()),
                mlfOnes(mlfMinus(nvars, lenlb), mlfScalar(1.0), NULL)),
              NULL),
            NULL));
        /*
         * lenlb = nvars;
         */
        mlfAssign(&lenlb, nvars);
    /*
     * end
     */
    }
    /*
     * 
     * if lenub > nvars
     */
    if (mlfTobool(mlfGt(lenub, nvars))) {
        /*
         * warning('Length of upper bounds is > length(x); ignoring extra bounds');
         */
        mclAssignAns(
          &ans,
          mlfWarning(
            NULL,
            mxCreateString(
              "Length of upper bounds is > length(x); ignoring extra bounds")));
        /*
         * ub = ub(1:nvars);
         */
        mlfAssign(
          ub, mlfIndexRef(*ub, "(?)", mlfColon(mlfScalar(1.0), nvars, NULL)));
        /*
         * lenub = nvars;
         */
        mlfAssign(&lenub, nvars);
    /*
     * elseif lenub < nvars
     */
    } else if (mlfTobool(mlfLt(lenub, nvars))) {
        /*
         * ub = [ub; inf*ones(nvars-lenub,1)];
         */
        mlfAssign(
          ub,
          mlfVertcat(
            mlfHorzcat(*ub, NULL),
            mlfHorzcat(
              mlfMtimes(
                mlfInf(),
                mlfOnes(mlfMinus(nvars, lenub), mlfScalar(1.0), NULL)),
              NULL),
            NULL));
        /*
         * lenub = nvars;
         */
        mlfAssign(&lenub, nvars);
    /*
     * end
     */
    }
    /*
     * 
     * % Check feasibility of bounds
     * len = min(lenlb,lenub);
     */
    mlfAssign(&len, mlfMin(NULL, lenlb, lenub, NULL));
    /*
     * if any( lb( (1:len)' ) > ub( (1:len)' ) )
     */
    if (mlfTobool(
          mlfAny(
            mlfGt(
              mlfIndexRef(
                *lb, "(?)", mlfCtranspose(mlfColon(mlfScalar(1.0), len, NULL))),
              mlfIndexRef(
                *ub,
                "(?)",
                mlfCtranspose(mlfColon(mlfScalar(1.0), len, NULL)))),
            NULL))) {
        /*
         * count = full(sum(lb>ub));
         */
        mlfAssign(&count, mlfFull(mlfSum(mlfGt(*lb, *ub), NULL)));
        /*
         * if count == 1
         */
        if (mlfTobool(mlfEq(count, mlfScalar(1.0)))) {
            /*
             * msg=sprintf(['\nExiting due to infeasibility:  %i lower bound exceeds the' ...
             */
            mlfAssign(
              msg,
              mlfSprintf(
                NULL,
                mlfHorzcat(
                  mxCreateString(
                    "\\nExiting due to infeasibility"
                    ":  %i lower bound exceeds the"),
                  mxCreateString(" corresponding upper bound.\\n"),
                  NULL),
                count,
                NULL));
        /*
         * ' corresponding upper bound.\n'],count);
         * else
         */
        } else {
            /*
             * msg=sprintf(['\nExiting due to infeasibility:  %i lower bounds exceed the' ...
             */
            mlfAssign(
              msg,
              mlfSprintf(
                NULL,
                mlfHorzcat(
                  mxCreateString(
                    "\\nExiting due to infeasibility"
                    ":  %i lower bounds exceed the"),
                  mxCreateString(" corresponding upper bounds.\\n"),
                  NULL),
                count,
                NULL));
        /*
         * ' corresponding upper bounds.\n'],count);
         * end 
         */
        }
    /*
     * end
     */
    }
    /*
     * % check if -inf in ub or inf in lb   
     * if any(eq(ub, -inf)) 
     */
    if (mlfTobool(mlfAny(mlfEq(*ub, mlfUminus(mlfInf())), NULL))) {
        /*
         * error('-Inf detected in upper bound: upper bounds must be > -Inf.');
         */
        mlfError(
          mxCreateString(
            "-Inf detected in upper bound: upper bounds must be > -Inf."));
    /*
     * elseif any(eq(lb,inf))
     */
    } else if (mlfTobool(mlfAny(mlfEq(*lb, mlfInf()), NULL))) {
        /*
         * error('+Inf detected in lower bound: lower bounds must be < Inf.');
         */
        mlfError(
          mxCreateString(
            "+Inf detected in lower bound: lower bounds must be < Inf."));
    /*
     * end
     */
    }
    /*
     * 
     * x = xin;
     */
    mlfAssign(&x, xin);
    mclValidateOutputs(
      "optim/private/checkbounds", 4, nargout_, &x, lb, ub, msg);
    mxDestroyArray(ans);
    mxDestroyArray(count);
    mxDestroyArray(len);
    mxDestroyArray(lenlb);
    mxDestroyArray(lenub);
    mxDestroyArray(lenx);
    mxDestroyArray(xin);
    return x;
}

/*
 * The function "mlfOptim_private_checkbounds" contains the normal interface
 * for the "optim/private/checkbounds" M-function from file
 * "C:\MATLABR11\toolbox\optim\private\checkbounds.m" (lines 1-62). This
 * function processes any input arguments and passes them to the implementation
 * version of the function, appearing above.
 */
mxArray * mlfOptim_private_checkbounds(mxArray * * lb,
                                       mxArray * * ub,
                                       mxArray * * msg,
                                       mxArray * xin,
                                       mxArray * lbin,
                                       mxArray * ubin,
                                       mxArray * nvars) {
    int nargout = 1;
    mxArray * x = mclGetUninitializedArray();
    mxArray * lb__ = mclGetUninitializedArray();
    mxArray * ub__ = mclGetUninitializedArray();
    mxArray * msg__ = mclGetUninitializedArray();
    mlfEnterNewContext(3, 4, lb, ub, msg, xin, lbin, ubin, nvars);
    if (lb != NULL) {
        ++nargout;
    }
    if (ub != NULL) {
        ++nargout;
    }
    if (msg != NULL) {
        ++nargout;
    }
    x
      = Moptim_private_checkbounds(
          &lb__, &ub__, &msg__, nargout, xin, lbin, ubin, nvars);
    mlfRestorePreviousContext(3, 4, lb, ub, msg, xin, lbin, ubin, nvars);
    if (lb != NULL) {
        mclCopyOutputArg(lb, lb__);
    } else {
        mxDestroyArray(lb__);
    }
    if (ub != NULL) {
        mclCopyOutputArg(ub, ub__);
    } else {
        mxDestroyArray(ub__);
    }
    if (msg != NULL) {
        mclCopyOutputArg(msg, msg__);
    } else {
        mxDestroyArray(msg__);
    }
    return mlfReturnValue(x);
}

/*
 * The function "mlxOptim_private_checkbounds" contains the feval interface for
 * the "optim/private/checkbounds" M-function from file
 * "C:\MATLABR11\toolbox\optim\private\checkbounds.m" (lines 1-62). The feval
 * function calls the implementation version of optim/private/checkbounds
 * through this function. This function processes any input arguments and
 * passes them to the implementation version of the function, appearing above.
 */
void mlxOptim_private_checkbounds(int nlhs,
                                  mxArray * plhs[],
                                  int nrhs,
                                  mxArray * prhs[]) {
    mxArray * mprhs[4];
    mxArray * mplhs[4];
    int i;
    if (nlhs > 4) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: optim/private/checkbounds Line: 1 Co"
            "lumn: 0 The function \"optim/private/checkbounds\" was cal"
            "led with more than the declared number of outputs (4)"));
    }
    if (nrhs > 4) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: optim/private/checkbounds Line: 1 C"
            "olumn: 0 The function \"optim/private/checkbounds\" was c"
            "alled with more than the declared number of inputs (4)"));
    }
    for (i = 0; i < 4; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 4 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 4; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(0, 4, mprhs[0], mprhs[1], mprhs[2], mprhs[3]);
    mplhs[0]
      = Moptim_private_checkbounds(
          &mplhs[1],
          &mplhs[2],
          &mplhs[3],
          nlhs,
          mprhs[0],
          mprhs[1],
          mprhs[2],
          mprhs[3]);
    mlfRestorePreviousContext(0, 4, mprhs[0], mprhs[1], mprhs[2], mprhs[3]);
    plhs[0] = mplhs[0];
    for (i = 1; i < 4 && i < nlhs; ++i) {
        plhs[i] = mplhs[i];
    }
    for (; i < 4; ++i) {
        mxDestroyArray(mplhs[i]);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -