Skip to content

Commit

Permalink
code tested against clang, apple-clang compilers. Fixed segfault caus…
Browse files Browse the repository at this point in the history
…ed by bad_cast in clang
  • Loading branch information
AlePalu committed Dec 5, 2023
1 parent e28c57b commit abb57dc
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 69 deletions.
1 change: 1 addition & 0 deletions .github/workflows/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FROM alpine:latest
# base system dependencies
RUN apk --no-cache add --update \
g++ \
clang \
libstdc++ \
cmake \
git \
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/test-linux-clang.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test-workflow
name: test-linux-gcc
on:
push:
branches: [ stable, develop ]
Expand All @@ -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
Expand All @@ -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
21 changes: 21 additions & 0 deletions .github/workflows/test-macos-clang.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

<h5> Physics-Informed Spatial and Functional Data Analysis </h5> </div>

![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).

Expand Down
2 changes: 1 addition & 1 deletion fdaPDE/core
Submodule core updated from a0cc00 to b12443
2 changes: 1 addition & 1 deletion fdaPDE/models/model_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ template <> struct IStatModel<SpaceTimeParabolic> {
DEFINE_BASE_STAT_MODEL_INTERFACE;
void set_lambda(const SVector<2>& lambda) { fdapde::invoke<void, 6>(*this, lambda); }
void set_lambda_T(double lambda_T) { fdapde::invoke<void, 7>(*this, lambda_T); }
void set_initial_condition(const DVector<double>& s, bool shift = true) {
void set_initial_condition(const DMatrix<double>& s, bool shift = true) {
fdapde::invoke<void, 8>(*this, s, shift);
}
};
Expand Down
60 changes: 0 additions & 60 deletions fdaPDE/models/space_time_parabolic_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,66 +125,6 @@ class SpaceTimeParabolicBase : public SpaceTimeBase<Model, SpaceTimeParabolic> {
// destructor
virtual ~SpaceTimeParabolicBase() = default;
};

/*
// base class for parabolic regularization, iterative solver
template <typename Model>
class SpaceTimeParabolicBase<Model, Iterative> : public SpaceTimeBase<Model, SpaceTimeParabolic> {
protected:
typedef SpaceTimeBase<Model, SpaceTimeParabolic> 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<double> s_; // N x 1 initial condition vector
DMatrix<double> 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<double>& 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<double>& R0() const { return pde_.R0(); } // mass matrix in space
const SpMatrix<double>& R1() const { return pde_.R1(); } // discretization of differential operator L
DMatrix<double> 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<double>& 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<double>& 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
Expand Down
75 changes: 73 additions & 2 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
@@ -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/
Expand All @@ -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

0 comments on commit abb57dc

Please sign in to comment.