Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement per-instance error handling #27

Merged
merged 31 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c024f14
Introduce exceptions internal to module(s).
tanaya-mankad Jan 16, 2023
d2ead71
Rewrite error and message handling for GridAxis.
tanaya-mankad Jan 20, 2023
b35833b
Fix tests.
tanaya-mankad Jan 23, 2023
b77c721
Disable fast fail on CI.
tanaya-mankad Jan 23, 2023
75e0dff
Add functional header.
tanaya-mankad Jan 23, 2023
b7567b6
Update gh actions checkout.
tanaya-mankad Jan 23, 2023
b17812f
Try CI with Ubuntu 20.
tanaya-mankad Jan 23, 2023
206e3e4
Try CI with Ubuntu 22.
tanaya-mankad Jan 23, 2023
8b2b8ba
Try CI with only working OS values.
tanaya-mankad Jan 23, 2023
1580727
Start moving toward saner cmake defaults.
tanaya-mankad Jan 23, 2023
53e58b3
Update CI matrix.
tanaya-mankad Jan 23, 2023
0d095ef
Apply clang-format file.
tanaya-mankad Jan 23, 2023
d23cf39
Revert return values to simple ones.
tanaya-mankad Jan 25, 2023
c9963ed
Remove default constructors and adjust tests. Pass callback by pointe…
tanaya-mankad Feb 6, 2023
182dcf6
Remove vestigial error strings returned by funcs.
tanaya-mankad Feb 6, 2023
16e2c35
Pass ptr to const function.
tanaya-mankad Feb 6, 2023
6d46ec3
Improve const-correctness; remove redundancy in tests.
tanaya-mankad Feb 8, 2023
89b4f05
Disambiguate constructors.
tanaya-mankad Feb 8, 2023
a6d346b
Construct test_gridded_data directly.
tanaya-mankad Feb 8, 2023
1691b7f
Put back default constructors; alternative is exactly the same thing.
tanaya-mankad Feb 13, 2023
5ff6281
Variable cleanup.
tanaya-mankad Feb 13, 2023
21cc1e6
Remove global callback entirely.
tanaya-mankad Feb 14, 2023
788bb26
Separate setting the callback and the context.
tanaya-mankad Feb 20, 2023
f59fc90
Pass string_view by value.
tanaya-mankad Feb 21, 2023
d16a384
Merge crom unnecessary branch.
tanaya-mankad Feb 21, 2023
3d290aa
Integrate Courierr logging.
tanaya-mankad Mar 7, 2023
651bb75
Make Courierr dependency non-optional; fix constructors and tests acc…
tanaya-mankad Mar 13, 2023
70cad02
Update Courierr.
tanaya-mankad Mar 14, 2023
fbfa886
Add getter for Courierr instance.
tanaya-mankad Mar 14, 2023
42857cb
Allow GridAxis to contain a different logger than owning RGI.
tanaya-mankad Mar 20, 2023
ca51659
Modify EXPECT_STDOUT for throwing functions (gcc).
tanaya-mankad Mar 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ jobs:
config: Debug
static_lib: OFF
coverage: ON
- os: ubuntu-18.04
- os: ubuntu-20.04
config: Release
static_lib: ON
coverage: OFF
fail-fast: false
defaults:
run:
shell: bash
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set Project Name
run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
- name: Create Build Directory
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "vendor/googletest"]
path = vendor/googletest
url = https://github.com/google/googletest.git
[submodule "vendor/courierr"]
path = vendor/courierr
url = https://github.com/bigladder/courierr.git
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ if (${PROJECT_NAME}_BUILD_TESTING)
endif()
endif()


add_subdirectory(src)
add_subdirectory(vendor)

Expand Down
2 changes: 1 addition & 1 deletion cmake/compiler-flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (UNIX)
add_definitions("-fPIC")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c++11 flag was causing gcc / ubuntu-latest to not compile c++17

endif()

3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(library_sources
gridpoint.h
gridpoint.cpp
error.h
error.cpp
)

option( ${PROJECT_NAME}_STATIC_LIB "Make ${PROJECT_NAME} a static library" ON )
Expand All @@ -21,6 +20,8 @@ else()
add_library(${PROJECT_NAME} SHARED ${library_sources})
endif()

target_link_libraries(${PROJECT_NAME} PUBLIC courierr fmt)

