From abb57dc2d9708b39f197d9d4f12ecdc1d8a0f1d4 Mon Sep 17 00:00:00 2001 From: AlePalu Date: Tue, 5 Dec 2023 09:18:23 +0100 Subject: [PATCH] code tested against clang, apple-clang compilers. Fixed segfault caused by bad_cast in clang --- .github/workflows/Dockerfile | 1 + .github/workflows/test-linux-clang.yml | 21 ++++++ .../{test-workflow.yml => test-linux-gcc.yml} | 6 +- .github/workflows/test-macos-clang.yml | 21 ++++++ README.md | 6 +- fdaPDE/core | 2 +- fdaPDE/models/model_wrappers.h | 2 +- fdaPDE/models/space_time_parabolic_base.h | 60 --------------- test/run_tests.sh | 75 ++++++++++++++++++- 9 files changed, 125 insertions(+), 69 deletions(-) create mode 100644 .github/workflows/test-linux-clang.yml rename .github/workflows/{test-workflow.yml => test-linux-gcc.yml} (79%) create mode 100644 .github/workflows/test-macos-clang.yml diff --git a/.github/workflows/Dockerfile b/.github/workflows/Dockerfile index bf63df5e..48e34bf5 100644 --- a/.github/workflows/Dockerfile +++ b/.github/workflows/Dockerfile @@ -6,6 +6,7 @@ FROM alpine:latest # base system dependencies RUN apk --no-cache add --update \ g++ \ + clang \ libstdc++ \ cmake \ git \ diff --git a/.github/workflows/test-linux-clang.yml b/.github/workflows/test-linux-clang.yml new file mode 100644 index 00000000..298cbd40 --- /dev/null +++ b/.github/workflows/test-linux-clang.yml @@ -0,0 +1,21 @@ +name: test-linux-clang +on: + push: + branches: [ stable, develop ] + +jobs: + build: + runs-on: ubuntu-latest + container: + image: alepalu/fdapde-docker-linux:latest + steps: + - name: checkout repository + uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: run_tests + run: | + cd test/ + export Eigen3_DIR=/usr/share/cmake/Modules # reguired to let eigen3 work with CMake in alpine + chmod +x run_tests.sh + ./run_tests.sh --compiler clang diff --git a/.github/workflows/test-workflow.yml b/.github/workflows/test-linux-gcc.yml similarity index 79% rename from .github/workflows/test-workflow.yml rename to .github/workflows/test-linux-gcc.yml index 3ba3c737..fa563e61 100644 --- a/.github/workflows/test-workflow.yml +++ b/.github/workflows/test-linux-gcc.yml @@ -1,4 +1,4 @@ -name: test-workflow +name: test-linux-gcc on: push: branches: [ stable, develop ] @@ -7,7 +7,7 @@ jobs: build: runs-on: ubuntu-latest container: - image: alepalu/fdapde-docker-image:latest + image: alepalu/fdapde-docker-linux:latest steps: - name: checkout repository uses: actions/checkout@v2 @@ -18,4 +18,4 @@ jobs: cd test/ export Eigen3_DIR=/usr/share/cmake/Modules # reguired to let eigen3 work with CMake in alpine chmod +x run_tests.sh - ./run_tests.sh + ./run_tests.sh --compiler gcc diff --git a/.github/workflows/test-macos-clang.yml b/.github/workflows/test-macos-clang.yml new file mode 100644 index 00000000..1066d74d --- /dev/null +++ b/.github/workflows/test-macos-clang.yml @@ -0,0 +1,21 @@ +name: test-macos-clang +on: + push: + branches: [ stable, develop ] + +jobs: + build: + runs-on: macos-latest + steps: + - name: checkout repository + uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: install_deps + run: | + brew install eigen + - name: run_tests + run: | + cd test/ + chmod +x run_tests.sh + ./run_tests.sh --compiler clang diff --git a/README.md b/README.md index faaf37c4..57063011 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,11 @@
Physics-Informed Spatial and Functional Data Analysis
-![test-linux-gcc](https://img.shields.io/github/actions/workflow/status/fdaPDE/fdaPDE-cpp/test-workflow.yml?branch=stable&label=test-linux-gcc) +![test-linux-gcc](https://img.shields.io/github/actions/workflow/status/fdaPDE/fdaPDE-cpp/test-linux-gcc.yml?branch=stable&label=test-linux-gcc) +![test-linux-clang](https://img.shields.io/github/actions/workflow/status/fdaPDE/fdaPDE-cpp/test-linux-clang.yml?branch=stable&label=test-linux-clang) +![test-macos-clang](https://img.shields.io/github/actions/workflow/status/fdaPDE/fdaPDE-cpp/test-macos-clang.yml?branch=stable&label=test-macos-clang) -fdaPDE is a C++ library for the analysis of spatial data and functional data observed over complex multidimensional domains, featuring a Partial Differential Equation regularization. +fdaPDE is a C++ library for the analysis of spatial and functional data observed over complex multidimensional domains, featuring a Partial Differential Equation regularization. It is built on top of the [fdaPDE Core Library](https://github.com/fdaPDE/fdaPDE-core). diff --git a/fdaPDE/core b/fdaPDE/core index a0cc007d..b1244330 160000 --- a/fdaPDE/core +++ b/fdaPDE/core @@ -1 +1 @@ -Subproject commit a0cc007d87d36bf1c89d18c6c07bac199d0f7fff +Subproject commit b12443306c5549053fd585d9922d7914214ce134 diff --git a/fdaPDE/models/model_wrappers.h b/fdaPDE/models/model_wrappers.h index 98de5c9c..7ee44e83 100644 --- a/fdaPDE/models/model_wrappers.h +++ b/fdaPDE/models/model_wrappers.h @@ -80,7 +80,7 @@ template <> struct IStatModel { DEFINE_BASE_STAT_MODEL_INTERFACE; void set_lambda(const SVector<2>& lambda) { fdapde::invoke(*this, lambda); } void set_lambda_T(double lambda_T) { fdapde::invoke(*this, lambda_T); } - void set_initial_condition(const DVector& s, bool shift = true) { + void set_initial_condition(const DMatrix& s, bool shift = true) { fdapde::invoke(*this, s, shift); } }; diff --git a/fdaPDE/models/space_time_parabolic_base.h b/fdaPDE/models/space_time_parabolic_base.h index d3941770..a47f0544 100644 --- a/fdaPDE/models/space_time_parabolic_base.h +++ b/fdaPDE/models/space_time_parabolic_base.h @@ -125,66 +125,6 @@ class SpaceTimeParabolicBase : public SpaceTimeBase { // destructor virtual ~SpaceTimeParabolicBase() = default; }; - - /* -// base class for parabolic regularization, iterative solver -template -class SpaceTimeParabolicBase : public SpaceTimeBase { - protected: - typedef SpaceTimeBase Base; - using Base::df_; // model's data - using Base::model; // underlying model object - using Base::pde_; // regularizing term in space - using Base::time_; // time interval [0,T] - - DMatrix s_; // N x 1 initial condition vector - DMatrix u_; // discretized forcing [1/DeltaT * (u_1 + R_0*s) \ldots u_n] - double DeltaT_; // time step (assumes equidistant points in time) - - public: - // constructor - SpaceTimeParabolicBase() = default; - SpaceTimeParabolicBase(const pde_ptr& pde, const DVector& time) : Base(pde, time) { } - // init data required for iterative solution of parabolic regularization - void init_regularization() { - // compute time step (assuming equidistant points) - DeltaT_ = time_[1] - time_[0]; - u_ = pde_.force(); // compute forcing term - // correct first n rows of discretized force as (u_1 + R0*s/DeltaT) - u_.block(0, 0, model().n_basis(), 1) += (1.0 / DeltaT_) * (pde_.R0() * s_); - } - - // getters - const SpMatrix& R0() const { return pde_.R0(); } // mass matrix in space - const SpMatrix& R1() const { return pde_.R1(); } // discretization of differential operator L - DMatrix u(std::size_t k) const { // discretization of forcing term u at time k - return u_.block(model().n_basis() * k, 0, model().n_basis(), 1); - } - double DeltaT() const { return DeltaT_; } - const DMatrix& s() const { return s_; } // initial condition - std::size_t n_basis() const { return pde_.n_dofs(); } // number of basis functions - - void P() { return; } // TODO - - // setters - // shift = true, cause the removal of the first time instant of data, in case it has been used to estimate the IC - void set_initial_condition(const DMatrix& s, bool shift = true) { - s_ = s; - if (shift) { // left shrink time domain by one node - std::size_t m = time_.rows(); // number of time instants - time_ = time_.tail(m - 1).eval(); // correct time interval [0,T] (eval() to avoid aliasing) - pde_.set_forcing(pde_.forcing_data().rightCols(m - 1)); - // remove from data the first time instant, reindex points - model().set_data(df_.tail(model().n_spatial_locs()).extract(), true); - } - } - void set_tolerance(double tol) { tol_ = tol; } - void set_max_iter(std::size_t max_iter) { max_iter_ = max_iter; } - - // destructor - virtual ~SpaceTimeParabolicBase() = default; -}; - */ } // namespace models } // namespace fdapde diff --git a/test/run_tests.sh b/test/run_tests.sh index f13b33d4..60367da6 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -1,9 +1,73 @@ #!/bin/sh -# cd into build directory +# set defaults +SCRIPT_NAME=$(basename "$0") BUILD_DIR=build/ +MEMCHECK=false +COMPILER="gcc" + +help() +{ + echo "Usage: .run_tests.sh [options] + + -m --memcheck use valgrind to checks for memory errors + -c --compiler sets compiler (gcc/clang), default gcc + -h --help shows this message" + exit 2 +} + +clean_build_dir() +{ + if [ -d "$BUILD_DIR" ]; + then + rm -r build/CMakeCache.txt build/CMakeFiles/ + fi +} + +## parse command line inputs +SHORT=m,c:,h +LONG=memcheck,compiler:,help +OPTS=$(getopt -a --n "$SCRIPT_NAME" --options $SHORT --longoptions $LONG -- "$@") + +eval set -- "$OPTS" + +while :; do + case "$1" in + -m | --memcheck ) + MEMCHECK=true + shift 1 + ;; + -c | --compiler ) + COMPILER="$2" + shift 2 + ;; + -h | --help ) + help + ;; + --) + shift; + break + ;; + *) + echo "Unexpected option: $1" + help + ;; + esac +done + +## set CMake compiler +if [ "$COMPILER" = "gcc" ]; then + export CC=/usr/bin/gcc + export CXX=/usr/bin/g++ +elif [ "$COMPILER" = "clang" ]; then + export CC=/usr/bin/clang + export CXX=/usr/bin/clang++ +fi + +# cd into build directory if [ -d "$BUILD_DIR" ]; then + clean_build_dir cd build/ else mkdir build/ @@ -12,4 +76,11 @@ fi cmake -Wno-dev ../CMakeLists.txt make -./fdapde_test + +if [ "$MEMCHECK" = true ]; then + valgrind --leak-check=full --track-origins=yes ./fdapde_test +else + ./fdapde_test +fi + +rm fdapde_test