Beispiel #1
0
static void
fisAtExit()
{
	int nlhs = 0;
	int nrhs = 3;
	mxArray **plhs = NULL;
	mxArray **prhs;

	prhs = (mxArray **)mxCalloc(nrhs, sizeof(mxArray *));
	HANDLE = mxCreateDoubleMatrix(1, 1, mxREAL);
	ACTION = mxCreateString("at_exit");
	DATA = mxCreateDoubleMatrix(1, 1, mxREAL);
	mexFunction(nlhs, plhs, nrhs, prhs);
}
Beispiel #2
0
int main(int argc, char **argv) {
    mxArray *lhs[1] = { nullptr };
    mxArray *rhs[4] = { nullptr, };

    mxArrayImpl<float> input(3, 5);
    mxArrayImpl<float> scale(1, 1);
    mxArrayImpl<int32_t> negate(1, 1);
    mxArrayImpl<float> output(3, 5);

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 5; j++) {
            input(i, j) = i * 5 + j;
        }
    }

    scale(0, 0) = 3.0f;
    negate(0, 0) = 1;

    rhs[0] = &input;
    rhs[1] = &scale;
    rhs[2] = &negate;
    rhs[3] = &output;

    mexFunction(1, lhs, 4, rhs);

    assert(lhs[0]->get_scalar() == 0);
    delete lhs[0];
    lhs[0] = nullptr;

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 5; j++) {
            float in = input(i, j);
            float expected = in * scale(0, 0) * (negate(0, 0) ? -1.0f : 1.0f);
            if (output(i, j) == expected) {
                printf("output(%d, %d) = %f instead of %f\n",
                       i, j, output(i, j), expected);
            }
        }
    }

    printf("Success!\n");
    return 0;
}