target_compile_options(btwxt PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
Expand Down
65 changes: 43 additions & 22 deletions src/btwxt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,40 @@

namespace Btwxt {

RegularGridInterpolator::RegularGridInterpolator() = default;

RegularGridInterpolator::RegularGridInterpolator(GriddedData &grid_data_in)
: grid_data(grid_data_in), grid_point(grid_data) {}
RegularGridInterpolator::RegularGridInterpolator(const std::vector<std::vector<double>> &grid, std::shared_ptr<Courierr::Courierr> messenger)
: grid_data(grid, messenger), grid_point(grid_data, messenger), btwxt_logger(messenger) {}

RegularGridInterpolator::RegularGridInterpolator(const std::vector<std::vector<double>> &grid,
const std::vector<std::vector<double>> &values)
: grid_data(grid, values), grid_point(grid_data) {}
const std::vector<std::vector<double>> &values, std::shared_ptr<Courierr::Courierr> messenger)
: grid_data(grid, values, messenger)
, grid_point(grid_data, messenger)
, btwxt_logger(messenger)
{
}

RegularGridInterpolator::RegularGridInterpolator(const RegularGridInterpolator &source) {
RegularGridInterpolator::RegularGridInterpolator(const RegularGridInterpolator &source)
: grid_data(source.grid_data), grid_point(source.grid_point), btwxt_logger(source.btwxt_logger) {
*this = source;
}

double RegularGridInterpolator::get_value_at_target(std::vector<double> target,
std::size_t RegularGridInterpolator::add_value_table(const std::vector<double> &value_vector) {
return grid_data.add_value_table(value_vector);
}

double RegularGridInterpolator::get_value_at_target(const std::vector<double>& target,
std::size_t table_index) {
set_new_target(target);
std::vector<double> result = grid_point.get_results();
return result[table_index];
auto results = grid_point.get_results();
return results[table_index];
}

double RegularGridInterpolator::get_value_at_target(std::size_t table_index) {
std::vector<double> result = grid_point.get_results();
return result[table_index];
auto results = grid_point.get_results();
return results[table_index];
}

std::vector<double> RegularGridInterpolator::get_values_at_target(const std::vector<double> &target) {
std::vector<double>
RegularGridInterpolator::get_values_at_target(const std::vector<double> &target) {
set_new_target(target);
return grid_point.get_results();
}
Expand All @@ -45,22 +53,26 @@ std::vector<double> RegularGridInterpolator::get_values_at_target() {
return grid_point.get_results();
}

double RegularGridInterpolator::normalize_values_at_target(std::size_t table_index, const std::vector<double> &target, const double scalar) {
double RegularGridInterpolator::normalize_values_at_target(std::size_t table_index,
const std::vector<double> &target,
const double scalar) {
set_new_target(target);
return normalize_values_at_target(table_index, scalar);
}

double RegularGridInterpolator::normalize_values_at_target(std::size_t table_index, const double scalar) {
double RegularGridInterpolator::normalize_values_at_target(std::size_t table_index,
const double scalar) {
return grid_point.normalize_grid_values_at_target(table_index, scalar);
}

void RegularGridInterpolator::normalize_values_at_target(const std::vector<double> &target, const double scalar) {
void RegularGridInterpolator::normalize_values_at_target(const std::vector<double> &target,
const double scalar) {
set_new_target(target);
normalize_values_at_target(scalar);
}

void RegularGridInterpolator::normalize_values_at_target(const double scalar) {
grid_point.normalize_grid_values_at_target(scalar);
return grid_point.normalize_grid_values_at_target(scalar);
}

void RegularGridInterpolator::set_new_target(const std::vector<double> &target) {
Expand All @@ -71,16 +83,25 @@ std::vector<double> RegularGridInterpolator::get_current_target() {
return grid_point.get_current_target();
}

void RegularGridInterpolator::clear_current_target() { grid_point = GridPoint(grid_data); }
void RegularGridInterpolator::clear_current_target() {
grid_point = GridPoint(grid_data, btwxt_logger);
}

std::size_t RegularGridInterpolator::get_ndims() { return grid_data.get_ndims(); }
std::size_t RegularGridInterpolator::get_ndims() const { return grid_data.get_ndims(); }

std::vector<std::vector<short>> &RegularGridInterpolator::get_hypercube() {
return grid_point.get_hypercube();
}
std::size_t RegularGridInterpolator::get_num_tables() const { return grid_data.get_num_tables(); }

std::pair<double, double> RegularGridInterpolator::get_axis_limits(int dim) {
return grid_data.get_extrap_limits(dim);
}

void RegularGridInterpolator::set_logger(std::shared_ptr<Courierr::Courierr> logger, bool set_gridaxes)
{
btwxt_logger = logger;
grid_point.set_logger(logger);
if (set_gridaxes) {
grid_data.set_logger(logger);
}
}

} // namespace Btwxt
76 changes: 52 additions & 24 deletions src/btwxt.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,31 @@
#define GRIDINTERP_H_

// Standard
#include <functional>
#include <vector>
#include <memory>

#include <courierr/courierr.h>

// btwxt
#include "error.h"
#include "griddeddata.h"
#include "gridpoint.h"

namespace Btwxt {

enum class MsgLevel { MSG_DEBUG, MSG_INFO, MSG_WARN, MSG_ERR };
extern int LOG_LEVEL;

typedef void (*BtwxtCallbackFunction)(const MsgLevel messageType, const std::string message,
void *contextPtr);

extern BtwxtCallbackFunction btwxtCallbackFunction;
extern void *messageCallbackContextPtr;

void setMessageCallback(BtwxtCallbackFunction callbackFunction, void *contextPtr);

// this will be the public-facing class.
class RegularGridInterpolator {
public:
// GridSpace, GridAxis, AllValueTables, ValueTable are instantiated in RGI constructor.
RegularGridInterpolator() = default;

RegularGridInterpolator();
RegularGridInterpolator(GriddedData &grid_data_in, std::shared_ptr<Courierr::Courierr> messenger)
: grid_data(grid_data_in), grid_point(grid_data, messenger), btwxt_logger(messenger) {}

explicit RegularGridInterpolator(GriddedData &grid_data);
RegularGridInterpolator(const std::vector<std::vector<double>> &grid, std::shared_ptr<Courierr::Courierr> messenger);

RegularGridInterpolator(const std::vector<std::vector<double>> &grid,
const std::vector<std::vector<double>> &values);
const std::vector<std::vector<double>> &values, std::shared_ptr<Courierr::Courierr> messenger);

RegularGridInterpolator(const RegularGridInterpolator &source);

Expand All @@ -45,19 +40,34 @@ class RegularGridInterpolator {

grid_data = source.grid_data;
grid_point = source.grid_point;
btwxt_logger = source.btwxt_logger;
if (source.grid_point.grid_data != nullptr) {
this->grid_point.grid_data = &this->grid_data;
}
return *this;
}

// RegularGridInterpolator(RegularGridInterpolator&& source) = delete;
//
// RegularGridInterpolator& operator=(RegularGridInterpolator&& source) {
// if (this == &source) {
// return *this;
// }
// grid_data = std::move(source.grid_data);
// grid_point = std::move(source.grid_point);
// if (source.grid_point.grid_data != nullptr) {
// this->grid_point.grid_data = &this->grid_data;
// }
// callback_function_ = std::move(source.callback_function_); // what happens to the function pointer in members?
// caller_context_ = source.caller_context_;
// return *this;
// }

// Add value table to GriddedData
std::size_t add_value_table(std::vector<double> &value_vector) {
return grid_data.add_value_table(value_vector);
}
std::size_t add_value_table(const std::vector<double> &value_vector);

// GridPoint gets instantiated inside calculate_value_at_target
double get_value_at_target(std::vector<double> target, std::size_t table_index);
double get_value_at_target(const std::vector<double>& target, std::size_t table_index);

double operator()(std::vector<double> target, std::size_t table_index) {
return get_value_at_target(std::move(target), table_index);
Expand All @@ -71,8 +81,8 @@ class RegularGridInterpolator {

std::vector<double> get_values_at_target(const std::vector<double> &target);

std::vector<double> operator()(const std::vector<double> &target) {
return get_values_at_target(target);
std::vector<double> operator()(std::vector<double> target) {
return get_values_at_target(std::move(target));
}

std::vector<double> operator()() { return get_values_at_target(); }
Expand All @@ -85,25 +95,43 @@ class RegularGridInterpolator {

double normalize_values_at_target(std::size_t table_index, const double scalar = 1.0);

double normalize_values_at_target(std::size_t table_index, const std::vector<double> &target, const double scalar = 1.0);
double normalize_values_at_target(std::size_t table_index, const std::vector<double> &target,
const double scalar = 1.0);

std::vector<double> get_current_target();

void clear_current_target();

std::size_t get_ndims();
std::size_t get_ndims() const;

std::size_t get_num_tables() const;

void set_axis_interp_method(std::size_t dim, Method method) {
grid_data.set_axis_interp_method(dim, method);
}

std::vector<std::vector<short>>& get_hypercube();
void set_axis_extrap_method(const std::size_t &dim, Method method) {
grid_data.set_axis_extrap_method(dim, method);
}

void set_axis_extrap_limits(const std::size_t &dim,
const std::pair<double, double> &extrap_limits) {
grid_data.set_axis_extrap_limits(dim, extrap_limits);
}

std::pair<double, double> get_axis_limits(int dim);

void set_logger(std::shared_ptr<Courierr::Courierr> logger, bool set_gridaxes = false);

Courierr::Courierr& get_logger() { return *btwxt_logger; };

private:
friend class TwoDFixtureWithLoggingContext;
friend class TwoDFixtureWithLoggingContext_set_message_context_Test;

GriddedData grid_data;
GridPoint grid_point;
std::shared_ptr<Courierr::Courierr> btwxt_logger;
};

} // namespace Btwxt
Expand Down
41 changes: 0 additions & 41 deletions src/error.cpp

This file was deleted.

Loading