diff --git a/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.h b/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.h index 0d6f509f188..0fff5ef4aea 100644 --- a/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.h +++ b/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.h @@ -22,7 +22,7 @@ #include "ITKOptimizersv4Export.h" #include -#include "lbfgs.h" +#include "itk_lbfgs.h" namespace itk { diff --git a/Modules/ThirdParty/libLBFGS/CMakeLists.txt b/Modules/ThirdParty/libLBFGS/CMakeLists.txt index 4014a511fbb..1d4179167e7 100644 --- a/Modules/ThirdParty/libLBFGS/CMakeLists.txt +++ b/Modules/ThirdParty/libLBFGS/CMakeLists.txt @@ -13,9 +13,14 @@ set(ITKLIBLBFGS_THIRD_PARTY 1) # set(ITKLIBLBFGS_NO_SRC 1) #else() -set(ITKLIBLBFGS_INCLUDE_DIRS ${ITKLIBLBFGS_SOURCE_DIR}/include ) +set(ITKLIBLBFGS_INCLUDE_DIRS ${ITKLIBLBFGS_SOURCE_DIR}/src) set(ITKLIBLBFGS_LIBRARIES itklbfgs) #endif() itk_module_impl() + +install(FILES ${ITKLIBLBFGS_SOURCE_DIR}/src/itk_lbfgs.h + DESTINATION ${ITKLIBLBFGS_INSTALL_INCLUDE_DIR} + COMPONENT Development + ) diff --git a/Modules/ThirdParty/libLBFGS/UpdateFromUpstream.sh b/Modules/ThirdParty/libLBFGS/UpdateFromUpstream.sh new file mode 100755 index 00000000000..d3665ab9aed --- /dev/null +++ b/Modules/ThirdParty/libLBFGS/UpdateFromUpstream.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -e +set -x +shopt -s dotglob + +readonly name="libLBFGS" +readonly ownership="libLBFGS Upstream " +readonly subtree="Modules/ThirdParty/libLBFGS/src/itklbfgs" +readonly repo="https://github.com/chokkan/liblbfgs.git" +readonly tag="v1.10" +readonly paths=" +COPYING +include/*.h +lib/*.c +lib/*.h +" + +extract_source () { + git_archive + pushd "${extractdir}/${name}-reduced" + echo "* -whitespace" >> .gitattributes + popd +} + +. "${BASH_SOURCE%/*}/../../../Utilities/Maintenance/update-third-party.bash" diff --git a/Modules/ThirdParty/libLBFGS/src/CMakeLists.txt b/Modules/ThirdParty/libLBFGS/src/CMakeLists.txt index 7babdc9462e..390dbcad0a0 100644 --- a/Modules/ThirdParty/libLBFGS/src/CMakeLists.txt +++ b/Modules/ThirdParty/libLBFGS/src/CMakeLists.txt @@ -1,25 +1,7 @@ -ADD_LIBRARY( itklbfgs - lbfgs.c -) - -IF(ITK_LIBRARY_PROPERTIES) - SET_TARGET_PROPERTIES(itklbfgs PROPERTIES ${ITK_LIBRARY_PROPERTIES}) -ENDIF(ITK_LIBRARY_PROPERTIES) - set(ITK3P_INSTALL_EXPORT_NAME "${ITKLIBLBFGS-targets}") set(ITK3P_INSTALL_INCLUDE_DIR "${ITKLIBLBFGS_INSTALL_INCLUDE_DIR}") set(ITK3P_INSTALL_RUNTIME_DIR "${ITKLIBLBFGS_INSTALL_RUNTIME_DIR}") set(ITK3P_INSTALL_LIBRARY_DIR "${ITKLIBLBFGS_INSTALL_LIBRARY_DIR}") set(ITK3P_INSTALL_ARCHIVE_DIR "${ITKLIBLBFGS_INSTALL_ARCHIVE_DIR}") - -IF(UNIX) - TARGET_LINK_LIBRARIES(itklbfgs m) -ENDIF(UNIX) - -INSTALL(TARGETS itklbfgs - EXPORT ${ITK3P_INSTALL_EXPORT_NAME} - RUNTIME DESTINATION ${ITK3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries - LIBRARY DESTINATION ${ITK3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries - ARCHIVE DESTINATION ${ITK3P_INSTALL_ARCHIVE_DIR} COMPONENT Development) - +add_subdirectory(itklbfgs) itk_module_target(itklbfgs NO_INSTALL) diff --git a/Modules/ThirdParty/libLBFGS/src/itk_lbfgs.h b/Modules/ThirdParty/libLBFGS/src/itk_lbfgs.h new file mode 100644 index 00000000000..3f55150d779 --- /dev/null +++ b/Modules/ThirdParty/libLBFGS/src/itk_lbfgs.h @@ -0,0 +1,27 @@ +/*========================================================================= + * + * Copyright NumFOCUS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ +/*========================================================================= + * Include file to wrap the internal ITK libLBFGS library header + *=========================================================================*/ + +#ifndef itk_lbfgs_h +#define itk_lbfgs_h + +#include + +#endif diff --git a/Modules/ThirdParty/libLBFGS/src/itklbfgs/.gitattributes b/Modules/ThirdParty/libLBFGS/src/itklbfgs/.gitattributes new file mode 100644 index 00000000000..562b12e16eb --- /dev/null +++ b/Modules/ThirdParty/libLBFGS/src/itklbfgs/.gitattributes @@ -0,0 +1 @@ +* -whitespace diff --git a/Modules/ThirdParty/libLBFGS/src/itklbfgs/CMakeLists.txt b/Modules/ThirdParty/libLBFGS/src/itklbfgs/CMakeLists.txt new file mode 100644 index 00000000000..41007f09388 --- /dev/null +++ b/Modules/ThirdParty/libLBFGS/src/itklbfgs/CMakeLists.txt @@ -0,0 +1,20 @@ +add_library(itklbfgs lib/lbfgs.c) +target_include_directories(itklbfgs PRIVATE include) + +if(ITK_LIBRARY_PROPERTIES) + set_target_properties(itklbfgs PROPERTIES ${ITK_LIBRARY_PROPERTIES}) +endif() + +if(UNIX) + target_link_libraries(itklbfgs m) +endif() + +install(TARGETS itklbfgs + EXPORT ${ITK3P_INSTALL_EXPORT_NAME} + RUNTIME DESTINATION ${ITK3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries + LIBRARY DESTINATION ${ITK3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries + ARCHIVE DESTINATION ${ITK3P_INSTALL_ARCHIVE_DIR} COMPONENT Development) + +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/include/lbfgs.h + DESTINATION ${ITK3P_INSTALL_INCLUDE_DIR}/itklbfgs/include) diff --git a/Modules/ThirdParty/libLBFGS/src/itklbfgs/COPYING b/Modules/ThirdParty/libLBFGS/src/itklbfgs/COPYING new file mode 100644 index 00000000000..406cbe215a6 --- /dev/null +++ b/Modules/ThirdParty/libLBFGS/src/itklbfgs/COPYING @@ -0,0 +1,22 @@ +The MIT License + +Copyright (c) 1990 Jorge Nocedal +Copyright (c) 2007-2010 Naoaki Okazaki + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Modules/ThirdParty/libLBFGS/include/lbfgs.h b/Modules/ThirdParty/libLBFGS/src/itklbfgs/include/lbfgs.h similarity index 99% rename from Modules/ThirdParty/libLBFGS/include/lbfgs.h rename to Modules/ThirdParty/libLBFGS/src/itklbfgs/include/lbfgs.h index 4a4ed0d2d93..cd944a3344f 100644 --- a/Modules/ThirdParty/libLBFGS/include/lbfgs.h +++ b/Modules/ThirdParty/libLBFGS/src/itklbfgs/include/lbfgs.h @@ -25,9 +25,6 @@ */ /* $Id$ */ -#ifdef USE_SSE -#include -#endif #ifndef __LBFGS_H__ #define __LBFGS_H__ @@ -62,7 +59,7 @@ typedef double lbfgsfloatval_t; #endif -/** +/** * \addtogroup liblbfgs_api libLBFGS API * @{ * @@ -71,7 +68,7 @@ typedef double lbfgsfloatval_t; /** * Return values of lbfgs(). - * + * * Roughly speaking, a negative value indicates an error. */ enum { @@ -368,7 +365,7 @@ typedef struct { * function and its gradients when needed. A client program must implement * this function to evaluate the values of the objective function and its * gradients, given current values of variables. - * + * * @param instance The user data sent for lbfgs() function by the client. * @param x The current values of variables. * @param g The gradient vector. The callback function must compute @@ -505,14 +502,14 @@ void lbfgs_parameter_init(lbfgs_parameter_t *param); * when libLBFGS is built with SSE/SSE2 optimization routines. A user does * not have to use this function for libLBFGS built without SSE/SSE2 * optimization. - * + * * @param n The number of variables. */ lbfgsfloatval_t* lbfgs_malloc(int n); /** * Free an array of variables. - * + * * @param x The array of variables allocated by ::lbfgs_malloc * function. */ diff --git a/Modules/ThirdParty/libLBFGS/src/arithmetic_ansi.h b/Modules/ThirdParty/libLBFGS/src/itklbfgs/lib/arithmetic_ansi.h similarity index 100% rename from Modules/ThirdParty/libLBFGS/src/arithmetic_ansi.h rename to Modules/ThirdParty/libLBFGS/src/itklbfgs/lib/arithmetic_ansi.h diff --git a/Modules/ThirdParty/libLBFGS/src/arithmetic_sse_double.h b/Modules/ThirdParty/libLBFGS/src/itklbfgs/lib/arithmetic_sse_double.h similarity index 100% rename from Modules/ThirdParty/libLBFGS/src/arithmetic_sse_double.h rename to Modules/ThirdParty/libLBFGS/src/itklbfgs/lib/arithmetic_sse_double.h diff --git a/Modules/ThirdParty/libLBFGS/src/arithmetic_sse_float.h b/Modules/ThirdParty/libLBFGS/src/itklbfgs/lib/arithmetic_sse_float.h similarity index 100% rename from Modules/ThirdParty/libLBFGS/src/arithmetic_sse_float.h rename to Modules/ThirdParty/libLBFGS/src/itklbfgs/lib/arithmetic_sse_float.h diff --git a/Modules/ThirdParty/libLBFGS/src/lbfgs.c b/Modules/ThirdParty/libLBFGS/src/itklbfgs/lib/lbfgs.c similarity index 99% rename from Modules/ThirdParty/libLBFGS/src/lbfgs.c rename to Modules/ThirdParty/libLBFGS/src/itklbfgs/lib/lbfgs.c index 7bf006b6f54..30ffcf2ab0b 100644 --- a/Modules/ThirdParty/libLBFGS/src/lbfgs.c +++ b/Modules/ThirdParty/libLBFGS/src/itklbfgs/lib/lbfgs.c @@ -65,7 +65,7 @@ licence. #include #endif/*HAVE_CONFIG_H*/ -//#include +#include #include #include #include @@ -132,7 +132,7 @@ typedef int (*line_search_proc)( callback_data_t *cd, const lbfgs_parameter_t *param ); - + static int line_search_backtracking( int n, lbfgsfloatval_t *x, @@ -1116,7 +1116,7 @@ static int line_search_morethuente( * @param brackt The pointer to the predicate if the trial value is * bracketed. * @retval int Status value. Zero indicates a normal termination. - * + * * @see * Jorge J. More and David J. Thuente. Line search algorithm with * guaranteed sufficient decrease. ACM Transactions on Mathematical @@ -1248,7 +1248,7 @@ static int update_trial_interval( x <- x, y <- t. - Case b: if f(t) <= f(x) && f'(t)*f'(x) > 0, x <- t, y <- y. - - Case c: if f(t) <= f(x) && f'(t)*f'(x) < 0, + - Case c: if f(t) <= f(x) && f'(t)*f'(x) < 0, x <- t, y <- x. */ if (*fx < *ft) {