Skip to content

Commit

Permalink
refactored integral histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiud committed Nov 11, 2024
1 parent 256760e commit bb9f3db
Show file tree
Hide file tree
Showing 19 changed files with 587 additions and 104 deletions.
6 changes: 4 additions & 2 deletions .ci/docker/lint.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ RUN wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.

FROM base AS deploy

RUN echo deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-19 main \
ARG clang_format_VERSION 19

RUN echo deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-${clang_format_VERSION} main \
>/etc/apt/sources.list.d/llvm.list

COPY --from=tools /etc/apt/trusted.gpg.d/apt.llvm.org.asc /etc/apt/trusted.gpg.d/apt.llvm.org.asc

RUN --mount=type=cache,target=/var/cache/apt \
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
--no-install-recommends --no-install-suggests \
clang-format-19 \
clang-format-${clang_format_VERSION} \
fd-find
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceAfterTemplateKeyword: false
FixNamespaceComments: true
Standard: c++17
Standard: c++20
TabWidth: 4
UseTab: Never
...
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-24.04
container: sergiud/hogpp:lint
container: sergiud/hogpp:lint-18
defaults:
run:
shell: bash -e -o pipefail {0}
Expand All @@ -17,12 +17,11 @@ jobs:

- name: Check code style
run: |
fdfind -g '*.[ch]pp' -x clang-format-19 --dry-run --Werror
fdfind -g '*.[ch]pp' -x clang-format-18 --dry-run --Werror
build-native:
name: ${{matrix.os}}-GCC-${{matrix.build_type}}
runs-on: ${{matrix.os}}
needs: lint
defaults:
run:
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ lint:pypy3.10:
needs: []

lint:cpp:
image: sergiud/hogpp:lint
image: sergiud/hogpp:lint-18
stage: test
allow_failure: true
script:
- fdfind -g '*.[ch]pp' -x clang-format-19 --dry-run --Werror
- fdfind -g '*.[ch]pp' -x clang-format-18 --dry-run --Werror
needs: []

build:bookworm:
Expand Down
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ endif (MSVC AND MSVC_VERSION GREATER_EQUAL 1930)
check_cxx_symbol_exists (std::execution::par execution HAVE_EXECUTION)

if (WIN32)
add_compile_definitions (NOMINMAX)
add_compile_definitions (WIN32_LEAN_AND_MEAN)
endif (WIN32)

