Skip to content

Commit 229a77d

Browse files
committed
Add tests for minpack_lmstr and minpack_lmstr1
1 parent e59cb88 commit 229a77d

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/api/tester.c

+61
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,65 @@ test_lmdif (void)
331331
return 0;
332332
}
333333

334+
void
335+
trial_lmstr_fcn(int m, int n, const double* x, double* fvec, double* fjrow, int* iflag,
336+
void* udata) {
337+
if (*iflag == 1) {
338+
fvec[0] = 10.0 * (x[1] - x[0] * x[0]);
339+
fvec[1] = 1.0 - x[0];
340+
} else {
341+
if (*iflag == 2) {
342+
fjrow[0] = -20.0 * x[0];
343+
fjrow[1] = 10.0;
344+
} else {
345+
fjrow[0] = -1.0;
346+
fjrow[1] = 0.0;
347+
}
348+
}
349+
}
350+
351+
int
352+
test_lmstr1 (void)
353+
{
354+
const int m = 2, n = 2;
355+
double x[2] = {-1.2, 1.0}, fvec[2], fjac[2*2];
356+
int info = 0;
357+
double tol = sqrt(minpack_dpmpar(1));
358+
int ipvt[n];
359+
int lwa = m*n + 5*n + m;
360+
double wa[lwa];
361+
362+
minpack_lmstr1(trial_lmstr_fcn, 2, 2, x, fvec, fjac, 2, tol, &info, ipvt, wa, lwa, NULL);
363+
if (!check(info, 4, "Unexpected info value")) return 1;
364+
if (!check(x[0], 1.0, 100*tol, "Unexpected x[0]")) return 1;
365+
if (!check(x[1], 1.0, 100*tol, "Unexpected x[1]")) return 1;
366+
if (!check(enorm(m, fvec), 0.0, tol, "Unexpected residual")) return 1;
367+
368+
return 0;
369+
}
370+
371+
int
372+
test_lmstr (void)
373+
{
374+
const int m = 2, n = 2;
375+
double x[2] = {-1.2, 1.0}, fvec[2], fjac[2*2], diag[2];
376+
int info = 0, nfev = 0, njev = 0;
377+
double tol = sqrt(minpack_dpmpar(1));
378+
int ipvt[n];
379+
double qtf[n], wa1[n], wa2[n], wa3[n], wa4[m];
380+
381+
minpack_lmstr(trial_lmstr_fcn, 2, 2, x, fvec, fjac, 2, tol, tol, 0.0, 2000, diag, 1,
382+
100.0, 0, &info, &nfev, &njev, ipvt, qtf, wa1, wa2, wa3, wa4, NULL);
383+
if (!check(info, 4, "Unexpected info value")) return 1;
384+
if (!check(nfev, 21, "Unexpected number of function evaluations")) return 1;
385+
if (!check(njev, 16, "Unexpected number of jacobian evaluations")) return 1;
386+
if (!check(x[0], 1.0, 100*tol, "Unexpected x[0]")) return 1;
387+
if (!check(x[1], 1.0, 100*tol, "Unexpected x[1]")) return 1;
388+
if (!check(enorm(m, fvec), 0.0, tol, "Unexpected residual")) return 1;
389+
390+
return 0;
391+
}
392+
334393
int
335394
main (void) {
336395
int stat = 0;
@@ -343,6 +402,8 @@ main (void) {
343402
stat += run("lmder ", test_lmder);
344403
stat += run("lmdif1", test_lmdif1);
345404
stat += run("lmdif ", test_lmdif);
405+
stat += run("lmstr1", test_lmstr1);
406+
stat += run("lmstr ", test_lmstr);
346407

347408
if (stat > 0) {
348409
fprintf(stderr, "[FAIL] %d test(s) failed\n", stat);

0 commit comments

Comments
 (0)