📄 optim_private_trdog.c
字号:
/*
* alpha = 1;
*/
mlfAssign(&alpha, mlfScalar(1.0));
/*
* else
*/
} else {
/*
* mdis = inf;
*/
mlfAssign(&mdis, mlfInf());
/*
* dis = max((u(arg)-x(arg))./sg(arg), (l(arg)-x(arg))./sg(arg));
*/
mlfAssign(
&dis,
mlfMax(
NULL,
mlfRdivide(
mlfMinus(
mlfIndexRef(u, "(?)", arg), mlfIndexRef(x, "(?)", arg)),
mlfIndexRef(sg, "(?)", arg)),
mlfRdivide(
mlfMinus(
mlfIndexRef(l, "(?)", arg), mlfIndexRef(x, "(?)", arg)),
mlfIndexRef(sg, "(?)", arg)),
NULL));
/*
* mdis = min(dis);
*/
mlfAssign(&mdis, mlfMin(NULL, dis, NULL, NULL));
/*
* mdis = theta*mdis;
*/
mlfAssign(&mdis, mlfMtimes(theta, mdis));
/*
* alpha = min(1,mdis);
*/
mlfAssign(&alpha, mlfMin(NULL, mlfScalar(1.0), mdis, NULL));
/*
* end
*/
}
/*
* sg = alpha*sg;
*/
mlfAssign(&sg, mlfMtimes(alpha, sg));
/*
* st = alpha*st;
*/
mlfAssign(&st, mlfMtimes(alpha, st));
/*
* ssg = full(alpha*ssg);
*/
mlfAssign(&ssg, mlfFull(mlfMtimes(alpha, ssg)));
/*
* qpval2 = rhs'*st + (.5*st)'*MM*st;
*/
mlfAssign(
&qpval2,
mlfPlus(
mlfMtimes(mlfCtranspose(rhs), st),
mlfMtimes(
mlfMtimes(mlfCtranspose(mlfMtimes(mlfScalar(.5), st)), MM), st)));
/*
* end
*/
}
/*
*
* % Choose the best of s, sg, ns.
* if qpval2 <= min(qpval1,qpval3)
*/
if (mlfTobool(mlfLe(qpval2, mlfMin(NULL, qpval1, qpval3, NULL)))) {
/*
* qpval = qpval2;
*/
mlfAssign(qpval, qpval2);
/*
* s = sg;
*/
mlfAssign(&s, sg);
/*
* snod = ssg;
*/
mlfAssign(snod, ssg);
/*
* elseif qpval1 <= min(qpval2,qpval3)
*/
} else if (mlfTobool(mlfLe(qpval1, mlfMin(NULL, qpval2, qpval3, NULL)))) {
/*
* qpval = qpval1;
*/
mlfAssign(qpval, qpval1);
/*
* snod = ss;
*/
mlfAssign(snod, ss);
/*
* else
*/
} else {
/*
* qpval = qpval3;
*/
mlfAssign(qpval, qpval3);
/*
* s = ns + r;
*/
mlfAssign(&s, mlfPlus(ns, r));
/*
* snod = nss + ssssave;
*/
mlfAssign(snod, mlfPlus(nss, ssssave));
/*
* end
*/
}
mclValidateOutputs(
"optim/private/trdog", 6, nargout_, &s, snod, qpval, posdef, pcgit, Z);
mxDestroyArray(DG);
mxDestroyArray(DM);
mxDestroyArray(HH);
mxDestroyArray(MM);
mxDestroyArray(R);
mxDestroyArray(W);
mxDestroyArray(WW);
mxDestroyArray(ZZ);
mxDestroyArray(alpha);
mxDestroyArray(arg);
mxDestroyArray(dis);
mxDestroyArray(fcnt);
mxDestroyArray(grad);
mxDestroyArray(ipt);
mxDestroyArray(lambda);
mxDestroyArray(mdis);
mxDestroyArray(mmdis);
mxDestroyArray(n);
mxDestroyArray(ng);
mxDestroyArray(ngrad);
mxDestroyArray(nrhs);
mxDestroyArray(nrmv2);
mxDestroyArray(ns);
mxDestroyArray(nss);
mxDestroyArray(nst);
mxDestroyArray(nx);
mxDestroyArray(permR);
mxDestroyArray(po);
mxDestroyArray(qpval0);
mxDestroyArray(qpval1);
mxDestroyArray(qpval2);
mxDestroyArray(qpval3);
mxDestroyArray(r);
mxDestroyArray(rhs);
mxDestroyArray(sg);
mxDestroyArray(ss);
mxDestroyArray(ssave);
mxDestroyArray(ssg);
mxDestroyArray(sssave);
mxDestroyArray(ssssave);
mxDestroyArray(st);
mxDestroyArray(stsave);
mxDestroyArray(tau);
mxDestroyArray(tol);
mxDestroyArray(tol2);
mxDestroyArray(v1);
mxDestroyArray(v2);
/*
*
*
*
*
*/
return s;
}
/*
* The function "mlfOptim_private_trdog" contains the normal interface for the
* "optim/private/trdog" M-function from file
* "C:\MATLABR11\toolbox\optim\private\trdog.m" (lines 1-226). This function
* processes any input arguments and passes them to the implementation version
* of the function, appearing above.
*/
mxArray * mlfOptim_private_trdog(mxArray * * snod,
mxArray * * qpval,
mxArray * * posdef,
mxArray * * pcgit,
mxArray * * Z,
mxArray * x,
mxArray * g,
mxArray * H,
mxArray * fdata,
mxArray * D,
mxArray * delta,
mxArray * dv,
mxArray * mtxmpy,
mxArray * pcmtx,
mxArray * pcoptions,
mxArray * tol,
mxArray * kmax,
mxArray * theta,
mxArray * l,
mxArray * u,
mxArray * Z_,
mxArray * dnewt,
mxArray * preconflag) {
int nargout = 1;
mxArray * s = mclGetUninitializedArray();
mxArray * snod__ = mclGetUninitializedArray();
mxArray * qpval__ = mclGetUninitializedArray();
mxArray * posdef__ = mclGetUninitializedArray();
mxArray * pcgit__ = mclGetUninitializedArray();
mxArray * Z__ = mclGetUninitializedArray();
mlfEnterNewContext(
5,
18,
snod,
qpval,
posdef,
pcgit,
Z,
x,
g,
H,
fdata,
D,
delta,
dv,
mtxmpy,
pcmtx,
pcoptions,
tol,
kmax,
theta,
l,
u,
Z_,
dnewt,
preconflag);
if (snod != NULL) {
++nargout;
}
if (qpval != NULL) {
++nargout;
}
if (posdef != NULL) {
++nargout;
}
if (pcgit != NULL) {
++nargout;
}
if (Z != NULL) {
++nargout;
}
s
= Moptim_private_trdog(
&snod__,
&qpval__,
&posdef__,
&pcgit__,
&Z__,
nargout,
x,
g,
H,
fdata,
D,
delta,
dv,
mtxmpy,
pcmtx,
pcoptions,
tol,
kmax,
theta,
l,
u,
Z_,
dnewt,
preconflag);
mlfRestorePreviousContext(
5,
18,
snod,
qpval,
posdef,
pcgit,
Z,
x,
g,
H,
fdata,
D,
delta,
dv,
mtxmpy,
pcmtx,
pcoptions,
tol,
kmax,
theta,
l,
u,
Z_,
dnewt,
preconflag);
if (snod != NULL) {
mclCopyOutputArg(snod, snod__);
} else {
mxDestroyArray(snod__);
}
if (qpval != NULL) {
mclCopyOutputArg(qpval, qpval__);
} else {
mxDestroyArray(qpval__);
}
if (posdef != NULL) {
mclCopyOutputArg(posdef, posdef__);
} else {
mxDestroyArray(posdef__);
}
if (pcgit != NULL) {
mclCopyOutputArg(pcgit, pcgit__);
} else {
mxDestroyArray(pcgit__);
}
if (Z != NULL) {
mclCopyOutputArg(Z, Z__);
} else {
mxDestroyArray(Z__);
}
return mlfReturnValue(s);
}
/*
* The function "mlxOptim_private_trdog" contains the feval interface for the
* "optim/private/trdog" M-function from file
* "C:\MATLABR11\toolbox\optim\private\trdog.m" (lines 1-226). The feval
* function calls the implementation version of optim/private/trdog through
* this function. This function processes any input arguments and passes them
* to the implementation version of the function, appearing above.
*/
void mlxOptim_private_trdog(int nlhs,
mxArray * plhs[],
int nrhs,
mxArray * prhs[]) {
mxArray * mprhs[18];
mxArray * mplhs[6];
int i;
if (nlhs > 6) {
mlfError(
mxCreateString(
"Run-time Error: File: optim/private/trdog Line: 1 Colu"
"mn: 0 The function \"optim/private/trdog\" was called "
"with more than the declared number of outputs (6)"));
}
if (nrhs > 18) {
mlfError(
mxCreateString(
"Run-time Error: File: optim/private/trdog Line: 1 Colu"
"mn: 0 The function \"optim/private/trdog\" was called "
"with more than the declared number of inputs (18)"));
}
for (i = 0; i < 6; ++i) {
mplhs[i] = NULL;
}
for (i = 0; i < 18 && i < nrhs; ++i) {
mprhs[i] = prhs[i];
}
for (; i < 18; ++i) {
mprhs[i] = NULL;
}
mlfEnterNewContext(
0,
18,
mprhs[0],
mprhs[1],
mprhs[2],
mprhs[3],
mprhs[4],
mprhs[5],
mprhs[6],
mprhs[7],
mprhs[8],
mprhs[9],
mprhs[10],
mprhs[11],
mprhs[12],
mprhs[13],
mprhs[14],
mprhs[15],
mprhs[16],
mprhs[17]);
mplhs[0]
= Moptim_private_trdog(
&mplhs[1],
&mplhs[2],
&mplhs[3],
&mplhs[4],
&mplhs[5],
nlhs,
mprhs[0],
mprhs[1],
mprhs[2],
mprhs[3],
mprhs[4],
mprhs[5],
mprhs[6],
mprhs[7],
mprhs[8],
mprhs[9],
mprhs[10],
mprhs[11],
mprhs[12],
mprhs[13],
mprhs[14],
mprhs[15],
mprhs[16],
mprhs[17]);
mlfRestorePreviousContext(
0,
18,
mprhs[0],
mprhs[1],
mprhs[2],
mprhs[3],
mprhs[4],
mprhs[5],
mprhs[6],
mprhs[7],
mprhs[8],
mprhs[9],
mprhs[10],
mprhs[11],
mprhs[12],
mprhs[13],
mprhs[14],
mprhs[15],
mprhs[16],
mprhs[17]);
plhs[0] = mplhs[0];
for (i = 1; i < 6 && i < nlhs; ++i) {
plhs[i] = mplhs[i];
}
for (; i < 6; ++i) {
mxDestroyArray(mplhs[i]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -