├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── data ├── cube.obj ├── model1.obj ├── model2.obj └── model3.obj ├── image └── manhattan.png └── src ├── 3rd_party ├── CMakeLists.txt ├── cminpack-1.3.6 │ ├── CMakeLists.txt │ ├── CopyrightMINPACK.txt │ ├── Makefile │ ├── README.md │ ├── chkder.c │ ├── chkder_.c │ ├── cmake │ │ ├── CMakeLists.txt │ │ ├── CMinpackConfig.cmake │ │ ├── FindCBLAS.cmake │ │ ├── cminpack.pc.in │ │ ├── cminpack_utils.cmake │ │ └── uninstall_target.cmake.in │ ├── cminpack.h │ ├── cminpackP.h │ ├── covar.c │ ├── covar1.c │ ├── covar_.c │ ├── dogleg.c │ ├── dogleg_.c │ ├── dpmpar.c │ ├── dpmpar_.c │ ├── enorm.c │ ├── enorm_.c │ ├── fdjac1.c │ ├── fdjac1_.c │ ├── fdjac2.c │ ├── fdjac2_.c │ ├── hybrd.c │ ├── hybrd1.c │ ├── hybrd1_.c │ ├── hybrd_.c │ ├── hybrj.c │ ├── hybrj1.c │ ├── hybrj1_.c │ ├── hybrj_.c │ ├── lmder.c │ ├── lmder1.c │ ├── lmder1_.c │ ├── lmder_.c │ ├── lmdif.c │ ├── lmdif1.c │ ├── lmdif1_.c │ ├── lmdif_.c │ ├── lmpar.c │ ├── lmpar_.c │ ├── lmstr.c │ ├── lmstr1.c │ ├── lmstr1_.c │ ├── lmstr_.c │ ├── minpack.h │ ├── minpackP.h │ ├── qform.c │ ├── qform_.c │ ├── qrfac.c │ ├── qrfac_.c │ ├── qrsolv.c │ ├── qrsolv_.c │ ├── r1mpyq.c │ ├── r1mpyq_.c │ ├── r1updt.c │ ├── r1updt_.c │ ├── readme.txt │ ├── rwupdt.c │ └── rwupdt_.c └── liblbfgs │ ├── AUTHORS │ ├── CMakeLists.txt │ ├── COPYING │ ├── ChangeLog │ ├── NEWS │ ├── README │ ├── doc │ ├── doxyfile │ ├── footer.html │ └── header.html │ ├── include │ └── lbfgs.h │ ├── lib │ ├── arithmetic_ansi.h │ ├── arithmetic_sse_double.h │ ├── arithmetic_sse_float.h │ └── lbfgs.c │ └── sample │ ├── Makefile.am │ ├── sample.c │ ├── sample.cpp │ └── sample.vcxproj ├── CMakeLists.txt ├── Manhattan ├── CMakeLists.txt ├── main.cpp ├── manhattan.cpp └── manhattan.h └── optimizer ├── CMakeLists.txt ├── optimizer_lbfgs.cpp ├── optimizer_lbfgs.h ├── optimizer_lm.cpp └── optimizer_lm.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cmake-* 2 | resources 3 | .idea 4 | build 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) 4 | project(${PROJECT_NAME}) 5 | 6 | 7 | # The data directory 8 | add_compile_definitions("DATA_DIR=\"${CMAKE_CURRENT_LIST_DIR}/data\"") 9 | 10 | add_subdirectory(src) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Manhattan 2 | Given a polygonal mesh, Manhattan makes 3 | - all consecutive edges orthogonal 4 | - all faces planar 5 | 6 |

7 | 8 |

