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

pybind11 #48

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/build-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: "true"

- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
with:
python-version: '3.10'
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: "true"

- name: Set up QEMU
if: matrix.platform-id == 'manylinux_aarch64'
Expand Down Expand Up @@ -70,6 +72,8 @@ jobs:
steps:
- name: Clone repo
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # 4.1.7
with:
submodules: "true"

- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # 5.1.1
with:
Expand All @@ -95,6 +99,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # 4.1.7
with:
submodules: "true"

- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # 5.1.1
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ __pycache__

# CMake
build

# jupyter
.ipynb_checkpoints
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "external/skiplist"]
path = external/skiplist
url = https://github.com/paulross/skiplist.git
[submodule "external/stl-cpp"]
path = external/stl-cpp
url = https://github.com/jmoralez/stl-cpp.git
1 change: 1 addition & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"${workspaceFolder}/include",
"${workspaceFolder}/build/_deps/**/include",
"${workspaceFolder}/build/_deps/**/cpp",
"${workspaceFolder}/.venv/lib/python3.10/site-packages/pybind11/include"
]
}
],
Expand Down
71 changes: 18 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,62 +1,27 @@
cmake_minimum_required(VERSION 3.25)
project(coreforecast)

include(FetchContent)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
project(_lib LANGUAGES CXX)

set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(APPLE)
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif()

if(UNIX)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC -O0 -g -Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC -O3 -Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
else()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Ob2 /Ot /Oy /W4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4068")
endif()

if(SKBUILD)
set(LIBRARY_OUTPUT_PATH ${SKBUILD_PLATLIB_DIR}/coreforecast/lib)
set(LIBRARY_OUTPUT_PATH ${SKBUILD_PLATLIB_DIR}/coreforecast)
else()
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/python/coreforecast/lib)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/python/coreforecast)
endif()

include_directories(include)
FetchContent_Declare(
stl-cpp
GIT_REPOSITORY https://github.com/jmoralez/stl-cpp.git
GIT_TAG 13d26c0d0653ddcdbf853de3f92f56faa831a330
)
FetchContent_GetProperties(stl-cpp)

if(NOT stl-cpp_POPULATED)
FetchContent_Populate(stl-cpp)
include_directories(${stl-cpp_SOURCE_DIR}/include)
endif()

FetchContent_Declare(
skiplist
GIT_REPOSITORY https://github.com/paulross/skiplist.git
GIT_TAG aace571a8564067820ff7a5e34ba68d0a9782153
)
FetchContent_GetProperties(skiplist)

if(NOT skiplist_POPULATED)
FetchContent_Populate(skiplist)
include_directories(${skiplist_SOURCE_DIR}/src/cpp)
endif()

file(GLOB SOURCES src/*.cpp ${skiplist_SOURCE_DIR}/src/cpp/SkipList.cpp)
add_library(coreforecast SHARED ${SOURCES})

if(MSVC)
set_target_properties(coreforecast PROPERTIES OUTPUT_NAME "libcoreforecast")
endif()
find_package(Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED)
set(PYBIND11_FINDPYTHON ON)
execute_process(
COMMAND "${Python_EXECUTABLE}" -m pybind11 --cmakedir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE pybind11_DIR)
find_package(pybind11 CONFIG REQUIRED)
execute_process(
COMMAND "${Python_EXECUTABLE}" -m pybind11 --includes
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE pybind11_INCLUDES)

include_directories(include external/skiplist/src/cpp external/stl-cpp/include ${pybind11_INCLUDES})
file(GLOB SOURCES src/*.cpp external/skiplist/src/cpp/SkipList.cpp)
pybind11_add_module(_lib ${SOURCES})
install(TARGETS _lib DESTINATION .)
1 change: 1 addition & 0 deletions external/skiplist
Submodule skiplist added at aace57
1 change: 1 addition & 0 deletions external/stl-cpp
Submodule stl-cpp added at 13d26c
31 changes: 31 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <cstdint>

#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>

using indptr_t = int32_t;
namespace py = pybind11;

template <typename T>
inline indptr_t FirstNotNaN(const T *data, indptr_t n)
{
indptr_t i = 0;
while (std::isnan(data[i]) && i < n)
{
++i;
}
return i;
}

template <typename T>
inline indptr_t FirstNotNaN(const T *data, indptr_t n, T *out)
{
indptr_t i = 0;
while (std::isnan(data[i]) && i < n)
{
out[i++] = std::numeric_limits<T>::quiet_NaN();
}
return i;
}
Loading
Loading