Expand All @@ -100,7 +101,7 @@ target_include_directories (hogpp INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_compile_features (hogpp INTERFACE cxx_std_17)
target_compile_features (hogpp INTERFACE cxx_std_20)
target_link_libraries (hogpp INTERFACE
Eigen3::Eigen
fmt::fmt
Expand All @@ -110,7 +111,6 @@ if (pybind11_FOUND AND Python_Development.Module_FOUND)
add_library (python_type_caster STATIC
python/type_caster/bounds.cpp
python/type_caster/bounds.hpp
python/type_caster/cartesianproduct.hpp
python/type_caster/stride.hpp
python/type_caster/tensor.hpp
python/type_caster/typesequence.hpp
Expand All @@ -124,7 +124,6 @@ if (pybind11_FOUND AND Python_Development.Module_FOUND)
target_link_libraries (python_type_caster PUBLIC opencv_core)
endif (OpenCV_FOUND)

target_compile_features (python_type_caster PUBLIC cxx_std_17)
target_link_libraries (python_type_caster PUBLIC
Eigen3::Eigen
hogpp::hogpp
Expand Down Expand Up @@ -188,6 +187,18 @@ endif (pybind11_FOUND AND Python_Development.Module_FOUND)

if (BUILD_TESTING)
if (Boost_unit_test_framework_FOUND)
add_executable (test_integral_histogram
tests/cpp/test_integral_histogram.cpp
)
target_link_libraries (test_integral_histogram PRIVATE
Boost::unit_test_framework
Eigen3::Eigen
hogpp::hogpp
)

add_test (NAME integral_histogram_full COMMAND test_integral_histogram -t full)
add_test (NAME integral_histogram_sub COMMAND test_integral_histogram -t sub)

add_executable (test_binning tests/cpp/test_binning.cpp)
target_link_libraries (test_binning PRIVATE hogpp::hogpp
Boost::unit_test_framework)
Expand Down
2 changes: 1 addition & 1 deletion docs/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Compiling from Source
Requirements
------------

- C++17 compiler
- C++20 compiler
- `CMake <https://gitlab.kitware.com/cmake/cmake>`__ 3.18
- `Eigen <https://gitlab.com/libeigen/eigen>`__ 3.3.7
- `fmt <https://github.com/fmtlib/fmt>`__ 6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,49 @@
// limitations under the License.
//

#ifndef PYTHON_TYPE_CASTER_CARTESIANPRODUCT_HPP
#define PYTHON_TYPE_CASTER_CARTESIANPRODUCT_HPP
#ifndef HOGPP_CARTESIANPRODUCT_HPP
#define HOGPP_CARTESIANPRODUCT_HPP

#include <concepts>
#include <tuple>
#include <type_traits>
#include <utility>

template<class... Sizes, class Function, class... Loops>
namespace hogpp {

template<std::integral... Sizes, class Body, std::integral... Loops>
constexpr void cartesianProduct(
const std::tuple<Sizes...>& /*s*/, const std::tuple<Loops...>& l,
Function&& func,
std::index_sequence<> /*unused*/) noexcept(noexcept(func(l)))
[[maybe_unused]] const std::tuple<Sizes...>& s,
const std::tuple<Loops...>& l, Body&& body,
std::index_sequence<> /*unused*/) noexcept(noexcept(body(l)))
{
func(l);
body(l);
}

template<class... Sizes, class Function, class... Loops, std::size_t Index,
std::size_t... Indices>
template<std::integral... Sizes, class Body, std::integral... Loops,
std::size_t Index, std::size_t... Indices>
constexpr void cartesianProduct(
const std::tuple<Sizes...>& s, const std::tuple<Loops...>& l,
Function&& func,
const std::tuple<Sizes...>& s, const std::tuple<Loops...>& l, Body&& body,
std::index_sequence<
Index,
Indices...> /*unused*/) noexcept(noexcept(func(std::declval<std::tuple<Sizes...>>())))
Indices...> /*unused*/) noexcept(noexcept(body(std::declval<std::tuple<Sizes...>>())))
{
for (auto i = 0; i < std::get<Index>(s); ++i) {
cartesianProduct(s, std::tuple_cat(l, std::make_tuple(i)),
std::forward<Function>(func),
std::forward<Body>(body),
std::index_sequence<Indices...>{});
}
}

template<class... Sizes, class Function>
constexpr void
cartesianProduct(const std::tuple<Sizes...>& s, Function&& func) noexcept(
noexcept(func(std::declval<std::tuple<Sizes...>>())))
template<std::integral... Sizes, class Body>
constexpr void cartesianProduct(
const std::tuple<Sizes...>& s,
Body&& body) noexcept(noexcept(body(std::declval<std::tuple<Sizes...>>())))
{
cartesianProduct(s, std::tuple<>{}, std::forward<Function>(func),
cartesianProduct(s, std::tuple<>{}, std::forward<Body>(body),
std::index_sequence_for<Sizes...>{});
}

#endif // PYTHON_TYPE_CASTER_CARTESIANPRODUCT_HPP
} // namespace hogpp

#endif // HOGPP_CARTESIANPRODUCT_HPP
10 changes: 5 additions & 5 deletions include/hogpp/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
#ifndef HOGPP_CONSTANTS_HPP
#define HOGPP_CONSTANTS_HPP

#include <numbers>

namespace hogpp::constants {

template<class T>
inline constexpr T pi = T(3.1415926535897932384626433832795028841971693993751);
inline constexpr T pi = std::numbers::pi_v<T>;

template<class T>
inline constexpr T two_pi =
T(6.28318530717958623199592693708837032318115234375);
inline constexpr T two_pi = 2 * pi<T>;

template<class T>
inline constexpr T half_pi =
T(1.5707963267948965579989817342720925807952880859375);
inline constexpr T half_pi = pi<T> / 2;

} // namespace hogpp::constants

Expand Down
Loading

0 comments on commit bb9f3db

Please sign in to comment.