Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
aa6efe4
Add Python bindings and example script
mblum Apr 26, 2025
3a33831
fix: restrict CI workflow branches to master only
mblum Apr 26, 2025
2d55fe4
refactor: reorganize CMake configuration
mblum Apr 26, 2025
57edb7f
refactor: remove Sources.cmake file
mblum Apr 26, 2025
994023f
refactor: remove unused gp_sparse.cc implementation file
mblum Apr 26, 2025
ea03d99
refactor: update CMake configuration for Python bindings
mblum Apr 26, 2025
2980f87
fix: name of Python module
mblum Apr 26, 2025
bea660b
refactor: update README.md for building and testing instructions
mblum Apr 26, 2025
84b02af
refactor: update CMake configuration for Python bindings and static l…
mblum Apr 26, 2025
9a86924
feat: add pyproject.toml for build system and project metadata
mblum Apr 26, 2025
dc1807d
refactor: streamline CI configuration by removing unnecessary build o…
mblum Apr 26, 2025
d0d791a
fix: ensure CI triggers on all branches for push events
mblum Apr 26, 2025
50945a0
fix: update CI configuration to trigger on all branches for push events
mblum Apr 26, 2025
5015891
fix: set default option for BUILD_PYTHON_BINDINGS to OFF
mblum Apr 26, 2025
c78d1e5
fix: add googletest dependency for CI builds on Linux and macOS
mblum Apr 26, 2025
58d014b
fix: remove unnecessary working-directory specification for test step
mblum Apr 26, 2025
7b8b544
fix: add flake8 configuration for code style enforcement
mblum Apr 26, 2025
50844d6
feat: add example for 2D Gaussian Process with SE kernel
mblum Apr 26, 2025
5565fa0
fix: update README for Python bindings
mblum Apr 26, 2025
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
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
max-line-length = 120
exclude =
.git,
__pycache__,
build,
dist,
*.egg-info
18 changes: 7 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: CI

on:
push:
branches: [ master, dev ]
branches: [ '**']
tags: [ 'v*' ]
pull_request:
branches: [ master, dev ]
branches: [ master ]

permissions:
contents: write
Expand All @@ -25,25 +25,21 @@ jobs:
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y cmake libeigen3-dev
sudo apt-get install -y cmake libeigen3-dev libgtest-dev

- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install cmake eigen
brew install cmake eigen googletest

- name: Configure CMake
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTS=ON \
-DBUILD_EXAMPLES=ON
run: cmake -B build -DCMAKE_BUILD_TYPE=Release -DLIBGP_BUILD_TESTS=ON

- name: Build
run: cmake --build build --config Release
run: cmake --build build

- name: Test
working-directory: build
run: ctest --output-on-failure -C Release
run: cmake --build build --target test

- name: Create Package
run: |
Expand Down
217 changes: 109 additions & 108 deletions CMakeLists.txt
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,127 +1,110 @@
# Created by Manuel Blum on 2011-05-25.
# Copyright 2013 University of Freiburg.

cmake_minimum_required(VERSION 3.14)

# Add cmake modules directory
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Include version validation
include(VersionValidation)
cmake_minimum_required(VERSION 3.14...3.22)

project(libgp
VERSION 0.1.5
DESCRIPTION "Gaussian Process Regression Library"
VERSION "0.1.5"
DESCRIPTION "C++ Library for Gaussian Process Regression"
LANGUAGES CXX)

# Validate version
validate_version(VERSION ${PROJECT_VERSION})

# Load common settings
include(CommonSettings)
include(FetchContent)

# Check for required C++ features
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
# Options
option(BUILD_PYTHON_BINDINGS "Build Python bindings" OFF)
option(LIBGP_BUILD_ALL "Build everything (tests and examples)" OFF)
option(LIBGP_BUILD_TESTS "Build libgp tests" ${LIBGP_BUILD_ALL})
option(LIBGP_BUILD_EXAMPLES "Build example applications" ${LIBGP_BUILD_ALL})
option(BUILD_SHARED_LIBS "Build shared libraries" OFF) # Changed to OFF for static linking

# Force C++17 before feature test
# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Added for Python bindings

# Configure version header
# Dependencies
find_package(Eigen3 REQUIRED)

# Generate version header
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/gp_version.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/gp_version.h
"${PROJECT_SOURCE_DIR}/include/gp_version.h.in"
"${PROJECT_BINARY_DIR}/include/gp_version.h"
@ONLY
)

# Feature tests
check_cxx_source_compiles("
#include <type_traits>
#include <string_view>
#include <optional>
int main() {
static_assert(std::is_same_v<int, int>);
std::string_view sv = \"test\";
std::optional<int> opt;
return 0;
}"
HAVE_CPP17_FEATURES
# Core library
add_library(gp STATIC # Changed to STATIC
src/gp.cc
src/gp_utils.cc
src/sampleset.cc
src/rprop.cc
src/cg.cc
src/input_dim_filter.cc
src/cov.cc
src/cov_factory.cc
src/cov_linear_ard.cc
src/cov_linear_one.cc
src/cov_matern3_iso.cc
src/cov_matern5_iso.cc
src/cov_noise.cc
src/cov_periodic.cc
src/cov_periodic_matern3_iso.cc
src/cov_prod.cc
src/cov_rq_iso.cc
src/cov_se_ard.cc
src/cov_se_iso.cc
src/cov_sum.cc
)

if(NOT HAVE_CPP17_FEATURES)
message(FATAL_ERROR "Compiler does not support required C++17 features")
endif()

# Set visibility settings
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)

# Find dependencies
set(CMAKE_PREFIX_PATH "/opt/homebrew/share/eigen3/cmake" ${CMAKE_PREFIX_PATH})
find_package(Eigen3 3.0.1 NO_MODULE REQUIRED)
find_package(Threads REQUIRED)

# Create library target
add_library(gp)
add_library(libgp::gp ALIAS gp)

# Include sources
include("Sources.cmake")
target_sources(gp PRIVATE ${LIBGP_SRC})

# Apply common settings
libgp_set_common_properties(gp)

# Modern way to handle include directories
target_include_directories(gp
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)

target_link_libraries(gp
PUBLIC
Eigen3::Eigen
PRIVATE
Threads::Threads
)
target_link_libraries(gp PUBLIC Eigen3::Eigen)

target_compile_definitions(gp
PRIVATE
libgp_EXPORTS
$<$<BOOL:${BUILD_TESTING}>:ENABLE_TESTING>
)
# Python bindings
if(BUILD_PYTHON_BINDINGS)
set(PYBIND11_FINDPYTHON ON)
find_package(pybind11 CONFIG REQUIRED)
pybind11_add_module(libgp src/bindings.cpp)
target_link_libraries(libgp PRIVATE gp Eigen3::Eigen)

# Enable testing with CTest
if(BUILD_TESTS)
# Install both the Python module and the shared library together
install(TARGETS libgp gp
LIBRARY DESTINATION .
RUNTIME DESTINATION .)
endif()

# Tests
if(LIBGP_BUILD_TESTS)
enable_testing()
include(CTest)
add_subdirectory(tests ${CMAKE_CURRENT_BINARY_DIR}/tests_build)
find_package(GTest REQUIRED)

function(add_gp_test name)
add_executable(${name} tests/${name}.cc)
target_link_libraries(${name} PRIVATE gp GTest::GTest GTest::Main)
add_test(NAME ${name} COMMAND ${name})
endfunction()

add_gp_test(test_gp_regression)
add_gp_test(test_log_likelihood)
add_gp_test(test_cov_factory)
add_gp_test(test_covariance_functions)
add_gp_test(test_gp_utils)
add_gp_test(test_optimizer)
endif()

# Examples
if(LIBGP_BUILD_EXAMPLES)
add_executable(gp_example_dense examples/gp_example_dense.cc)
target_link_libraries(gp_example_dense PRIVATE gp)
endif()

# Installation
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/libgp)

# Configure version file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/libgpConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

# Configure config files
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/libgp-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/libgpConfig.cmake"
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)

install(TARGETS gp
EXPORT libgp-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand All @@ -130,16 +113,15 @@ install(TARGETS gp
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)


install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
PATTERN "*.h.in" EXCLUDE
)

# Install CMake config files
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/libgpConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libgpConfigVersion.cmake"
DESTINATION ${INSTALL_CONFIGDIR}
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/gp_version.h"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

# Export targets
Expand All @@ -149,14 +131,33 @@ install(EXPORT libgp-targets
DESTINATION ${INSTALL_CONFIGDIR}
)

# Generate pkg-config file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/contrib/libgp.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libgp.pc @ONLY)
# Create and install config files
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/libgpConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/contrib/libgp.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libgpConfig.cmake"
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/libgpConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libgpConfigVersion.cmake"
DESTINATION ${INSTALL_CONFIGDIR}
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgp.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# Generate and install pkg-config file
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/contrib/libgp.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libgp.pc"
@ONLY
)

# Add components
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libgp.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A C++ library for Gaussian process regression. A Gaussian process defines a dist

1. Create a build directory and configure the project with tests enabled:
```bash
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON
cmake -B build -DCMAKE_BUILD_TYPE=Release
```

2. Build the library:
Expand All @@ -27,30 +27,36 @@ cmake --build build

For development and debugging, you can use Debug build type:
```bash
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DLIBGP_BUILD_TESTS=ON
```

### Running Tests

The project uses Google Test for unit testing. Tests are automatically configured when building the project.

1. Build the tests (they are built automatically with the main build):
1. Build the tests:
```bash
cmake -B build -DCMAKE_BUILD_TYPE=Release -DLIBGP_BUILD_TESTS=ON
cmake --build build
```

2. Run all tests:
```bash
cd build
ctest --output-on-failure
cmake --build build --target test
```

### Examples

The library includes example code demonstrating how to use Gaussian Process regression. To build and run the examples:

```bash
./build/examples/gpdense
cmake -B build -DCMAKE_BUILD_TYPE=Release -DLIBGP_BUILD_EXAMPLES=ON
cmake --build build
```

Then run the example:
```bash
./build/gp_example_dense
```

The example demonstrates:
Expand All @@ -62,17 +68,13 @@ The example demonstrates:
For more details, see the source code in `examples/gp_example_dense.cc`.


## Installing
## Python Bindings

```bash
cmake --install build
```
This library provides Python bindings for Gaussian Process regression. The bindings are generated using pybind11, allowing you to use the C++ library directly in Python.

After installation, you can use libgp in your CMake project:

```cmake
find_package(libgp REQUIRED)
target_link_libraries(your_target PRIVATE libgp::gp)
```bash
pip install .
python examples/python_example.py
```

## Implemented covariance functions
Expand Down
Loading
Loading