📄 color.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 "color.h"
/*
* The function "Mcolor" is the implementation version of the "color"
* M-function from file "C:\MATLABR11\toolbox\optim\color.m" (lines 1-41). 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 [group] = color(J,p);
*/
static mxArray * Mcolor(int nargout_, mxArray * J, mxArray * p) {
mxArray * group = mclGetUninitializedArray();
mxArray * i = mclGetUninitializedArray();
mxArray * index = mclGetUninitializedArray();
mxArray * inner = mclGetUninitializedArray();
mclForLoopIterator iterator_0;
mxArray * k = mclGetUninitializedArray();
mxArray * lenindex = mclGetUninitializedArray();
mxArray * m = mclGetUninitializedArray();
mxArray * n = mclGetUninitializedArray();
mxArray * nargin_ = mclGetUninitializedArray();
mxArray * ncol = mclGetUninitializedArray();
mxArray * rows = mclGetUninitializedArray();
mlfAssign(&nargin_, mlfNargin(0, J, p, NULL));
mclValidateInputs("color", 2, &J, &p);
mclCopyArray(&J);
mclCopyArray(&p);
/*
* %COLOR Column partition for sparse finite differences.
* %
* % GROUP = COLOR(J,P) returns a partition of the
* % column corresponding to a coloring of the column-
* % intersection graph. GROUP(I) = J means column I is
* % colored J.
* %
* % All columns belonging to a color can be estimated
* % in a single finite difference.
* %
*
* % Copyright (c) 1990-98 by The MathWorks, Inc.
* % $Revision: 1.1 $ $Date: 1998/03/20 01:59:06 $
*
* %
* [m,n] = size(J);
*/
mlfSize(mlfVarargout(&m, &n, NULL), J, NULL);
/*
* if nargin < 2,
*/
if (mlfTobool(mlfLt(nargin_, mlfScalar(2.0)))) {
/*
* p = 1:n;
*/
mlfAssign(&p, mlfColon(mlfScalar(1.0), n, NULL));
/*
* end
*/
}
/*
* J = J(:,p);
*/
mlfAssign(&J, mlfIndexRef(J, "(?,?)", mlfCreateColonIndex(), p));
/*
* group = zeros(n,1);
*/
mlfAssign(&group, mlfZeros(n, mlfScalar(1.0), NULL));
/*
* ncol = 0;
*/
mlfAssign(&ncol, mlfScalar(0.0));
/*
* J = spones(J);
*/
mlfAssign(&J, mlfSpones(J));
/*
* while any(group==0)
*/
while (mlfTobool(mlfAny(mlfEq(group, mlfScalar(0.0)), NULL))) {
/*
* % Build group for ncol
* ncol = ncol + 1;
*/
mlfAssign(&ncol, mlfPlus(ncol, mlfScalar(1.0)));
/*
* rows = zeros(m,1);
*/
mlfAssign(&rows, mlfZeros(m, mlfScalar(1.0), NULL));
/*
* index = find(group == 0);
*/
mlfAssign(&index, mlfFind(NULL, NULL, mlfEq(group, mlfScalar(0.0))));
/*
* lenindex = length(index);
*/
mlfAssign(&lenindex, mlfLength(index));
/*
* for i = 1:lenindex
*/
for (mclForStart(&iterator_0, mlfScalar(1.0), lenindex, NULL);
mclForNext(&iterator_0, &i);
) {
/*
* k = index(i);
*/
mlfAssign(&k, mlfIndexRef(index, "(?)", i));
/*
* inner = J(:,k)'*rows;
*/
mlfAssign(
&inner,
mlfMtimes(
mlfCtranspose(
mlfIndexRef(J, "(?,?)", mlfCreateColonIndex(), k)),
rows));
/*
* if inner == 0
*/
if (mlfTobool(mlfEq(inner, mlfScalar(0.0)))) {
/*
* group(k) = ncol;
*/
mlfIndexAssign(&group, "(?)", k, ncol);
/*
* rows = rows + J(:,k);
*/
mlfAssign(
&rows,
mlfPlus(
rows, mlfIndexRef(J, "(?,?)", mlfCreateColonIndex(), k)));
/*
* end
*/
}
/*
* end
*/
}
/*
* end
*/
}
/*
* group(p)= group;
*/
mlfIndexAssign(&group, "(?)", p, group);
mclValidateOutputs("color", 1, nargout_, &group);
mxDestroyArray(J);
mxDestroyArray(i);
mxDestroyArray(index);
mxDestroyArray(inner);
mxDestroyArray(k);
mxDestroyArray(lenindex);
mxDestroyArray(m);
mxDestroyArray(n);
mxDestroyArray(nargin_);
mxDestroyArray(ncol);
mxDestroyArray(p);
mxDestroyArray(rows);
return group;
}
/*
* The function "mlfColor" contains the normal interface for the "color"
* M-function from file "C:\MATLABR11\toolbox\optim\color.m" (lines 1-41). This
* function processes any input arguments and passes them to the implementation
* version of the function, appearing above.
*/
mxArray * mlfColor(mxArray * J, mxArray * p) {
int nargout = 1;
mxArray * group = mclGetUninitializedArray();
mlfEnterNewContext(0, 2, J, p);
group = Mcolor(nargout, J, p);
mlfRestorePreviousContext(0, 2, J, p);
return mlfReturnValue(group);
}
/*
* The function "mlxColor" contains the feval interface for the "color"
* M-function from file "C:\MATLABR11\toolbox\optim\color.m" (lines 1-41). The
* feval function calls the implementation version of color through this
* function. This function processes any input arguments and passes them to the
* implementation version of the function, appearing above.
*/
void mlxColor(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
mxArray * mprhs[2];
mxArray * mplhs[1];
int i;
if (nlhs > 1) {
mlfError(
mxCreateString(
"Run-time Error: File: color Line: 1 Column: 0 The function \"color"
"\" was called with more than the declared number of outputs (1)"));
}
if (nrhs > 2) {
mlfError(
mxCreateString(
"Run-time Error: File: color Line: 1 Column: 0 The function \"color"
"\" was called with more than the declared number of inputs (2)"));
}
for (i = 0; i < 1; ++i) {
mplhs[i] = NULL;
}
for (i = 0; i < 2 && i < nrhs; ++i) {
mprhs[i] = prhs[i];
}
for (; i < 2; ++i) {
mprhs[i] = NULL;
}
mlfEnterNewContext(0, 2, mprhs[0], mprhs[1]);
mplhs[0] = Mcolor(nlhs, mprhs[0], mprhs[1]);
mlfRestorePreviousContext(0, 2, mprhs[0], mprhs[1]);
plhs[0] = mplhs[0];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -