| 1 | ///////////////////////////////////////////////////////////////////////////////// | 
|---|
| 2 | // | 
|---|
| 3 | //  Levenberg - Marquardt non-linear minimization algorithm | 
|---|
| 4 | //  Copyright (C) 2004-05  Manolis Lourakis (lourakis at ics forth gr) | 
|---|
| 5 | //  Institute of Computer Science, Foundation for Research & Technology - Hellas | 
|---|
| 6 | //  Heraklion, Crete, Greece. | 
|---|
| 7 | // | 
|---|
| 8 | //  This program is free software; you can redistribute it and/or modify | 
|---|
| 9 | //  it under the terms of the GNU General Public License as published by | 
|---|
| 10 | //  the Free Software Foundation; either version 2 of the License, or | 
|---|
| 11 | //  (at your option) any later version. | 
|---|
| 12 | // | 
|---|
| 13 | //  This program is distributed in the hope that it will be useful, | 
|---|
| 14 | //  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 15 | //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 16 | //  GNU General Public License for more details. | 
|---|
| 17 | // | 
|---|
| 18 | ///////////////////////////////////////////////////////////////////////////////// | 
|---|
| 19 |  | 
|---|
| 20 | /******************************************************************************** | 
|---|
| 21 | * Miscelaneous functions for Levenberg-Marquardt nonlinear minimization. The | 
|---|
| 22 | * same core code is used with appropriate #defines to derive single and double | 
|---|
| 23 | * precision versions, see also misc_core.c | 
|---|
| 24 | ********************************************************************************/ | 
|---|
| 25 |  | 
|---|
| 26 | #include <stdio.h> | 
|---|
| 27 | #include <stdlib.h> | 
|---|
| 28 | #include <math.h> | 
|---|
| 29 | #include <float.h> | 
|---|
| 30 |  | 
|---|
| 31 | #include "levmar.h" | 
|---|
| 32 | #include "misc.h" | 
|---|
| 33 |  | 
|---|
| 34 | #if !defined(LM_DBL_PREC) && !defined(LM_SNGL_PREC) | 
|---|
| 35 | #error At least one of LM_DBL_PREC, LM_SNGL_PREC should be defined! | 
|---|
| 36 | #endif | 
|---|
| 37 |  | 
|---|
| 38 | #ifdef LM_SNGL_PREC | 
|---|
| 39 | /* single precision (float) definitions */ | 
|---|
| 40 | #define LM_REAL float | 
|---|
| 41 | #define LM_PREFIX s | 
|---|
| 42 |  | 
|---|
| 43 | #define LM_REAL_EPSILON FLT_EPSILON | 
|---|
| 44 | #define __SUBCNST(x) x##F | 
|---|
| 45 | #define LM_CNST(x) __SUBCNST(x) // force substitution | 
|---|
| 46 |  | 
|---|
| 47 | #include "misc_core.c" // read in core code | 
|---|
| 48 |  | 
|---|
| 49 | #undef LM_REAL | 
|---|
| 50 | #undef LM_PREFIX | 
|---|
| 51 | #undef LM_REAL_EPSILON | 
|---|
| 52 | #undef __SUBCNST | 
|---|
| 53 | #undef LM_CNST | 
|---|
| 54 | #endif /* LM_SNGL_PREC */ | 
|---|
| 55 |  | 
|---|
| 56 | #ifdef LM_DBL_PREC | 
|---|
| 57 | /* double precision definitions */ | 
|---|
| 58 | #define LM_REAL double | 
|---|
| 59 | #define LM_PREFIX d | 
|---|
| 60 |  | 
|---|
| 61 | #define LM_REAL_EPSILON DBL_EPSILON | 
|---|
| 62 | #define LM_CNST(x) (x) | 
|---|
| 63 |  | 
|---|
| 64 | #include "misc_core.c" // read in core code | 
|---|
| 65 |  | 
|---|
| 66 | #undef LM_REAL | 
|---|
| 67 | #undef LM_PREFIX | 
|---|
| 68 | #undef LM_REAL_EPSILON | 
|---|
| 69 | #undef LM_CNST | 
|---|
| 70 | #endif /* LM_DBL_PREC */ | 
|---|