Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions .github/scripts/install_llvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

sudo apt update
sudo apt install -y clang libc++-dev libclang-rt-dev lld
4 changes: 4 additions & 0 deletions .github/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

sudo apt update
sudo apt install -y ninja-build build-essential cmake
66 changes: 45 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
name: Test

on:
push:
branches:
- main
run-name: Test
on: pull_request

jobs:
ctest:
gcc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up
run: bash .github/scripts/setup.sh
- name: Install gcc
run: sudo apt install -y gcc
- name: Build tests
run: |
cmake --preset test_gcc -B build/debug/gcc
cd ./build/debug/gcc && ninja
- name: Run tests
run: |
./build/debug/gcc/test/mvPolynomial_test

clang:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up vcpkg
- uses: actions/checkout@v5
- name: Set up
run: bash .github/scripts/setup.sh
- name: Install llvm
run: bash .github/scripts/install_llvm.sh
- name: Build tests
run: |
git clone --depth 1 -b 2025.08.27 https://github.com/microsoft/vcpkg.git vcpkg
- name: Install build tools
cmake --preset test_clang -B build/debug/clang
cd ./build/debug/clang && ninja
- name: Run tests
run: |
sudo apt update
sudo apt install -y ninja-build build-essential cmake
echo "$(pwd)/vcpkg" >> $GITHUB_PATH
./build/debug/clang/test/mvPolynomial_test

clang_memory:
# libstdc++ and libc++ have uninitialized variables,
# so I skip this job temporarily.
if: "false"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up
run: bash .github/scripts/setup.sh
- name: Install llvm
run: bash .github/scripts/install_llvm.sh
- name: Build tests
run: |
./vcpkg/bootstrap-vcpkg.sh
cmake --preset CI_test
cd ./build/debug && ninja
env:
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
cmake --preset test_clang_memory -B build/debug/clang/memory
cd ./build/debug/clang/memory && ninja
- name: Run tests
run: ctest --test-dir ./build/debug/test
run: |
./build/debug/clang/memory/test/mvPolynomial_test
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

114 changes: 100 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,122 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_OPTIMIZE_DEPENDENCIES ON)

# Library
# Boost
find_package(Boost CONFIG REQUIRED)
list(APPEND extra_headers ${Boost_INCLUDE_DIRS})
include(FetchContent)
if (MVPOLYNOMIAL_BUILD_TESTS)
FetchContent_Declare(
eigen3
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 549bf8c75b6aae071cde2f28aa48f16ee3ae60b0 # 5.0.0
OVERRIDE_FIND_PACKAGE
)
# The reason why I use CACHE INTERNAL is written in the following link:
# https://cmake.org/cmake/help/latest/module/FetchContent.html#overriding-where-to-find-cmakelists-txt
set(EIGEN_BUILD_TESTING OFF CACHE INTERNAL "")
set(EIGEN_BUILD_CMAKE_PACKAGE ON CACHE INTERNAL "")
FetchContent_MakeAvailable(eigen3)

# Eigen
find_package(Eigen3 CONFIG REQUIRED NO_MODULE)
list(APPEND extra_libs Eigen3::Eigen)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG e424e3f2e607da02742f73db84873b8084fc714c # 12.0.0
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(fmt)
else()
find_package(Eigen3 5.0.0 CONFIG REQUIRED)
find_package(fmt 12.0.0 CONFIG REQUIRED)
endif()

# fmt
find_package(fmt CONFIG REQUIRED)
list(APPEND extra_libs Eigen3::Eigen)
list(APPEND extra_libs fmt::fmt)

add_library(mvPolynomial_compiler_flags INTERFACE)
target_compile_features(mvPolynomial_compiler_flags INTERFACE cxx_std_20)
# To avoid add_subdirectory,
FetchContent_Declare(
platanus
GIT_REPOSITORY https://github.com/sukeya/platanus.git
GIT_TAG 23a9ba9cd6bfe38b01fd7e87e28ae42dd8b2744f # origin/main
)
FetchContent_MakeAvailable(platanus)
list(APPEND extra_libs platanus)