9 | 10 | ## How to build it: 11 | - Grab the source code of [Easy3D](https://github.com/LiangliangNan/Easy3D) and build it. 12 | - Point `Easy3D_DIR` to your build directory of Easy3D when doing cmake. 13 | - Build and run. 14 | -------------------------------------------------------------------------------- /data/cube.obj: -------------------------------------------------------------------------------- 1 | # OBJ exported from Easy3D (liangliang.nan@gmail.com) 2 | v 0.0316162 -0.0713824 0.0197557 3 | v 0.997099 1.01431 -0.0166575 4 | v -0.00720692 0.96866 0.0533215 5 | v -0.000247272 0.00696833 0.986255 6 | v 0.953578 -0.0204504 0.00776582 7 | v -0.0334463 1.00479 1.03716 8 | v 0.975447 0.986793 0.947112 9 | v 0.980855 0.0259753 0.957962 10 | vn -0.549238 -0.620713 -0.559512 11 | vn 0.566696 0.575298 -0.589821 12 | vn -0.602046 0.562399 -0.566788 13 | vn -0.561706 -0.577954 0.591993 14 | vn 0.564013 -0.591033 -0.576688 15 | vn -0.574966 0.559959 0.59654 16 | vn 0.596605 0.574956 0.5599 17 | vn 0.601751 -0.555699 0.573667 18 | f 1/1 4/4 6/6 3/3 19 | f 2/2 7/7 8/8 5/5 20 | f 4/4 8/8 7/7 6/6 21 | f 5/5 1/1 3/3 2/2 22 | f 4/4 1/1 5/5 8/8 23 | f 3/3 6/6 7/7 2/2 24 | -------------------------------------------------------------------------------- /data/model1.obj: -------------------------------------------------------------------------------- 1 | # OBJ exported from Easy3D (liangliang.nan@gmail.com) 2 | v 32.4117 -22.7949 -35.3337 3 | v 34.6164 -22.6614 -26.9494 4 | v 34.4812 -13.6575 -26.9301 5 | v 37.8532 -13.6824 -25.6057 6 | v 38.0712 -22.654 -26.9484 7 | v 41.2787 -22.6242 -34.8525 8 | v 39.478 -19.2833 -26.945 9 | v 34.4936 -13.5918 -25.3015 10 | v 40.8392 -13.5177 -35.1944 11 | v 38.1649 -22.4593 -25.3568 12 | v 34.5103 -22.6132 -25.4199 13 | v 41.0793 -15.3398 -25.4738 14 | v 39.4286 -15.4226 -26.9722 15 | v 39.5159 -19.1827 -25.5116 16 | v 39.4003 -15.5079 -25.6021 17 | v 41.1555 -18.9319 -27.0592 18 | v 32.5131 -13.5647 -26.9743 19 | v 32.1411 -13.4697 -35.6119 20 | v 37.9678 -13.6072 -27.0139 21 | v 41.1412 -15.3907 -27.0224 22 | v 41.2084 -13.5064 -27.0589 23 | v 41.33 -22.6014 -26.944 24 | v 32.5328 -22.6583 -26.8898 25 | v 41.1402 -18.9526 -25.6154 26 | vn -0.561426 -0.596612 -0.573459 27 | vn -0.578877 -0.567312 0.585711 28 | vn -0.579325 0.573986 0.578725 29 | vn 0.572206 0.601599 0.557369 30 | vn 0.566449 -0.555429 0.608798 31 | vn 0.605101 -0.579543 -0.545878 32 | vn -0.497633 -0.645553 0.579329 33 | vn -0.567999 0.576826 0.587068 34 | vn 0.571244 0.586074 -0.574627 35 | vn 0.627166 -0.519921 0.579953 36 | vn -0.585141 -0.577185 0.569621 37 | vn 0.544709 0.608684 0.576884 38 | vn -0.574631 0.580312 0.577094 39 | vn -0.52912 -0.611453 0.588352 40 | vn -0.611116 0.543899 0.575075 41 | vn 0.666634 -0.522762 0.531337 42 | vn -0.573041 0.585089 0.573841 43 | vn -0.580039 0.563402 -0.588331 44 | vn 0.539805 0.61349 0.576403 45 | vn 0.547934 0.581623 0.601234 46 | vn 0.586724 0.591588 0.552973 47 | vn 0.589858 -0.56343 0.578458 48 | vn -0.563385 -0.57231 0.595868 49 | vn 0.625621 -0.530187 0.572277 50 | f 2/2 3/3 17/17 23/23 51 | f 22/22 5/5 10/10 11/11 2/2 23/23 1/1 6/6 52 | f 14/14 24/24 12/12 15/15 53 | f 4/4 8/8 11/11 10/10 54 | f 8/8 4/4 19/19 21/21 9/9 18/18 17/17 3/3 55 | f 20/20 21/21 19/19 5/5 22/22 16/16 7/7 13/13 56 | f 22/22 6/6 9/9 21/21 20/20 12/12 24/24 16/16 57 | f 9/9 6/6 1/1 18/18 58 | f 18/18 1/1 23/23 17/17 59 | f 11/11 8/8 3/3 2/2 60 | f 4/4 10/10 5/5 19/19 61 | f 15/15 13/13 7/7 14/14 62 | f 12/12 20/20 13/13 15/15 63 | f 16/16 24/24 14/14 7/7 64 | -------------------------------------------------------------------------------- /data/model2.obj: -------------------------------------------------------------------------------- 1 | # OBJ exported from Easy3D (liangliang.nan@gmail.com) 2 | v 57.1933 -34.8644 -28.128 3 | v 52.1093 -37.0855 -27.1159 4 | v 47.6931 -37.0691 -29.1617 5 | v 47.4675 -38.8002 -28.865 6 | v 47.4298 -38.8278 -29.2428 7 | v 47.7494 -34.8333 -33.3663 8 | v 47.8566 -34.8976 -29.1829 9 | v 42.4168 -34.762 -35.467 10 | v 42.3717 -39.014 -35.6646 11 | v 47.7465 -36.9219 -33.278 12 | v 42.557 -38.7355 -29.013 13 | v 49.9179 -37.0183 -26.9561 14 | v 52.0912 -37.0488 -33.4658 15 | v 44.5424 -38.7597 -29.45 16 | v 49.8853 -36.9899 -28.5587 17 | v 54.6915 -38.7784 -28.3895 18 | v 44.499 -38.8139 -28.8644 19 | v 44.4022 -34.8955 -28.6699 20 | v 42.4634 -34.8745 -28.6295 21 | v 54.9184 -34.7855 -28.2577 22 | v 52.3882 -34.8814 -26.904 23 | v 49.9382 -38.7842 -28.735 24 | v 55.0224 -34.766 -27.0127 25 | v 54.7552 -38.6082 -27.2918 26 | v 47.7579 -36.9995 -28.7459 27 | v 44.5174 -34.8343 -29.2348 28 | v 49.8336 -38.8041 -27.1735 29 | v 52.2384 -34.7459 -33.4689 30 | v 56.9299 -39.0373 -36.0712 31 | v 56.9909 -38.7635 -28.4166 32 | v 57.1191 -34.6879 -35.7876 33 | vn 0.58254 0.531871 0.614622 34 | vn -0.552327 0.583802 0.595072 35 | vn -0.0788012 0.674954 0.73364 36 | vn -0.618073 -0.544327 0.567181 37 | vn -0.517377 -0.544929 0.659829 38 | vn 0.574354 0.566011 0.591396 39 | vn 0.587687 0.550413 0.593018 40 | vn -0.588238 0.596058 -0.546527 41 | vn -0.586625 -0.575292 -0.570009 42 | vn 0.608822 0.560572 0.561332 43 | vn -0.577446 -0.592668 0.561516 44 | vn -0.552159 0.559211 0.618388 45 | vn -0.53279 0.611145 0.585351 46 | vn 0.522475 -0.55567 0.646723 47 | vn -0.615677 0.561035 0.553337 48 | vn 0.514507 -0.646286 0.563558 49 | vn 0.517567 -0.585942 0.623535 50 | vn 0.527767 0.570233 0.629521 51 | vn -0.583983 0.544348 0.602203 52 | vn 0.626998 0.497054 0.599842 53 | vn -0.518407 0.560496 0.645832 54 | vn -0.571743 -0.596434 0.563361 55 | vn 0.622954 0.538845 0.567075 56 | vn 0.611288 -0.587625 0.530117 57 | vn -0.461923 0.624263 0.630018 58 | vn 0.498947 0.600726 0.624645 59 | vn -0.597219 -0.583527 0.550296 60 | vn -0.541124 0.630859 0.556059 61 | vn 0.546503 -0.584971 -0.599285 62 | vn 0.563104 -0.596137 0.572307 63 | vn 0.585781 0.584715 -0.561221 64 | f 4/4 5/5 14/14 17/17 11/11 9/9 29/29 30/30 16/16 24/24 27/27 22/22 65 | f 28/28 21/21 23/23 20/20 1/1 31/31 8/8 19/19 18/18 26/26 7/7 6/6 66 | f 23/23 21/21 2/2 12/12 27/27 24/24 67 | f 21/21 28/28 13/13 2/2 68 | f 20/20 23/23 24/24 16/16 69 | f 18/18 19/19 11/11 17/17 70 | f 12/12 2/2 13/13 10/10 3/3 25/25 15/15 71 | f 1/1 30/30 29/29 31/31 72 | f 26/26 18/18 17/17 14/14 73 | f 19/19 8/8 9/9 11/11 74 | f 31/31 29/29 9/9 8/8 75 | f 12/12 15/15 22/22 27/27 76 | f 25/25 3/3 5/5 4/4 77 | f 10/10 6/6 7/7 3/3 78 | f 13/13 28/28 6/6 10/10 79 | f 15/15 25/25 4/4 22/22 80 | f 20/20 16/16 30/30 1/1 81 | f 5/5 3/3 7/7 26/26 14/14 82 | -------------------------------------------------------------------------------- /data/model3.obj: -------------------------------------------------------------------------------- 1 | # OBJ exported from Easy3D (liangliang.nan@gmail.com) 2 | v 3.40018 2.55048 1.1089 3 | v 3.42975 0.440686 1.58839 4 | v 2.83871 0.444079 1.75758 5 | v 3.42775 2.37775 1.79825 6 | v 2.57217 0.287346 1.72161 7 | v 3.42098 2.37499 1.5952 8 | v 3.48204 2.39558 1.57572 9 | v 3.38647 0.303177 1.07572 10 | v 2.55578 0.282664 1.07694 11 | v 3.48039 0.462121 1.5795 12 | v 2.87797 2.3804 1.5726 13 | v 2.82051 2.38108 1.77826 14 | v 2.53879 2.53783 1.76858 15 | v 3.47391 0.45174 1.40303 16 | v 3.51117 2.38752 1.44285 17 | v 3.41358 2.38034 1.44507 18 | v 2.54831 2.55121 1.10754 19 | v 3.42292 2.52395 1.79657 20 | v 3.408 0.306553 1.75697 21 | v 3.42256 0.456419 1.77847 22 | v 2.90476 0.439675 1.54839 23 | v 3.39832 0.479229 1.40167 24 | vn 0.568706 0.587567 -0.575621 25 | vn 0.740057 0.0210027 0.672216 26 | vn 0.521613 0.464571 0.715607 27 | vn 0.558517 -0.604034 0.568508 28 | vn -0.583928 -0.596088 0.551096 29 | vn 0.733283 -0.107915 0.671305 30 | vn 0.422752 0.754549 0.501932 31 | vn 0.568665 -0.571193 -0.591911 32 | vn -0.571752 -0.581191 -0.579065 33 | vn 0.494512 -0.56863 0.657356 34 | vn 0.476545 -0.586102 0.655278 35 | vn 0.491847 -0.490939 0.719073 36 | vn -0.602755 0.551841 0.576332 37 | vn 0.570418 -0.645545 -0.507833 38 | vn 0.589448 0.559208 -0.582956 39 | vn 0.482045 0.579804 -0.656856 40 | vn -0.577332 0.591874 -0.56247 41 | vn 0.577716 0.545621 0.607076 42 | vn 0.585853 -0.56166 0.584221 43 | vn 0.52558 0.642017 0.558193 44 | vn 0.471541 0.601879 0.644508 45 | vn 0.563978 -0.43944 -0.699157 46 | f 13/13 18/18 1/1 17/17 47 | f 22/22 16/16 15/15 14/14 48 | f 8/8 9/9 17/17 1/1 49 | f 6/6 16/16 22/22 2/2 20/20 19/19 8/8 1/1 18/18 4/4 50 | f 9/9 5/5 13/13 17/17 51 | f 4/4 18/18 13/13 5/5 19/19 20/20 3/3 12/12 52 | f 9/9 8/8 19/19 5/5 53 | f 6/6 4/4 12/12 11/11 54 | f 20/20 2/2 21/21 3/3 55 | f 15/15 7/7 10/10 14/14 56 | f 22/22 14/14 10/10 2/2 57 | f 15/15 16/16 6/6 7/7 58 | f 11/11 21/21 2/2 10/10 7/7 6/6 59 | f 12/12 3/3 21/21 11/11 60 | -------------------------------------------------------------------------------- /image/manhattan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiangliangNan/Manhattan/e296727ae48c5267ec4b23778dcea4f4065320a5/image/manhattan.png -------------------------------------------------------------------------------- /src/3rd_party/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | add_subdirectory("cminpack-1.3.6") 4 | set_target_properties(3rd_cminpack PROPERTIES FOLDER "3rd_party") 5 | 6 | add_subdirectory("liblbfgs") -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The name of our project is "CMINPACK". CMakeLists files in this project can 2 | # refer to the root source directory of the project as ${CMINPACK_SOURCE_DIR} and 3 | # to the root binary directory of the project as ${CMINPACK_BINARY_DIR}. 4 | cmake_minimum_required (VERSION 3.1) 5 | project (CMINPACK) 6 | 7 | string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) 8 | 9 | set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) 10 | 11 | include(${PROJECT_SOURCE_DIR}/cmake/cminpack_utils.cmake) 12 | # Set version and OS-specific settings 13 | set(CMINPACK_VERSION 1.3.6 CACHE STRING "CMinpack version") 14 | set(CMINPACK_SOVERSION 1 CACHE STRING "CMinpack API version") 15 | GET_OS_INFO() 16 | 17 | # Add an "uninstall" target 18 | #CONFIGURE_FILE ("${PROJECT_SOURCE_DIR}/cmake/uninstall_target.cmake.in" 19 | # "${PROJECT_BINARY_DIR}/uninstall_target.cmake" IMMEDIATE @ONLY) 20 | #ADD_CUSTOM_TARGET (uninstall "${CMAKE_COMMAND}" -P 21 | # "${PROJECT_BINARY_DIR}/uninstall_target.cmake") 22 | 23 | enable_testing() 24 | 25 | option (BUILD_SHARED_LIBS "Build shared libraries instead of static." OFF) 26 | if (BUILD_SHARED_LIBS) 27 | message (STATUS "Building shared libraries.") 28 | else () 29 | message (STATUS "Building static libraries.") 30 | # set(CMAKE_RELEASE_POSTFIX _s) 31 | # set(CMAKE_RELWITHDEBINFO_POSTFIX _s) 32 | # set(CMAKE_DEBUG_POSTFIX _s) 33 | # set(CMAKE_MINSIZEREL_POSTFIX _s) 34 | if(WIN32) 35 | add_definitions(-DCMINPACK_NO_DLL) 36 | endif(WIN32) 37 | endif () 38 | 39 | option(USE_BLAS "Compile cminpack using cblas library if possible" OFF) 40 | 41 | #set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/../build) 42 | 43 | if(NOT "${CMAKE_PREFIX_PATH}" STREQUAL "") 44 | include_directories(${CMAKE_PREFIX_PATH}/include) 45 | endif() 46 | 47 | set (cminpack_srcs 48 | cminpack.h cminpackP.h 49 | chkder.c enorm.c hybrd1.c hybrj.c lmdif1.c lmstr1.c qrfac.c r1updt.c 50 | dogleg.c fdjac1.c hybrd.c lmder1.c lmdif.c lmstr.c qrsolv.c rwupdt.c 51 | dpmpar.c fdjac2.c hybrj1.c lmder.c lmpar.c qform.c r1mpyq.c covar.c covar1.c 52 | minpack.h 53 | chkder_.c enorm_.c hybrd1_.c hybrj_.c lmdif1_.c lmstr1_.c qrfac_.c r1updt_.c 54 | dogleg_.c fdjac1_.c hybrd_.c lmder1_.c lmdif_.c lmstr_.c qrsolv_.c rwupdt_.c 55 | dpmpar_.c fdjac2_.c hybrj1_.c lmder_.c lmpar_.c qform_.c r1mpyq_.c covar_.c 56 | ) 57 | set (cminpack_hdrs 58 | cminpack.h minpack.h) 59 | 60 | add_library (3rd_cminpack ${cminpack_srcs}) 61 | 62 | if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") 63 | TARGET_LINK_LIBRARIES(3rd_cminpack m) 64 | endif() 65 | 66 | 67 | include (CheckLibraryExists) 68 | include (CheckFunctionExists) 69 | check_function_exists (sqrt HAVE_SQRT_NO_LIBM) 70 | if (NOT HAVE_SQRT_NO_LIBM) 71 | check_library_exists ("m" sqrt "" HAVE_LIBM) 72 | if (HAVE_LIBM) 73 | target_link_libraries(3rd_cminpack PUBLIC m) 74 | endif() 75 | endif () 76 | 77 | # Link with CBLAS library if requested 78 | if (USE_BLAS) 79 | find_package (CBLAS) 80 | if (CBLAS_FOUND) 81 | target_link_libraries(3rd_cminpack PUBLIC ${CBLAS_LIBRARIES}) 82 | set_target_properties(3rd_cminpack PROPERTIES LINK_FLAGS "${CBLAS_LINKER_FLAGS}") 83 | target_compile_definitions(3rd_cminpack PUBLIC USE_CBLAS) 84 | endif() 85 | endif() 86 | 87 | set_target_properties (3rd_cminpack PROPERTIES POSITION_INDEPENDENT_CODE ON) 88 | 89 | add_subdirectory (cmake) 90 | #add_subdirectory (examples) 91 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/CopyrightMINPACK.txt: -------------------------------------------------------------------------------- 1 | Minpack Copyright Notice (1999) University of Chicago. All rights reserved 2 | 3 | Redistribution and use in source and binary forms, with or 4 | without modification, are permitted provided that the 5 | following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above 8 | copyright notice, this list of conditions and the following 9 | disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials 14 | provided with the distribution. 15 | 16 | 3. The end-user documentation included with the 17 | redistribution, if any, must include the following 18 | acknowledgment: 19 | 20 | "This product includes software developed by the 21 | University of Chicago, as Operator of Argonne National 22 | Laboratory. 23 | 24 | Alternately, this acknowledgment may appear in the software 25 | itself, if and wherever such third-party acknowledgments 26 | normally appear. 27 | 28 | 4. WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS" 29 | WITHOUT WARRANTY OF ANY KIND. THE COPYRIGHT HOLDER, THE 30 | UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, AND 31 | THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES, EXPRESS OR 32 | IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES 33 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE 34 | OR NON-INFRINGEMENT, (2) DO NOT ASSUME ANY LEGAL LIABILITY 35 | OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR 36 | USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE OF 37 | THE SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4) 38 | DO NOT WARRANT THAT THE SOFTWARE WILL FUNCTION 39 | UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT ANY ERRORS WILL 40 | BE CORRECTED. 41 | 42 | 5. LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT 43 | HOLDER, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF 44 | ENERGY, OR THEIR EMPLOYEES: BE LIABLE FOR ANY INDIRECT, 45 | INCIDENTAL, CONSEQUENTIAL, SPECIAL OR PUNITIVE DAMAGES OF 46 | ANY KIND OR NATURE, INCLUDING BUT NOT LIMITED TO LOSS OF 47 | PROFITS OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, WHETHER 48 | SUCH LIABILITY IS ASSERTED ON THE BASIS OF CONTRACT, TORT 49 | (INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR OTHERWISE, 50 | EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE 51 | POSSIBILITY OF SUCH LOSS OR DAMAGES. 52 | 53 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/Makefile: -------------------------------------------------------------------------------- 1 | PACKAGE=cminpack 2 | VERSION=1.3.6 3 | 4 | CC=gcc 5 | CFLAGS= -O3 -g -Wall -Wextra 6 | 7 | ### The default configuration is to compile the double precision version 8 | 9 | ### configuration for the LAPACK/BLAS (double precision) version: 10 | ## make LIBSUFFIX= CFLAGS="-O3 -g -Wall -Wextra -D__cminpack_float__" 11 | #LIBSUFFIX=s 12 | #CFLAGS="-O3 -g -Wall -Wextra -DUSE_CBLAS -DUSE_LAPACK" 13 | CFLAGS_L=$(CFLAGS) -DUSE_CBLAS -DUSE_LAPACK 14 | LDADD_L=-framework Accelerate 15 | 16 | ### configuration for the long double version: 17 | ## make LIBSUFFIX=s CFLAGS="-O3 -g -Wall -Wextra -D__cminpack_long_double__" 18 | #LIBSUFFIX=s 19 | #CFLAGS="-O3 -g -Wall -Wextra -D__cminpack_long_double__" 20 | CFLAGS_LD=$(CFLAGS) -D__cminpack_long_double__ 21 | 22 | ### configuration for the float (single precision) version: 23 | ## make LIBSUFFIX=s CFLAGS="-O3 -g -Wall -Wextra -D__cminpack_float__" 24 | #LIBSUFFIX=s 25 | #CFLAGS="-O3 -g -Wall -Wextra -D__cminpack_float__" 26 | CFLAGS_F=$(CFLAGS) -D__cminpack_float__ 27 | 28 | ### configuration for the half (half precision) version: 29 | ## make LIBSUFFIX=h CFLAGS="-O3 -g -Wall -Wextra -I/opt/local/include -D__cminpack_half__" LDADD="-L/opt/local/lib -lHalf" CC=g++ 30 | #LIBSUFFIX=h 31 | #CFLAGS="-O3 -g -Wall -Wextra -I/opt/local/include -D__cminpack_half__" 32 | #LDADD="-L/opt/local/lib -lHalf" 33 | #CC=g++ 34 | CFLAGS_H=$(CFLAGS) -I/opt/local/include -D__cminpack_half__ 35 | LDADD_H=-L/opt/local/lib -lHalf 36 | CC_H=$(CXX) 37 | 38 | RANLIB=ranlib 39 | 40 | LIB=libcminpack$(LIBSUFFIX).a 41 | 42 | OBJS = \ 43 | $(LIBSUFFIX)chkder.o $(LIBSUFFIX)enorm.o $(LIBSUFFIX)hybrd1.o $(LIBSUFFIX)hybrj.o \ 44 | $(LIBSUFFIX)lmdif1.o $(LIBSUFFIX)lmstr1.o $(LIBSUFFIX)qrfac.o $(LIBSUFFIX)r1updt.o \ 45 | $(LIBSUFFIX)dogleg.o $(LIBSUFFIX)fdjac1.o $(LIBSUFFIX)hybrd.o $(LIBSUFFIX)lmder1.o \ 46 | $(LIBSUFFIX)lmdif.o $(LIBSUFFIX)lmstr.o $(LIBSUFFIX)qrsolv.o $(LIBSUFFIX)rwupdt.o \ 47 | $(LIBSUFFIX)dpmpar.o $(LIBSUFFIX)fdjac2.o $(LIBSUFFIX)hybrj1.o $(LIBSUFFIX)lmder.o \ 48 | $(LIBSUFFIX)lmpar.o $(LIBSUFFIX)qform.o $(LIBSUFFIX)r1mpyq.o $(LIBSUFFIX)covar.o $(LIBSUFFIX)covar1.o \ 49 | $(LIBSUFFIX)chkder_.o $(LIBSUFFIX)enorm_.o $(LIBSUFFIX)hybrd1_.o $(LIBSUFFIX)hybrj_.o \ 50 | $(LIBSUFFIX)lmdif1_.o $(LIBSUFFIX)lmstr1_.o $(LIBSUFFIX)qrfac_.o $(LIBSUFFIX)r1updt_.o \ 51 | $(LIBSUFFIX)dogleg_.o $(LIBSUFFIX)fdjac1_.o $(LIBSUFFIX)hybrd_.o $(LIBSUFFIX)lmder1_.o \ 52 | $(LIBSUFFIX)lmdif_.o $(LIBSUFFIX)lmstr_.o $(LIBSUFFIX)qrsolv_.o $(LIBSUFFIX)rwupdt_.o \ 53 | $(LIBSUFFIX)dpmpar_.o $(LIBSUFFIX)fdjac2_.o $(LIBSUFFIX)hybrj1_.o $(LIBSUFFIX)lmder_.o \ 54 | $(LIBSUFFIX)lmpar_.o $(LIBSUFFIX)qform_.o $(LIBSUFFIX)r1mpyq_.o $(LIBSUFFIX)covar_.o 55 | 56 | # target dir for install 57 | DESTDIR=/usr/local 58 | # 59 | # Static library target 60 | # 61 | 62 | all: $(LIB) 63 | 64 | double: 65 | $(MAKE) LIBSUFFIX= 66 | 67 | lapack: 68 | $(MAKE) LIBSUFFIX=l CFLAGS="$(CFLAGS_L)" LDADD="$(LDADD_L)" 69 | 70 | longdouble: 71 | $(MAKE) LIBSUFFIX=ld CFLAGS="$(CFLAGS_LD)" 72 | 73 | float: 74 | $(MAKE) LIBSUFFIX=s CFLAGS="$(CFLAGS_F)" 75 | 76 | half: 77 | $(MAKE) LIBSUFFIX=h CFLAGS="$(CFLAGS_H)" LDADD="$(LDADD_H)" CC="$(CC_H)" 78 | 79 | fortran cuda: 80 | $(MAKE) -C $@ 81 | 82 | check checkdouble checklapack checklongdouble checkfloat checkhalf checkfail: 83 | $(MAKE) -C examples $@ 84 | 85 | $(LIB): $(OBJS) 86 | $(AR) r $@ $(OBJS); $(RANLIB) $@ 87 | 88 | $(LIBSUFFIX)%.o: %.c 89 | ${CC} ${CFLAGS} -c -o $@ $< 90 | 91 | install: $(LIB) 92 | cp $(LIB) ${DESTDIR}/lib 93 | chmod 644 ${DESTDIR}/lib/$(LIB) 94 | $(RANLIB) -t ${DESTDIR}/lib/$(LIB) # might be unnecessary 95 | cp minpack.h ${DESTDIR}/include 96 | chmod 644 ${DESTDIR}/include/minpack.h 97 | cp cminpack.h ${DESTDIR}/include 98 | chmod 644 ${DESTDIR}/include/cminpack.h 99 | 100 | clean: 101 | rm -f $(OBJS) $(LIB) 102 | $(MAKE) -C examples clean 103 | $(MAKE) -C fortran clean 104 | 105 | veryclean: clean 106 | rm -f *.o libcminpack*.a *.gcno *.gcda *~ #*# 107 | $(MAKE) -C examples veryclean 108 | $(MAKE) -C examples veryclean LIBSUFFIX=s 109 | $(MAKE) -C examples veryclean LIBSUFFIX=h 110 | $(MAKE) -C examples veryclean LIBSUFFIX=l 111 | $(MAKE) -C fortran veryclean 112 | 113 | .PHONY: dist all double lapack longdouble float half fortran cuda check checkhalf checkfail clean veryclean 114 | 115 | # COPYFILE_DISABLE=true and COPY_EXTENDED_ATTRIBUTES_DISABLE=true are used to disable inclusion 116 | # of file attributes (._* files) in the tar file on MacOSX 117 | dist: 118 | mkdir $(PACKAGE)-$(VERSION) 119 | env COPYFILE_DISABLE=true COPY_EXTENDED_ATTRIBUTES_DISABLE=true tar --exclude-from dist-exclude --exclude $(PACKAGE)-$(VERSION) -cf - . | (cd $(PACKAGE)-$(VERSION); tar xf -) 120 | tar zcvf $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION) 121 | rm -rf $(PACKAGE)-$(VERSION) 122 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/chkder.c: -------------------------------------------------------------------------------- 1 | #include "cminpack.h" 2 | #include 3 | #include "cminpackP.h" 4 | 5 | #define log10e 0.43429448190325182765 6 | #define factor 100. 7 | 8 | /* Table of constant values */ 9 | 10 | __cminpack_attr__ 11 | void __cminpack_func__(chkder)(int m, int n, const real *x, 12 | real *fvec, real *fjac, int ldfjac, real *xp, 13 | real *fvecp, int mode, real *err) 14 | { 15 | /* Local variables */ 16 | int i, j; 17 | real eps, epsf, temp, epsmch; 18 | real epslog; 19 | 20 | /* ********** */ 21 | 22 | /* subroutine chkder */ 23 | 24 | /* this subroutine checks the gradients of m nonlinear functions */ 25 | /* in n variables, evaluated at a point x, for consistency with */ 26 | /* the functions themselves. the user must call chkder twice, */ 27 | /* first with mode = 1 and then with mode = 2. */ 28 | 29 | /* mode = 1. on input, x must contain the point of evaluation. */ 30 | /* on output, xp is set to a neighboring point. */ 31 | 32 | /* mode = 2. on input, fvec must contain the functions and the */ 33 | /* rows of fjac must contain the gradients */ 34 | /* of the respective functions each evaluated */ 35 | /* at x, and fvecp must contain the functions */ 36 | /* evaluated at xp. */ 37 | /* on output, err contains measures of correctness of */ 38 | /* the respective gradients. */ 39 | 40 | /* the subroutine does not perform reliably if cancellation or */ 41 | /* rounding errors cause a severe loss of significance in the */ 42 | /* evaluation of a function. therefore, none of the components */ 43 | /* of x should be unusually small (in particular, zero) or any */ 44 | /* other value which may cause loss of significance. */ 45 | 46 | /* the subroutine statement is */ 47 | 48 | /* subroutine chkder(m,n,x,fvec,fjac,ldfjac,xp,fvecp,mode,err) */ 49 | 50 | /* where */ 51 | 52 | /* m is a positive integer input variable set to the number */ 53 | /* of functions. */ 54 | 55 | /* n is a positive integer input variable set to the number */ 56 | /* of variables. */ 57 | 58 | /* x is an input array of length n. */ 59 | 60 | /* fvec is an array of length m. on input when mode = 2, */ 61 | /* fvec must contain the functions evaluated at x. */ 62 | 63 | /* fjac is an m by n array. on input when mode = 2, */ 64 | /* the rows of fjac must contain the gradients of */ 65 | /* the respective functions evaluated at x. */ 66 | 67 | /* ldfjac is a positive integer input parameter not less than m */ 68 | /* which specifies the leading dimension of the array fjac. */ 69 | 70 | /* xp is an array of length n. on output when mode = 1, */ 71 | /* xp is set to a neighboring point of x. */ 72 | 73 | /* fvecp is an array of length m. on input when mode = 2, */ 74 | /* fvecp must contain the functions evaluated at xp. */ 75 | 76 | /* mode is an integer input variable set to 1 on the first call */ 77 | /* and 2 on the second. other values of mode are equivalent */ 78 | /* to mode = 1. */ 79 | 80 | /* err is an array of length m. on output when mode = 2, */ 81 | /* err contains measures of correctness of the respective */ 82 | /* gradients. if there is no severe loss of significance, */ 83 | /* then if err(i) is 1.0 the i-th gradient is correct, */ 84 | /* while if err(i) is 0.0 the i-th gradient is incorrect. */ 85 | /* for values of err between 0.0 and 1.0, the categorization */ 86 | /* is less certain. in general, a value of err(i) greater */ 87 | /* than 0.5 indicates that the i-th gradient is probably */ 88 | /* correct, while a value of err(i) less than 0.5 indicates */ 89 | /* that the i-th gradient is probably incorrect. */ 90 | 91 | /* subprograms called */ 92 | 93 | /* minpack supplied ... dpmpar */ 94 | 95 | /* fortran supplied ... dabs,dlog10,dsqrt */ 96 | 97 | /* argonne national laboratory. minpack project. march 1980. */ 98 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 99 | 100 | /* ********** */ 101 | 102 | /* epsmch is the machine precision. */ 103 | 104 | epsmch = __cminpack_func__(dpmpar)(1); 105 | 106 | eps = sqrt(epsmch); 107 | 108 | if (mode != 2) { 109 | 110 | /* mode = 1. */ 111 | 112 | for (j = 0; j < n; ++j) { 113 | temp = eps * fabs(x[j]); 114 | if (temp == 0.) { 115 | temp = eps; 116 | } 117 | xp[j] = x[j] + temp; 118 | } 119 | return; 120 | } 121 | 122 | /* mode = 2. */ 123 | 124 | epsf = factor * epsmch; 125 | epslog = log10e * log(eps); 126 | for (i = 0; i < m; ++i) { 127 | err[i] = 0.; 128 | } 129 | for (j = 0; j < n; ++j) { 130 | temp = fabs(x[j]); 131 | if (temp == 0.) { 132 | temp = 1.; 133 | } 134 | for (i = 0; i < m; ++i) { 135 | err[i] += temp * fjac[i + j * ldfjac]; 136 | } 137 | } 138 | for (i = 0; i < m; ++i) { 139 | temp = 1.; 140 | if (fvec[i] != 0. && fvecp[i] != 0. && 141 | fabs(fvecp[i] - fvec[i]) >= epsf * fabs(fvec[i])) 142 | { 143 | temp = eps * fabs((fvecp[i] - fvec[i]) / eps - err[i]) 144 | / (fabs(fvec[i]) + 145 | fabs(fvecp[i])); 146 | } 147 | err[i] = 1.; 148 | if (temp > epsmch && temp < eps) { 149 | err[i] = (log10e * log(temp) - epslog) / epslog; 150 | } 151 | if (temp >= eps) { 152 | err[i] = 0.; 153 | } 154 | } 155 | 156 | /* last card of subroutine chkder. */ 157 | 158 | } /* chkder_ */ 159 | 160 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/chkder_.c: -------------------------------------------------------------------------------- 1 | /* chkder.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "minpack.h" 7 | #include 8 | #include "minpackP.h" 9 | 10 | #define log10e 0.43429448190325182765 11 | #define factor 100. 12 | 13 | /* Table of constant values */ 14 | 15 | __minpack_attr__ 16 | void __minpack_func__(chkder)(const int *m, const int *n, const real *x, 17 | real *fvec, real *fjac, const int *ldfjac, real *xp, 18 | real *fvecp, const int *mode, real *err) 19 | { 20 | /* Initialized data */ 21 | 22 | const int c__1 = 1; 23 | 24 | /* System generated locals */ 25 | int fjac_dim1, fjac_offset, i__1, i__2; 26 | 27 | /* Local variables */ 28 | int i__, j; 29 | real eps, epsf, temp, epsmch; 30 | real epslog; 31 | 32 | /* ********** */ 33 | 34 | /* subroutine chkder */ 35 | 36 | /* this subroutine checks the gradients of m nonlinear functions */ 37 | /* in n variables, evaluated at a point x, for consistency with */ 38 | /* the functions themselves. the user must call chkder twice, */ 39 | /* first with mode = 1 and then with mode = 2. */ 40 | 41 | /* mode = 1. on input, x must contain the point of evaluation. */ 42 | /* on output, xp is set to a neighboring point. */ 43 | 44 | /* mode = 2. on input, fvec must contain the functions and the */ 45 | /* rows of fjac must contain the gradients */ 46 | /* of the respective functions each evaluated */ 47 | /* at x, and fvecp must contain the functions */ 48 | /* evaluated at xp. */ 49 | /* on output, err contains measures of correctness of */ 50 | /* the respective gradients. */ 51 | 52 | /* the subroutine does not perform reliably if cancellation or */ 53 | /* rounding errors cause a severe loss of significance in the */ 54 | /* evaluation of a function. therefore, none of the components */ 55 | /* of x should be unusually small (in particular, zero) or any */ 56 | /* other value which may cause loss of significance. */ 57 | 58 | /* the subroutine statement is */ 59 | 60 | /* subroutine chkder(m,n,x,fvec,fjac,ldfjac,xp,fvecp,mode,err) */ 61 | 62 | /* where */ 63 | 64 | /* m is a positive integer input variable set to the number */ 65 | /* of functions. */ 66 | 67 | /* n is a positive integer input variable set to the number */ 68 | /* of variables. */ 69 | 70 | /* x is an input array of length n. */ 71 | 72 | /* fvec is an array of length m. on input when mode = 2, */ 73 | /* fvec must contain the functions evaluated at x. */ 74 | 75 | /* fjac is an m by n array. on input when mode = 2, */ 76 | /* the rows of fjac must contain the gradients of */ 77 | /* the respective functions evaluated at x. */ 78 | 79 | /* ldfjac is a positive integer input parameter not less than m */ 80 | /* which specifies the leading dimension of the array fjac. */ 81 | 82 | /* xp is an array of length n. on output when mode = 1, */ 83 | /* xp is set to a neighboring point of x. */ 84 | 85 | /* fvecp is an array of length m. on input when mode = 2, */ 86 | /* fvecp must contain the functions evaluated at xp. */ 87 | 88 | /* mode is an integer input variable set to 1 on the first call */ 89 | /* and 2 on the second. other values of mode are equivalent */ 90 | /* to mode = 1. */ 91 | 92 | /* err is an array of length m. on output when mode = 2, */ 93 | /* err contains measures of correctness of the respective */ 94 | /* gradients. if there is no severe loss of significance, */ 95 | /* then if err(i) is 1.0 the i-th gradient is correct, */ 96 | /* while if err(i) is 0.0 the i-th gradient is incorrect. */ 97 | /* for values of err between 0.0 and 1.0, the categorization */ 98 | /* is less certain. in general, a value of err(i) greater */ 99 | /* than 0.5 indicates that the i-th gradient is probably */ 100 | /* correct, while a value of err(i) less than 0.5 indicates */ 101 | /* that the i-th gradient is probably incorrect. */ 102 | 103 | /* subprograms called */ 104 | 105 | /* minpack supplied ... dpmpar */ 106 | 107 | /* fortran supplied ... dabs,dlog10,dsqrt */ 108 | 109 | /* argonne national laboratory. minpack project. march 1980. */ 110 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 111 | 112 | /* ********** */ 113 | /* Parameter adjustments */ 114 | --err; 115 | --fvecp; 116 | --fvec; 117 | --xp; 118 | --x; 119 | fjac_dim1 = *ldfjac; 120 | fjac_offset = 1 + fjac_dim1 * 1; 121 | fjac -= fjac_offset; 122 | 123 | /* Function Body */ 124 | 125 | /* epsmch is the machine precision. */ 126 | 127 | epsmch = __minpack_func__(dpmpar)(&c__1); 128 | 129 | eps = sqrt(epsmch); 130 | 131 | if (*mode == 2) { 132 | goto L20; 133 | } 134 | 135 | /* mode = 1. */ 136 | 137 | i__1 = *n; 138 | for (j = 1; j <= i__1; ++j) { 139 | temp = eps * fabs(x[j]); 140 | if (temp == 0.) { 141 | temp = eps; 142 | } 143 | xp[j] = x[j] + temp; 144 | /* L10: */ 145 | } 146 | /* goto L70; */ 147 | return; 148 | L20: 149 | 150 | /* mode = 2. */ 151 | 152 | epsf = factor * epsmch; 153 | epslog = log10e * log(eps); 154 | i__1 = *m; 155 | for (i__ = 1; i__ <= i__1; ++i__) { 156 | err[i__] = 0.; 157 | /* L30: */ 158 | } 159 | i__1 = *n; 160 | for (j = 1; j <= i__1; ++j) { 161 | temp = fabs(x[j]); 162 | if (temp == 0.) { 163 | temp = 1.; 164 | } 165 | i__2 = *m; 166 | for (i__ = 1; i__ <= i__2; ++i__) { 167 | err[i__] += temp * fjac[i__ + j * fjac_dim1]; 168 | /* L40: */ 169 | } 170 | /* L50: */ 171 | } 172 | i__1 = *m; 173 | for (i__ = 1; i__ <= i__1; ++i__) { 174 | temp = 1.; 175 | if (fvec[i__] != 0. && fvecp[i__] != 0. && fabs(fvecp[i__] - 176 | fvec[i__]) >= epsf * fabs(fvec[i__])) 177 | { 178 | temp = eps * fabs((fvecp[i__] - fvec[i__]) / eps - err[i__]) 179 | / (fabs(fvec[i__]) + 180 | fabs(fvecp[i__])); 181 | } 182 | err[i__] = 1.; 183 | if (temp > epsmch && temp < eps) { 184 | err[i__] = (log10e * log(temp) - epslog) / epslog; 185 | } 186 | if (temp >= eps) { 187 | err[i__] = 0.; 188 | } 189 | /* L60: */ 190 | } 191 | /* L70: */ 192 | 193 | /* return 0; */ 194 | 195 | /* last card of subroutine chkder. */ 196 | 197 | } /* chkder_ */ 198 | 199 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PKG_DESC "CMinPack") 2 | set(PKG_EXTERNAL_DEPS "") 3 | set(pkg_conf_file ${CMAKE_CURRENT_BINARY_DIR}/cminpack.pc) 4 | if (USE_BLAS AND CBLAS_FOUND) 5 | set(PC_CMINPACK_CFLAGS "-DUSE_CBLAS") 6 | if (NOT "${BLAS_LIBRARIES}" STREQUAL "") 7 | string(REPLACE ";" " -l" PC_CMINPACK_LIBRARIES "${BLAS_LIBRARIES}") 8 | set(PC_CMINPACK_LIBRARIES "-l${PC_CMINPACK_LIBRARIES}") 9 | endif() 10 | set(PC_CMINPACK_LDFLAGS "${BLAS_LINKER_FLAGS}") 11 | endif() 12 | configure_file(cminpack.pc.in ${pkg_conf_file} @ONLY) 13 | install(FILES ${pkg_conf_file} 14 | DESTINATION ${CMINPACK_LIB_INSTALL_DIR}/pkgconfig/ COMPONENT pkgconfig) 15 | 16 | install(FILES CMinpackConfig.cmake DESTINATION share/cmake/CMinpack) 17 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/cmake/CMinpackConfig.cmake: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Find CMinpack 3 | # 4 | # This sets the following variables: 5 | # CMINPACK_FOUND - True if CMinpack was found. 6 | # CMINPACK_INCLUDE_DIRS - Directories containing the CMinpack include files. 7 | # CMINPACK_LIBRARIES - Libraries needed to use CMinpack. 8 | # CMINPACK_LIBRARIES_DEBUG - Libraries needed to use CMinpack, debug version. 9 | # CMINPACK_DEFINITIONS - Compiler flags for CMinpack. 10 | 11 | find_package(PkgConfig) 12 | pkg_check_modules(PC_CMINPACK cminpack) 13 | set(CMINPACK_DEFINITIONS ${PC_CMINPACK_CFLAGS_OTHER}) 14 | 15 | find_path(CMINPACK_INCLUDE_DIR cminpack.h 16 | HINTS ${PC_CMINPACK_INCLUDEDIR} ${PC_CMINPACK_INCLUDE_DIRS} "${CMINPACK_ROOT}" "$ENV{CMINPACK_ROOT}" 17 | PATHS "$ENV{PROGRAMFILES}/CMinpack" "$ENV{PROGRAMW6432}/CMinpack" 18 | PATH_SUFFIXES include/cminpack-1) 19 | 20 | # Prefer static libraries in Windows over shared ones 21 | if(WIN32) 22 | find_library(CMINPACK_LIBRARY 23 | NAMES cminpack_s cminpack 24 | HINTS ${PC_CMINPACK_LIBDIR} ${PC_CMINPACK_LIBRARY_DIRS} "${CMINPACK_ROOT}" "$ENV{CMINPACK_ROOT}" 25 | PATHS "$ENV{PROGRAMFILES}/CMinpack" "$ENV{PROGRAMW6432}/CMinpack" 26 | PATH_SUFFIXES lib) 27 | 28 | find_library(CMINPACK_LIBRARY_DEBUG 29 | NAMES cminpack_s-gd cminpack-gd cminpack_s cminpack 30 | HINTS ${PC_CMINPACK_LIBDIR} ${PC_CMINPACK_LIBRARY_DIRS} "${CMINPACK_ROOT}" "$ENV{CMINPACK_ROOT}" 31 | PATHS "$ENV{PROGRAMFILES}/CMinpack" "$ENV{PROGRAMW6432}/CMinpack" 32 | PATH_SUFFIXES lib) 33 | else(WIN32) 34 | find_library(CMINPACK_LIBRARY 35 | NAMES cminpack 36 | HINTS ${PC_CMINPACK_LIBDIR} ${PC_CMINPACK_LIBRARY_DIRS} "${CMINPACK_ROOT}" "$ENV{CMINPACK_ROOT}" 37 | PATH_SUFFIXES lib) 38 | 39 | find_library(CMINPACK_LIBRARY_DEBUG 40 | NAMES cminpack-gd cminpack 41 | HINTS ${PC_CMINPACK_LIBDIR} ${PC_CMINPACK_LIBRARY_DIRS} "${CMINPACK_ROOT}" "$ENV{CMINPACK_ROOT}" 42 | PATH_SUFFIXES lib) 43 | endif(WIN32) 44 | 45 | if(NOT CMINPACK_LIBRARY_DEBUG) 46 | set(CMINPACK_LIBRARY_DEBUG ${CMINPACK_LIBRARY}) 47 | endif(NOT CMINPACK_LIBRARY_DEBUG) 48 | 49 | set(CMINPACK_INCLUDE_DIRS ${CMINPACK_INCLUDE_DIR}) 50 | set(CMINPACK_LIBRARIES optimized ${CMINPACK_LIBRARY} debug ${CMINPACK_LIBRARY_DEBUG}) 51 | list(APPEND CMINPACK_LIBRARIES "${PC_CMINPACK_LIBRARIES}") 52 | 53 | include(FindPackageHandleStandardArgs) 54 | find_package_handle_standard_args(CMinpack DEFAULT_MSG 55 | CMINPACK_LIBRARY CMINPACK_INCLUDE_DIR) 56 | 57 | mark_as_advanced(CMINPACK_LIBRARY CMINPACK_LIBRARY_DEBUG CMINPACK_INCLUDE_DIR) 58 | 59 | if(CMINPACK_FOUND) 60 | message(STATUS "CMinPack found (include: ${CMINPACK_INCLUDE_DIRS}, libs: ${CMINPACK_LIBRARIES})") 61 | if(WIN32) 62 | get_filename_component(cminpack_lib ${CMINPACK_LIBRARY} NAME_WE) 63 | set(CMINPACK_IS_STATIC_DEFAULT OFF) 64 | if("${cminpack_lib}" STREQUAL "cminpack_s") 65 | set(CMINPACK_IS_STATIC_DEFAULT ON) 66 | endif("${cminpack_lib}" STREQUAL "cminpack_s") 67 | option(CMINPACK_IS_STATIC "Set to OFF if you use shared cminpack library." ${CMINPACK_IS_STATIC_DEFAULT}) 68 | if(CMINPACK_IS_STATIC) 69 | add_definitions(-DCMINPACK_NO_DLL) 70 | endif(CMINPACK_IS_STATIC) 71 | endif(WIN32) 72 | endif(CMINPACK_FOUND) 73 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/cmake/FindCBLAS.cmake: -------------------------------------------------------------------------------- 1 | # - Find CBLAS library 2 | # 3 | # This module finds an installed fortran library that implements the CBLAS 4 | # linear-algebra interface (see http://www.netlib.org/blas/), with CBLAS 5 | # interface. 6 | # 7 | # This module sets the following variables: 8 | # CBLAS_FOUND - set to true if a library implementing the CBLAS interface is found 9 | # CBLAS_LIBRARIES - list of libraries (using full path name) to link against to use CBLAS 10 | # CBLAS_INCLUDE_DIR - path to includes 11 | # CBLAS_INCLUDE_FILE - the file to be included to use CBLAS 12 | # 13 | 14 | SET(CBLAS_LIBRARIES) 15 | SET(CBLAS_INCLUDE_DIR) 16 | SET(CBLAS_INCLUDE_FILE) 17 | 18 | # CBLAS in Intel mkl 19 | FIND_PACKAGE(MKL QUIET) 20 | IF (MKL_FOUND AND NOT CBLAS_LIBRARIES) 21 | SET(CBLAS_LIBRARIES ${MKL_LIBRARIES}) 22 | SET(CBLAS_INCLUDE_DIR ${MKL_INCLUDE_DIR}) 23 | SET(CBLAS_INCLUDE_FILE "mkl_cblas.h") 24 | ENDIF (MKL_FOUND AND NOT CBLAS_LIBRARIES) 25 | 26 | # Old CBLAS search 27 | SET(_verbose TRUE) 28 | INCLUDE(CheckFunctionExists) 29 | INCLUDE(CheckIncludeFile) 30 | 31 | MACRO(CHECK_ALL_LIBRARIES LIBRARIES _prefix _name _flags _list _include _search_include) 32 | # This macro checks for the existence of the combination of fortran libraries 33 | # given by _list. If the combination is found, this macro checks (using the 34 | # Check_Fortran_Function_Exists macro) whether can link against that library 35 | # combination using the name of a routine given by _name using the linker 36 | # flags given by _flags. If the combination of libraries is found and passes 37 | # the link test, LIBRARIES is set to the list of complete library paths that 38 | # have been found. Otherwise, LIBRARIES is set to FALSE. 39 | # N.B. _prefix is the prefix applied to the names of all cached variables that 40 | # are generated internally and marked advanced by this macro. 41 | SET(__list) 42 | FOREACH(_elem ${_list}) 43 | IF(__list) 44 | SET(__list "${__list} - ${_elem}") 45 | ELSE(__list) 46 | SET(__list "${_elem}") 47 | ENDIF(__list) 48 | ENDFOREACH(_elem) 49 | IF(_verbose) 50 | MESSAGE(STATUS "Checking for [${__list}]") 51 | ENDIF(_verbose) 52 | SET(_libraries_work TRUE) 53 | SET(${LIBRARIES}) 54 | SET(_combined_name) 55 | SET(_paths) 56 | FOREACH(_library ${_list}) 57 | SET(_combined_name ${_combined_name}_${_library}) 58 | # did we find all the libraries in the _list until now? 59 | # (we stop at the first unfound one) 60 | IF(_libraries_work) 61 | IF(APPLE) 62 | FIND_LIBRARY(${_prefix}_${_library}_LIBRARY 63 | NAMES ${_library} 64 | PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV 65 | DYLD_LIBRARY_PATH 66 | ) 67 | ELSE(APPLE) 68 | FIND_LIBRARY(${_prefix}_${_library}_LIBRARY 69 | NAMES ${_library} 70 | PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV 71 | LD_LIBRARY_PATH 72 | ) 73 | ENDIF(APPLE) 74 | MARK_AS_ADVANCED(${_prefix}_${_library}_LIBRARY) 75 | IF(${_prefix}_${_library}_LIBRARY) 76 | GET_FILENAME_COMPONENT(_path ${${_prefix}_${_library}_LIBRARY} PATH) 77 | LIST(APPEND _paths ${_path}/../include ${_path}/../../include) 78 | ENDIF(${_prefix}_${_library}_LIBRARY) 79 | SET(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY}) 80 | SET(_libraries_work ${${_prefix}_${_library}_LIBRARY}) 81 | ENDIF(_libraries_work) 82 | ENDFOREACH(_library ${_list}) 83 | # Test include 84 | SET(_bug_search_include ${_search_include}) #CMAKE BUG!!! SHOULD NOT BE THAT 85 | IF(_bug_search_include) 86 | FIND_PATH(${_prefix}${_combined_name}_INCLUDE ${_include} ${_paths}) 87 | MARK_AS_ADVANCED(${_prefix}${_combined_name}_INCLUDE) 88 | IF(${_prefix}${_combined_name}_INCLUDE) 89 | IF (_verbose) 90 | MESSAGE(STATUS "Includes found") 91 | ENDIF (_verbose) 92 | SET(${_prefix}_INCLUDE_DIR ${${_prefix}${_combined_name}_INCLUDE}) 93 | SET(${_prefix}_INCLUDE_FILE ${_include}) 94 | ELSE(${_prefix}${_combined_name}_INCLUDE) 95 | SET(_libraries_work FALSE) 96 | ENDIF(${_prefix}${_combined_name}_INCLUDE) 97 | ELSE(_bug_search_include) 98 | SET(${_prefix}_INCLUDE_DIR) 99 | SET(${_prefix}_INCLUDE_FILE ${_include}) 100 | ENDIF(_bug_search_include) 101 | # Test this combination of libraries. 102 | IF(_libraries_work) 103 | SET(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}}) 104 | CHECK_FUNCTION_EXISTS(${_name} ${_prefix}${_combined_name}_WORKS) 105 | SET(CMAKE_REQUIRED_LIBRARIES) 106 | MARK_AS_ADVANCED(${_prefix}${_combined_name}_WORKS) 107 | SET(_libraries_work ${${_prefix}${_combined_name}_WORKS}) 108 | IF(_verbose AND _libraries_work) 109 | MESSAGE(STATUS "Libraries found") 110 | ENDIF(_verbose AND _libraries_work) 111 | ENDIF(_libraries_work) 112 | # Fin 113 | IF(NOT _libraries_work) 114 | SET(${LIBRARIES} NOTFOUND) 115 | ENDIF(NOT _libraries_work) 116 | ENDMACRO(CHECK_ALL_LIBRARIES) 117 | 118 | # Generic CBLAS library 119 | IF(NOT CBLAS_LIBRARIES) 120 | CHECK_ALL_LIBRARIES( 121 | CBLAS_LIBRARIES 122 | CBLAS 123 | cblas_dgemm 124 | "" 125 | "cblas" 126 | "cblas.h" 127 | TRUE ) 128 | ENDIF() 129 | 130 | # CBLAS in ATLAS library? (http://math-atlas.sourceforge.net/) 131 | IF(NOT CBLAS_LIBRARIES) 132 | CHECK_ALL_LIBRARIES( 133 | CBLAS_LIBRARIES 134 | CBLAS 135 | cblas_dgemm 136 | "" 137 | "cblas;atlas" 138 | "cblas.h" 139 | TRUE ) 140 | ENDIF() 141 | 142 | # CBLAS in BLAS library 143 | IF(NOT CBLAS_LIBRARIES) 144 | CHECK_ALL_LIBRARIES( 145 | CBLAS_LIBRARIES 146 | CBLAS 147 | cblas_dgemm 148 | "" 149 | "blas" 150 | "cblas.h" 151 | TRUE ) 152 | ENDIF() 153 | 154 | # Apple CBLAS library? 155 | IF(NOT CBLAS_LIBRARIES) 156 | CHECK_ALL_LIBRARIES( 157 | CBLAS_LIBRARIES 158 | CBLAS 159 | cblas_dgemm 160 | "" 161 | "Accelerate" 162 | "Accelerate/Accelerate.h" 163 | FALSE ) 164 | ENDIF() 165 | 166 | IF( NOT CBLAS_LIBRARIES ) 167 | CHECK_ALL_LIBRARIES( 168 | CBLAS_LIBRARIES 169 | CBLAS 170 | cblas_dgemm 171 | "" 172 | "vecLib" 173 | "vecLib/vecLib.h" 174 | FALSE ) 175 | ENDIF() 176 | 177 | include ( FindPackageHandleStandardArgs ) 178 | find_package_handle_standard_args ( CBLAS DEFAULT_MSG CBLAS_LIBRARIES 179 | ) 180 | 181 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/cmake/cminpack.pc.in: -------------------------------------------------------------------------------- 1 | # This file was generated by CMake for @PROJECT_NAME@ 2 | prefix=@CMAKE_INSTALL_PREFIX@ 3 | exec_prefix=${prefix} 4 | libdir=${prefix}/@CMINPACK_LIB_INSTALL_DIR@ 5 | includedir=${prefix}/@CMINPACK_INCLUDE_INSTALL_DIR@ 6 | 7 | Name: @PROJECT_NAME@ 8 | Description: @PKG_DESC@ 9 | Version: @CMINPACK_VERSION@ 10 | Requires: @PKG_EXTERNAL_DEPS@ 11 | Libs: -L${libdir} -lcminpack -lm @PC_CMINPACK_LIBRARIES@ @PC_CMINPACK_LDFLAGS@ 12 | Cflags: -I${includedir} @CMINPACK_CFLAGS@ 13 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/cmake/cminpack_utils.cmake: -------------------------------------------------------------------------------- 1 | macro(GET_OS_INFO) 2 | string(REGEX MATCH "Linux" OS_LINUX ${CMAKE_SYSTEM_NAME}) 3 | string(REGEX MATCH "BSD" OS_BSD ${CMAKE_SYSTEM_NAME}) 4 | if(WIN32) 5 | set(OS_WIN TRUE) 6 | endif(WIN32) 7 | 8 | if(NOT DEFINED CMINPACK_LIB_INSTALL_DIR) 9 | set(CMINPACK_LIB_INSTALL_DIR "lib") 10 | if(OS_LINUX) 11 | if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") 12 | set(CMINPACK_LIB_INSTALL_DIR "lib64") 13 | else(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") 14 | set(CMINPACK_LIB_INSTALL_DIR "lib") 15 | endif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") 16 | message (STATUS "Operating system is Linux") 17 | elseif(OS_BSD) 18 | message (STATUS "Operating system is BSD") 19 | elseif(OS_WIN) 20 | message (STATUS "Operating system is Windows") 21 | else(OS_LINUX) 22 | message (STATUS "Operating system is generic Unix") 23 | endif(OS_LINUX) 24 | endif(NOT DEFINED CMINPACK_LIB_INSTALL_DIR) 25 | set(CMINPACK_INCLUDE_INSTALL_DIR 26 | "include/${PROJECT_NAME_LOWER}-${CMINPACK_MAJOR_VERSION}") 27 | endmacro(GET_OS_INFO) 28 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/cmake/uninstall_target.cmake.in: -------------------------------------------------------------------------------- 1 | if(NOT EXISTS "@PROJECT_BINARY_DIR@/install_manifest.txt") 2 | message(FATAL_ERROR "Cannot find install manifest: \"@PROJECT_BINARY_DIR@/install_manifest.txt\"") 3 | endif(NOT EXISTS "@PROJECT_BINARY_DIR@/install_manifest.txt") 4 | 5 | file(READ "@PROJECT_BINARY_DIR@/install_manifest.txt" files) 6 | string(REGEX REPLACE "\n" ";" files "${files}") 7 | foreach(file ${files}) 8 | message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 9 | if(EXISTS "$ENV{DESTDIR}${file}") 10 | exec_program("@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 11 | OUTPUT_VARIABLE rm_out RETURN_VALUE rm_retval) 12 | if(NOT "${rm_retval}" STREQUAL 0) 13 | message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 14 | endif(NOT "${rm_retval}" STREQUAL 0) 15 | else(EXISTS "$ENV{DESTDIR}${file}") 16 | message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") 17 | endif(EXISTS "$ENV{DESTDIR}${file}") 18 | endforeach(file) 19 | 20 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/cminpackP.h: -------------------------------------------------------------------------------- 1 | /* Internal header file for cminpack, by Frederic Devernay. */ 2 | #ifndef __CMINPACKP_H__ 3 | #define __CMINPACKP_H__ 4 | 5 | #ifndef __CMINPACK_H__ 6 | #error "cminpackP.h in an internal cminpack header, and must be included after all other headers (including cminpack.h)" 7 | #endif 8 | 9 | #if (defined (USE_CBLAS) || defined (USE_LAPACK)) && !defined (__cminpack_double__) 10 | #error "cminpack can use cblas and lapack only in double precision mode" 11 | #endif 12 | 13 | #ifdef USE_CBLAS 14 | #ifdef __APPLE__ 15 | #include 16 | #else 17 | #include 18 | #endif 19 | #define __cminpack_enorm__(n,x) cblas_dnrm2(n,x,1) 20 | #else 21 | #define __cminpack_enorm__(n,x) __cminpack_func__(enorm)(n,x) 22 | #endif 23 | 24 | #ifdef USE_LAPACK 25 | #ifdef __APPLE__ 26 | #include 27 | #else 28 | #if defined(__LP64__) /* In LP64 match sizes with the 32 bit ABI */ 29 | typedef int __CLPK_integer; 30 | typedef int __CLPK_logical; 31 | typedef float __CLPK_real; 32 | typedef double __CLPK_doublereal; 33 | typedef __CLPK_logical (*__CLPK_L_fp)(); 34 | typedef int __CLPK_ftnlen; 35 | #else 36 | typedef long int __CLPK_integer; 37 | typedef long int __CLPK_logical; 38 | typedef float __CLPK_real; 39 | typedef double __CLPK_doublereal; 40 | typedef __CLPK_logical (*__CLPK_L_fp)(); 41 | typedef long int __CLPK_ftnlen; 42 | #endif 43 | //extern void dlartg_(double *f, double *g, double *cs, double *sn, double *r__); 44 | int dlartg_(__CLPK_doublereal *f, __CLPK_doublereal *g, __CLPK_doublereal *cs, 45 | __CLPK_doublereal *sn, __CLPK_doublereal *r__); 46 | //extern void dgeqp3_(int *m, int *n, double *a, int *lda, int *jpvt, double *tau, double *work, int *lwork, int *info); 47 | int dgeqp3_(__CLPK_integer *m, __CLPK_integer *n, __CLPK_doublereal *a, __CLPK_integer * 48 | lda, __CLPK_integer *jpvt, __CLPK_doublereal *tau, __CLPK_doublereal *work, __CLPK_integer *lwork, 49 | __CLPK_integer *info); 50 | //extern void dgeqrf_(int *m, int *n, double *a, int *lda, double *tau, double *work, int *lwork, int *info); 51 | int dgeqrf_(__CLPK_integer *m, __CLPK_integer *n, __CLPK_doublereal *a, __CLPK_integer * 52 | lda, __CLPK_doublereal *tau, __CLPK_doublereal *work, __CLPK_integer *lwork, __CLPK_integer *info); 53 | #endif 54 | #endif 55 | 56 | #include "minpackP.h" 57 | 58 | #endif /* !__CMINPACKP_H__ */ 59 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/covar.c: -------------------------------------------------------------------------------- 1 | #include "cminpack.h" 2 | #include 3 | #include "cminpackP.h" 4 | 5 | __cminpack_attr__ 6 | void __cminpack_func__(covar)(int n, real *r, int ldr, 7 | const int *ipvt, real tol, real *wa) 8 | { 9 | /* Local variables */ 10 | int i, j, k, l, ii, jj; 11 | int sing; 12 | real temp, tolr; 13 | 14 | /* ********** */ 15 | 16 | /* subroutine covar */ 17 | 18 | /* given an m by n matrix a, the problem is to determine */ 19 | /* the covariance matrix corresponding to a, defined as */ 20 | 21 | /* t */ 22 | /* inverse(a *a) . */ 23 | 24 | /* this subroutine completes the solution of the problem */ 25 | /* if it is provided with the necessary information from the */ 26 | /* qr factorization, with column pivoting, of a. that is, if */ 27 | /* a*p = q*r, where p is a permutation matrix, q has orthogonal */ 28 | /* columns, and r is an upper triangular matrix with diagonal */ 29 | /* elements of nonincreasing magnitude, then covar expects */ 30 | /* the full upper triangle of r and the permutation matrix p. */ 31 | /* the covariance matrix is then computed as */ 32 | 33 | /* t t */ 34 | /* p*inverse(r *r)*p . */ 35 | 36 | /* if a is nearly rank deficient, it may be desirable to compute */ 37 | /* the covariance matrix corresponding to the linearly independent */ 38 | /* columns of a. to define the numerical rank of a, covar uses */ 39 | /* the tolerance tol. if l is the largest integer such that */ 40 | 41 | /* abs(r(l,l)) .gt. tol*abs(r(1,1)) , */ 42 | 43 | /* then covar computes the covariance matrix corresponding to */ 44 | /* the first l columns of r. for k greater than l, column */ 45 | /* and row ipvt(k) of the covariance matrix are set to zero. */ 46 | 47 | /* the subroutine statement is */ 48 | 49 | /* subroutine covar(n,r,ldr,ipvt,tol,wa) */ 50 | 51 | /* where */ 52 | 53 | /* n is a positive integer input variable set to the order of r. */ 54 | 55 | /* r is an n by n array. on input the full upper triangle must */ 56 | /* contain the full upper triangle of the matrix r. on output */ 57 | /* r contains the square symmetric covariance matrix. */ 58 | 59 | /* ldr is a positive integer input variable not less than n */ 60 | /* which specifies the leading dimension of the array r. */ 61 | 62 | /* ipvt is an integer input array of length n which defines the */ 63 | /* permutation matrix p such that a*p = q*r. column j of p */ 64 | /* is column ipvt(j) of the identity matrix. */ 65 | 66 | /* tol is a nonnegative input variable used to define the */ 67 | /* numerical rank of a in the manner described above. */ 68 | 69 | /* wa is a work array of length n. */ 70 | 71 | /* subprograms called */ 72 | 73 | /* fortran-supplied ... dabs */ 74 | 75 | /* argonne national laboratory. minpack project. august 1980. */ 76 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 77 | 78 | /* ********** */ 79 | tolr = tol * fabs(r[0]); 80 | 81 | /* form the inverse of r in the full upper triangle of r. */ 82 | 83 | l = -1; 84 | for (k = 0; k < n; ++k) { 85 | if (fabs(r[k + k * ldr]) <= tolr) { 86 | break; 87 | } 88 | r[k + k * ldr] = 1. / r[k + k * ldr]; 89 | if (k > 0) { 90 | for (j = 0; j < k; ++j) { 91 | // coverity[copy_paste_error] 92 | temp = r[k + k * ldr] * r[j + k * ldr]; 93 | r[j + k * ldr] = 0.; 94 | for (i = 0; i <= j; ++i) { 95 | r[i + k * ldr] -= temp * r[i + j * ldr]; 96 | } 97 | } 98 | } 99 | l = k; 100 | } 101 | 102 | /* form the full upper triangle of the inverse of (r transpose)*r */ 103 | /* in the full upper triangle of r. */ 104 | 105 | if (l >= 0) { 106 | for (k = 0; k <= l; ++k) { 107 | if (k > 0) { 108 | for (j = 0; j < k; ++j) { 109 | temp = r[j + k * ldr]; 110 | for (i = 0; i <= j; ++i) { 111 | r[i + j * ldr] += temp * r[i + k * ldr]; 112 | } 113 | } 114 | } 115 | temp = r[k + k * ldr]; 116 | for (i = 0; i <= k; ++i) { 117 | r[i + k * ldr] *= temp; 118 | } 119 | } 120 | } 121 | 122 | /* form the full lower triangle of the covariance matrix */ 123 | /* in the strict lower triangle of r and in wa. */ 124 | 125 | for (j = 0; j < n; ++j) { 126 | jj = ipvt[j]-1; 127 | sing = j > l; 128 | for (i = 0; i <= j; ++i) { 129 | if (sing) { 130 | r[i + j * ldr] = 0.; 131 | } 132 | ii = ipvt[i]-1; 133 | if (ii > jj) { 134 | r[ii + jj * ldr] = r[i + j * ldr]; 135 | } 136 | else if (ii < jj) { 137 | r[jj + ii * ldr] = r[i + j * ldr]; 138 | } 139 | } 140 | wa[jj] = r[j + j * ldr]; 141 | } 142 | 143 | /* symmetrize the covariance matrix in r. */ 144 | 145 | for (j = 0; j < n; ++j) { 146 | for (i = 0; i < j; ++i) { 147 | r[i + j * ldr] = r[j + i * ldr]; 148 | } 149 | r[j + j * ldr] = wa[j]; 150 | } 151 | 152 | /* last card of subroutine covar. */ 153 | 154 | } /* covar_ */ 155 | 156 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/covar1.c: -------------------------------------------------------------------------------- 1 | #include "cminpack.h" 2 | #include 3 | #include "cminpackP.h" 4 | 5 | /* covar1 estimates the variance-covariance matrix: 6 | C = sigma**2 (JtJ)**+ 7 | where (JtJ)**+ is the inverse of JtJ or the pseudo-inverse of JtJ (in case J does not have full rank), 8 | and sigma**2 = fsumsq / (m - k) 9 | where fsumsq is the residual sum of squares and k is the rank of J. 10 | */ 11 | __cminpack_attr__ 12 | int __cminpack_func__(covar1)(int m, int n, real fsumsq, real *r, int ldr, 13 | const int *ipvt, real tol, real *wa) 14 | { 15 | /* Local variables */ 16 | int i, j, k, l, ii, jj; 17 | int sing; 18 | real temp, tolr; 19 | 20 | /* ********** */ 21 | 22 | /* subroutine covar */ 23 | 24 | /* given an m by n matrix a, the problem is to determine */ 25 | /* the covariance matrix corresponding to a, defined as */ 26 | 27 | /* t */ 28 | /* inverse(a *a) . */ 29 | 30 | /* this subroutine completes the solution of the problem */ 31 | /* if it is provided with the necessary information from the */ 32 | /* qr factorization, with column pivoting, of a. that is, if */ 33 | /* a*p = q*r, where p is a permutation matrix, q has orthogonal */ 34 | /* columns, and r is an upper triangular matrix with diagonal */ 35 | /* elements of nonincreasing magnitude, then covar expects */ 36 | /* the full upper triangle of r and the permutation matrix p. */ 37 | /* the covariance matrix is then computed as */ 38 | 39 | /* t t */ 40 | /* p*inverse(r *r)*p . */ 41 | 42 | /* if a is nearly rank deficient, it may be desirable to compute */ 43 | /* the covariance matrix corresponding to the linearly independent */ 44 | /* columns of a. to define the numerical rank of a, covar uses */ 45 | /* the tolerance tol. if l is the largest integer such that */ 46 | 47 | /* abs(r(l,l)) .gt. tol*abs(r(1,1)) , */ 48 | 49 | /* then covar computes the covariance matrix corresponding to */ 50 | /* the first l columns of r. for k greater than l, column */ 51 | /* and row ipvt(k) of the covariance matrix are set to zero. */ 52 | 53 | /* the subroutine statement is */ 54 | 55 | /* subroutine covar(n,r,ldr,ipvt,tol,wa) */ 56 | 57 | /* where */ 58 | 59 | /* n is a positive integer input variable set to the order of r. */ 60 | 61 | /* r is an n by n array. on input the full upper triangle must */ 62 | /* contain the full upper triangle of the matrix r. on output */ 63 | /* r contains the square symmetric covariance matrix. */ 64 | 65 | /* ldr is a positive integer input variable not less than n */ 66 | /* which specifies the leading dimension of the array r. */ 67 | 68 | /* ipvt is an integer input array of length n which defines the */ 69 | /* permutation matrix p such that a*p = q*r. column j of p */ 70 | /* is column ipvt(j) of the identity matrix. */ 71 | 72 | /* tol is a nonnegative input variable used to define the */ 73 | /* numerical rank of a in the manner described above. */ 74 | 75 | /* wa is a work array of length n. */ 76 | 77 | /* subprograms called */ 78 | 79 | /* fortran-supplied ... dabs */ 80 | 81 | /* argonne national laboratory. minpack project. august 1980. */ 82 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 83 | 84 | /* ********** */ 85 | tolr = tol * fabs(r[0]); 86 | 87 | /* form the inverse of r in the full upper triangle of r. */ 88 | 89 | l = -1; 90 | for (k = 0; k < n; ++k) { 91 | if (fabs(r[k + k * ldr]) <= tolr) { 92 | break; 93 | } 94 | r[k + k * ldr] = 1. / r[k + k * ldr]; 95 | if (k > 0) { 96 | for (j = 0; j < k; ++j) { 97 | // coverity[copy_paste_error] 98 | temp = r[k + k * ldr] * r[j + k * ldr]; 99 | r[j + k * ldr] = 0.; 100 | for (i = 0; i <= j; ++i) { 101 | r[i + k * ldr] -= temp * r[i + j * ldr]; 102 | } 103 | } 104 | } 105 | l = k; 106 | } 107 | 108 | /* form the full upper triangle of the inverse of (r transpose)*r */ 109 | /* in the full upper triangle of r. */ 110 | 111 | if (l >= 0) { 112 | for (k = 0; k <= l; ++k) { 113 | if (k > 0) { 114 | for (j = 0; j < k; ++j) { 115 | temp = r[j + k * ldr]; 116 | for (i = 0; i <= j; ++i) { 117 | r[i + j * ldr] += temp * r[i + k * ldr]; 118 | } 119 | } 120 | } 121 | temp = r[k + k * ldr]; 122 | for (i = 0; i <= k; ++i) { 123 | r[i + k * ldr] *= temp; 124 | } 125 | } 126 | } 127 | 128 | /* form the full lower triangle of the covariance matrix */ 129 | /* in the strict lower triangle of r and in wa. */ 130 | 131 | for (j = 0; j < n; ++j) { 132 | jj = ipvt[j]-1; 133 | sing = j > l; 134 | for (i = 0; i <= j; ++i) { 135 | if (sing) { 136 | r[i + j * ldr] = 0.; 137 | } 138 | ii = ipvt[i]-1; 139 | if (ii > jj) { 140 | r[ii + jj * ldr] = r[i + j * ldr]; 141 | } 142 | else if (ii < jj) { 143 | r[jj + ii * ldr] = r[i + j * ldr]; 144 | } 145 | } 146 | wa[jj] = r[j + j * ldr]; 147 | } 148 | 149 | /* symmetrize the covariance matrix in r. */ 150 | 151 | temp = fsumsq / (m - (l + 1)); 152 | for (j = 0; j < n; ++j) { 153 | for (i = 0; i < j; ++i) { 154 | r[j + i * ldr] *= temp; 155 | r[i + j * ldr] = r[j + i * ldr]; 156 | } 157 | r[j + j * ldr] = temp * wa[j]; 158 | } 159 | 160 | /* last card of subroutine covar. */ 161 | if (l == (n - 1)) { 162 | return 0; 163 | } 164 | return l + 1; 165 | } /* covar_ */ 166 | 167 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/covar_.c: -------------------------------------------------------------------------------- 1 | /* covar.f -- translated by f2c (version 20100827). 2 | You must link the resulting object file with libf2c: 3 | on Microsoft Windows system, link with libf2c.lib; 4 | on Linux or Unix systems, link with .../path/to/libf2c.a -lm 5 | or, if you install libf2c.a in a standard place, with -lf2c -lm 6 | -- in that order, at the end of the command line, as in 7 | cc *.o -lf2c -lm 8 | Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., 9 | 10 | http://www.netlib.org/f2c/libf2c.zip 11 | */ 12 | 13 | #include "minpack.h" 14 | #include 15 | #include "minpackP.h" 16 | 17 | __minpack_attr__ 18 | void __minpack_func__(covar)(const int *n, real *r__, const int *ldr, 19 | const int *ipvt, const real *tol, real *wa) 20 | { 21 | /* System generated locals */ 22 | int r_dim1, r_offset, i__1, i__2, i__3; 23 | 24 | /* Local variables */ 25 | int i__, j, k, l, ii, jj, km1; 26 | int sing; 27 | real temp, tolr; 28 | 29 | /* ********** */ 30 | 31 | /* subroutine covar */ 32 | 33 | /* given an m by n matrix a, the problem is to determine */ 34 | /* the covariance matrix corresponding to a, defined as */ 35 | 36 | /* t */ 37 | /* inverse(a *a) . */ 38 | 39 | /* this subroutine completes the solution of the problem */ 40 | /* if it is provided with the necessary information from the */ 41 | /* qr factorization, with column pivoting, of a. that is, if */ 42 | /* a*p = q*r, where p is a permutation matrix, q has orthogonal */ 43 | /* columns, and r is an upper triangular matrix with diagonal */ 44 | /* elements of nonincreasing magnitude, then covar expects */ 45 | /* the full upper triangle of r and the permutation matrix p. */ 46 | /* the covariance matrix is then computed as */ 47 | 48 | /* t t */ 49 | /* p*inverse(r *r)*p . */ 50 | 51 | /* if a is nearly rank deficient, it may be desirable to compute */ 52 | /* the covariance matrix corresponding to the linearly independent */ 53 | /* columns of a. to define the numerical rank of a, covar uses */ 54 | /* the tolerance tol. if l is the largest integer such that */ 55 | 56 | /* abs(r(l,l)) .gt. tol*abs(r(1,1)) , */ 57 | 58 | /* then covar computes the covariance matrix corresponding to */ 59 | /* the first l columns of r. for k greater than l, column */ 60 | /* and row ipvt(k) of the covariance matrix are set to zero. */ 61 | 62 | /* the subroutine statement is */ 63 | 64 | /* subroutine covar(n,r,ldr,ipvt,tol,wa) */ 65 | 66 | /* where */ 67 | 68 | /* n is a positive integer input variable set to the order of r. */ 69 | 70 | /* r is an n by n array. on input the full upper triangle must */ 71 | /* contain the full upper triangle of the matrix r. on output */ 72 | /* r contains the square symmetric covariance matrix. */ 73 | 74 | /* ldr is a positive integer input variable not less than n */ 75 | /* which specifies the leading dimension of the array r. */ 76 | 77 | /* ipvt is an integer input array of length n which defines the */ 78 | /* permutation matrix p such that a*p = q*r. column j of p */ 79 | /* is column ipvt(j) of the identity matrix. */ 80 | 81 | /* tol is a nonnegative input variable used to define the */ 82 | /* numerical rank of a in the manner described above. */ 83 | 84 | /* wa is a work array of length n. */ 85 | 86 | /* subprograms called */ 87 | 88 | /* fortran-supplied ... dabs */ 89 | 90 | /* argonne national laboratory. minpack project. august 1980. */ 91 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 92 | 93 | /* ********** */ 94 | /* Parameter adjustments */ 95 | --wa; 96 | --ipvt; 97 | tolr = *tol * fabs(r__[0]); 98 | r_dim1 = *ldr; 99 | r_offset = 1 + r_dim1; 100 | r__ -= r_offset; 101 | 102 | /* Function Body */ 103 | 104 | /* form the inverse of r in the full upper triangle of r. */ 105 | 106 | l = 0; 107 | i__1 = *n; 108 | for (k = 1; k <= i__1; ++k) { 109 | if (fabs(r__[k + k * r_dim1]) <= tolr) { 110 | goto L50; 111 | } 112 | r__[k + k * r_dim1] = 1. / r__[k + k * r_dim1]; 113 | km1 = k - 1; 114 | if (km1 < 1) { 115 | goto L30; 116 | } 117 | i__2 = km1; 118 | for (j = 1; j <= i__2; ++j) { 119 | // coverity[copy_paste_error] 120 | temp = r__[k + k * r_dim1] * r__[j + k * r_dim1]; 121 | r__[j + k * r_dim1] = 0.; 122 | i__3 = j; 123 | for (i__ = 1; i__ <= i__3; ++i__) { 124 | r__[i__ + k * r_dim1] -= temp * r__[i__ + j * r_dim1]; 125 | /* L10: */ 126 | } 127 | /* L20: */ 128 | } 129 | L30: 130 | l = k; 131 | /* L40: */ 132 | } 133 | L50: 134 | 135 | /* form the full upper triangle of the inverse of (r transpose)*r */ 136 | /* in the full upper triangle of r. */ 137 | 138 | if (l < 1) { 139 | goto L110; 140 | } 141 | i__1 = l; 142 | for (k = 1; k <= i__1; ++k) { 143 | km1 = k - 1; 144 | if (km1 < 1) { 145 | goto L80; 146 | } 147 | i__2 = km1; 148 | for (j = 1; j <= i__2; ++j) { 149 | temp = r__[j + k * r_dim1]; 150 | i__3 = j; 151 | for (i__ = 1; i__ <= i__3; ++i__) { 152 | r__[i__ + j * r_dim1] += temp * r__[i__ + k * r_dim1]; 153 | /* L60: */ 154 | } 155 | /* L70: */ 156 | } 157 | L80: 158 | temp = r__[k + k * r_dim1]; 159 | i__2 = k; 160 | for (i__ = 1; i__ <= i__2; ++i__) { 161 | r__[i__ + k * r_dim1] = temp * r__[i__ + k * r_dim1]; 162 | /* L90: */ 163 | } 164 | /* L100: */ 165 | } 166 | L110: 167 | 168 | /* form the full lower triangle of the covariance matrix */ 169 | /* in the strict lower triangle of r and in wa. */ 170 | 171 | i__1 = *n; 172 | for (j = 1; j <= i__1; ++j) { 173 | jj = ipvt[j]; 174 | sing = j > l; 175 | i__2 = j; 176 | for (i__ = 1; i__ <= i__2; ++i__) { 177 | if (sing) { 178 | r__[i__ + j * r_dim1] = 0.; 179 | } 180 | ii = ipvt[i__]; 181 | if (ii > jj) { 182 | r__[ii + jj * r_dim1] = r__[i__ + j * r_dim1]; 183 | } 184 | if (ii < jj) { 185 | r__[jj + ii * r_dim1] = r__[i__ + j * r_dim1]; 186 | } 187 | /* L120: */ 188 | } 189 | wa[jj] = r__[j + j * r_dim1]; 190 | /* L130: */ 191 | } 192 | 193 | /* symmetrize the covariance matrix in r. */ 194 | 195 | i__1 = *n; 196 | for (j = 1; j <= i__1; ++j) { 197 | i__2 = j; 198 | for (i__ = 1; i__ <= i__2; ++i__) { 199 | r__[i__ + j * r_dim1] = r__[j + i__ * r_dim1]; 200 | /* L140: */ 201 | } 202 | r__[j + j * r_dim1] = wa[j]; 203 | /* L150: */ 204 | } 205 | /*return 0;*/ 206 | 207 | /* last card of subroutine covar. */ 208 | 209 | } /* covar_ */ 210 | 211 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/enorm.c: -------------------------------------------------------------------------------- 1 | #include "cminpack.h" 2 | #include 3 | #include "cminpackP.h" 4 | 5 | /* 6 | About the values for rdwarf and rgiant. 7 | 8 | The original values, both in single-precision FORTRAN source code and in double-precision code were: 9 | #define rdwarf 3.834e-20 10 | #define rgiant 1.304e19 11 | See for example: 12 | http://www.netlib.org/slatec/src/denorm.f 13 | http://www.netlib.org/slatec/src/enorm.f 14 | However, rdwarf is smaller than sqrt(FLT_MIN) = 1.0842021724855044e-19, so that rdwarf**2 will 15 | underflow. This contradicts the constraints expressed in the comments below. 16 | 17 | We changed these constants to those proposed by the 18 | implementation found in MPFIT http://cow.physics.wisc.edu/~craigm/idl/fitting.html 19 | 20 | cmpfit-1.2 proposes the following definitions: 21 | rdwarf = sqrt(dpmpar(2)*1.5) * 10 22 | rgiant = sqrt(dpmpar(3)) * 0.1 23 | 24 | The half version does not really worked that way, so we use for half: 25 | rdwarf = sqrt(dpmpar(2)) * 2 26 | rgiant = sqrt(dpmpar(3)) * 0.5 27 | Any suggestion is welcome. Half CMINPACK is really only a 28 | proof-of-concept anyway. 29 | 30 | See the example/tenorm*c, which computes these values 31 | */ 32 | #define double_dwarf (1.82691291192569e-153) 33 | #define double_giant (1.34078079299426e+153) 34 | #define long_double_dwarf (2.245696932951581572e-2465l) 35 | #define long_double_giant (1.090748135619415929e+2465l) 36 | #define float_dwarf (1.327871072777421e-18f) 37 | #define float_giant (1.844674297419792e+18f) 38 | #define half_dwarf (0.015625f) 39 | #define half_giant (127.9375f) 40 | 41 | #define dwarf(type) _dwarf(type) 42 | #define _dwarf(type) type ## _dwarf 43 | #define giant(type) _giant(type) 44 | #define _giant(type) type ## _giant 45 | 46 | #define rdwarf dwarf(realm) 47 | #define rgiant giant(realm) 48 | 49 | __cminpack_attr__ 50 | real __cminpack_func__(enorm)(int n, const real *x) 51 | { 52 | #ifdef USE_CBLAS 53 | return cblas_dnrm2(n, x, 1); 54 | #else /* !USE_CBLAS */ 55 | /* System generated locals */ 56 | real ret_val, d1; 57 | 58 | /* Local variables */ 59 | int i; 60 | real s1, s2, s3, xabs, x1max, x3max, agiant; 61 | 62 | /* ********** */ 63 | 64 | /* function enorm */ 65 | 66 | /* given an n-vector x, this function calculates the */ 67 | /* euclidean norm of x. */ 68 | 69 | /* the euclidean norm is computed by accumulating the sum of */ 70 | /* squares in three different sums. the sums of squares for the */ 71 | /* small and large components are scaled so that no overflows */ 72 | /* occur. non-destructive underflows are permitted. underflows */ 73 | /* and overflows do not occur in the computation of the unscaled */ 74 | /* sum of squares for the intermediate components. */ 75 | /* the definitions of small, intermediate and large components */ 76 | /* depend on two constants, rdwarf and rgiant. the main */ 77 | /* restrictions on these constants are that rdwarf**2 not */ 78 | /* underflow and rgiant**2 not overflow. the constants */ 79 | /* given here are suitable for every known computer. */ 80 | 81 | /* the function statement is */ 82 | 83 | /* double precision function enorm(n,x) */ 84 | 85 | /* where */ 86 | 87 | /* n is a positive integer input variable. */ 88 | 89 | /* x is an input array of length n. */ 90 | 91 | /* subprograms called */ 92 | 93 | /* fortran-supplied ... dabs,dsqrt */ 94 | 95 | /* argonne national laboratory. minpack project. march 1980. */ 96 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 97 | 98 | /* ********** */ 99 | 100 | s1 = 0.; 101 | s2 = 0.; 102 | s3 = 0.; 103 | x1max = 0.; 104 | x3max = 0.; 105 | agiant = rgiant / (real)n; 106 | for (i = 0; i < n; ++i) { 107 | xabs = fabs(x[i]); 108 | if (xabs >= agiant) { 109 | /* sum for large components. */ 110 | if (xabs > x1max) { 111 | /* Computing 2nd power */ 112 | d1 = x1max / xabs; 113 | s1 = 1. + s1 * (d1 * d1); 114 | x1max = xabs; 115 | } else { 116 | /* Computing 2nd power */ 117 | d1 = xabs / x1max; 118 | s1 += d1 * d1; 119 | } 120 | } else if (xabs <= rdwarf) { 121 | /* sum for small components. */ 122 | if (xabs > x3max) { 123 | /* Computing 2nd power */ 124 | d1 = x3max / xabs; 125 | s3 = 1. + s3 * (d1 * d1); 126 | x3max = xabs; 127 | } else if (xabs != 0.) { 128 | /* Computing 2nd power */ 129 | d1 = xabs / x3max; 130 | s3 += d1 * d1; 131 | } 132 | } else { 133 | /* sum for intermediate components. */ 134 | /* Computing 2nd power */ 135 | s2 += xabs * xabs; 136 | } 137 | } 138 | 139 | /* calculation of norm. */ 140 | 141 | if (s1 != 0.) { 142 | ret_val = x1max * sqrt(s1 + (s2 / x1max) / x1max); 143 | } else if (s2 != 0.) { 144 | if (s2 >= x3max) { 145 | ret_val = sqrt(s2 * (1. + (x3max / s2) * (x3max * s3))); 146 | } else { 147 | ret_val = sqrt(x3max * ((s2 / x3max) + (x3max * s3))); 148 | } 149 | } else { 150 | ret_val = x3max * sqrt(s3); 151 | } 152 | return ret_val; 153 | 154 | /* last card of function enorm. */ 155 | #endif /* !USE_CBLAS */ 156 | } /* enorm_ */ 157 | 158 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/enorm_.c: -------------------------------------------------------------------------------- 1 | /* enorm.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "minpack.h" 7 | #include 8 | 9 | #include "minpackP.h" 10 | 11 | /* 12 | About the values for rdwarf and rgiant. 13 | 14 | The original values, both in single-precision FORTRAN source code and in double-precision code were: 15 | #define rdwarf 3.834e-20 16 | #define rgiant 1.304e19 17 | See for example: 18 | http://www.netlib.org/slatec/src/denorm.f 19 | http://www.netlib.org/slatec/src/enorm.f 20 | However, rdwarf is smaller than sqrt(FLT_MIN) = 1.0842021724855044e-19, so that rdwarf**2 will 21 | underflow. This contradicts the constraints expressed in the comments below. 22 | 23 | We changed these constants to those proposed by the 24 | implementation found in MPFIT http://cow.physics.wisc.edu/~craigm/idl/fitting.html 25 | 26 | cmpfit-1.2 proposes the following definitions: 27 | rdwarf = sqrt(dpmpar(2)*1.5) * 10 28 | rgiant = sqrt(dpmpar(3)) * 0.1 29 | 30 | The half version does not really worked that way, so we use for half: 31 | rdwarf = sqrt(dpmpar(2)) * 2 32 | rgiant = sqrt(dpmpar(3)) * 0.5 33 | Any suggestion is welcome. Half CMINPACK is really only a 34 | proof-of-concept anyway. 35 | 36 | See the example/tenorm*c, which computes these values 37 | */ 38 | #define double_dwarf (1.82691291192569e-153) 39 | #define double_giant (1.34078079299426e+153) 40 | #define long_double_dwarf (2.245696932951581572e-2465l) 41 | #define long_double_giant (1.090748135619415929e+2465l) 42 | #define float_dwarf (1.327871072777421e-18f) 43 | #define float_giant (1.844674297419792e+18f) 44 | #define half_dwarf (0.015625f) 45 | #define half_giant (127.9375f) 46 | 47 | #define dwarf(type) _dwarf(type) 48 | #define _dwarf(type) type ## _dwarf 49 | #define giant(type) _giant(type) 50 | #define _giant(type) type ## _giant 51 | 52 | #define rdwarf dwarf(realm) 53 | #define rgiant giant(realm) 54 | 55 | __minpack_attr__ 56 | real __minpack_func__(enorm)(const int *n, const real *x) 57 | { 58 | /* System generated locals */ 59 | int i__1; 60 | real ret_val, d__1; 61 | 62 | /* Local variables */ 63 | int i__; 64 | real s1, s2, s3, xabs, x1max, x3max, agiant, floatn; 65 | 66 | /* ********** */ 67 | 68 | /* function enorm */ 69 | 70 | /* given an n-vector x, this function calculates the */ 71 | /* euclidean norm of x. */ 72 | 73 | /* the euclidean norm is computed by accumulating the sum of */ 74 | /* squares in three different sums. the sums of squares for the */ 75 | /* small and large components are scaled so that no overflows */ 76 | /* occur. non-destructive underflows are permitted. underflows */ 77 | /* and overflows do not occur in the computation of the unscaled */ 78 | /* sum of squares for the intermediate components. */ 79 | /* the definitions of small, intermediate and large components */ 80 | /* depend on two constants, rdwarf and rgiant. the main */ 81 | /* restrictions on these constants are that rdwarf**2 not */ 82 | /* underflow and rgiant**2 not overflow. the constants */ 83 | /* given here are suitable for every known computer. */ 84 | 85 | /* the function statement is */ 86 | 87 | /* double precision function enorm(n,x) */ 88 | 89 | /* where */ 90 | 91 | /* n is a positive integer input variable. */ 92 | 93 | /* x is an input array of length n. */ 94 | 95 | /* subprograms called */ 96 | 97 | /* fortran-supplied ... dabs,dsqrt */ 98 | 99 | /* argonne national laboratory. minpack project. march 1980. */ 100 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 101 | 102 | /* ********** */ 103 | /* Parameter adjustments */ 104 | --x; 105 | 106 | /* Function Body */ 107 | s1 = 0.; 108 | s2 = 0.; 109 | s3 = 0.; 110 | x1max = 0.; 111 | x3max = 0.; 112 | floatn = (real) (*n); 113 | agiant = rgiant / floatn; 114 | i__1 = *n; 115 | for (i__ = 1; i__ <= i__1; ++i__) { 116 | xabs = fabs(x[i__]); 117 | if (xabs > rdwarf && xabs < agiant) { 118 | goto L70; 119 | } 120 | if (xabs <= rdwarf) { 121 | goto L30; 122 | } 123 | 124 | /* sum for large components. */ 125 | 126 | if (xabs <= x1max) { 127 | goto L10; 128 | } 129 | /* Computing 2nd power */ 130 | d__1 = x1max / xabs; 131 | s1 = 1. + s1 * (d__1 * d__1); 132 | x1max = xabs; 133 | goto L20; 134 | L10: 135 | /* Computing 2nd power */ 136 | d__1 = xabs / x1max; 137 | s1 += d__1 * d__1; 138 | L20: 139 | goto L60; 140 | L30: 141 | 142 | /* sum for small components. */ 143 | 144 | if (xabs <= x3max) { 145 | goto L40; 146 | } 147 | /* Computing 2nd power */ 148 | d__1 = x3max / xabs; 149 | s3 = 1. + s3 * (d__1 * d__1); 150 | x3max = xabs; 151 | goto L50; 152 | L40: 153 | if (xabs != 0.) { 154 | /* Computing 2nd power */ 155 | d__1 = xabs / x3max; 156 | s3 += d__1 * d__1; 157 | } 158 | L50: 159 | L60: 160 | goto L80; 161 | L70: 162 | 163 | /* sum for intermediate components. */ 164 | 165 | /* Computing 2nd power */ 166 | d__1 = xabs; 167 | s2 += d__1 * d__1; 168 | L80: 169 | /* L90: */ 170 | ; 171 | } 172 | 173 | /* calculation of norm. */ 174 | 175 | if (s1 == 0.) { 176 | goto L100; 177 | } 178 | ret_val = x1max * sqrt(s1 + s2 / x1max / x1max); 179 | goto L130; 180 | L100: 181 | if (s2 == 0.) { 182 | goto L110; 183 | } 184 | if (s2 >= x3max) { 185 | ret_val = sqrt(s2 * (1. + x3max / s2 * (x3max * s3))); 186 | } else { 187 | ret_val = sqrt(x3max * (s2 / x3max + x3max * s3)); 188 | } 189 | goto L120; 190 | L110: 191 | ret_val = x3max * sqrt(s3); 192 | L120: 193 | L130: 194 | return ret_val; 195 | 196 | /* last card of function enorm. */ 197 | 198 | } /* enorm_ */ 199 | 200 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/fdjac1.c: -------------------------------------------------------------------------------- 1 | /* fdjac1.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "cminpack.h" 7 | #include 8 | #include "cminpackP.h" 9 | 10 | __cminpack_attr__ 11 | int __cminpack_func__(fdjac1)(__cminpack_decl_fcn_nn__ void *p, int n, real *x, const real * 12 | fvec, real *fjac, int ldfjac, int ml, 13 | int mu, real epsfcn, real *wa1, real *wa2) 14 | { 15 | /* System generated locals */ 16 | int fjac_dim1, fjac_offset; 17 | 18 | /* Local variables */ 19 | real h; 20 | int i, j, k; 21 | real eps, temp; 22 | int msum; 23 | real epsmch; 24 | int iflag = 0; 25 | 26 | /* ********** */ 27 | 28 | /* subroutine fdjac1 */ 29 | 30 | /* this subroutine computes a forward-difference approximation */ 31 | /* to the n by n jacobian matrix associated with a specified */ 32 | /* problem of n functions in n variables. if the jacobian has */ 33 | /* a banded form, then function evaluations are saved by only */ 34 | /* approximating the nonzero terms. */ 35 | 36 | /* the subroutine statement is */ 37 | 38 | /* subroutine fdjac1(fcn,n,x,fvec,fjac,ldfjac,iflag,ml,mu,epsfcn, */ 39 | /* wa1,wa2) */ 40 | 41 | /* where */ 42 | 43 | /* fcn is the name of the user-supplied subroutine which */ 44 | /* calculates the functions. fcn must be declared */ 45 | /* in an external statement in the user calling */ 46 | /* program, and should be written as follows. */ 47 | 48 | /* subroutine fcn(n,x,fvec,iflag) */ 49 | /* integer n,iflag */ 50 | /* double precision x(n),fvec(n) */ 51 | /* ---------- */ 52 | /* calculate the functions at x and */ 53 | /* return this vector in fvec. */ 54 | /* ---------- */ 55 | /* return */ 56 | /* end */ 57 | 58 | /* the value of iflag should not be changed by fcn unless */ 59 | /* the user wants to terminate execution of fdjac1. */ 60 | /* in this case set iflag to a negative integer. */ 61 | 62 | /* n is a positive integer input variable set to the number */ 63 | /* of functions and variables. */ 64 | 65 | /* x is an input array of length n. */ 66 | 67 | /* fvec is an input array of length n which must contain the */ 68 | /* functions evaluated at x. */ 69 | 70 | /* fjac is an output n by n array which contains the */ 71 | /* approximation to the jacobian matrix evaluated at x. */ 72 | 73 | /* ldfjac is a positive integer input variable not less than n */ 74 | /* which specifies the leading dimension of the array fjac. */ 75 | 76 | /* iflag is an integer variable which can be used to terminate */ 77 | /* the execution of fdjac1. see description of fcn. */ 78 | 79 | /* ml is a nonnegative integer input variable which specifies */ 80 | /* the number of subdiagonals within the band of the */ 81 | /* jacobian matrix. if the jacobian is not banded, set */ 82 | /* ml to at least n - 1. */ 83 | 84 | /* epsfcn is an input variable used in determining a suitable */ 85 | /* step length for the forward-difference approximation. this */ 86 | /* approximation assumes that the relative errors in the */ 87 | /* functions are of the order of epsfcn. if epsfcn is less */ 88 | /* than the machine precision, it is assumed that the relative */ 89 | /* errors in the functions are of the order of the machine */ 90 | /* precision. */ 91 | 92 | /* mu is a nonnegative integer input variable which specifies */ 93 | /* the number of superdiagonals within the band of the */ 94 | /* jacobian matrix. if the jacobian is not banded, set */ 95 | /* mu to at least n - 1. */ 96 | 97 | /* wa1 and wa2 are work arrays of length n. if ml + mu + 1 is at */ 98 | /* least n, then the jacobian is considered dense, and wa2 is */ 99 | /* not referenced. */ 100 | 101 | /* subprograms called */ 102 | 103 | /* minpack-supplied ... dpmpar */ 104 | 105 | /* fortran-supplied ... dabs,dmax1,dsqrt */ 106 | 107 | /* argonne national laboratory. minpack project. march 1980. */ 108 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 109 | 110 | /* ********** */ 111 | /* Parameter adjustments */ 112 | --wa2; 113 | --wa1; 114 | --fvec; 115 | --x; 116 | fjac_dim1 = ldfjac; 117 | fjac_offset = 1 + fjac_dim1 * 1; 118 | fjac -= fjac_offset; 119 | 120 | /* Function Body */ 121 | 122 | /* epsmch is the machine precision. */ 123 | 124 | epsmch = __cminpack_func__(dpmpar)(1); 125 | 126 | eps = sqrt((max(epsfcn,epsmch))); 127 | msum = ml + mu + 1; 128 | if (msum >= n) { 129 | 130 | /* computation of dense approximate jacobian. */ 131 | 132 | for (j = 1; j <= n; ++j) { 133 | temp = x[j]; 134 | h = eps * fabs(temp); 135 | if (h == 0.) { 136 | h = eps; 137 | } 138 | x[j] = temp + h; 139 | /* the last parameter of fcn_nn() is set to 2 to differentiate 140 | calls made to compute the function from calls made to compute 141 | the Jacobian (see fcn() in examples/hybdrv.c, and how njev 142 | is used to compute the number of Jacobian evaluations) */ 143 | iflag = fcn_nn(p, n, &x[1], &wa1[1], 2); 144 | if (iflag < 0) { 145 | return iflag; 146 | } 147 | x[j] = temp; 148 | for (i = 1; i <= n; ++i) { 149 | fjac[i + j * fjac_dim1] = (wa1[i] - fvec[i]) / h; 150 | } 151 | } 152 | return 0; 153 | } 154 | 155 | /* computation of banded approximate jacobian. */ 156 | 157 | for (k = 1; k <= msum; ++k) { 158 | for (j = k; j <= n; j += msum) { 159 | wa2[j] = x[j]; 160 | h = eps * fabs(wa2[j]); 161 | if (h == 0.) { 162 | h = eps; 163 | } 164 | x[j] = wa2[j] + h; 165 | } 166 | iflag = fcn_nn(p, n, &x[1], &wa1[1], 1); 167 | if (iflag < 0) { 168 | return iflag; 169 | } 170 | for (j = k; j <= n; j += msum) { 171 | x[j] = wa2[j]; 172 | h = eps * fabs(wa2[j]); 173 | if (h == 0.) { 174 | h = eps; 175 | } 176 | for (i = 1; i <= n; ++i) { 177 | fjac[i + j * fjac_dim1] = 0.; 178 | if (i >= j - mu && i <= j + ml) { 179 | fjac[i + j * fjac_dim1] = (wa1[i] - fvec[i]) / h; 180 | } 181 | } 182 | } 183 | } 184 | return 0; 185 | 186 | /* last card of subroutine fdjac1. */ 187 | 188 | } /* fdjac1_ */ 189 | 190 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/fdjac1_.c: -------------------------------------------------------------------------------- 1 | /* fdjac1.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "minpack.h" 7 | #include 8 | #include "minpackP.h" 9 | 10 | __minpack_attr__ 11 | void __minpack_func__(fdjac1)(__minpack_decl_fcn_nn__ const int *n, real *x, const real * 12 | fvec, real *fjac, const int *ldfjac, int *iflag, const int *ml, 13 | const int *mu, const real *epsfcn, real *wa1, real *wa2) 14 | { 15 | /* Table of constant values */ 16 | 17 | const int c__1 = 1; 18 | 19 | /* System generated locals */ 20 | int fjac_dim1, fjac_offset, i__1, i__2, i__3, i__4; 21 | 22 | /* Local variables */ 23 | real h__; 24 | int i__, j, k; 25 | real eps, temp; 26 | int msum; 27 | real epsmch; 28 | 29 | /* ********** */ 30 | 31 | /* subroutine fdjac1 */ 32 | 33 | /* this subroutine computes a forward-difference approximation */ 34 | /* to the n by n jacobian matrix associated with a specified */ 35 | /* problem of n functions in n variables. if the jacobian has */ 36 | /* a banded form, then function evaluations are saved by only */ 37 | /* approximating the nonzero terms. */ 38 | 39 | /* the subroutine statement is */ 40 | 41 | /* subroutine fdjac1(fcn,n,x,fvec,fjac,ldfjac,iflag,ml,mu,epsfcn, */ 42 | /* wa1,wa2) */ 43 | 44 | /* where */ 45 | 46 | /* fcn is the name of the user-supplied subroutine which */ 47 | /* calculates the functions. fcn must be declared */ 48 | /* in an external statement in the user calling */ 49 | /* program, and should be written as follows. */ 50 | 51 | /* subroutine fcn(n,x,fvec,iflag) */ 52 | /* integer n,iflag */ 53 | /* double precision x(n),fvec(n) */ 54 | /* ---------- */ 55 | /* calculate the functions at x and */ 56 | /* return this vector in fvec. */ 57 | /* ---------- */ 58 | /* return */ 59 | /* end */ 60 | 61 | /* the value of iflag should not be changed by fcn unless */ 62 | /* the user wants to terminate execution of fdjac1. */ 63 | /* in this case set iflag to a negative integer. */ 64 | 65 | /* n is a positive integer input variable set to the number */ 66 | /* of functions and variables. */ 67 | 68 | /* x is an input array of length n. */ 69 | 70 | /* fvec is an input array of length n which must contain the */ 71 | /* functions evaluated at x. */ 72 | 73 | /* fjac is an output n by n array which contains the */ 74 | /* approximation to the jacobian matrix evaluated at x. */ 75 | 76 | /* ldfjac is a positive integer input variable not less than n */ 77 | /* which specifies the leading dimension of the array fjac. */ 78 | 79 | /* iflag is an integer variable which can be used to terminate */ 80 | /* the execution of fdjac1. see description of fcn. */ 81 | 82 | /* ml is a nonnegative integer input variable which specifies */ 83 | /* the number of subdiagonals within the band of the */ 84 | /* jacobian matrix. if the jacobian is not banded, set */ 85 | /* ml to at least n - 1. */ 86 | 87 | /* epsfcn is an input variable used in determining a suitable */ 88 | /* step length for the forward-difference approximation. this */ 89 | /* approximation assumes that the relative errors in the */ 90 | /* functions are of the order of epsfcn. if epsfcn is less */ 91 | /* than the machine precision, it is assumed that the relative */ 92 | /* errors in the functions are of the order of the machine */ 93 | /* precision. */ 94 | 95 | /* mu is a nonnegative integer input variable which specifies */ 96 | /* the number of superdiagonals within the band of the */ 97 | /* jacobian matrix. if the jacobian is not banded, set */ 98 | /* mu to at least n - 1. */ 99 | 100 | /* wa1 and wa2 are work arrays of length n. if ml + mu + 1 is at */ 101 | /* least n, then the jacobian is considered dense, and wa2 is */ 102 | /* not referenced. */ 103 | 104 | /* subprograms called */ 105 | 106 | /* minpack-supplied ... dpmpar */ 107 | 108 | /* fortran-supplied ... dabs,dmax1,dsqrt */ 109 | 110 | /* argonne national laboratory. minpack project. march 1980. */ 111 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 112 | 113 | /* ********** */ 114 | /* Parameter adjustments */ 115 | --wa2; 116 | --wa1; 117 | --fvec; 118 | --x; 119 | fjac_dim1 = *ldfjac; 120 | fjac_offset = 1 + fjac_dim1 * 1; 121 | fjac -= fjac_offset; 122 | 123 | /* Function Body */ 124 | 125 | /* epsmch is the machine precision. */ 126 | 127 | epsmch = __minpack_func__(dpmpar)(&c__1); 128 | 129 | eps = sqrt((max(*epsfcn,epsmch))); 130 | msum = *ml + *mu + 1; 131 | if (msum < *n) { 132 | goto L40; 133 | } 134 | 135 | /* computation of dense approximate jacobian. */ 136 | 137 | i__1 = *n; 138 | for (j = 1; j <= i__1; ++j) { 139 | temp = x[j]; 140 | h__ = eps * fabs(temp); 141 | if (h__ == 0.) { 142 | h__ = eps; 143 | } 144 | x[j] = temp + h__; 145 | fcn_nn(n, &x[1], &wa1[1], iflag); 146 | if (*iflag < 0) { 147 | goto L30; 148 | } 149 | x[j] = temp; 150 | i__2 = *n; 151 | for (i__ = 1; i__ <= i__2; ++i__) { 152 | fjac[i__ + j * fjac_dim1] = (wa1[i__] - fvec[i__]) / h__; 153 | /* L10: */ 154 | } 155 | /* L20: */ 156 | } 157 | L30: 158 | /* goto L110; */ 159 | return; 160 | L40: 161 | 162 | /* computation of banded approximate jacobian. */ 163 | 164 | i__1 = msum; 165 | for (k = 1; k <= i__1; ++k) { 166 | i__2 = *n; 167 | i__3 = msum; 168 | for (j = k; j <= i__2; j += i__3) { 169 | wa2[j] = x[j]; 170 | h__ = eps * fabs(wa2[j]); 171 | if (h__ == 0.) { 172 | h__ = eps; 173 | } 174 | x[j] = wa2[j] + h__; 175 | /* L60: */ 176 | } 177 | fcn_nn(n, &x[1], &wa1[1], iflag); 178 | if (*iflag < 0) { 179 | /* goto L100; */ 180 | return; 181 | } 182 | i__3 = *n; 183 | i__2 = msum; 184 | for (j = k; j <= i__3; j += i__2) { 185 | x[j] = wa2[j]; 186 | h__ = eps * fabs(wa2[j]); 187 | if (h__ == 0.) { 188 | h__ = eps; 189 | } 190 | i__4 = *n; 191 | for (i__ = 1; i__ <= i__4; ++i__) { 192 | fjac[i__ + j * fjac_dim1] = 0.; 193 | if (i__ >= j - *mu && i__ <= j + *ml) { 194 | fjac[i__ + j * fjac_dim1] = (wa1[i__] - fvec[i__]) / h__; 195 | } 196 | /* L70: */ 197 | } 198 | /* L80: */ 199 | } 200 | /* L90: */ 201 | } 202 | /* L100: */ 203 | /* L110: */ 204 | return; 205 | 206 | /* last card of subroutine fdjac1. */ 207 | 208 | } /* fdjac1_ */ 209 | 210 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/fdjac2.c: -------------------------------------------------------------------------------- 1 | #include "cminpack.h" 2 | #include 3 | #include "cminpackP.h" 4 | 5 | __cminpack_attr__ 6 | int __cminpack_func__(fdjac2)(__cminpack_decl_fcn_mn__ void *p, int m, int n, real *x, 7 | const real *fvec, real *fjac, int ldfjac, 8 | real epsfcn, real *wa) 9 | { 10 | /* Local variables */ 11 | real h; 12 | int i, j; 13 | real eps, temp, epsmch; 14 | int iflag; 15 | 16 | /* ********** */ 17 | 18 | /* subroutine fdjac2 */ 19 | 20 | /* this subroutine computes a forward-difference approximation */ 21 | /* to the m by n jacobian matrix associated with a specified */ 22 | /* problem of m functions in n variables. */ 23 | 24 | /* the subroutine statement is */ 25 | 26 | /* subroutine fdjac2(fcn,m,n,x,fvec,fjac,ldfjac,iflag,epsfcn,wa) */ 27 | 28 | /* where */ 29 | 30 | /* fcn is the name of the user-supplied subroutine which */ 31 | /* calculates the functions. fcn must be declared */ 32 | /* in an external statement in the user calling */ 33 | /* program, and should be written as follows. */ 34 | 35 | /* subroutine fcn(m,n,x,fvec,iflag) */ 36 | /* integer m,n,iflag */ 37 | /* double precision x(n),fvec(m) */ 38 | /* ---------- */ 39 | /* calculate the functions at x and */ 40 | /* return this vector in fvec. */ 41 | /* ---------- */ 42 | /* return */ 43 | /* end */ 44 | 45 | /* the value of iflag should not be changed by fcn unless */ 46 | /* the user wants to terminate execution of fdjac2. */ 47 | /* in this case set iflag to a negative integer. */ 48 | 49 | /* m is a positive integer input variable set to the number */ 50 | /* of functions. */ 51 | 52 | /* n is a positive integer input variable set to the number */ 53 | /* of variables. n must not exceed m. */ 54 | 55 | /* x is an input array of length n. */ 56 | 57 | /* fvec is an input array of length m which must contain the */ 58 | /* functions evaluated at x. */ 59 | 60 | /* fjac is an output m by n array which contains the */ 61 | /* approximation to the jacobian matrix evaluated at x. */ 62 | 63 | /* ldfjac is a positive integer input variable not less than m */ 64 | /* which specifies the leading dimension of the array fjac. */ 65 | 66 | /* iflag is an integer variable which can be used to terminate */ 67 | /* the execution of fdjac2. see description of fcn. */ 68 | 69 | /* epsfcn is an input variable used in determining a suitable */ 70 | /* step length for the forward-difference approximation. this */ 71 | /* approximation assumes that the relative errors in the */ 72 | /* functions are of the order of epsfcn. if epsfcn is less */ 73 | /* than the machine precision, it is assumed that the relative */ 74 | /* errors in the functions are of the order of the machine */ 75 | /* precision. */ 76 | 77 | /* wa is a work array of length m. */ 78 | 79 | /* subprograms called */ 80 | 81 | /* user-supplied ...... fcn */ 82 | 83 | /* minpack-supplied ... dpmpar */ 84 | 85 | /* fortran-supplied ... dabs,dmax1,dsqrt */ 86 | 87 | /* argonne national laboratory. minpack project. march 1980. */ 88 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 89 | 90 | /* ********** */ 91 | 92 | /* epsmch is the machine precision. */ 93 | 94 | epsmch = __cminpack_func__(dpmpar)(1); 95 | 96 | eps = sqrt((max(epsfcn,epsmch))); 97 | for (j = 0; j < n; ++j) { 98 | temp = x[j]; 99 | h = eps * fabs(temp); 100 | if (h == 0.) { 101 | h = eps; 102 | } 103 | x[j] = temp + h; 104 | /* the last parameter of fcn_mn() is set to 2 to differentiate 105 | calls made to compute the function from calls made to compute 106 | the Jacobian (see fcn() in examples/lmfdrv.c, and how njev 107 | is used to compute the number of Jacobian evaluations) */ 108 | iflag = fcn_mn(p, m, n, x, wa, 2); 109 | if (iflag < 0) { 110 | return iflag; 111 | } 112 | x[j] = temp; 113 | for (i = 0; i < m; ++i) { 114 | fjac[i + j * ldfjac] = (wa[i] - fvec[i]) / h; 115 | } 116 | } 117 | return 0; 118 | 119 | /* last card of subroutine fdjac2. */ 120 | 121 | } /* fdjac2_ */ 122 | 123 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/fdjac2_.c: -------------------------------------------------------------------------------- 1 | /* fdjac2.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "minpack.h" 7 | #include 8 | #include "minpackP.h" 9 | 10 | __minpack_attr__ 11 | void __minpack_func__(fdjac2)(__minpack_decl_fcn_mn__ const int *m, const int *n, real *x, 12 | const real *fvec, real *fjac, const int *ldfjac, int *iflag, 13 | const real *epsfcn, real *wa) 14 | { 15 | /* Table of constant values */ 16 | 17 | const int c__1 = 1; 18 | 19 | /* System generated locals */ 20 | int fjac_dim1, fjac_offset, i__1, i__2; 21 | 22 | /* Local variables */ 23 | real h__; 24 | int i__, j; 25 | real eps, temp, epsmch; 26 | 27 | /* ********** */ 28 | 29 | /* subroutine fdjac2 */ 30 | 31 | /* this subroutine computes a forward-difference approximation */ 32 | /* to the m by n jacobian matrix associated with a specified */ 33 | /* problem of m functions in n variables. */ 34 | 35 | /* the subroutine statement is */ 36 | 37 | /* subroutine fdjac2(fcn,m,n,x,fvec,fjac,ldfjac,iflag,epsfcn,wa) */ 38 | 39 | /* where */ 40 | 41 | /* fcn is the name of the user-supplied subroutine which */ 42 | /* calculates the functions. fcn must be declared */ 43 | /* in an external statement in the user calling */ 44 | /* program, and should be written as follows. */ 45 | 46 | /* subroutine fcn(m,n,x,fvec,iflag) */ 47 | /* integer m,n,iflag */ 48 | /* double precision x(n),fvec(m) */ 49 | /* ---------- */ 50 | /* calculate the functions at x and */ 51 | /* return this vector in fvec. */ 52 | /* ---------- */ 53 | /* return */ 54 | /* end */ 55 | 56 | /* the value of iflag should not be changed by fcn unless */ 57 | /* the user wants to terminate execution of fdjac2. */ 58 | /* in this case set iflag to a negative integer. */ 59 | 60 | /* m is a positive integer input variable set to the number */ 61 | /* of functions. */ 62 | 63 | /* n is a positive integer input variable set to the number */ 64 | /* of variables. n must not exceed m. */ 65 | 66 | /* x is an input array of length n. */ 67 | 68 | /* fvec is an input array of length m which must contain the */ 69 | /* functions evaluated at x. */ 70 | 71 | /* fjac is an output m by n array which contains the */ 72 | /* approximation to the jacobian matrix evaluated at x. */ 73 | 74 | /* ldfjac is a positive integer input variable not less than m */ 75 | /* which specifies the leading dimension of the array fjac. */ 76 | 77 | /* iflag is an integer variable which can be used to terminate */ 78 | /* the execution of fdjac2. see description of fcn. */ 79 | 80 | /* epsfcn is an input variable used in determining a suitable */ 81 | /* step length for the forward-difference approximation. this */ 82 | /* approximation assumes that the relative errors in the */ 83 | /* functions are of the order of epsfcn. if epsfcn is less */ 84 | /* than the machine precision, it is assumed that the relative */ 85 | /* errors in the functions are of the order of the machine */ 86 | /* precision. */ 87 | 88 | /* wa is a work array of length m. */ 89 | 90 | /* subprograms called */ 91 | 92 | /* user-supplied ...... fcn */ 93 | 94 | /* minpack-supplied ... dpmpar */ 95 | 96 | /* fortran-supplied ... dabs,dmax1,dsqrt */ 97 | 98 | /* argonne national laboratory. minpack project. march 1980. */ 99 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 100 | 101 | /* ********** */ 102 | /* Parameter adjustments */ 103 | --wa; 104 | --fvec; 105 | --x; 106 | fjac_dim1 = *ldfjac; 107 | fjac_offset = 1 + fjac_dim1 * 1; 108 | fjac -= fjac_offset; 109 | 110 | /* Function Body */ 111 | 112 | /* epsmch is the machine precision. */ 113 | 114 | epsmch = __minpack_func__(dpmpar)(&c__1); 115 | 116 | eps = sqrt((max(*epsfcn,epsmch))); 117 | i__1 = *n; 118 | for (j = 1; j <= i__1; ++j) { 119 | temp = x[j]; 120 | h__ = eps * fabs(temp); 121 | if (h__ == 0.) { 122 | h__ = eps; 123 | } 124 | x[j] = temp + h__; 125 | fcn_mn(m, n, &x[1], &wa[1], iflag); 126 | if (*iflag < 0) { 127 | /* goto L30; */ 128 | return; 129 | } 130 | x[j] = temp; 131 | i__2 = *m; 132 | for (i__ = 1; i__ <= i__2; ++i__) { 133 | fjac[i__ + j * fjac_dim1] = (wa[i__] - fvec[i__]) / h__; 134 | /* L10: */ 135 | } 136 | /* L20: */ 137 | } 138 | /* L30: */ 139 | return; 140 | 141 | /* last card of subroutine fdjac2. */ 142 | 143 | } /* fdjac2_ */ 144 | 145 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/hybrd1.c: -------------------------------------------------------------------------------- 1 | /* hybrd1.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "cminpack.h" 7 | #include "cminpackP.h" 8 | 9 | __cminpack_attr__ 10 | int __cminpack_func__(hybrd1)(__cminpack_decl_fcn_nn__ void *p, int n, real *x, real * 11 | fvec, real tol, real *wa, int lwa) 12 | { 13 | /* Initialized data */ 14 | 15 | const real factor = 100.; 16 | 17 | /* Local variables */ 18 | int j, ml, lr, mu, mode, nfev; 19 | real xtol; 20 | int index; 21 | real epsfcn; 22 | int maxfev, nprint; 23 | int info; 24 | 25 | /* ********** */ 26 | 27 | /* subroutine hybrd1 */ 28 | 29 | /* the purpose of hybrd1 is to find a zero of a system of */ 30 | /* n nonlinear functions in n variables by a modification */ 31 | /* of the powell hybrid method. this is done by using the */ 32 | /* more general nonlinear equation solver hybrd. the user */ 33 | /* must provide a subroutine which calculates the functions. */ 34 | /* the jacobian is then calculated by a forward-difference */ 35 | /* approximation. */ 36 | 37 | /* the subroutine statement is */ 38 | 39 | /* subroutine hybrd1(fcn,n,x,fvec,tol,info,wa,lwa) */ 40 | 41 | /* where */ 42 | 43 | /* fcn is the name of the user-supplied subroutine which */ 44 | /* calculates the functions. fcn must be declared */ 45 | /* in an external statement in the user calling */ 46 | /* program, and should be written as follows. */ 47 | 48 | /* subroutine fcn(n,x,fvec,iflag) */ 49 | /* integer n,iflag */ 50 | /* double precision x(n),fvec(n) */ 51 | /* ---------- */ 52 | /* calculate the functions at x and */ 53 | /* return this vector in fvec. */ 54 | /* --------- */ 55 | /* return */ 56 | /* end */ 57 | 58 | /* the value of iflag should not be changed by fcn unless */ 59 | /* the user wants to terminate execution of hybrd1. */ 60 | /* in this case set iflag to a negative integer. */ 61 | 62 | /* n is a positive integer input variable set to the number */ 63 | /* of functions and variables. */ 64 | 65 | /* x is an array of length n. on input x must contain */ 66 | /* an initial estimate of the solution vector. on output x */ 67 | /* contains the final estimate of the solution vector. */ 68 | 69 | /* fvec is an output array of length n which contains */ 70 | /* the functions evaluated at the output x. */ 71 | 72 | /* tol is a nonnegative input variable. termination occurs */ 73 | /* when the algorithm estimates that the relative error */ 74 | /* between x and the solution is at most tol. */ 75 | 76 | /* info is an integer output variable. if the user has */ 77 | /* terminated execution, info is set to the (negative) */ 78 | /* value of iflag. see description of fcn. otherwise, */ 79 | /* info is set as follows. */ 80 | 81 | /* info = 0 improper input parameters. */ 82 | 83 | /* info = 1 algorithm estimates that the relative error */ 84 | /* between x and the solution is at most tol. */ 85 | 86 | /* info = 2 number of calls to fcn has reached or exceeded */ 87 | /* 200*(n+1). */ 88 | 89 | /* info = 3 tol is too small. no further improvement in */ 90 | /* the approximate solution x is possible. */ 91 | 92 | /* info = 4 iteration is not making good progress. */ 93 | 94 | /* wa is a work array of length lwa. */ 95 | 96 | /* lwa is a positive integer input variable not less than */ 97 | /* (n*(3*n+13))/2. */ 98 | 99 | /* subprograms called */ 100 | 101 | /* user-supplied ...... fcn */ 102 | 103 | /* minpack-supplied ... hybrd */ 104 | 105 | /* argonne national laboratory. minpack project. march 1980. */ 106 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 107 | 108 | /* ********** */ 109 | /* Parameter adjustments */ 110 | --fvec; 111 | --x; 112 | --wa; 113 | 114 | /* Function Body */ 115 | 116 | /* check the input parameters for errors. */ 117 | 118 | if (n <= 0 || tol < 0. || lwa < n * (n * 3 + 13) / 2) { 119 | return 0; 120 | } 121 | 122 | /* call hybrd. */ 123 | 124 | maxfev = (n + 1) * 200; 125 | xtol = tol; 126 | ml = n - 1; 127 | mu = n - 1; 128 | epsfcn = 0.; 129 | mode = 2; 130 | for (j = 1; j <= n; ++j) { 131 | wa[j] = 1.; 132 | } 133 | nprint = 0; 134 | lr = n * (n + 1) / 2; 135 | index = n * 6 + lr; 136 | info = __cminpack_func__(hybrd)(__cminpack_param_fcn_nn__ p, n, &x[1], &fvec[1], xtol, maxfev, ml, mu, epsfcn, & 137 | wa[1], mode, factor, nprint, &nfev, &wa[index + 1], n, & 138 | wa[n * 6 + 1], lr, &wa[n + 1], &wa[(n << 1) + 1], &wa[n * 3 139 | + 1], &wa[(n << 2) + 1], &wa[n * 5 + 1]); 140 | if (info == 5) { 141 | info = 4; 142 | } 143 | return info; 144 | 145 | /* last card of subroutine hybrd1. */ 146 | 147 | } /* hybrd1_ */ 148 | 149 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/hybrd1_.c: -------------------------------------------------------------------------------- 1 | /* hybrd1.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "minpack.h" 7 | #include 8 | #include "minpackP.h" 9 | 10 | __minpack_attr__ 11 | void __minpack_func__(hybrd1)(__minpack_decl_fcn_nn__ const int *n, real *x, real * 12 | fvec, const real *tol, int *info, real *wa, const int *lwa) 13 | { 14 | /* Initialized data */ 15 | 16 | const real factor = 100.; 17 | 18 | /* System generated locals */ 19 | int i__1; 20 | 21 | /* Local variables */ 22 | int j, ml, lr, mu, mode, nfev; 23 | real xtol; 24 | int index; 25 | real epsfcn; 26 | int maxfev, nprint; 27 | 28 | /* ********** */ 29 | 30 | /* subroutine hybrd1 */ 31 | 32 | /* the purpose of hybrd1 is to find a zero of a system of */ 33 | /* n nonlinear functions in n variables by a modification */ 34 | /* of the powell hybrid method. this is done by using the */ 35 | /* more general nonlinear equation solver hybrd. the user */ 36 | /* must provide a subroutine which calculates the functions. */ 37 | /* the jacobian is then calculated by a forward-difference */ 38 | /* approximation. */ 39 | 40 | /* the subroutine statement is */ 41 | 42 | /* subroutine hybrd1(fcn,n,x,fvec,tol,info,wa,lwa) */ 43 | 44 | /* where */ 45 | 46 | /* fcn is the name of the user-supplied subroutine which */ 47 | /* calculates the functions. fcn must be declared */ 48 | /* in an external statement in the user calling */ 49 | /* program, and should be written as follows. */ 50 | 51 | /* subroutine fcn(n,x,fvec,iflag) */ 52 | /* integer n,iflag */ 53 | /* double precision x(n),fvec(n) */ 54 | /* ---------- */ 55 | /* calculate the functions at x and */ 56 | /* return this vector in fvec. */ 57 | /* --------- */ 58 | /* return */ 59 | /* end */ 60 | 61 | /* the value of iflag should not be changed by fcn unless */ 62 | /* the user wants to terminate execution of hybrd1. */ 63 | /* in this case set iflag to a negative integer. */ 64 | 65 | /* n is a positive integer input variable set to the number */ 66 | /* of functions and variables. */ 67 | 68 | /* x is an array of length n. on input x must contain */ 69 | /* an initial estimate of the solution vector. on output x */ 70 | /* contains the final estimate of the solution vector. */ 71 | 72 | /* fvec is an output array of length n which contains */ 73 | /* the functions evaluated at the output x. */ 74 | 75 | /* tol is a nonnegative input variable. termination occurs */ 76 | /* when the algorithm estimates that the relative error */ 77 | /* between x and the solution is at most tol. */ 78 | 79 | /* info is an integer output variable. if the user has */ 80 | /* terminated execution, info is set to the (negative) */ 81 | /* value of iflag. see description of fcn. otherwise, */ 82 | /* info is set as follows. */ 83 | 84 | /* info = 0 improper input parameters. */ 85 | 86 | /* info = 1 algorithm estimates that the relative error */ 87 | /* between x and the solution is at most tol. */ 88 | 89 | /* info = 2 number of calls to fcn has reached or exceeded */ 90 | /* 200*(n+1). */ 91 | 92 | /* info = 3 tol is too small. no further improvement in */ 93 | /* the approximate solution x is possible. */ 94 | 95 | /* info = 4 iteration is not making good progress. */ 96 | 97 | /* wa is a work array of length lwa. */ 98 | 99 | /* lwa is a positive integer input variable not less than */ 100 | /* (n*(3*n+13))/2. */ 101 | 102 | /* subprograms called */ 103 | 104 | /* user-supplied ...... fcn */ 105 | 106 | /* minpack-supplied ... hybrd */ 107 | 108 | /* argonne national laboratory. minpack project. march 1980. */ 109 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 110 | 111 | /* ********** */ 112 | /* Parameter adjustments */ 113 | --fvec; 114 | --x; 115 | --wa; 116 | 117 | /* Function Body */ 118 | *info = 0; 119 | 120 | /* check the input parameters for errors. */ 121 | 122 | if (*n <= 0 || *tol < 0. || *lwa < *n * (*n * 3 + 13) / 2) { 123 | /* goto L20; */ 124 | return; 125 | } 126 | 127 | /* call hybrd. */ 128 | 129 | maxfev = (*n + 1) * 200; 130 | xtol = *tol; 131 | ml = *n - 1; 132 | mu = *n - 1; 133 | epsfcn = 0.; 134 | mode = 2; 135 | i__1 = *n; 136 | for (j = 1; j <= i__1; ++j) { 137 | wa[j] = 1.; 138 | /* L10: */ 139 | } 140 | nprint = 0; 141 | lr = *n * (*n + 1) / 2; 142 | index = *n * 6 + lr; 143 | __minpack_func__(hybrd)(__minpack_param_fcn_nn__ n, &x[1], &fvec[1], &xtol, &maxfev, &ml, &mu, &epsfcn, & 144 | wa[1], &mode, &factor, &nprint, info, &nfev, &wa[index + 1], n, & 145 | wa[*n * 6 + 1], &lr, &wa[*n + 1], &wa[(*n << 1) + 1], &wa[*n * 3 146 | + 1], &wa[(*n << 2) + 1], &wa[*n * 5 + 1]); 147 | if (*info == 5) { 148 | *info = 4; 149 | } 150 | /* L20: */ 151 | return; 152 | 153 | /* last card of subroutine hybrd1. */ 154 | 155 | } /* hybrd1_ */ 156 | 157 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/hybrj1.c: -------------------------------------------------------------------------------- 1 | /* hybrj1.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "cminpack.h" 7 | #include "cminpackP.h" 8 | 9 | __cminpack_attr__ 10 | int __cminpack_func__(hybrj1)(__cminpack_decl_fcnder_nn__ void *p, int n, real *x, real * 11 | fvec, real *fjac, int ldfjac, real tol, 12 | real *wa, int lwa) 13 | { 14 | /* Initialized data */ 15 | 16 | const real factor = 100.; 17 | 18 | /* System generated locals */ 19 | int fjac_dim1, fjac_offset; 20 | 21 | /* Local variables */ 22 | int j, lr, mode, nfev, njev; 23 | real xtol; 24 | int maxfev, nprint; 25 | int info; 26 | 27 | /* ********** */ 28 | 29 | /* subroutine hybrj1 */ 30 | 31 | /* the purpose of hybrj1 is to find a zero of a system of */ 32 | /* n nonlinear functions in n variables by a modification */ 33 | /* of the powell hybrid method. this is done by using the */ 34 | /* more general nonlinear equation solver hybrj. the user */ 35 | /* must provide a subroutine which calculates the functions */ 36 | /* and the jacobian. */ 37 | 38 | /* the subroutine statement is */ 39 | 40 | /* subroutine hybrj1(fcn,n,x,fvec,fjac,ldfjac,tol,info,wa,lwa) */ 41 | 42 | /* where */ 43 | 44 | /* fcn is the name of the user-supplied subroutine which */ 45 | /* calculates the functions and the jacobian. fcn must */ 46 | /* be declared in an external statement in the user */ 47 | /* calling program, and should be written as follows. */ 48 | 49 | /* subroutine fcn(n,x,fvec,fjac,ldfjac,iflag) */ 50 | /* integer n,ldfjac,iflag */ 51 | /* double precision x(n),fvec(n),fjac(ldfjac,n) */ 52 | /* ---------- */ 53 | /* if iflag = 1 calculate the functions at x and */ 54 | /* return this vector in fvec. do not alter fjac. */ 55 | /* if iflag = 2 calculate the jacobian at x and */ 56 | /* return this matrix in fjac. do not alter fvec. */ 57 | /* --------- */ 58 | /* return */ 59 | /* end */ 60 | 61 | /* the value of iflag should not be changed by fcn unless */ 62 | /* the user wants to terminate execution of hybrj1. */ 63 | /* in this case set iflag to a negative integer. */ 64 | 65 | /* n is a positive integer input variable set to the number */ 66 | /* of functions and variables. */ 67 | 68 | /* x is an array of length n. on input x must contain */ 69 | /* an initial estimate of the solution vector. on output x */ 70 | /* contains the final estimate of the solution vector. */ 71 | 72 | /* fvec is an output array of length n which contains */ 73 | /* the functions evaluated at the output x. */ 74 | 75 | /* fjac is an output n by n array which contains the */ 76 | /* orthogonal matrix q produced by the qr factorization */ 77 | /* of the final approximate jacobian. */ 78 | 79 | /* ldfjac is a positive integer input variable not less than n */ 80 | /* which specifies the leading dimension of the array fjac. */ 81 | 82 | /* tol is a nonnegative input variable. termination occurs */ 83 | /* when the algorithm estimates that the relative error */ 84 | /* between x and the solution is at most tol. */ 85 | 86 | /* info is an integer output variable. if the user has */ 87 | /* terminated execution, info is set to the (negative) */ 88 | /* value of iflag. see description of fcn. otherwise, */ 89 | /* info is set as follows. */ 90 | 91 | /* info = 0 improper input parameters. */ 92 | 93 | /* info = 1 algorithm estimates that the relative error */ 94 | /* between x and the solution is at most tol. */ 95 | 96 | /* info = 2 number of calls to fcn with iflag = 1 has */ 97 | /* reached 100*(n+1). */ 98 | 99 | /* info = 3 tol is too small. no further improvement in */ 100 | /* the approximate solution x is possible. */ 101 | 102 | /* info = 4 iteration is not making good progress. */ 103 | 104 | /* wa is a work array of length lwa. */ 105 | 106 | /* lwa is a positive integer input variable not less than */ 107 | /* (n*(n+13))/2. */ 108 | 109 | /* subprograms called */ 110 | 111 | /* user-supplied ...... fcn */ 112 | 113 | /* minpack-supplied ... hybrj */ 114 | 115 | /* argonne national laboratory. minpack project. march 1980. */ 116 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 117 | 118 | /* ********** */ 119 | /* Parameter adjustments */ 120 | --fvec; 121 | --x; 122 | fjac_dim1 = ldfjac; 123 | fjac_offset = 1 + fjac_dim1 * 1; 124 | fjac -= fjac_offset; 125 | --wa; 126 | 127 | /* Function Body */ 128 | 129 | /* check the input parameters for errors. */ 130 | 131 | if (n <= 0 || ldfjac < n || tol < 0. || lwa < n * (n + 13) / 2) { 132 | return 0; 133 | } 134 | 135 | /* call hybrj. */ 136 | 137 | maxfev = (n + 1) * 100; 138 | xtol = tol; 139 | mode = 2; 140 | for (j = 1; j <= n; ++j) { 141 | wa[j] = 1.; 142 | /* L10: */ 143 | } 144 | nprint = 0; 145 | lr = n * (n + 1) / 2; 146 | info = __cminpack_func__(hybrj)(__cminpack_param_fcnder_nn__ p, n, &x[1], &fvec[1], &fjac[fjac_offset], ldfjac, xtol, 147 | maxfev, &wa[1], mode, factor, nprint, &nfev, &njev, &wa[ 148 | n * 6 + 1], lr, &wa[n + 1], &wa[(n << 1) + 1], &wa[n * 3 + 1], 149 | &wa[(n << 2) + 1], &wa[n * 5 + 1]); 150 | if (info == 5) { 151 | info = 4; 152 | } 153 | return info; 154 | 155 | /* last card of subroutine hybrj1. */ 156 | 157 | } /* hybrj1_ */ 158 | 159 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/hybrj1_.c: -------------------------------------------------------------------------------- 1 | /* hybrj1.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "minpack.h" 7 | #include 8 | #include "minpackP.h" 9 | 10 | 11 | __minpack_attr__ 12 | void __minpack_func__(hybrj1)(__minpack_decl_fcnder_nn__ const int *n, real *x, real * 13 | fvec, real *fjac, const int *ldfjac, const real *tol, int * 14 | info, real *wa, const int *lwa) 15 | { 16 | /* Initialized data */ 17 | 18 | const real factor = 100.; 19 | 20 | /* System generated locals */ 21 | int fjac_dim1, fjac_offset, i__1; 22 | 23 | /* Local variables */ 24 | int j, lr, mode, nfev, njev; 25 | real xtol; 26 | int maxfev, nprint; 27 | 28 | /* ********** */ 29 | 30 | /* subroutine hybrj1 */ 31 | 32 | /* the purpose of hybrj1 is to find a zero of a system of */ 33 | /* n nonlinear functions in n variables by a modification */ 34 | /* of the powell hybrid method. this is done by using the */ 35 | /* more general nonlinear equation solver hybrj. the user */ 36 | /* must provide a subroutine which calculates the functions */ 37 | /* and the jacobian. */ 38 | 39 | /* the subroutine statement is */ 40 | 41 | /* subroutine hybrj1(fcn,n,x,fvec,fjac,ldfjac,tol,info,wa,lwa) */ 42 | 43 | /* where */ 44 | 45 | /* fcn is the name of the user-supplied subroutine which */ 46 | /* calculates the functions and the jacobian. fcn must */ 47 | /* be declared in an external statement in the user */ 48 | /* calling program, and should be written as follows. */ 49 | 50 | /* subroutine fcn(n,x,fvec,fjac,ldfjac,iflag) */ 51 | /* integer n,ldfjac,iflag */ 52 | /* double precision x(n),fvec(n),fjac(ldfjac,n) */ 53 | /* ---------- */ 54 | /* if iflag = 1 calculate the functions at x and */ 55 | /* return this vector in fvec. do not alter fjac. */ 56 | /* if iflag = 2 calculate the jacobian at x and */ 57 | /* return this matrix in fjac. do not alter fvec. */ 58 | /* --------- */ 59 | /* return */ 60 | /* end */ 61 | 62 | /* the value of iflag should not be changed by fcn unless */ 63 | /* the user wants to terminate execution of hybrj1. */ 64 | /* in this case set iflag to a negative integer. */ 65 | 66 | /* n is a positive integer input variable set to the number */ 67 | /* of functions and variables. */ 68 | 69 | /* x is an array of length n. on input x must contain */ 70 | /* an initial estimate of the solution vector. on output x */ 71 | /* contains the final estimate of the solution vector. */ 72 | 73 | /* fvec is an output array of length n which contains */ 74 | /* the functions evaluated at the output x. */ 75 | 76 | /* fjac is an output n by n array which contains the */ 77 | /* orthogonal matrix q produced by the qr factorization */ 78 | /* of the final approximate jacobian. */ 79 | 80 | /* ldfjac is a positive integer input variable not less than n */ 81 | /* which specifies the leading dimension of the array fjac. */ 82 | 83 | /* tol is a nonnegative input variable. termination occurs */ 84 | /* when the algorithm estimates that the relative error */ 85 | /* between x and the solution is at most tol. */ 86 | 87 | /* info is an integer output variable. if the user has */ 88 | /* terminated execution, info is set to the (negative) */ 89 | /* value of iflag. see description of fcn. otherwise, */ 90 | /* info is set as follows. */ 91 | 92 | /* info = 0 improper input parameters. */ 93 | 94 | /* info = 1 algorithm estimates that the relative error */ 95 | /* between x and the solution is at most tol. */ 96 | 97 | /* info = 2 number of calls to fcn with iflag = 1 has */ 98 | /* reached 100*(n+1). */ 99 | 100 | /* info = 3 tol is too small. no further improvement in */ 101 | /* the approximate solution x is possible. */ 102 | 103 | /* info = 4 iteration is not making good progress. */ 104 | 105 | /* wa is a work array of length lwa. */ 106 | 107 | /* lwa is a positive integer input variable not less than */ 108 | /* (n*(n+13))/2. */ 109 | 110 | /* subprograms called */ 111 | 112 | /* user-supplied ...... fcn */ 113 | 114 | /* minpack-supplied ... hybrj */ 115 | 116 | /* argonne national laboratory. minpack project. march 1980. */ 117 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 118 | 119 | /* ********** */ 120 | /* Parameter adjustments */ 121 | --fvec; 122 | --x; 123 | fjac_dim1 = *ldfjac; 124 | fjac_offset = 1 + fjac_dim1 * 1; 125 | fjac -= fjac_offset; 126 | --wa; 127 | 128 | /* Function Body */ 129 | *info = 0; 130 | 131 | /* check the input parameters for errors. */ 132 | 133 | if (*n <= 0 || *ldfjac < *n || *tol < 0. || *lwa < *n * (*n + 13) / 2) { 134 | /* goto L20; */ 135 | return; 136 | } 137 | 138 | /* call hybrj. */ 139 | 140 | maxfev = (*n + 1) * 100; 141 | xtol = *tol; 142 | mode = 2; 143 | i__1 = *n; 144 | for (j = 1; j <= i__1; ++j) { 145 | wa[j] = 1.; 146 | /* L10: */ 147 | } 148 | nprint = 0; 149 | lr = *n * (*n + 1) / 2; 150 | __minpack_func__(hybrj)(__minpack_param_fcnder_nn__ n, &x[1], &fvec[1], &fjac[fjac_offset], ldfjac, &xtol, & 151 | maxfev, &wa[1], &mode, &factor, &nprint, info, &nfev, &njev, &wa[* 152 | n * 6 + 1], &lr, &wa[*n + 1], &wa[(*n << 1) + 1], &wa[*n * 3 + 1], 153 | &wa[(*n << 2) + 1], &wa[*n * 5 + 1]); 154 | if (*info == 5) { 155 | *info = 4; 156 | } 157 | /* L20: */ 158 | return; 159 | 160 | /* last card of subroutine hybrj1. */ 161 | 162 | } /* hybrj1_ */ 163 | 164 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/lmder1.c: -------------------------------------------------------------------------------- 1 | #include "cminpack.h" 2 | #include "cminpackP.h" 3 | 4 | __cminpack_attr__ 5 | int __cminpack_func__(lmder1)(__cminpack_decl_fcnder_mn__ void *p, int m, int n, real *x, 6 | real *fvec, real *fjac, int ldfjac, real tol, 7 | int *ipvt, real *wa, int lwa) 8 | { 9 | /* Initialized data */ 10 | 11 | const real factor = 100.; 12 | 13 | /* Local variables */ 14 | int mode, nfev, njev; 15 | real ftol, gtol, xtol; 16 | int maxfev, nprint; 17 | int info; 18 | 19 | /* ********** */ 20 | 21 | /* subroutine lmder1 */ 22 | 23 | /* the purpose of lmder1 is to minimize the sum of the squares of */ 24 | /* m nonlinear functions in n variables by a modification of the */ 25 | /* levenberg-marquardt algorithm. this is done by using the more */ 26 | /* general least-squares solver lmder. the user must provide a */ 27 | /* subroutine which calculates the functions and the jacobian. */ 28 | 29 | /* the subroutine statement is */ 30 | 31 | /* subroutine lmder1(fcn,m,n,x,fvec,fjac,ldfjac,tol,info, */ 32 | /* ipvt,wa,lwa) */ 33 | 34 | /* where */ 35 | 36 | /* fcn is the name of the user-supplied subroutine which */ 37 | /* calculates the functions and the jacobian. fcn must */ 38 | /* be declared in an external statement in the user */ 39 | /* calling program, and should be written as follows. */ 40 | 41 | /* subroutine fcn(m,n,x,fvec,fjac,ldfjac,iflag) */ 42 | /* integer m,n,ldfjac,iflag */ 43 | /* double precision x(n),fvec(m),fjac(ldfjac,n) */ 44 | /* ---------- */ 45 | /* if iflag = 1 calculate the functions at x and */ 46 | /* return this vector in fvec. do not alter fjac. */ 47 | /* if iflag = 2 calculate the jacobian at x and */ 48 | /* return this matrix in fjac. do not alter fvec. */ 49 | /* ---------- */ 50 | /* return */ 51 | /* end */ 52 | 53 | /* the value of iflag should not be changed by fcn unless */ 54 | /* the user wants to terminate execution of lmder1. */ 55 | /* in this case set iflag to a negative integer. */ 56 | 57 | /* m is a positive integer input variable set to the number */ 58 | /* of functions. */ 59 | 60 | /* n is a positive integer input variable set to the number */ 61 | /* of variables. n must not exceed m. */ 62 | 63 | /* x is an array of length n. on input x must contain */ 64 | /* an initial estimate of the solution vector. on output x */ 65 | /* contains the final estimate of the solution vector. */ 66 | 67 | /* fvec is an output array of length m which contains */ 68 | /* the functions evaluated at the output x. */ 69 | 70 | /* fjac is an output m by n array. the upper n by n submatrix */ 71 | /* of fjac contains an upper triangular matrix r with */ 72 | /* diagonal elements of nonincreasing magnitude such that */ 73 | 74 | /* t t t */ 75 | /* p *(jac *jac)*p = r *r, */ 76 | 77 | /* where p is a permutation matrix and jac is the final */ 78 | /* calculated jacobian. column j of p is column ipvt(j) */ 79 | /* (see below) of the identity matrix. the lower trapezoidal */ 80 | /* part of fjac contains information generated during */ 81 | /* the computation of r. */ 82 | 83 | /* ldfjac is a positive integer input variable not less than m */ 84 | /* which specifies the leading dimension of the array fjac. */ 85 | 86 | /* tol is a nonnegative input variable. termination occurs */ 87 | /* when the algorithm estimates either that the relative */ 88 | /* error in the sum of squares is at most tol or that */ 89 | /* the relative error between x and the solution is at */ 90 | /* most tol. */ 91 | 92 | /* info is an integer output variable. if the user has */ 93 | /* terminated execution, info is set to the (negative) */ 94 | /* value of iflag. see description of fcn. otherwise, */ 95 | /* info is set as follows. */ 96 | 97 | /* info = 0 improper input parameters. */ 98 | 99 | /* info = 1 algorithm estimates that the relative error */ 100 | /* in the sum of squares is at most tol. */ 101 | 102 | /* info = 2 algorithm estimates that the relative error */ 103 | /* between x and the solution is at most tol. */ 104 | 105 | /* info = 3 conditions for info = 1 and info = 2 both hold. */ 106 | 107 | /* info = 4 fvec is orthogonal to the columns of the */ 108 | /* jacobian to machine precision. */ 109 | 110 | /* info = 5 number of calls to fcn with iflag = 1 has */ 111 | /* reached 100*(n+1). */ 112 | 113 | /* info = 6 tol is too small. no further reduction in */ 114 | /* the sum of squares is possible. */ 115 | 116 | /* info = 7 tol is too small. no further improvement in */ 117 | /* the approximate solution x is possible. */ 118 | 119 | /* ipvt is an integer output array of length n. ipvt */ 120 | /* defines a permutation matrix p such that jac*p = q*r, */ 121 | /* where jac is the final calculated jacobian, q is */ 122 | /* orthogonal (not stored), and r is upper triangular */ 123 | /* with diagonal elements of nonincreasing magnitude. */ 124 | /* column j of p is column ipvt(j) of the identity matrix. */ 125 | 126 | /* wa is a work array of length lwa. */ 127 | 128 | /* lwa is a positive integer input variable not less than 5*n+m. */ 129 | 130 | /* subprograms called */ 131 | 132 | /* user-supplied ...... fcn */ 133 | 134 | /* minpack-supplied ... lmder */ 135 | 136 | /* argonne national laboratory. minpack project. march 1980. */ 137 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 138 | 139 | /* ********** */ 140 | 141 | /* check the input parameters for errors. */ 142 | 143 | if (n <= 0 || m < n || ldfjac < m || tol < 0. || lwa < n * 5 + m) { 144 | return 0; 145 | } 146 | 147 | /* call lmder. */ 148 | 149 | maxfev = (n + 1) * 100; 150 | ftol = tol; 151 | xtol = tol; 152 | gtol = 0.; 153 | mode = 1; 154 | nprint = 0; 155 | info = __cminpack_func__(lmder)(__cminpack_param_fcnder_mn__ p, m, n, x, fvec, fjac, ldfjac, 156 | ftol, xtol, gtol, maxfev, wa, mode, factor, nprint, 157 | &nfev, &njev, ipvt, &wa[n], &wa[(n << 1)], & 158 | wa[n * 3], &wa[(n << 2)], &wa[n * 5]); 159 | if (info == 8) { 160 | info = 4; 161 | } 162 | return info; 163 | 164 | /* last card of subroutine lmder1. */ 165 | 166 | } /* lmder1_ */ 167 | 168 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/lmdif1.c: -------------------------------------------------------------------------------- 1 | #include "cminpack.h" 2 | #include "cminpackP.h" 3 | 4 | __cminpack_attr__ 5 | int __cminpack_func__(lmdif1)(__cminpack_decl_fcn_mn__ void *p, int m, int n, real *x, 6 | real *fvec, real tol, int *iwa, 7 | real *wa, int lwa) 8 | { 9 | /* Initialized data */ 10 | 11 | const real factor = 100.; 12 | 13 | int mp5n, mode, nfev; 14 | real ftol, gtol, xtol; 15 | real epsfcn; 16 | int maxfev, nprint; 17 | int info; 18 | 19 | /* ********** */ 20 | 21 | /* subroutine lmdif1 */ 22 | 23 | /* the purpose of lmdif1 is to minimize the sum of the squares of */ 24 | /* m nonlinear functions in n variables by a modification of the */ 25 | /* levenberg-marquardt algorithm. this is done by using the more */ 26 | /* general least-squares solver lmdif. the user must provide a */ 27 | /* subroutine which calculates the functions. the jacobian is */ 28 | /* then calculated by a forward-difference approximation. */ 29 | 30 | /* the subroutine statement is */ 31 | 32 | /* subroutine lmdif1(fcn,m,n,x,fvec,tol,info,iwa,wa,lwa) */ 33 | 34 | /* where */ 35 | 36 | /* fcn is the name of the user-supplied subroutine which */ 37 | /* calculates the functions. fcn must be declared */ 38 | /* in an external statement in the user calling */ 39 | /* program, and should be written as follows. */ 40 | 41 | /* subroutine fcn(m,n,x,fvec,iflag) */ 42 | /* integer m,n,iflag */ 43 | /* double precision x(n),fvec(m) */ 44 | /* ---------- */ 45 | /* calculate the functions at x and */ 46 | /* return this vector in fvec. */ 47 | /* ---------- */ 48 | /* return */ 49 | /* end */ 50 | 51 | /* the value of iflag should not be changed by fcn unless */ 52 | /* the user wants to terminate execution of lmdif1. */ 53 | /* in this case set iflag to a negative integer. */ 54 | 55 | /* m is a positive integer input variable set to the number */ 56 | /* of functions. */ 57 | 58 | /* n is a positive integer input variable set to the number */ 59 | /* of variables. n must not exceed m. */ 60 | 61 | /* x is an array of length n. on input x must contain */ 62 | /* an initial estimate of the solution vector. on output x */ 63 | /* contains the final estimate of the solution vector. */ 64 | 65 | /* fvec is an output array of length m which contains */ 66 | /* the functions evaluated at the output x. */ 67 | 68 | /* tol is a nonnegative input variable. termination occurs */ 69 | /* when the algorithm estimates either that the relative */ 70 | /* error in the sum of squares is at most tol or that */ 71 | /* the relative error between x and the solution is at */ 72 | /* most tol. */ 73 | 74 | /* info is an integer output variable. if the user has */ 75 | /* terminated execution, info is set to the (negative) */ 76 | /* value of iflag. see description of fcn. otherwise, */ 77 | /* info is set as follows. */ 78 | 79 | /* info = 0 improper input parameters. */ 80 | 81 | /* info = 1 algorithm estimates that the relative error */ 82 | /* in the sum of squares is at most tol. */ 83 | 84 | /* info = 2 algorithm estimates that the relative error */ 85 | /* between x and the solution is at most tol. */ 86 | 87 | /* info = 3 conditions for info = 1 and info = 2 both hold. */ 88 | 89 | /* info = 4 fvec is orthogonal to the columns of the */ 90 | /* jacobian to machine precision. */ 91 | 92 | /* info = 5 number of calls to fcn has reached or */ 93 | /* exceeded 200*(n+1). */ 94 | 95 | /* info = 6 tol is too small. no further reduction in */ 96 | /* the sum of squares is possible. */ 97 | 98 | /* info = 7 tol is too small. no further improvement in */ 99 | /* the approximate solution x is possible. */ 100 | 101 | /* iwa is an integer work array of length n. */ 102 | 103 | /* wa is a work array of length lwa. */ 104 | 105 | /* lwa is a positive integer input variable not less than */ 106 | /* m*n+5*n+m. */ 107 | 108 | /* subprograms called */ 109 | 110 | /* user-supplied ...... fcn */ 111 | 112 | /* minpack-supplied ... lmdif */ 113 | 114 | /* argonne national laboratory. minpack project. march 1980. */ 115 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 116 | 117 | /* ********** */ 118 | 119 | /* check the input parameters for errors. */ 120 | 121 | if (n <= 0 || m < n || tol < 0. || lwa < m * n + n * 5 + m) { 122 | return 0; 123 | } 124 | 125 | /* call lmdif. */ 126 | 127 | maxfev = (n + 1) * 200; 128 | ftol = tol; 129 | xtol = tol; 130 | gtol = 0.; 131 | epsfcn = 0.; 132 | mode = 1; 133 | nprint = 0; 134 | mp5n = m + n * 5; 135 | info = __cminpack_func__(lmdif)(__cminpack_param_fcn_mn__ p, m, n, x, fvec, ftol, xtol, gtol, maxfev, 136 | epsfcn, wa, mode, factor, nprint, &nfev, &wa[mp5n], 137 | m, iwa, &wa[n], &wa[(n << 1)], &wa[n * 3], 138 | &wa[(n << 2)], &wa[n * 5]); 139 | if (info == 8) { 140 | info = 4; 141 | } 142 | return info; 143 | 144 | /* last card of subroutine lmdif1. */ 145 | 146 | } /* lmdif1_ */ 147 | 148 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/lmdif1_.c: -------------------------------------------------------------------------------- 1 | /* lmdif1.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "minpack.h" 7 | #include 8 | #include "minpackP.h" 9 | 10 | 11 | __minpack_attr__ 12 | void __minpack_func__(lmdif1)(__minpack_decl_fcn_mn__ const int *m, const int *n, real *x, 13 | real *fvec, const real *tol, int *info, int *iwa, 14 | real *wa, const int *lwa) 15 | { 16 | /* Initialized data */ 17 | 18 | const real factor = 100.; 19 | 20 | int mp5n, mode, nfev; 21 | real ftol, gtol, xtol; 22 | real epsfcn; 23 | int maxfev, nprint; 24 | 25 | /* ********** */ 26 | 27 | /* subroutine lmdif1 */ 28 | 29 | /* the purpose of lmdif1 is to minimize the sum of the squares of */ 30 | /* m nonlinear functions in n variables by a modification of the */ 31 | /* levenberg-marquardt algorithm. this is done by using the more */ 32 | /* general least-squares solver lmdif. the user must provide a */ 33 | /* subroutine which calculates the functions. the jacobian is */ 34 | /* then calculated by a forward-difference approximation. */ 35 | 36 | /* the subroutine statement is */ 37 | 38 | /* subroutine lmdif1(fcn,m,n,x,fvec,tol,info,iwa,wa,lwa) */ 39 | 40 | /* where */ 41 | 42 | /* fcn is the name of the user-supplied subroutine which */ 43 | /* calculates the functions. fcn must be declared */ 44 | /* in an external statement in the user calling */ 45 | /* program, and should be written as follows. */ 46 | 47 | /* subroutine fcn(m,n,x,fvec,iflag) */ 48 | /* integer m,n,iflag */ 49 | /* double precision x(n),fvec(m) */ 50 | /* ---------- */ 51 | /* calculate the functions at x and */ 52 | /* return this vector in fvec. */ 53 | /* ---------- */ 54 | /* return */ 55 | /* end */ 56 | 57 | /* the value of iflag should not be changed by fcn unless */ 58 | /* the user wants to terminate execution of lmdif1. */ 59 | /* in this case set iflag to a negative integer. */ 60 | 61 | /* m is a positive integer input variable set to the number */ 62 | /* of functions. */ 63 | 64 | /* n is a positive integer input variable set to the number */ 65 | /* of variables. n must not exceed m. */ 66 | 67 | /* x is an array of length n. on input x must contain */ 68 | /* an initial estimate of the solution vector. on output x */ 69 | /* contains the final estimate of the solution vector. */ 70 | 71 | /* fvec is an output array of length m which contains */ 72 | /* the functions evaluated at the output x. */ 73 | 74 | /* tol is a nonnegative input variable. termination occurs */ 75 | /* when the algorithm estimates either that the relative */ 76 | /* error in the sum of squares is at most tol or that */ 77 | /* the relative error between x and the solution is at */ 78 | /* most tol. */ 79 | 80 | /* info is an integer output variable. if the user has */ 81 | /* terminated execution, info is set to the (negative) */ 82 | /* value of iflag. see description of fcn. otherwise, */ 83 | /* info is set as follows. */ 84 | 85 | /* info = 0 improper input parameters. */ 86 | 87 | /* info = 1 algorithm estimates that the relative error */ 88 | /* in the sum of squares is at most tol. */ 89 | 90 | /* info = 2 algorithm estimates that the relative error */ 91 | /* between x and the solution is at most tol. */ 92 | 93 | /* info = 3 conditions for info = 1 and info = 2 both hold. */ 94 | 95 | /* info = 4 fvec is orthogonal to the columns of the */ 96 | /* jacobian to machine precision. */ 97 | 98 | /* info = 5 number of calls to fcn has reached or */ 99 | /* exceeded 200*(n+1). */ 100 | 101 | /* info = 6 tol is too small. no further reduction in */ 102 | /* the sum of squares is possible. */ 103 | 104 | /* info = 7 tol is too small. no further improvement in */ 105 | /* the approximate solution x is possible. */ 106 | 107 | /* iwa is an integer work array of length n. */ 108 | 109 | /* wa is a work array of length lwa. */ 110 | 111 | /* lwa is a positive integer input variable not less than */ 112 | /* m*n+5*n+m. */ 113 | 114 | /* subprograms called */ 115 | 116 | /* user-supplied ...... fcn */ 117 | 118 | /* minpack-supplied ... lmdif */ 119 | 120 | /* argonne national laboratory. minpack project. march 1980. */ 121 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 122 | 123 | /* ********** */ 124 | /* Parameter adjustments */ 125 | --fvec; 126 | --iwa; 127 | --x; 128 | --wa; 129 | 130 | /* Function Body */ 131 | *info = 0; 132 | 133 | /* check the input parameters for errors. */ 134 | 135 | if (*n <= 0 || *m < *n || *tol < 0. || *lwa < *m * *n + *n * 5 + *m) { 136 | /* goto L10; */ 137 | return; 138 | } 139 | 140 | /* call lmdif. */ 141 | 142 | maxfev = (*n + 1) * 200; 143 | ftol = *tol; 144 | xtol = *tol; 145 | gtol = 0.; 146 | epsfcn = 0.; 147 | mode = 1; 148 | nprint = 0; 149 | mp5n = *m + *n * 5; 150 | __minpack_func__(lmdif)(__minpack_param_fcn_mn__ m, n, &x[1], &fvec[1], &ftol, &xtol, >ol, &maxfev, & 151 | epsfcn, &wa[1], &mode, &factor, &nprint, info, &nfev, &wa[mp5n + 152 | 1], m, &iwa[1], &wa[*n + 1], &wa[(*n << 1) + 1], &wa[*n * 3 + 1], 153 | &wa[(*n << 2) + 1], &wa[*n * 5 + 1]); 154 | if (*info == 8) { 155 | *info = 4; 156 | } 157 | /* L10: */ 158 | return; 159 | 160 | /* last card of subroutine lmdif1. */ 161 | 162 | } /* lmdif1_ */ 163 | 164 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/lmstr1.c: -------------------------------------------------------------------------------- 1 | #include "cminpack.h" 2 | #include "cminpackP.h" 3 | 4 | __cminpack_attr__ 5 | int __cminpack_func__(lmstr1)(__cminpack_decl_fcnderstr_mn__ void *p, int m, int n, real *x, 6 | real *fvec, real *fjac, int ldfjac, real tol, 7 | int *ipvt, real *wa, int lwa) 8 | { 9 | /* Initialized data */ 10 | 11 | const real factor = 100.; 12 | 13 | /* Local variables */ 14 | int mode, nfev, njev; 15 | real ftol, gtol, xtol; 16 | int maxfev, nprint; 17 | int info; 18 | 19 | /* ********** */ 20 | 21 | /* subroutine lmstr1 */ 22 | 23 | /* the purpose of lmstr1 is to minimize the sum of the squares of */ 24 | /* m nonlinear functions in n variables by a modification of */ 25 | /* the levenberg-marquardt algorithm which uses minimal storage. */ 26 | /* this is done by using the more general least-squares solver */ 27 | /* lmstr. the user must provide a subroutine which calculates */ 28 | /* the functions and the rows of the jacobian. */ 29 | 30 | /* the subroutine statement is */ 31 | 32 | /* subroutine lmstr1(fcn,m,n,x,fvec,fjac,ldfjac,tol,info, */ 33 | /* ipvt,wa,lwa) */ 34 | 35 | /* where */ 36 | 37 | /* fcn is the name of the user-supplied subroutine which */ 38 | /* calculates the functions and the rows of the jacobian. */ 39 | /* fcn must be declared in an external statement in the */ 40 | /* user calling program, and should be written as follows. */ 41 | 42 | /* subroutine fcn(m,n,x,fvec,fjrow,iflag) */ 43 | /* integer m,n,iflag */ 44 | /* double precision x(n),fvec(m),fjrow(n) */ 45 | /* ---------- */ 46 | /* if iflag = 1 calculate the functions at x and */ 47 | /* return this vector in fvec. */ 48 | /* if iflag = i calculate the (i-1)-st row of the */ 49 | /* jacobian at x and return this vector in fjrow. */ 50 | /* ---------- */ 51 | /* return */ 52 | /* end */ 53 | 54 | /* the value of iflag should not be changed by fcn unless */ 55 | /* the user wants to terminate execution of lmstr1. */ 56 | /* in this case set iflag to a negative integer. */ 57 | 58 | /* m is a positive integer input variable set to the number */ 59 | /* of functions. */ 60 | 61 | /* n is a positive integer input variable set to the number */ 62 | /* of variables. n must not exceed m. */ 63 | 64 | /* x is an array of length n. on input x must contain */ 65 | /* an initial estimate of the solution vector. on output x */ 66 | /* contains the final estimate of the solution vector. */ 67 | 68 | /* fvec is an output array of length m which contains */ 69 | /* the functions evaluated at the output x. */ 70 | 71 | /* fjac is an output n by n array. the upper triangle of fjac */ 72 | /* contains an upper triangular matrix r such that */ 73 | 74 | /* t t t */ 75 | /* p *(jac *jac)*p = r *r, */ 76 | 77 | /* where p is a permutation matrix and jac is the final */ 78 | /* calculated jacobian. column j of p is column ipvt(j) */ 79 | /* (see below) of the identity matrix. the lower triangular */ 80 | /* part of fjac contains information generated during */ 81 | /* the computation of r. */ 82 | 83 | /* ldfjac is a positive integer input variable not less than n */ 84 | /* which specifies the leading dimension of the array fjac. */ 85 | 86 | /* tol is a nonnegative input variable. termination occurs */ 87 | /* when the algorithm estimates either that the relative */ 88 | /* error in the sum of squares is at most tol or that */ 89 | /* the relative error between x and the solution is at */ 90 | /* most tol. */ 91 | 92 | /* info is an integer output variable. if the user has */ 93 | /* terminated execution, info is set to the (negative) */ 94 | /* value of iflag. see description of fcn. otherwise, */ 95 | /* info is set as follows. */ 96 | 97 | /* info = 0 improper input parameters. */ 98 | 99 | /* info = 1 algorithm estimates that the relative error */ 100 | /* in the sum of squares is at most tol. */ 101 | 102 | /* info = 2 algorithm estimates that the relative error */ 103 | /* between x and the solution is at most tol. */ 104 | 105 | /* info = 3 conditions for info = 1 and info = 2 both hold. */ 106 | 107 | /* info = 4 fvec is orthogonal to the columns of the */ 108 | /* jacobian to machine precision. */ 109 | 110 | /* info = 5 number of calls to fcn with iflag = 1 has */ 111 | /* reached 100*(n+1). */ 112 | 113 | /* info = 6 tol is too small. no further reduction in */ 114 | /* the sum of squares is possible. */ 115 | 116 | /* info = 7 tol is too small. no further improvement in */ 117 | /* the approximate solution x is possible. */ 118 | 119 | /* ipvt is an integer output array of length n. ipvt */ 120 | /* defines a permutation matrix p such that jac*p = q*r, */ 121 | /* where jac is the final calculated jacobian, q is */ 122 | /* orthogonal (not stored), and r is upper triangular. */ 123 | /* column j of p is column ipvt(j) of the identity matrix. */ 124 | 125 | /* wa is a work array of length lwa. */ 126 | 127 | /* lwa is a positive integer input variable not less than 5*n+m. */ 128 | 129 | /* subprograms called */ 130 | 131 | /* user-supplied ...... fcn */ 132 | 133 | /* minpack-supplied ... lmstr */ 134 | 135 | /* argonne national laboratory. minpack project. march 1980. */ 136 | /* burton s. garbow, dudley v. goetschel, kenneth e. hillstrom, */ 137 | /* jorge j. more */ 138 | 139 | /* ********** */ 140 | 141 | /* check the input parameters for errors. */ 142 | 143 | if (n <= 0 || m < n || ldfjac < n || tol < 0. || lwa < n * 5 + m) { 144 | return 0; 145 | } 146 | 147 | /* call lmstr. */ 148 | 149 | maxfev = (n + 1) * 100; 150 | ftol = tol; 151 | xtol = tol; 152 | gtol = 0.; 153 | mode = 1; 154 | nprint = 0; 155 | info = __cminpack_func__(lmstr)(__cminpack_param_fcnderstr_mn__ p, m, n, x, fvec, fjac, ldfjac, 156 | ftol, xtol, gtol, maxfev, wa, mode, factor, nprint, 157 | &nfev, &njev, ipvt, &wa[n], &wa[(n << 1)], & 158 | wa[n * 3], &wa[(n << 2)], &wa[n * 5]); 159 | if (info == 8) { 160 | info = 4; 161 | } 162 | return info; 163 | 164 | /* last card of subroutine lmstr1. */ 165 | 166 | } /* lmstr1_ */ 167 | 168 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/minpackP.h: -------------------------------------------------------------------------------- 1 | /* Internal header file for cminpack, by Frederic Devernay. */ 2 | #ifndef __MINPACKP_H__ 3 | #define __MINPACKP_H__ 4 | 5 | #ifndef __CMINPACK_H__ 6 | #error "minpackP.h in an internal cminpack header, and must be included after all other headers (including cminpack.h)" 7 | #endif 8 | 9 | #include 10 | 11 | #define double_EPSILON DBL_EPSILON 12 | #define double_MIN DBL_MIN 13 | #define double_MAX DBL_MAX 14 | #define long_double_EPSILON LDBL_EPSILON 15 | #define long_double_MIN LDBL_MIN 16 | #define long_double_MAX LDBL_MAX 17 | #define float_EPSILON FLT_EPSILON 18 | #define float_MIN FLT_MIN 19 | #define float_MAX FLT_MAX 20 | #define half_EPSILON HALF_EPSILON 21 | #define half_MIN HALF_NRM_MIN 22 | #define half_MAX HALF_MAX 23 | 24 | #define real __cminpack_real__ 25 | #ifdef __cminpack_long_double__ 26 | #define realm long_double 27 | #define fabs(x) fabsl(x) 28 | #define sqrt(x) sqrtl(x) 29 | #define log(x) logl(x) 30 | #define exp(x) expl(x) 31 | #define sin(x) sinl(x) 32 | #define cos(x) cosl(x) 33 | #define tan(x) tanl(x) 34 | #define asin(x) asinl(x) 35 | #define acos(x) acosl(x) 36 | #define atan(x) atanl(x) 37 | #define floor(x) floorl(x) 38 | #define ceil(x) ceill(x) 39 | extern long double floorl ( long double ); 40 | extern long double ellpkl ( long double ); 41 | #else 42 | #define realm real 43 | #endif 44 | #define min(a,b) ((a) <= (b) ? (a) : (b)) 45 | #define max(a,b) ((a) >= (b) ? (a) : (b)) 46 | #define abs(x) ((x) >= 0 ? (x) : -(x)) 47 | #define TRUE_ (1) 48 | #define FALSE_ (0) 49 | 50 | #endif /* !__MINPACKP_H__ */ 51 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/qform.c: -------------------------------------------------------------------------------- 1 | /* qform.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "cminpack.h" 7 | #include "cminpackP.h" 8 | 9 | __cminpack_attr__ 10 | void __cminpack_func__(qform)(int m, int n, real *q, int 11 | ldq, real *wa) 12 | { 13 | /* System generated locals */ 14 | int q_dim1, q_offset; 15 | 16 | /* Local variables */ 17 | int i, j, k, l, jm1, np1; 18 | real sum, temp; 19 | int minmn; 20 | 21 | /* ********** */ 22 | 23 | /* subroutine qform */ 24 | 25 | /* this subroutine proceeds from the computed qr factorization of */ 26 | /* an m by n matrix a to accumulate the m by m orthogonal matrix */ 27 | /* q from its factored form. */ 28 | 29 | /* the subroutine statement is */ 30 | 31 | /* subroutine qform(m,n,q,ldq,wa) */ 32 | 33 | /* where */ 34 | 35 | /* m is a positive integer input variable set to the number */ 36 | /* of rows of a and the order of q. */ 37 | 38 | /* n is a positive integer input variable set to the number */ 39 | /* of columns of a. */ 40 | 41 | /* q is an m by m array. on input the full lower trapezoid in */ 42 | /* the first min(m,n) columns of q contains the factored form. */ 43 | /* on output q has been accumulated into a square matrix. */ 44 | 45 | /* ldq is a positive integer input variable not less than m */ 46 | /* which specifies the leading dimension of the array q. */ 47 | 48 | /* wa is a work array of length m. */ 49 | 50 | /* subprograms called */ 51 | 52 | /* fortran-supplied ... min0 */ 53 | 54 | /* argonne national laboratory. minpack project. march 1980. */ 55 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 56 | 57 | /* ********** */ 58 | /* Parameter adjustments */ 59 | --wa; 60 | q_dim1 = ldq; 61 | q_offset = 1 + q_dim1 * 1; 62 | q -= q_offset; 63 | 64 | /* Function Body */ 65 | 66 | /* zero out upper triangle of q in the first min(m,n) columns. */ 67 | 68 | minmn = min(m,n); 69 | if (minmn >= 2) { 70 | for (j = 2; j <= minmn; ++j) { 71 | jm1 = j - 1; 72 | for (i = 1; i <= jm1; ++i) { 73 | q[i + j * q_dim1] = 0.; 74 | } 75 | } 76 | } 77 | 78 | /* initialize remaining columns to those of the identity matrix. */ 79 | 80 | np1 = n + 1; 81 | if (m >= np1) { 82 | for (j = np1; j <= m; ++j) { 83 | for (i = 1; i <= m; ++i) { 84 | q[i + j * q_dim1] = 0.; 85 | } 86 | q[j + j * q_dim1] = 1.; 87 | } 88 | } 89 | 90 | /* accumulate q from its factored form. */ 91 | 92 | for (l = 1; l <= minmn; ++l) { 93 | k = minmn - l + 1; 94 | for (i = k; i <= m; ++i) { 95 | wa[i] = q[i + k * q_dim1]; 96 | q[i + k * q_dim1] = 0.; 97 | } 98 | q[k + k * q_dim1] = 1.; 99 | if (wa[k] != 0.) { 100 | for (j = k; j <= m; ++j) { 101 | sum = 0.; 102 | for (i = k; i <= m; ++i) { 103 | sum += q[i + j * q_dim1] * wa[i]; 104 | } 105 | temp = sum / wa[k]; 106 | for (i = k; i <= m; ++i) { 107 | q[i + j * q_dim1] -= temp * wa[i]; 108 | } 109 | } 110 | } 111 | } 112 | 113 | /* last card of subroutine qform. */ 114 | 115 | } /* qform_ */ 116 | 117 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/qform_.c: -------------------------------------------------------------------------------- 1 | /* qform.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "minpack.h" 7 | #include 8 | #include "minpackP.h" 9 | 10 | 11 | __minpack_attr__ 12 | void __minpack_func__(qform)(const int *m, const int *n, real *q, const int * 13 | ldq, real *wa) 14 | { 15 | /* System generated locals */ 16 | int q_dim1, q_offset, i__1, i__2, i__3; 17 | 18 | /* Local variables */ 19 | int i__, j, k, l, jm1, np1; 20 | real sum, temp; 21 | int minmn; 22 | 23 | /* ********** */ 24 | 25 | /* subroutine qform */ 26 | 27 | /* this subroutine proceeds from the computed qr factorization of */ 28 | /* an m by n matrix a to accumulate the m by m orthogonal matrix */ 29 | /* q from its factored form. */ 30 | 31 | /* the subroutine statement is */ 32 | 33 | /* subroutine qform(m,n,q,ldq,wa) */ 34 | 35 | /* where */ 36 | 37 | /* m is a positive integer input variable set to the number */ 38 | /* of rows of a and the order of q. */ 39 | 40 | /* n is a positive integer input variable set to the number */ 41 | /* of columns of a. */ 42 | 43 | /* q is an m by m array. on input the full lower trapezoid in */ 44 | /* the first min(m,n) columns of q contains the factored form. */ 45 | /* on output q has been accumulated into a square matrix. */ 46 | 47 | /* ldq is a positive integer input variable not less than m */ 48 | /* which specifies the leading dimension of the array q. */ 49 | 50 | /* wa is a work array of length m. */ 51 | 52 | /* subprograms called */ 53 | 54 | /* fortran-supplied ... min0 */ 55 | 56 | /* argonne national laboratory. minpack project. march 1980. */ 57 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 58 | 59 | /* ********** */ 60 | /* Parameter adjustments */ 61 | --wa; 62 | q_dim1 = *ldq; 63 | q_offset = 1 + q_dim1 * 1; 64 | q -= q_offset; 65 | 66 | /* Function Body */ 67 | 68 | /* zero out upper triangle of q in the first min(m,n) columns. */ 69 | 70 | minmn = min(*m,*n); 71 | if (minmn < 2) { 72 | goto L30; 73 | } 74 | i__1 = minmn; 75 | for (j = 2; j <= i__1; ++j) { 76 | jm1 = j - 1; 77 | i__2 = jm1; 78 | for (i__ = 1; i__ <= i__2; ++i__) { 79 | q[i__ + j * q_dim1] = 0.; 80 | /* L10: */ 81 | } 82 | /* L20: */ 83 | } 84 | L30: 85 | 86 | /* initialize remaining columns to those of the identity matrix. */ 87 | 88 | np1 = *n + 1; 89 | if (*m < np1) { 90 | goto L60; 91 | } 92 | i__1 = *m; 93 | for (j = np1; j <= i__1; ++j) { 94 | i__2 = *m; 95 | for (i__ = 1; i__ <= i__2; ++i__) { 96 | q[i__ + j * q_dim1] = 0.; 97 | /* L40: */ 98 | } 99 | q[j + j * q_dim1] = 1.; 100 | /* L50: */ 101 | } 102 | L60: 103 | 104 | /* accumulate q from its factored form. */ 105 | 106 | i__1 = minmn; 107 | for (l = 1; l <= i__1; ++l) { 108 | k = minmn - l + 1; 109 | i__2 = *m; 110 | for (i__ = k; i__ <= i__2; ++i__) { 111 | wa[i__] = q[i__ + k * q_dim1]; 112 | q[i__ + k * q_dim1] = 0.; 113 | /* L70: */ 114 | } 115 | q[k + k * q_dim1] = 1.; 116 | if (wa[k] == 0.) { 117 | goto L110; 118 | } 119 | i__2 = *m; 120 | for (j = k; j <= i__2; ++j) { 121 | sum = 0.; 122 | i__3 = *m; 123 | for (i__ = k; i__ <= i__3; ++i__) { 124 | sum += q[i__ + j * q_dim1] * wa[i__]; 125 | /* L80: */ 126 | } 127 | temp = sum / wa[k]; 128 | i__3 = *m; 129 | for (i__ = k; i__ <= i__3; ++i__) { 130 | q[i__ + j * q_dim1] -= temp * wa[i__]; 131 | /* L90: */ 132 | } 133 | /* L100: */ 134 | } 135 | L110: 136 | /* L120: */ 137 | ; 138 | } 139 | return; 140 | 141 | /* last card of subroutine qform. */ 142 | 143 | } /* qform_ */ 144 | 145 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/r1mpyq.c: -------------------------------------------------------------------------------- 1 | /* r1mpyq.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "cminpack.h" 7 | #include 8 | #include "cminpackP.h" 9 | 10 | __cminpack_attr__ 11 | void __cminpack_func__(r1mpyq)(int m, int n, real *a, int 12 | lda, const real *v, const real *w) 13 | { 14 | /* System generated locals */ 15 | int a_dim1, a_offset; 16 | 17 | /* Local variables */ 18 | int i, j, nm1, nmj; 19 | real cos, sin, temp; 20 | 21 | /* ********** */ 22 | 23 | /* subroutine r1mpyq */ 24 | 25 | /* given an m by n matrix a, this subroutine computes a*q where */ 26 | /* q is the product of 2*(n - 1) transformations */ 27 | 28 | /* gv(n-1)*...*gv(1)*gw(1)*...*gw(n-1) */ 29 | 30 | /* and gv(i), gw(i) are givens rotations in the (i,n) plane which */ 31 | /* eliminate elements in the i-th and n-th planes, respectively. */ 32 | /* q itself is not given, rather the information to recover the */ 33 | /* gv, gw rotations is supplied. */ 34 | 35 | /* the subroutine statement is */ 36 | 37 | /* subroutine r1mpyq(m,n,a,lda,v,w) */ 38 | 39 | /* where */ 40 | 41 | /* m is a positive integer input variable set to the number */ 42 | /* of rows of a. */ 43 | 44 | /* n is a positive integer input variable set to the number */ 45 | /* of columns of a. */ 46 | 47 | /* a is an m by n array. on input a must contain the matrix */ 48 | /* to be postmultiplied by the orthogonal matrix q */ 49 | /* described above. on output a*q has replaced a. */ 50 | 51 | /* lda is a positive integer input variable not less than m */ 52 | /* which specifies the leading dimension of the array a. */ 53 | 54 | /* v is an input array of length n. v(i) must contain the */ 55 | /* information necessary to recover the givens rotation gv(i) */ 56 | /* described above. */ 57 | 58 | /* w is an input array of length n. w(i) must contain the */ 59 | /* information necessary to recover the givens rotation gw(i) */ 60 | /* described above. */ 61 | 62 | /* subroutines called */ 63 | 64 | /* fortran-supplied ... dabs,dsqrt */ 65 | 66 | /* argonne national laboratory. minpack project. march 1980. */ 67 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 68 | 69 | /* ********** */ 70 | /* Parameter adjustments */ 71 | --w; 72 | --v; 73 | a_dim1 = lda; 74 | a_offset = 1 + a_dim1 * 1; 75 | a -= a_offset; 76 | 77 | /* Function Body */ 78 | 79 | /* apply the first set of givens rotations to a. */ 80 | 81 | nm1 = n - 1; 82 | if (nm1 < 1) { 83 | return; 84 | } 85 | for (nmj = 1; nmj <= nm1; ++nmj) { 86 | j = n - nmj; 87 | if (fabs(v[j]) > 1.) { 88 | cos = 1. / v[j]; 89 | sin = sqrt(1. - cos * cos); 90 | } else { 91 | sin = v[j]; 92 | cos = sqrt(1. - sin * sin); 93 | } 94 | for (i = 1; i <= m; ++i) { 95 | temp = cos * a[i + j * a_dim1] - sin * a[i + n * a_dim1]; 96 | a[i + n * a_dim1] = sin * a[i + j * a_dim1] + cos * a[ 97 | i + n * a_dim1]; 98 | a[i + j * a_dim1] = temp; 99 | } 100 | } 101 | 102 | /* apply the second set of givens rotations to a. */ 103 | 104 | for (j = 1; j <= nm1; ++j) { 105 | if (fabs(w[j]) > 1.) { 106 | cos = 1. / w[j]; 107 | sin = sqrt(1. - cos * cos); 108 | } else { 109 | sin = w[j]; 110 | cos = sqrt(1. - sin * sin); 111 | } 112 | for (i = 1; i <= m; ++i) { 113 | temp = cos * a[i + j * a_dim1] + sin * a[i + n * a_dim1]; 114 | a[i + n * a_dim1] = -sin * a[i + j * a_dim1] + cos * a[i + n * a_dim1]; 115 | a[i + j * a_dim1] = temp; 116 | } 117 | } 118 | 119 | /* last card of subroutine r1mpyq. */ 120 | 121 | } /* r1mpyq_ */ 122 | 123 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/r1mpyq_.c: -------------------------------------------------------------------------------- 1 | /* r1mpyq.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "minpack.h" 7 | #include 8 | #include "minpackP.h" 9 | 10 | 11 | __minpack_attr__ 12 | void __minpack_func__(r1mpyq)(const int *m, const int *n, real *a, const int * 13 | lda, const real *v, const real *w) 14 | { 15 | /* System generated locals */ 16 | int a_dim1, a_offset, i__1, i__2; 17 | real d__1, d__2; 18 | 19 | /* Local variables */ 20 | int i__, j, nm1, nmj; 21 | real cos__, sin__, temp; 22 | 23 | /* ********** */ 24 | 25 | /* subroutine r1mpyq */ 26 | 27 | /* given an m by n matrix a, this subroutine computes a*q where */ 28 | /* q is the product of 2*(n - 1) transformations */ 29 | 30 | /* gv(n-1)*...*gv(1)*gw(1)*...*gw(n-1) */ 31 | 32 | /* and gv(i), gw(i) are givens rotations in the (i,n) plane which */ 33 | /* eliminate elements in the i-th and n-th planes, respectively. */ 34 | /* q itself is not given, rather the information to recover the */ 35 | /* gv, gw rotations is supplied. */ 36 | 37 | /* the subroutine statement is */ 38 | 39 | /* subroutine r1mpyq(m,n,a,lda,v,w) */ 40 | 41 | /* where */ 42 | 43 | /* m is a positive integer input variable set to the number */ 44 | /* of rows of a. */ 45 | 46 | /* n is a positive integer input variable set to the number */ 47 | /* of columns of a. */ 48 | 49 | /* a is an m by n array. on input a must contain the matrix */ 50 | /* to be postmultiplied by the orthogonal matrix q */ 51 | /* described above. on output a*q has replaced a. */ 52 | 53 | /* lda is a positive integer input variable not less than m */ 54 | /* which specifies the leading dimension of the array a. */ 55 | 56 | /* v is an input array of length n. v(i) must contain the */ 57 | /* information necessary to recover the givens rotation gv(i) */ 58 | /* described above. */ 59 | 60 | /* w is an input array of length n. w(i) must contain the */ 61 | /* information necessary to recover the givens rotation gw(i) */ 62 | /* described above. */ 63 | 64 | /* subroutines called */ 65 | 66 | /* fortran-supplied ... dabs,dsqrt */ 67 | 68 | /* argonne national laboratory. minpack project. march 1980. */ 69 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ 70 | 71 | /* ********** */ 72 | /* Parameter adjustments */ 73 | --w; 74 | --v; 75 | a_dim1 = *lda; 76 | a_offset = 1 + a_dim1 * 1; 77 | a -= a_offset; 78 | 79 | /* Function Body */ 80 | 81 | /* apply the first set of givens rotations to a. */ 82 | 83 | nm1 = *n - 1; 84 | if (nm1 < 1) { 85 | /* goto L50; */ 86 | return; 87 | } 88 | i__1 = nm1; 89 | for (nmj = 1; nmj <= i__1; ++nmj) { 90 | j = *n - nmj; 91 | if ((d__1 = v[j], abs(d__1)) > 1.) { 92 | cos__ = 1. / v[j]; 93 | /* Computing 2nd power */ 94 | d__2 = cos__; 95 | sin__ = sqrt(1. - d__2 * d__2); 96 | } else { 97 | sin__ = v[j]; 98 | /* Computing 2nd power */ 99 | d__2 = sin__; 100 | cos__ = sqrt(1. - d__2 * d__2); 101 | } 102 | i__2 = *m; 103 | for (i__ = 1; i__ <= i__2; ++i__) { 104 | temp = cos__ * a[i__ + j * a_dim1] - sin__ * a[i__ + *n * a_dim1]; 105 | a[i__ + *n * a_dim1] = sin__ * a[i__ + j * a_dim1] + cos__ * a[ 106 | i__ + *n * a_dim1]; 107 | a[i__ + j * a_dim1] = temp; 108 | /* L10: */ 109 | } 110 | /* L20: */ 111 | } 112 | 113 | /* apply the second set of givens rotations to a. */ 114 | 115 | i__1 = nm1; 116 | for (j = 1; j <= i__1; ++j) { 117 | if ((d__1 = w[j], abs(d__1)) > 1.) { 118 | cos__ = 1. / w[j]; 119 | /* Computing 2nd power */ 120 | d__2 = cos__; 121 | sin__ = sqrt(1. - d__2 * d__2); 122 | } else { 123 | sin__ = w[j]; 124 | /* Computing 2nd power */ 125 | d__2 = sin__; 126 | cos__ = sqrt(1. - d__2 * d__2); 127 | } 128 | i__2 = *m; 129 | for (i__ = 1; i__ <= i__2; ++i__) { 130 | temp = cos__ * a[i__ + j * a_dim1] + sin__ * a[i__ + *n * a_dim1]; 131 | a[i__ + *n * a_dim1] = -sin__ * a[i__ + j * a_dim1] + cos__ * a[ 132 | i__ + *n * a_dim1]; 133 | a[i__ + j * a_dim1] = temp; 134 | /* L30: */ 135 | } 136 | /* L40: */ 137 | } 138 | /* L50: */ 139 | return; 140 | 141 | /* last card of subroutine r1mpyq. */ 142 | 143 | } /* r1mpyq_ */ 144 | 145 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/readme.txt: -------------------------------------------------------------------------------- 1 | ====== readme for minpack ====== 2 | 3 | Minpack includes software for solving nonlinear equations and 4 | nonlinear least squares problems. Five algorithmic paths each include 5 | a core subroutine and an easy-to-use driver. The algorithms proceed 6 | either from an analytic specification of the Jacobian matrix or 7 | directly from the problem functions. The paths include facilities for 8 | systems of equations with a banded Jacobian matrix, for least squares 9 | problems with a large amount of data, and for checking the consistency 10 | of the Jacobian matrix with the functions. 11 | 12 | This directory contains the double-precision versions. 13 | 14 | Jorge More', Burt Garbow, and Ken Hillstrom at Argonne National Laboratory. 15 | 16 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/rwupdt.c: -------------------------------------------------------------------------------- 1 | /* rwupdt.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "cminpack.h" 7 | #include 8 | #include "cminpackP.h" 9 | 10 | __cminpack_attr__ 11 | void __cminpack_func__(rwupdt)(int n, real *r, int ldr, 12 | const real *w, real *b, real *alpha, real *cos, 13 | real *sin) 14 | { 15 | /* Initialized data */ 16 | 17 | #define p5 .5 18 | #define p25 .25 19 | 20 | /* System generated locals */ 21 | int r_dim1, r_offset; 22 | 23 | /* Local variables */ 24 | int i, j, jm1; 25 | real tan, temp, rowj, cotan; 26 | 27 | /* ********** */ 28 | 29 | /* subroutine rwupdt */ 30 | 31 | /* given an n by n upper triangular matrix r, this subroutine */ 32 | /* computes the qr decomposition of the matrix formed when a row */ 33 | /* is added to r. if the row is specified by the vector w, then */ 34 | /* rwupdt determines an orthogonal matrix q such that when the */ 35 | /* n+1 by n matrix composed of r augmented by w is premultiplied */ 36 | /* by (q transpose), the resulting matrix is upper trapezoidal. */ 37 | /* the matrix (q transpose) is the product of n transformations */ 38 | 39 | /* g(n)*g(n-1)* ... *g(1) */ 40 | 41 | /* where g(i) is a givens rotation in the (i,n+1) plane which */ 42 | /* eliminates elements in the (n+1)-st plane. rwupdt also */ 43 | /* computes the product (q transpose)*c where c is the */ 44 | /* (n+1)-vector (b,alpha). q itself is not accumulated, rather */ 45 | /* the information to recover the g rotations is supplied. */ 46 | 47 | /* the subroutine statement is */ 48 | 49 | /* subroutine rwupdt(n,r,ldr,w,b,alpha,cos,sin) */ 50 | 51 | /* where */ 52 | 53 | /* n is a positive integer input variable set to the order of r. */ 54 | 55 | /* r is an n by n array. on input the upper triangular part of */ 56 | /* r must contain the matrix to be updated. on output r */ 57 | /* contains the updated triangular matrix. */ 58 | 59 | /* ldr is a positive integer input variable not less than n */ 60 | /* which specifies the leading dimension of the array r. */ 61 | 62 | /* w is an input array of length n which must contain the row */ 63 | /* vector to be added to r. */ 64 | 65 | /* b is an array of length n. on input b must contain the */ 66 | /* first n elements of the vector c. on output b contains */ 67 | /* the first n elements of the vector (q transpose)*c. */ 68 | 69 | /* alpha is a variable. on input alpha must contain the */ 70 | /* (n+1)-st element of the vector c. on output alpha contains */ 71 | /* the (n+1)-st element of the vector (q transpose)*c. */ 72 | 73 | /* cos is an output array of length n which contains the */ 74 | /* cosines of the transforming givens rotations. */ 75 | 76 | /* sin is an output array of length n which contains the */ 77 | /* sines of the transforming givens rotations. */ 78 | 79 | /* subprograms called */ 80 | 81 | /* fortran-supplied ... dabs,dsqrt */ 82 | 83 | /* argonne national laboratory. minpack project. march 1980. */ 84 | /* burton s. garbow, dudley v. goetschel, kenneth e. hillstrom, */ 85 | /* jorge j. more */ 86 | 87 | /* ********** */ 88 | /* Parameter adjustments */ 89 | --sin; 90 | --cos; 91 | --b; 92 | --w; 93 | r_dim1 = ldr; 94 | r_offset = 1 + r_dim1 * 1; 95 | r -= r_offset; 96 | 97 | /* Function Body */ 98 | 99 | for (j = 1; j <= n; ++j) { 100 | rowj = w[j]; 101 | jm1 = j - 1; 102 | 103 | /* apply the previous transformations to */ 104 | /* r(i,j), i=1,2,...,j-1, and to w(j). */ 105 | 106 | if (jm1 >= 1) { 107 | for (i = 1; i <= jm1; ++i) { 108 | temp = cos[i] * r[i + j * r_dim1] + sin[i] * rowj; 109 | rowj = -sin[i] * r[i + j * r_dim1] + cos[i] * rowj; 110 | r[i + j * r_dim1] = temp; 111 | } 112 | } 113 | 114 | /* determine a givens rotation which eliminates w(j). */ 115 | 116 | cos[j] = 1.; 117 | sin[j] = 0.; 118 | if (rowj != 0.) { 119 | if (fabs(r[j + j * r_dim1]) < fabs(rowj)) { 120 | cotan = r[j + j * r_dim1] / rowj; 121 | sin[j] = p5 / sqrt(p25 + p25 * (cotan * cotan)); 122 | cos[j] = sin[j] * cotan; 123 | } else { 124 | tan = rowj / r[j + j * r_dim1]; 125 | cos[j] = p5 / sqrt(p25 + p25 * (tan * tan)); 126 | sin[j] = cos[j] * tan; 127 | } 128 | 129 | /* apply the current transformation to r(j,j), b(j), and alpha. */ 130 | 131 | r[j + j * r_dim1] = cos[j] * r[j + j * r_dim1] + sin[j] * rowj; 132 | temp = cos[j] * b[j] + sin[j] * *alpha; 133 | *alpha = -sin[j] * b[j] + cos[j] * *alpha; 134 | b[j] = temp; 135 | } 136 | } 137 | 138 | /* last card of subroutine rwupdt. */ 139 | 140 | } /* rwupdt_ */ 141 | 142 | -------------------------------------------------------------------------------- /src/3rd_party/cminpack-1.3.6/rwupdt_.c: -------------------------------------------------------------------------------- 1 | /* rwupdt.f -- translated by f2c (version 20020621). 2 | You must link the resulting object file with the libraries: 3 | -lf2c -lm (in that order) 4 | */ 5 | 6 | #include "minpack.h" 7 | #include 8 | #include "minpackP.h" 9 | 10 | 11 | __minpack_attr__ 12 | void __minpack_func__(rwupdt)(const int *n, real *r__, const int *ldr, 13 | const real *w, real *b, real *alpha, real *cos__, 14 | real *sin__) 15 | { 16 | /* Initialized data */ 17 | 18 | #define p5 .5 19 | #define p25 .25 20 | 21 | /* System generated locals */ 22 | int r_dim1, r_offset, i__1, i__2; 23 | real d__1; 24 | 25 | /* Local variables */ 26 | int i__, j, jm1; 27 | real tan__, temp, rowj, cotan; 28 | 29 | /* ********** */ 30 | 31 | /* subroutine rwupdt */ 32 | 33 | /* given an n by n upper triangular matrix r, this subroutine */ 34 | /* computes the qr decomposition of the matrix formed when a row */ 35 | /* is added to r. if the row is specified by the vector w, then */ 36 | /* rwupdt determines an orthogonal matrix q such that when the */ 37 | /* n+1 by n matrix composed of r augmented by w is premultiplied */ 38 | /* by (q transpose), the resulting matrix is upper trapezoidal. */ 39 | /* the matrix (q transpose) is the product of n transformations */ 40 | 41 | /* g(n)*g(n-1)* ... *g(1) */ 42 | 43 | /* where g(i) is a givens rotation in the (i,n+1) plane which */ 44 | /* eliminates elements in the (n+1)-st plane. rwupdt also */ 45 | /* computes the product (q transpose)*c where c is the */ 46 | /* (n+1)-vector (b,alpha). q itself is not accumulated, rather */ 47 | /* the information to recover the g rotations is supplied. */ 48 | 49 | /* the subroutine statement is */ 50 | 51 | /* subroutine rwupdt(n,r,ldr,w,b,alpha,cos,sin) */ 52 | 53 | /* where */ 54 | 55 | /* n is a positive integer input variable set to the order of r. */ 56 | 57 | /* r is an n by n array. on input the upper triangular part of */ 58 | /* r must contain the matrix to be updated. on output r */ 59 | /* contains the updated triangular matrix. */ 60 | 61 | /* ldr is a positive integer input variable not less than n */ 62 | /* which specifies the leading dimension of the array r. */ 63 | 64 | /* w is an input array of length n which must contain the row */ 65 | /* vector to be added to r. */ 66 | 67 | /* b is an array of length n. on input b must contain the */ 68 | /* first n elements of the vector c. on output b contains */ 69 | /* the first n elements of the vector (q transpose)*c. */ 70 | 71 | /* alpha is a variable. on input alpha must contain the */ 72 | /* (n+1)-st element of the vector c. on output alpha contains */ 73 | /* the (n+1)-st element of the vector (q transpose)*c. */ 74 | 75 | /* cos is an output array of length n which contains the */ 76 | /* cosines of the transforming givens rotations. */ 77 | 78 | /* sin is an output array of length n which contains the */ 79 | /* sines of the transforming givens rotations. */ 80 | 81 | /* subprograms called */ 82 | 83 | /* fortran-supplied ... dabs,dsqrt */ 84 | 85 | /* argonne national laboratory. minpack project. march 1980. */ 86 | /* burton s. garbow, dudley v. goetschel, kenneth e. hillstrom, */ 87 | /* jorge j. more */ 88 | 89 | /* ********** */ 90 | /* Parameter adjustments */ 91 | --sin__; 92 | --cos__; 93 | --b; 94 | --w; 95 | r_dim1 = *ldr; 96 | r_offset = 1 + r_dim1 * 1; 97 | r__ -= r_offset; 98 | 99 | /* Function Body */ 100 | 101 | i__1 = *n; 102 | for (j = 1; j <= i__1; ++j) { 103 | rowj = w[j]; 104 | jm1 = j - 1; 105 | 106 | /* apply the previous transformations to */ 107 | /* r(i,j), i=1,2,...,j-1, and to w(j). */ 108 | 109 | if (jm1 < 1) { 110 | goto L20; 111 | } 112 | i__2 = jm1; 113 | for (i__ = 1; i__ <= i__2; ++i__) { 114 | temp = cos__[i__] * r__[i__ + j * r_dim1] + sin__[i__] * rowj; 115 | rowj = -sin__[i__] * r__[i__ + j * r_dim1] + cos__[i__] * rowj; 116 | r__[i__ + j * r_dim1] = temp; 117 | /* L10: */ 118 | } 119 | L20: 120 | 121 | /* determine a givens rotation which eliminates w(j). */ 122 | 123 | cos__[j] = 1.; 124 | sin__[j] = 0.; 125 | if (rowj == 0.) { 126 | goto L50; 127 | } 128 | if ((d__1 = r__[j + j * r_dim1], abs(d__1)) >= abs(rowj)) { 129 | goto L30; 130 | } 131 | cotan = r__[j + j * r_dim1] / rowj; 132 | /* Computing 2nd power */ 133 | d__1 = cotan; 134 | sin__[j] = p5 / sqrt(p25 + p25 * (d__1 * d__1)); 135 | cos__[j] = sin__[j] * cotan; 136 | goto L40; 137 | L30: 138 | tan__ = rowj / r__[j + j * r_dim1]; 139 | /* Computing 2nd power */ 140 | d__1 = tan__; 141 | cos__[j] = p5 / sqrt(p25 + p25 * (d__1 * d__1)); 142 | sin__[j] = cos__[j] * tan__; 143 | L40: 144 | 145 | /* apply the current transformation to r(j,j), b(j), and alpha. */ 146 | 147 | r__[j + j * r_dim1] = cos__[j] * r__[j + j * r_dim1] + sin__[j] * 148 | rowj; 149 | temp = cos__[j] * b[j] + sin__[j] * *alpha; 150 | *alpha = -sin__[j] * b[j] + cos__[j] * *alpha; 151 | b[j] = temp; 152 | L50: 153 | /* L60: */ 154 | ; 155 | } 156 | return; 157 | 158 | /* last card of subroutine rwupdt. */ 159 | 160 | } /* rwupdt_ */ 161 | 162 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/AUTHORS: -------------------------------------------------------------------------------- 1 | Naoaki Okazaki 2 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) 4 | project(3rd_liblbfgs) 5 | 6 | 7 | set(liblbfgs_HEADERS 8 | include/lbfgs.h 9 | ) 10 | 11 | set(liblbfgs_SOURCES 12 | lib/arithmetic_ansi.h 13 | lib/arithmetic_sse_double.h 14 | lib/arithmetic_sse_float.h 15 | lib/lbfgs.c 16 | ) 17 | 18 | 19 | add_library(3rd_liblbfgs STATIC ${liblbfgs_SOURCES} ${liblbfgs_HEADERS}) 20 | 21 | set_target_properties(3rd_liblbfgs PROPERTIES FOLDER "3rd_party") 22 | 23 | target_include_directories(3rd_liblbfgs PRIVATE 24 | ${CMAKE_CURRENT_LIST_DIR}/include 25 | ) 26 | 27 | 28 | target_compile_definitions(3rd_liblbfgs PRIVATE USE_SSE __SSE__ __SSE2__ __SSE3__ HAVE_EMMINTRIN_H HAVE_XMMINTRIN_H) 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/COPYING: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 1990 Jorge Nocedal 4 | Copyright (c) 2007-2010 Naoaki Okazaki 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/ChangeLog: -------------------------------------------------------------------------------- 1 | 2010-xx-xx Naoaki Okazaki 2 | 3 | * libLBFGS 1.10: 4 | - Fixed compiling errors on Mac OS X; this patch was kindly submitted by Nic Schraudolph. 5 | - Reduced compiling warnings on Mac OS X; this patch was kindly submitted by Tamas Nepusz. 6 | 7 | 8 | 2010-01-29 Naoaki Okazaki 9 | 10 | * libLBFGS 1.9: 11 | - Fixed a mistake in checking the validity of the parameters "ftol" and "wolfe"; this mistake was discovered by Kevin S. Van Horn. 12 | 13 | 14 | 2009-07-13 Naoaki Okazaki 15 | 16 | * libLBFGS 1.8: 17 | - Accepted the patch submitted by Takashi Imamichi; the backtracking method now has three criteria for choosing the step length. 18 | - Updated the documentation to explain the above three criteria. 19 | 20 | 21 | 2009-02-28 Naoaki Okazaki 22 | 23 | * libLBFGS 1.7: 24 | - Improved OWL-QN routines for stability. 25 | - Removed the support of OWL-QN method in MoreThuente algorithm 26 | because it accidentally fails in early stages of iterations for some 27 | objectives. Because of this change, the OW-LQN method must be used 28 | with the backtracking algorithm (LBFGS_LINESEARCH_BACKTRACKING), or 29 | the library returns LBFGSERR_INVALID_LINESEARCH. 30 | - Renamed line search algorithms as follows: 31 | - LBFGS_LINESEARCH_BACKTRACKING: regular Wolfe condition. 32 | - LBFGS_LINESEARCH_BACKTRACKING_LOOSE: regular Wolfe condition. 33 | - LBFGS_LINESEARCH_BACKTRACKING_STRONG: strong Wolfe condition. 34 | - Source code clean-up. 35 | 36 | 37 | 2008-11-02 Naoaki Okazaki 38 | 39 | * libLBFGS 1.6: 40 | - Improved line-search algorithm with strong Wolfe condition, which 41 | was contributed by Takashi Imamichi. This routine is now default for 42 | LBFGS_LINESEARCH_BACKTRACKING. The previous line search algorithm 43 | with regular Wolfe condition is still available as 44 | LBFGS_LINESEARCH_BACKTRACKING_LOOSE. 45 | - Configurable stop index for L1-norm computation. A member variable 46 | lbfgs_parameter_t::orthantwise_end was added to specify the index 47 | number at which the library stops computing the L1 norm of the 48 | variables. This is useful to prevent some variables from being 49 | regularized by the OW-LQN method. 50 | - A sample program written in C++ (sample/sample.cpp). 51 | 52 | 53 | 2008-07-10 Naoaki Okazaki 54 | 55 | * libLBFGS 1.5: 56 | - Configurable starting index for L1-norm computation. A member 57 | variable lbfgs_parameter_t::orthantwise_start was added to specify 58 | the index number from which the library computes the L1 norm of the 59 | variables. 60 | - Fixed a zero-division error when the initial variables have already 61 | been a minimizer (reported by Takashi Imamichi). In this case, the 62 | library returns LBFGS_ALREADY_MINIMIZED status code. 63 | - Defined LBFGS_SUCCESS status code as zero; removed unused constants, 64 | LBFGSFALSE and LBFGSTRUE. 65 | - Fixed a compile error in an implicit down-cast. 66 | 67 | 68 | 2008-04-25 Naoaki Okazaki 69 | 70 | * libLBFGS 1.4: 71 | - Configurable line search algorithms. A member variable 72 | lbfgs_parameter_t::linesearch was added to choose either MoreThuente 73 | method (LBFGS_LINESEARCH_MORETHUENTE) or backtracking algorithm 74 | (LBFGS_LINESEARCH_BACKTRACKING). 75 | - Fixed a bug: the previous version did not compute psuedo-gradients 76 | properly in the line search routines for OW-LQN. This bug might quit 77 | an iteration process too early when the OW-LQN routine was activated 78 | (0 < lbfgs_parameter_t::orthantwise_c). 79 | - Configure script for POSIX environments. 80 | - SSE/SSE2 optimizations with GCC. 81 | - New functions lbfgs_malloc and lbfgs_free to use SSE/SSE2 routines 82 | transparently. It is uncessary to use these functions for libLBFGS 83 | built without SSE/SSE2 routines; you can still use any memory 84 | allocators if SSE/SSE2 routines are disabled in libLBFGS. 85 | 86 | 87 | 2007-12-16 Naoaki Okazaki 88 | 89 | * libLBFGS 1.3: 90 | - An API change. An argument was added to lbfgs() function to receive 91 | the final value of the objective function. This argument can be set 92 | to NULL if the final value is unnecessary. 93 | - Fixed a null-pointer bug in the sample code (reported by Takashi 94 | Imamichi). 95 | - Added build scripts for Microsoft Visual Studio 2005 and GCC. 96 | - Added README file. 97 | 98 | 99 | 2007-12-13 Naoaki Okazaki 100 | 101 | * libLBFGS 1.2: 102 | - Fixed a serious bug in orthant-wise L-BFGS. An important variable 103 | was used without initialization. 104 | - Configurable L-BFGS parameters (number of limited memories, epsilon). 105 | 106 | 107 | 2007-12-01 Naoaki Okazaki 108 | 109 | * libLBFGS 1.1: 110 | - Implemented orthant-wise L-BFGS. 111 | - Implemented lbfgs_parameter_init() function. 112 | - Fixed several bugs. 113 | - API documentation. 114 | 115 | 116 | 2007-09-20 Naoaki Okazaki 117 | 118 | * libLBFGS 1.0 119 | - Initial release. 120 | 121 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiangliangNan/Manhattan/e296727ae48c5267ec4b23778dcea4f4065320a5/src/3rd_party/liblbfgs/NEWS -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/README: -------------------------------------------------------------------------------- 1 | 2 | libLBFGS: C library of limited-memory BFGS (L-BFGS) 3 | 4 | Copyright (c) 1990, Jorge Nocedal 5 | Copyright (c) 2007-2010, Naoaki Okazaki 6 | 7 | ========================================================================= 8 | 1. Introduction 9 | ========================================================================= 10 | libLBFGS is a C port of the implementation of Limited-memory 11 | Broyden-Fletcher-Goldfarb-Shanno (L-BFGS) method written by Jorge Nocedal. 12 | The original FORTRAN source code is available at: 13 | http://www.ece.northwestern.edu/~nocedal/lbfgs.html 14 | 15 | The L-BFGS method solves the unconstrainted minimization problem: 16 | minimize F(x), x = (x1, x2, ..., xN), 17 | only if the objective function F(x) and its gradient G(x) are computable. 18 | 19 | Refer to the libLBFGS web site for more information. 20 | http://www.chokkan.org/software/liblbfgs/ 21 | 22 | 23 | 24 | ========================================================================= 25 | 2. How to build 26 | ========================================================================= 27 | [Microsoft Visual Studio 2008] 28 | Open the solution file "lbfgs.sln" and build it. 29 | 30 | [GCC] 31 | $ ./configure 32 | $ make 33 | $ make install # To install libLBFGS library and header. 34 | 35 | 36 | 37 | ========================================================================= 38 | 3. Note on SSE/SSE2 optimization 39 | ========================================================================= 40 | This library has SSE/SSE2 optimization routines for vector arithmetic 41 | operations on Intel/AMD processors. The SSE2 routine is for 64 bit double 42 | values, and the SSE routine is for 32 bit float values. Since the default 43 | parameters in libLBFGS are tuned for double precision values, it may need 44 | to modify these parameters to use the SSE optimization routines. 45 | 46 | To use the SSE2 optimization routine, specify --enable-sse2 option to the 47 | configure script. 48 | 49 | $ ./configure --enable-sse2 50 | 51 | To build libLBFGS with SSE2 optimization enabled on Microsoft Visual 52 | Studio 2005, define USE_SSE and __SSE2__ symbols. 53 | 54 | Make sure to run libLBFGS on processors where SSE2 instrunctions are 55 | available. The library does not check the existence of SSE2 instructions. 56 | 57 | To package maintainers, 58 | 59 | Please do not enable SSE/SSE2 optimization routine. The library built 60 | with SSE/SSE2 optimization will crash without any notice when necessary 61 | SSE/SSE2 instructions are unavailable on CPUs. 62 | 63 | 64 | 65 | ========================================================================= 66 | 4. License 67 | ========================================================================= 68 | libLBFGS is distributed under the term of the MIT license. 69 | Please refer to COPYING file in the distribution. 70 | 71 | $Id$ 72 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/doc/footer.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | Copyright (c) 2002-2014 by Naoaki Okazaki 4 |
$datetime 5 |
6 | 7 | 8 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/doc/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | libLBFGS: L-BFGS library written in C 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/lib/arithmetic_ansi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ANSI C implementation of vector operations. 3 | * 4 | * Copyright (c) 2007-2010 Naoaki Okazaki 5 | * All rights reserved. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | /* $Id$ */ 27 | 28 | #include 29 | #include 30 | 31 | #if LBFGS_FLOAT == 32 && LBFGS_IEEE_FLOAT 32 | #define fsigndiff(x, y) (((*(uint32_t*)(x)) ^ (*(uint32_t*)(y))) & 0x80000000U) 33 | #else 34 | #define fsigndiff(x, y) (*(x) * (*(y) / fabs(*(y))) < 0.) 35 | #endif/*LBFGS_IEEE_FLOAT*/ 36 | 37 | inline static void* vecalloc(size_t size) 38 | { 39 | void *memblock = malloc(size); 40 | if (memblock) { 41 | memset(memblock, 0, size); 42 | } 43 | return memblock; 44 | } 45 | 46 | inline static void vecfree(void *memblock) 47 | { 48 | free(memblock); 49 | } 50 | 51 | inline static void vecset(lbfgsfloatval_t *x, const lbfgsfloatval_t c, const int n) 52 | { 53 | int i; 54 | 55 | for (i = 0;i < n;++i) { 56 | x[i] = c; 57 | } 58 | } 59 | 60 | inline static void veccpy(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const int n) 61 | { 62 | int i; 63 | 64 | for (i = 0;i < n;++i) { 65 | y[i] = x[i]; 66 | } 67 | } 68 | 69 | inline static void vecncpy(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const int n) 70 | { 71 | int i; 72 | 73 | for (i = 0;i < n;++i) { 74 | y[i] = -x[i]; 75 | } 76 | } 77 | 78 | inline static void vecadd(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const lbfgsfloatval_t c, const int n) 79 | { 80 | int i; 81 | 82 | for (i = 0;i < n;++i) { 83 | y[i] += c * x[i]; 84 | } 85 | } 86 | 87 | inline static void vecdiff(lbfgsfloatval_t *z, const lbfgsfloatval_t *x, const lbfgsfloatval_t *y, const int n) 88 | { 89 | int i; 90 | 91 | for (i = 0;i < n;++i) { 92 | z[i] = x[i] - y[i]; 93 | } 94 | } 95 | 96 | inline static void vecscale(lbfgsfloatval_t *y, const lbfgsfloatval_t c, const int n) 97 | { 98 | int i; 99 | 100 | for (i = 0;i < n;++i) { 101 | y[i] *= c; 102 | } 103 | } 104 | 105 | inline static void vecmul(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const int n) 106 | { 107 | int i; 108 | 109 | for (i = 0;i < n;++i) { 110 | y[i] *= x[i]; 111 | } 112 | } 113 | 114 | inline static void vecdot(lbfgsfloatval_t* s, const lbfgsfloatval_t *x, const lbfgsfloatval_t *y, const int n) 115 | { 116 | int i; 117 | *s = 0.; 118 | for (i = 0;i < n;++i) { 119 | *s += x[i] * y[i]; 120 | } 121 | } 122 | 123 | inline static void vec2norm(lbfgsfloatval_t* s, const lbfgsfloatval_t *x, const int n) 124 | { 125 | vecdot(s, x, x, n); 126 | *s = (lbfgsfloatval_t)sqrt(*s); 127 | } 128 | 129 | inline static void vec2norminv(lbfgsfloatval_t* s, const lbfgsfloatval_t *x, const int n) 130 | { 131 | vec2norm(s, x, n); 132 | *s = (lbfgsfloatval_t)(1.0 / *s); 133 | } 134 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/sample/Makefile.am: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | 3 | EXTRA_DIST = \ 4 | sample.cpp \ 5 | sample.vcxproj 6 | 7 | noinst_PROGRAMS = sample 8 | 9 | sample_SOURCES = \ 10 | sample.c 11 | 12 | sample_LDADD = ../lib/liblbfgs.la 13 | 14 | AM_CFLAGS = @CFLAGS@ 15 | INCLUDES = @INCLUDES@ 16 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/sample/sample.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static lbfgsfloatval_t evaluate( 5 | void *instance, 6 | const lbfgsfloatval_t *x, 7 | lbfgsfloatval_t *g, 8 | const int n, 9 | const lbfgsfloatval_t step 10 | ) 11 | { 12 | int i; 13 | lbfgsfloatval_t fx = 0.0; 14 | 15 | for (i = 0;i < n;i += 2) { 16 | lbfgsfloatval_t t1 = 1.0 - x[i]; 17 | lbfgsfloatval_t t2 = 10.0 * (x[i+1] - x[i] * x[i]); 18 | g[i+1] = 20.0 * t2; 19 | g[i] = -2.0 * (x[i] * g[i+1] + t1); 20 | fx += t1 * t1 + t2 * t2; 21 | } 22 | return fx; 23 | } 24 | 25 | static int progress( 26 | void *instance, 27 | const lbfgsfloatval_t *x, 28 | const lbfgsfloatval_t *g, 29 | const lbfgsfloatval_t fx, 30 | const lbfgsfloatval_t xnorm, 31 | const lbfgsfloatval_t gnorm, 32 | const lbfgsfloatval_t step, 33 | int n, 34 | int k, 35 | int ls 36 | ) 37 | { 38 | printf("Iteration %d:\n", k); 39 | printf(" fx = %f, x[0] = %f, x[1] = %f\n", fx, x[0], x[1]); 40 | printf(" xnorm = %f, gnorm = %f, step = %f\n", xnorm, gnorm, step); 41 | printf("\n"); 42 | return 0; 43 | } 44 | 45 | #define N 100 46 | 47 | int main(int argc, char *argv[]) 48 | { 49 | int i, ret = 0; 50 | lbfgsfloatval_t fx; 51 | lbfgsfloatval_t *x = lbfgs_malloc(N); 52 | lbfgs_parameter_t param; 53 | 54 | if (x == NULL) { 55 | printf("ERROR: Failed to allocate a memory block for variables.\n"); 56 | return 1; 57 | } 58 | 59 | /* Initialize the variables. */ 60 | for (i = 0;i < N;i += 2) { 61 | x[i] = -1.2; 62 | x[i+1] = 1.0; 63 | } 64 | 65 | /* Initialize the parameters for the L-BFGS optimization. */ 66 | lbfgs_parameter_init(¶m); 67 | /*param.linesearch = LBFGS_LINESEARCH_BACKTRACKING;*/ 68 | 69 | /* 70 | Start the L-BFGS optimization; this will invoke the callback functions 71 | evaluate() and progress() when necessary. 72 | */ 73 | ret = lbfgs(N, x, &fx, evaluate, progress, NULL, ¶m); 74 | 75 | /* Report the result. */ 76 | printf("L-BFGS optimization terminated with status code = %d\n", ret); 77 | printf(" fx = %f, x[0] = %f, x[1] = %f\n", fx, x[0], x[1]); 78 | 79 | lbfgs_free(x); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/sample/sample.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class objective_function 5 | { 6 | protected: 7 | lbfgsfloatval_t *m_x; 8 | 9 | public: 10 | objective_function() : m_x(NULL) 11 | { 12 | } 13 | 14 | virtual ~objective_function() 15 | { 16 | if (m_x != NULL) { 17 | lbfgs_free(m_x); 18 | m_x = NULL; 19 | } 20 | } 21 | 22 | int run(int N) 23 | { 24 | lbfgsfloatval_t fx; 25 | lbfgsfloatval_t *m_x = lbfgs_malloc(N); 26 | 27 | if (m_x == NULL) { 28 | printf("ERROR: Failed to allocate a memory block for variables.\n"); 29 | return 1; 30 | } 31 | 32 | /* Initialize the variables. */ 33 | for (int i = 0;i < N;i += 2) { 34 | m_x[i] = -1.2; 35 | m_x[i+1] = 1.0; 36 | } 37 | 38 | /* 39 | Start the L-BFGS optimization; this will invoke the callback functions 40 | evaluate() and progress() when necessary. 41 | */ 42 | int ret = lbfgs(N, m_x, &fx, _evaluate, _progress, this, NULL); 43 | 44 | /* Report the result. */ 45 | printf("L-BFGS optimization terminated with status code = %d\n", ret); 46 | printf(" fx = %f, x[0] = %f, x[1] = %f\n", fx, m_x[0], m_x[1]); 47 | 48 | return ret; 49 | } 50 | 51 | protected: 52 | static lbfgsfloatval_t _evaluate( 53 | void *instance, 54 | const lbfgsfloatval_t *x, 55 | lbfgsfloatval_t *g, 56 | const int n, 57 | const lbfgsfloatval_t step 58 | ) 59 | { 60 | return reinterpret_cast(instance)->evaluate(x, g, n, step); 61 | } 62 | 63 | lbfgsfloatval_t evaluate( 64 | const lbfgsfloatval_t *x, 65 | lbfgsfloatval_t *g, 66 | const int n, 67 | const lbfgsfloatval_t step 68 | ) 69 | { 70 | lbfgsfloatval_t fx = 0.0; 71 | 72 | for (int i = 0;i < n;i += 2) { 73 | lbfgsfloatval_t t1 = 1.0 - x[i]; 74 | lbfgsfloatval_t t2 = 10.0 * (x[i+1] - x[i] * x[i]); 75 | g[i+1] = 20.0 * t2; 76 | g[i] = -2.0 * (x[i] * g[i+1] + t1); 77 | fx += t1 * t1 + t2 * t2; 78 | } 79 | return fx; 80 | } 81 | 82 | static int _progress( 83 | void *instance, 84 | const lbfgsfloatval_t *x, 85 | const lbfgsfloatval_t *g, 86 | const lbfgsfloatval_t fx, 87 | const lbfgsfloatval_t xnorm, 88 | const lbfgsfloatval_t gnorm, 89 | const lbfgsfloatval_t step, 90 | int n, 91 | int k, 92 | int ls 93 | ) 94 | { 95 | return reinterpret_cast(instance)->progress(x, g, fx, xnorm, gnorm, step, n, k, ls); 96 | } 97 | 98 | int progress( 99 | const lbfgsfloatval_t *x, 100 | const lbfgsfloatval_t *g, 101 | const lbfgsfloatval_t fx, 102 | const lbfgsfloatval_t xnorm, 103 | const lbfgsfloatval_t gnorm, 104 | const lbfgsfloatval_t step, 105 | int n, 106 | int k, 107 | int ls 108 | ) 109 | { 110 | printf("Iteration %d:\n", k); 111 | printf(" fx = %f, x[0] = %f, x[1] = %f\n", fx, x[0], x[1]); 112 | printf(" xnorm = %f, gnorm = %f, step = %f\n", xnorm, gnorm, step); 113 | printf("\n"); 114 | return 0; 115 | } 116 | }; 117 | 118 | 119 | 120 | #define N 100 121 | 122 | int main(int argc, char *argv) 123 | { 124 | objective_function obj; 125 | return obj.run(N); 126 | } 127 | -------------------------------------------------------------------------------- /src/3rd_party/liblbfgs/sample/sample.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {B4D7D5F5-4A4E-49D5-B38A-E5673520DE66} 15 | sample 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | Unicode 22 | true 23 | v140 24 | 25 | 26 | Application 27 | Unicode 28 | v140 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>10.0.30319.1 42 | $(SolutionDir)$(Configuration)\ 43 | $(Configuration)\ 44 | true 45 | $(SolutionDir)$(Configuration)\ 46 | $(Configuration)\ 47 | false 48 | AllRules.ruleset 49 | 50 | 51 | AllRules.ruleset 52 | 53 | 54 | 55 | 56 | 57 | Disabled 58 | $(SolutionDir)include;%(AdditionalIncludeDirectories) 59 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 60 | true 61 | EnableFastChecks 62 | MultiThreadedDebugDLL 63 | 64 | 65 | Level3 66 | EditAndContinue 67 | 68 | 69 | true 70 | Console 71 | MachineX86 72 | 73 | 74 | 75 | 76 | MaxSpeed 77 | true 78 | $(SolutionDir)include;%(AdditionalIncludeDirectories) 79 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 80 | MultiThreadedDLL 81 | true 82 | 83 | 84 | Level3 85 | ProgramDatabase 86 | 87 | 88 | true 89 | Console 90 | true 91 | true 92 | MachineX86 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | {c4405b73-a899-44bf-8681-04ce040b6705} 101 | false 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | # specify the C++ standard 4 | set(CMAKE_CXX_STANDARD 11) 5 | 6 | get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) 7 | project(${PROJECT_NAME}) 8 | 9 | 10 | ### Configuration 11 | set(MANHATTAN_ROOT ${CMAKE_CURRENT_LIST_DIR}) 12 | set(MANHATTAN_EXTERNAL ${MANHATTAN_ROOT}/3rd_party) 13 | set(MANHATTAN_EXTERNAL_cminpack_DIR ${MANHATTAN_EXTERNAL}/cminpack-1.3.6) 14 | set(MANHATTAN_EXTERNAL_liblbfgs_DIR ${MANHATTAN_EXTERNAL}/liblbfgs) 15 | set(MANHATTAN_optimizer_DIR ${MANHATTAN_ROOT}/optimizer) 16 | 17 | add_subdirectory(3rd_party) 18 | add_subdirectory(optimizer) 19 | add_subdirectory(Manhattan) -------------------------------------------------------------------------------- /src/Manhattan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | # specify the C++ standard 4 | set(CMAKE_CXX_STANDARD 11) 5 | 6 | get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) 7 | project(${PROJECT_NAME}) 8 | 9 | # request Easy3D 10 | find_package(Easy3D COMPONENTS viewer REQUIRED) 11 | 12 | add_executable(${PROJECT_NAME} 13 | main.cpp 14 | manhattan.h 15 | manhattan.cpp 16 | ) 17 | 18 | target_include_directories(${PROJECT_NAME} PRIVATE ${MANHATTAN_optimizer_DIR}) 19 | 20 | # link to the viewer module of Easy3D 21 | target_link_libraries(${PROJECT_NAME} easy3d::viewer optimizer) 22 | -------------------------------------------------------------------------------- /src/Manhattan/main.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * Copyright (C) 2015 Liangliang Nan 3 | * https://3d.bk.tudelft.nl/liangliang/ 4 | * 5 | * This file is part of Easy3D. If it is useful in your research/work, 6 | * I would be grateful if you show your appreciation by citing it: 7 | * ------------------------------------------------------------------ 8 | * Liangliang Nan. 9 | * Easy3D: a lightweight, easy-to-use, and efficient C++ library 10 | * for processing and rendering 3D data. 11 | * Journal of Open Source Software, 6(64), 3255, 2021. 12 | * ------------------------------------------------------------------ 13 | * 14 | * Easy3D is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License Version 3 16 | * as published by the Free Software Foundation. 17 | * 18 | * Easy3D is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program. If not, see . 25 | ********************************************************************/ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "manhattan.h" 33 | 34 | using namespace easy3d; 35 | 36 | 37 | int main(int argc, char** argv) { 38 | // Initialize Easy3D. 39 | initialize(); 40 | 41 | MultiViewer viewer(2, 2, "Manhattan"); 42 | viewer.set_usage("drag the mouse to rotate the model"); 43 | 44 | // load the model 45 | const std::string model_file = std::string(DATA_DIR) + "/model1.obj"; 46 | auto model = viewer.add_model(model_file); 47 | if (!model) { 48 | LOG(ERROR) << "failed to load model from file: " << model_file; 49 | return EXIT_FAILURE; 50 | } 51 | 52 | auto input_mesh = dynamic_cast(model); 53 | if (!input_mesh) { 54 | LOG(ERROR) << "the loaded model is not a surface mesh"; 55 | return EXIT_FAILURE; 56 | } 57 | 58 | // --------------------------------------------------------------------------- 59 | // now we Manhattanize the input mesh 60 | auto output_mesh = new SurfaceMesh(*input_mesh); // make a copy of the input mesh 61 | Manhattan::apply(output_mesh); // Manhattanize the mesh 62 | output_mesh->set_name("result"); 63 | viewer.add_model(std::shared_ptr(output_mesh)); // add the mesh to the viewer, so input and output are shown next to each other 64 | 65 | // --------------------------------------------------------------------------- 66 | // setup content for view(0, 0): the surface of the input mesh (this is the default behavior) 67 | viewer.assign(0, 0, input_mesh); 68 | 69 | // --------------------------------------------------------------------------- 70 | // setup content for view(1, 0): the wireframe of the input mesh 71 | auto input_wireframe = input_mesh->renderer()->get_lines_drawable("edges"); 72 | input_wireframe->set_impostor_type(LinesDrawable::CYLINDER); 73 | input_wireframe->set_line_width(2); 74 | input_wireframe->set_uniform_coloring(vec4(0.7f, 0.7f, 1.0f, 1.0f)); 75 | input_wireframe->set_visible(true); // by default wireframe is hidden 76 | viewer.assign(1, 0, input_wireframe); 77 | 78 | // --------------------------------------------------------------------------- 79 | // setup content for view(0, 1): the surface of the output mesh (this is the default behavior) 80 | viewer.assign(0, 1, output_mesh); 81 | 82 | // --------------------------------------------------------------------------- 83 | // setup content for view(1, 1): the wireframe of the output mesh 84 | auto output_wireframe = output_mesh->renderer()->get_lines_drawable("edges"); 85 | output_wireframe->set_impostor_type(LinesDrawable::CYLINDER); 86 | output_wireframe->set_line_width(2); 87 | output_wireframe->set_uniform_coloring(vec4(0.7f, 0.7f, 1.0f, 1.0f)); 88 | output_wireframe->set_visible(true); // by default wireframe is hidden 89 | viewer.assign(1, 1, output_wireframe); 90 | 91 | // --------------------------------------------------------------------------- 92 | 93 | return viewer.run(); 94 | } 95 | -------------------------------------------------------------------------------- /src/Manhattan/manhattan.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * Copyright (C) 2015 Liangliang Nan 3 | * https://3d.bk.tudelft.nl/liangliang/ 4 | * 5 | * This file is part of Easy3D. If it is useful in your research/work, 6 | * I would be grateful if you show your appreciation by citing it: 7 | * ------------------------------------------------------------------ 8 | * Liangliang Nan. 9 | * Easy3D: a lightweight, easy-to-use, and efficient C++ library 10 | * for processing and rendering 3D data. 11 | * Journal of Open Source Software, 6(64), 3255, 2021. 12 | * ------------------------------------------------------------------ 13 | * 14 | * Easy3D is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License Version 3 16 | * as published by the Free Software Foundation. 17 | * 18 | * Easy3D is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program. If not, see . 25 | ********************************************************************/ 26 | 27 | #ifndef EASY3D_SURFACE_MESH_MANHATTAN_H 28 | #define EASY3D_SURFACE_MESH_MANHATTAN_H 29 | 30 | 31 | namespace easy3d { 32 | 33 | class SurfaceMesh; 34 | 35 | /// Manhattan makes a noisy Manhattan-world surface mesh (near) perfect, i.e., 36 | /// - near orthogonal consecutive edges orthogonal 37 | /// - polygonal faces planar 38 | /// Note: triangle meshes cannot be processed. 39 | class Manhattan { 40 | public: 41 | static void apply( 42 | SurfaceMesh *mesh, 43 | double ortho_thresh = 0.2, // threshold for two subsequent edges to be orthogonal. It is abs(dot product) of two edge vectors (normalized) 44 | double w_orig_pos = 1.0, // weight for preventing vertices from deviating from their original positions 45 | double w_ortho = 500.0, // weight for the orthogonality energy term 46 | double w_facet_planar = 500.0 // weight for the face planarity energy term 47 | ); 48 | }; 49 | } 50 | 51 | #endif // EASY3D_SURFACE_MESH_MANHATTAN_H -------------------------------------------------------------------------------- /src/optimizer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) 4 | project(${PROJECT_NAME}) 5 | 6 | 7 | set(optimizer_HEADERS 8 | optimizer_lbfgs.h 9 | optimizer_lm.h 10 | ) 11 | 12 | set(optimizer_SOURCES 13 | optimizer_lbfgs.cpp 14 | optimizer_lm.cpp 15 | ) 16 | 17 | add_library(${PROJECT_NAME} STATIC ${optimizer_SOURCES} ${optimizer_HEADERS}) 18 | 19 | target_include_directories(${PROJECT_NAME} PRIVATE 20 | ${MANHATTAN_optimizer_DIR} 21 | ${MANHATTAN_EXTERNAL_cminpack_DIR} 22 | ${MANHATTAN_EXTERNAL_liblbfgs_DIR} 23 | ) 24 | 25 | target_link_libraries(${PROJECT_NAME} PRIVATE 3rd_liblbfgs 3rd_cminpack) 26 | -------------------------------------------------------------------------------- /src/optimizer/optimizer_lbfgs.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * Copyright (C) 2015 Liangliang Nan 3 | * https://3d.bk.tudelft.nl/liangliang/ 4 | * 5 | * This file is part of Easy3D. If it is useful in your research/work, 6 | * I would be grateful if you show your appreciation by citing it: 7 | * ------------------------------------------------------------------ 8 | * Liangliang Nan. 9 | * Easy3D: a lightweight, easy-to-use, and efficient C++ library 10 | * for processing and rendering 3D data. 11 | * Journal of Open Source Software, 6(64), 3255, 2021. 12 | * ------------------------------------------------------------------ 13 | * 14 | * Easy3D is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License Version 3 16 | * as published by the Free Software Foundation. 17 | * 18 | * Easy3D is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program. If not, see . 25 | ********************************************************************/ 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | 34 | Objective_LBFGS::Objective_LBFGS(const int n, void* data) 35 | : num_var_(n) 36 | , data_(data) 37 | {} 38 | 39 | 40 | Objective_LBFGS::~Objective_LBFGS() 41 | {} 42 | 43 | 44 | double Objective_LBFGS::evaluate(const double *x, double *g) 45 | { 46 | double fx = 0.0; 47 | for (int i = 0; i < num_var_; i += 2) { 48 | double t1 = 1.0 - x[i]; 49 | double t2 = 10.0 * (x[i+1] - x[i] * x[i]); 50 | g[i+1] = 20.0 * t2; 51 | g[i] = -2.0 * (x[i] * g[i+1] + t1); 52 | fx += t1 * t1 + t2 * t2; 53 | } 54 | return fx; 55 | } 56 | 57 | 58 | 59 | 60 | Optimizer_LBFGS::Optimizer_LBFGS() 61 | : obj_value_(std::numeric_limits::max()) 62 | , iteration_(0) 63 | , func_(nullptr) 64 | { 65 | } 66 | 67 | 68 | Optimizer_LBFGS::~Optimizer_LBFGS() 69 | { 70 | } 71 | 72 | 73 | bool Optimizer_LBFGS::run(Objective_LBFGS* func, int N, double* x) 74 | { 75 | func_ = func; 76 | obj_value_ = std::numeric_limits::max(); 77 | iteration_ = 0; 78 | 79 | auto _evaluate = [](void *instance, const double *x, double *g, const int n, const double step) -> double { 80 | return reinterpret_cast(instance)->func_->evaluate(x, g); 81 | }; 82 | 83 | auto _progress = [](void *instance, const double *x, const double *g, const double fx, 84 | const double xnorm, const double gnorm, const double step, int n, int k, int ls) -> int { 85 | return reinterpret_cast(instance)->progress(x, g, fx, xnorm, gnorm, step, n, k, ls); 86 | }; 87 | 88 | /* 89 | Start the L-BFGS optimization; this will invoke the callback functions 90 | evaluate() and progress() when necessary. 91 | */ 92 | obj_value_ = 0.0; 93 | int ret = lbfgs(N, x, &obj_value_, _evaluate, _progress, this, nullptr); 94 | 95 | /* Report the result. */ 96 | if (ret == 0) { 97 | printf("L-BFGS optimization terminated with status code = %d (successful). num_iter = %d\n", ret, iteration_); 98 | return true; 99 | } 100 | else { 101 | printf("L-BFGS optimization terminated with status code = %d (failed). num_iter = %d\n", ret, iteration_); 102 | return false; 103 | } 104 | } 105 | 106 | 107 | bool Optimizer_LBFGS::run(Objective_LBFGS* func, int N, std::vector& x) { 108 | return run(func, N, x.data()); 109 | } 110 | 111 | 112 | double Optimizer_LBFGS::objective() const { 113 | return obj_value_; 114 | } 115 | 116 | 117 | int Optimizer_LBFGS::progress( 118 | const double *x, 119 | const double *g, 120 | const double fx, 121 | const double xnorm, 122 | const double gnorm, 123 | const double step, 124 | int n, 125 | int k, 126 | int ls 127 | ) 128 | { 129 | iteration_ = k; 130 | 131 | #if 0 132 | printf("Iteration %d:\n", k); 133 | printf(" fx = %f, x[0] = %f, x[1] = %f, g[0] = %f, g[1] = %f\n", fx, x[0], x[1], g[0], g[1]); 134 | printf(" xnorm = %f, gnorm = %f, step = %f\n", xnorm, gnorm, step); 135 | printf("\n"); 136 | #else 137 | printf("Iteration %d: fx = %f, xnorm = %f, gnorm = %f\n", k, fx, xnorm, gnorm); 138 | #endif 139 | 140 | return 0; 141 | } 142 | -------------------------------------------------------------------------------- /src/optimizer/optimizer_lbfgs.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * Copyright (C) 2015 Liangliang Nan 3 | * https://3d.bk.tudelft.nl/liangliang/ 4 | * 5 | * This file is part of Easy3D. If it is useful in your research/work, 6 | * I would be grateful if you show your appreciation by citing it: 7 | * ------------------------------------------------------------------ 8 | * Liangliang Nan. 9 | * Easy3D: a lightweight, easy-to-use, and efficient C++ library 10 | * for processing and rendering 3D data. 11 | * Journal of Open Source Software, 6(64), 3255, 2021. 12 | * ------------------------------------------------------------------ 13 | * 14 | * Easy3D is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License Version 3 16 | * as published by the Free Software Foundation. 17 | * 18 | * Easy3D is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program. If not, see . 25 | ********************************************************************/ 26 | 27 | #ifndef MANHATTAN_OPTIMIZER_LBFGS_H 28 | #define MANHATTAN_OPTIMIZER_LBFGS_H 29 | 30 | #include 31 | 32 | 33 | // objective function, allowing user problem to inherit from it. 34 | class Objective_LBFGS 35 | { 36 | public: 37 | 38 | /** 39 | * Constructor. 40 | * @param n The number of variables. 41 | * @param data The user data sent to lbfgs() function by the client. 42 | */ 43 | Objective_LBFGS(const int n, void* data = nullptr); 44 | 45 | virtual ~Objective_LBFGS(); 46 | 47 | /** 48 | * Evaluate the values of the objective function and its gradients, given current values of variables. 49 | * This function will be called internally by the lbfgs() function when needed. 50 | * @param x The current values of variables. 51 | * @param g The gradient vector. 52 | * @return The value of the objective function for the current variables. 53 | * @example The following code implements this function that aims at minimizing the Rosenbrock function: 54 | * @code 55 | * double fx = 0.0; 56 | * for (int i = 0; i < num_var_; i += 2) { 57 | * double t1 = 1.0 - x[i]; 58 | * double t2 = 10.0 * (x[i+1] - x[i] * x[i]); 59 | * g[i+1] = 20.0 * t2; 60 | * g[i] = -2.0 * (x[i] * g[i+1] + t1); 61 | * fx += t1 * t1 + t2 * t2; 62 | * } 63 | * return fx; 64 | * @endcode 65 | */ 66 | inline virtual double evaluate(const double *x, double *g) = 0; 67 | 68 | private: 69 | int num_var_; 70 | void* data_; 71 | }; 72 | 73 | 74 | // More optimizers are available in ALGLIB 75 | 76 | class Optimizer_LBFGS 77 | { 78 | public: 79 | Optimizer_LBFGS(); 80 | virtual ~Optimizer_LBFGS(); 81 | 82 | /** 83 | * The core function that minimizes the objective function. 84 | * @param func the objective function. 85 | * @param n number of variables 86 | * @param x the variables which provide the initial guess and return the results. 87 | * @return ture on success and false on failure. 88 | */ 89 | bool run(Objective_LBFGS* func, int n, double* x); 90 | bool run(Objective_LBFGS* func, int n, std::vector& x); 91 | 92 | /// on success, allow user to query the final value of the objective function. 93 | double objective() const; 94 | 95 | /// on success, allow user to query the number of iterations of the optimization process 96 | int iterations() const; 97 | 98 | protected: 99 | 100 | /* The interface to receive the progress of the optimization process. 101 | * The function returns zero to continue the optimization process. 102 | * Returning a non-zero value will cancel the optimization process. 103 | */ 104 | virtual int progress( 105 | const double *x, // The current values of variables. 106 | const double *g, // The current gradient values of variables. 107 | const double fx, // The current value of the objective function. 108 | const double xnorm, // The Euclidean norm of the variables. 109 | const double gnorm, // The Euclidean norm of the gradients. 110 | const double step, // The line-search step used for this iteration. 111 | int n, // The number of variables. 112 | int k, // The iteration count. 113 | int ls // The number of evaluations called for this iteration. 114 | ); 115 | 116 | protected: 117 | double obj_value_; 118 | int iteration_; 119 | Objective_LBFGS* func_; 120 | 121 | private: 122 | //copying disabled 123 | Optimizer_LBFGS(const Optimizer_LBFGS&); 124 | Optimizer_LBFGS& operator=(const Optimizer_LBFGS&); 125 | }; 126 | 127 | 128 | #endif // MANHATTAN_OPTIMIZER_LBFGS_H 129 | -------------------------------------------------------------------------------- /src/optimizer/optimizer_lm.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * Copyright (C) 2015 Liangliang Nan 3 | * https://3d.bk.tudelft.nl/liangliang/ 4 | * 5 | * This file is part of Easy3D. If it is useful in your research/work, 6 | * I would be grateful if you show your appreciation by citing it: 7 | * ------------------------------------------------------------------ 8 | * Liangliang Nan. 9 | * Easy3D: a lightweight, easy-to-use, and efficient C++ library 10 | * for processing and rendering 3D data. 11 | * Journal of Open Source Software, 6(64), 3255, 2021. 12 | * ------------------------------------------------------------------ 13 | * 14 | * Easy3D is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License Version 3 16 | * as published by the Free Software Foundation. 17 | * 18 | * Easy3D is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program. If not, see . 25 | ********************************************************************/ 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | 33 | Objective_LM::Objective_LM(int num_func, int num_var, void* data) 34 | : num_func_(num_func) 35 | , num_var_(num_var) 36 | , data_(data) 37 | {} 38 | 39 | 40 | Objective_LM::~Objective_LM() 41 | {} 42 | 43 | 44 | int Objective_LM::evaluate(const double *x, double *fvec) 45 | { 46 | fvec[0] = x[0] - 1.0; 47 | fvec[1] = x[1] - 1.0; 48 | return 0; 49 | } 50 | 51 | 52 | 53 | Optimizer_LM::Optimizer_LM() { 54 | } 55 | 56 | 57 | Optimizer_LM::~Optimizer_LM() { 58 | 59 | } 60 | 61 | 62 | Optimizer_LM::Parameters::Parameters() { 63 | maxcall = 10000; 64 | epsilon = 1.e-14; 65 | stepbound = 100.; 66 | ftol = 1.e-14; 67 | xtol = 1.e-14; 68 | gtol = 1.e-14; 69 | nprint = 0; 70 | } 71 | 72 | 73 | bool Optimizer_LM::run(Objective_LM *func, double *x, Parameters *param) 74 | { 75 | // use default parameter if ctrl == 0 76 | if (!param) 77 | param = &default_control_; 78 | 79 | func_ = func; 80 | 81 | // *** allocate work space. 82 | 83 | double *fvec, *diag, *fjac, *qtf, *wa1, *wa2, *wa3, *wa4; 84 | int *ipvt; 85 | 86 | int m = func->num_function(); 87 | int n = func->num_variables(); 88 | 89 | if (!(fvec = new double[m]) || !(diag = new double[n]) || !(qtf = new double[n]) || 90 | !(fjac = new double[n*m]) || !(wa1 = new double[n]) || !(wa2 = new double[n]) || 91 | !(wa3 = new double[n]) || !(wa4 = new double[m]) || !(ipvt = new int[n])) 92 | { 93 | if (fvec) delete[](fvec); 94 | if (diag) delete[](diag); 95 | if (qtf) delete[](qtf); 96 | if (fjac) delete[](fjac); 97 | if (wa1) delete[](wa1); 98 | if (wa2) delete[](wa2); 99 | if (wa3) delete[](wa3); 100 | if (wa4) delete[](wa4); 101 | if (ipvt) delete[](ipvt); 102 | 103 | param->info = 9; 104 | return false; 105 | } 106 | 107 | // *** perform fit. 108 | 109 | param->info = 0; 110 | param->nfev = 0; 111 | 112 | auto evaluate_func = [](void *instance, int num_fun, int num_var, const double* var, double* fvec, int iflag) ->int { 113 | return reinterpret_cast(instance)->func_->evaluate(var, fvec); 114 | }; 115 | 116 | // this goes through the modified legacy interface: 117 | param->info = 118 | lmdif( 119 | evaluate_func, 120 | this, 121 | m, 122 | n, 123 | x, 124 | fvec, 125 | param->ftol, 126 | param->xtol, 127 | param->gtol, 128 | param->maxcall*(n + 1), 129 | param->epsilon, 130 | diag, 131 | 1, 132 | param->stepbound, 133 | param->nprint, 134 | &(param->nfev), 135 | fjac, 136 | m, 137 | ipvt, 138 | qtf, 139 | wa1, 140 | wa2, 141 | wa3, 142 | wa4 143 | ); 144 | 145 | if (param->info >= 8) 146 | param->info = 4; 147 | 148 | // *** clean up. 149 | 150 | delete[](fvec); 151 | delete[](diag); 152 | delete[](qtf); 153 | delete[](fjac); 154 | delete[](wa1); 155 | delete[](wa2); 156 | delete[](wa3); 157 | delete[](wa4); 158 | delete[](ipvt); 159 | 160 | printf("LM optimization terminated with status code = %d. num_iter = %d\n", param->info, param->nfev); 161 | 162 | return true; 163 | } 164 | 165 | 166 | bool Optimizer_LM::run(Objective_LM *func, std::vector& x, Parameters *param) { 167 | return run(func, x.data(), param); 168 | } 169 | --------------------------------------------------------------------------------