From 6cf3485cf3fa5e2c9a835fdd7fcb143f935d199f Mon Sep 17 00:00:00 2001 From: Carl Philipp Klemm <philipp@uvos.xyz> Date: Fri, 26 May 2023 13:43:54 +0200 Subject: [PATCH] add pkgconfig support --- CMakeLists.txt | 7 +++++++ drt.cpp | 25 +++++++++++++++---------- eisdrt/types.h | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec5ecba..b263a8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,13 @@ if(DEFINED EIS_FOUND) endif(DEFINED TORCH_LIBRARIES) endif(DEFINED EIS_FOUND) +if(DEFINED PKGCONFIG_FOUND) + configure_file(pkgconfig/libeisdrt_torch.pc.in pkgconfig/libeisdrt_torch.pc @ONLY) + configure_file(pkgconfig/libeisdrt.pc.in pkgconfig/libeisdrt.pc @ONLY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libeisdrt_torch.pc DESTINATION lib/pkgconfig) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libeisdrt.pc DESTINATION lib/pkgconfig) +endif(DEFINED PKGCONFIG_FOUND) + set(API_HEADERS_DIR eisdrt/) set(API_HEADERS ${API_HEADERS_DIR}/eigendrt.h diff --git a/drt.cpp b/drt.cpp index a5f6e1a..6812217 100644 --- a/drt.cpp +++ b/drt.cpp @@ -19,6 +19,8 @@ // #include "eisdrt/eigendrt.h" +#include "eisdrt/types.h" +#include <stdexcept> #ifdef USE_EISGEN #include "eisdrt/eisdrt.h" @@ -117,17 +119,11 @@ public: int64_t size = x.size(); Eigen::Vector<fv, Eigen::Dynamic> xLeft = x.head(x.size()-1); - std::cout<<"aMatrixReal:\n"<<aMatrixReal<<"\nxLeft:\n"<<xLeft<<"\nx:\n"<<x<<std::endl; Eigen::Vector<fv, Eigen::Dynamic> t = aMatrixReal*xLeft; - std::cout<<"T1:\n"<<t<<std::endl; t = t - impedanceSpectra.real(); - std::cout<<"T2:\n"<<t<<std::endl; t = t.array() + x[size-1]; - std::cout<<"T3:\n"<<t<<std::endl; t = t.array().pow(2); - std::cout<<"T4:\n"<<t<<std::endl; fv MSE_re = t.sum(); - std::cout<<"T5:\n"<<MSE_re<<std::endl; t = (aMatrixImag*xLeft - impedanceSpectra.imag()).array().pow(2); fv MSE_im = t.sum(); @@ -155,7 +151,6 @@ public: fv operator()(Eigen::VectorX<fv>& x, Eigen::VectorX<fv>& grad) { grad = getGrad(std::bind(&RtFunct::function, this, std::placeholders::_1), x, epsilon); - std::cout<<"grad:\n"<<grad<<std::endl; return function(x); } }; @@ -187,14 +182,24 @@ Eigen::VectorX<fv> calcDrt(Eigen::VectorX<std::complex<fv>>& impedanceSpectra, E RtFunct<fv> funct(impedanceSpectra, aMatrixImag, aMatrixReal, 0.01, fp.step); Eigen::VectorX<fv> x = guesStartingPoint(omegaTensor, impedanceSpectra); - std::cout<<"StartingPoint\n"<<x<<std::endl; Eigen::Matrix<fv, Eigen::Dynamic, 2> bounds = calcBounds(impedanceSpectra, x); Eigen::VectorX<fv> lowerBounds = bounds.col(0); Eigen::VectorX<fv> upperBounds = bounds.col(1); fv fx; - fm.iterations = solver.minimize(funct, x, fx, lowerBounds, upperBounds); - fm.fx = fx; + try + { + fm.iterations = solver.minimize(funct, x, fx, lowerBounds, upperBounds); + fm.fx = fx; + } + catch(const std::invalid_argument& ex) + { + throw drt_errror(std::string(ex.what())); + } + catch(const std::runtime_error& ex) + { + throw drt_errror(std::string(ex.what())); + } return x; } diff --git a/eisdrt/types.h b/eisdrt/types.h index 1d3c028..4427b3e 100644 --- a/eisdrt/types.h +++ b/eisdrt/types.h @@ -18,6 +18,8 @@ */ #pragma once +#include <exception> +#include <string> /** Types for use with all eisdrt apis @@ -26,6 +28,22 @@ Types for use with all eisdrt apis * @{ */ + +/** + * @brief Exception thrown if drt could not be calcualted + */ +class drt_errror: public std::exception +{ + std::string whatStr; +public: + drt_errror(const std::string& whatIn): whatStr(whatIn) + {} + virtual const char* what() const noexcept override + { + return whatStr.c_str(); + } +}; + /** * @brief Returned information on a fit */ -- GitLab