add_library(${PROJECT_NAME} INTERFACE)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20)
target_include_directories(
${PROJECT_NAME}
INTERFACE
${extra_headers}
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(
${PROJECT_NAME}
INTERFACE
${extra_libs}
mvPolynomial_compiler_flags
)

if (BUILD_TESTS)
include(CTest)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(gcc "$<COMPILE_LANG_AND_ID:CXX,GNU>")
set(clang "$<COMPILE_LANG_AND_ID:CXX,Clang>")
set(msvc "$<COMPILE_LANG_AND_ID:CXX,MSVC>")

set(gcc_like $<OR:${gcc},${clang})

if (MVPOLYNOMIAL_BUILD_TESTS)
enable_testing()

set(boost_test_dependencies
algorithm
array
assert
bind
config
concept_check
container_hash
conversion
core
detail
describe
exception
function
functional
function_types
fusion
io
iterator
mp11
mpl
numeric_conversion
optional
predef
preprocessor
regex
range
smart_ptr
static_assert
throw_exception
tuple
typeof
type_traits
unordered
utility
)

foreach(deplib ${boost_test_dependencies})
FetchContent_Declare(
${deplib}
GIT_REPOSITORY https://github.com/boostorg/${deplib}.git
GIT_TAG boost-1.89.0
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(${deplib})
endforeach()

FetchContent_Declare(
boost_unit_test
GIT_REPOSITORY https://github.com/boostorg/test.git
GIT_TAG boost-1.89.0
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(boost_unit_test)

add_subdirectory(test)
endif()
41 changes: 33 additions & 8 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
{
"version": 9,
"version": 10,
"cmakeMinimumRequired": {
"major": 3,
"minor": 30,
"patch": 0
"minor": 31
},
"configurePresets": [
{
"name": "CI_test",
"binaryDir": "${sourceDir}/build/debug",
"name": "test",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BUILD_TESTS": "ON",
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
"MVPOLYNOMIAL_BUILD_TESTS": "ON"
},
"generator": "Ninja"
},
{
"name": "test_gcc",
"inherits": ["test"],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_CXX_FLAGS": "-O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined,pointer-compare,pointer-subtract,leak -D EIGEN_MAX_ALIGN_BYTES=0"
}
},
{
"name": "clang",
"cacheVariables": {
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_LINKER_TYPE": "LLD"
}
},
{
"name": "test_clang",
"inherits": ["test", "clang"],
"cacheVariables": {
"CMAKE_CXX_FLAGS": "-stdlib=libc++ -O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined,leak -D EIGEN_MAX_ALIGN_BYTES=0"
}
},
{
"name": "test_clang_memory",
"inherits": ["test", "clang"],
"cacheVariables": {
"CMAKE_CXX_FLAGS": "-stdlib=libc++ -O1 -g -fno-omit-frame-pointer -fsanitize=memory"
}
}
]
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2023 sukeya
Copyright 2023,2025 Yuya Asano

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
53 changes: 27 additions & 26 deletions include/mvPolynomial/index_comparer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,32 @@

#include <concepts>
#include <compare>
#include <cstddef>

namespace mvPolynomial {
/**
* \brief A class comparing two multivariable polynomials by its indeces.
* \tparam IntType the type of elements of indices.
* \tparam D the dimension of indices.
*/
template <std::signed_integral IntType, int D>
class IndexComparer {
template <std::signed_integral Int_, int D>
class IndexComparer final {
public:
static_assert(D > 0, "IndexComparer: the dimension must be positive.");

using Index = IndexType<IntType, D>;
using Int = Int_;
using Index = IndexType<Int, D>;

static constexpr int dim = D;

/**
* \brief If the elems of lhd are equal to that of rhd until i th time and lhd[i] is greater than
* rhd[i], return true: otherwise, false.
* \brief If lhd[i] == rhd[i] for i = 0, ..., N - 1 and lhd[N] > rhd[N],
* return greater: if lhd[N] < rhd[N], return less: otherwise, return equal.
* \param[in] lhd an index
* \param[in] rhd an index
*/
constexpr bool operator()(const Index& lhd, const Index& rhd) const noexcept {
for (std::size_t i = 0; i != lhd.size(); ++i) {
auto comp = lhd[i] <=> rhd[i];
if (comp > 0) {
return true;
} else if (comp < 0) {
return false;
}
}
return false;
}

constexpr std::strong_ordering get_ordering(const Index& lhd, const Index& rhd) const noexcept {
for (std::size_t i = 0; i != lhd.size(); ++i) {
static constexpr std::strong_ordering Compare(const Index& lhd, const Index& rhd) {
for (std::size_t i = 0; i < lhd.size(); ++i) {
auto comp = lhd[i] <=> rhd[i];
if (comp > 0) {
return std::strong_ordering::greater;
Expand All @@ -48,14 +40,23 @@ class IndexComparer {
}
return std::strong_ordering::equal;
}
};

template <std::signed_integral IntType>
class IndexComparer<IntType, 1> {
public:
using Index = IntType;

constexpr bool operator()(Index lhd, Index rhd) const noexcept { return lhd > rhd; }
/**
* \brief If lhd[i] == rhd[i] for i = 0, ..., N - 1 and lhd[N] > rhd[N],
* return true: otherwise, false.
* \param[in] lhd an index
* \param[in] rhd an index
*/
bool operator()(const Index& lhd, const Index& rhd) const {
for (std::size_t i = 0; i < lhd.size(); ++i) {
if (lhd[i] > rhd[i]) {
return true;
} else if (lhd[i] < rhd[i]) {
return false;
}
}
return false;
}
};
} // namespace mvPolynomial

Expand Down
Loading