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

minor improvements #6

Closed
wants to merge 7 commits into from
Closed
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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
-readability-container-data-pointer,
-readability-suspicious-call-argument,
-readability-implicit-bool-conversion,
-readability-uppercase-literal-suffix,
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-cppcoreguidelines-special-member-functions,
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ jobs:
matrix:
build-type: [ Release, RelWithDebInfo ]
compiler: [
{ cxx: g++-11, pkgs: gcc-11 libtbb-dev },
#{ cxx: g++-12, pkgs: gcc-12 libtbb-dev }, # disabled because of warnings in the std library
{ cxx: g++-11, pkgs: g++-11 libtbb-dev },
{ cxx: g++-12, pkgs: g++-12 libtbb-dev },
{ cxx: clang++-14, pkgs: clang-14 libtbb-dev },
{ cxx: clang++-15, pkgs: clang-15 libtbb-dev },
]
lib-type: [
{ name: Static, cmake-flag: "OFF" },
{ name: Shared, cmake-flag: "ON" },
]

defaults:
run:
working-directory: ${{ github.workspace }}/build

name: ${{ matrix.compiler.cxx }}, ${{ matrix.build-type }}, ${{ matrix.lib-type.name }}
name: ${{ matrix.compiler.cxx }}, ${{ matrix.build-type }}

steps:
- name: checkout-repo
Expand All @@ -41,7 +37,7 @@ jobs:
- name: setup-build
env:
CXX: ${{ matrix.compiler.cxx }}
run: cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DGAPP_LINK_TBB=ON -DBUILD_SHARED_LIBS=${{ matrix.lib-type.cmake-flag }}
run: cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DGAPP_LINK_TBB=ON -DBUILD_SHARED_LIBS=OFF

- name: build
run: cmake --build . --parallel
Expand Down
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.21)

project(gapp VERSION 0.1 LANGUAGES CXX)
project(gapp VERSION 0.1.0 LANGUAGES CXX)

include(CheckIPOSupported)
include(CTest)
Expand Down Expand Up @@ -86,7 +86,7 @@ else() # GNU style compiler interface
set(GAPP_WARN_FLAGS "${GAPP_WARN_FLAGS} -Werror -pedantic-errors")
endif()

set(GAPP_OPT_FLAGS "-O3 -fno-math-errno -fno-signed-zeros -fno-trapping-math -freciprocal-math -fno-rounding-math")
set(GAPP_OPT_FLAGS "-O3 -fno-math-errno -fno-trapping-math -freciprocal-math -fno-signed-zeros -fno-associative-math -fno-finite-math-only")
if(GAPP_USE_MARCH_NATIVE)
set(GAPP_OPT_FLAGS "${GAPP_OPT_FLAGS} -march=native")
endif()
Expand All @@ -101,7 +101,8 @@ else() # GNU style compiler interface

# gcc specific options
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(GAPP_WARN_FLAGS "${GAPP_WARN_FLAGS} -Wlogical-op")
# https://gcc.gnu.org/bugzilla//show_bug.cgi?id=71434 with gcc 12 even though it's a system header + pragma diagnostic doesn't work
set(GAPP_WARN_FLAGS "${GAPP_WARN_FLAGS} -Wlogical-op -Wno-maybe-uninitialized")
endif()
# clang specific options
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand Down Expand Up @@ -139,9 +140,9 @@ target_include_directories(gapp SYSTEM INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURR

target_compile_features(gapp PUBLIC "cxx_std_20")
target_compile_definitions(gapp PUBLIC "$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:GAPP_BUILD_STATIC>")
target_compile_definitions(gapp PUBLIC "$<$<BOOL:${GAPP_DISABLE_EXCEPTIONS}>:GAPP_NO_EXCEPTIONS>")
target_compile_options(gapp PUBLIC "$<$<CXX_COMPILER_ID:MSVC>:-Zc:preprocessor>")

# Dependencies
find_package(TBB)
if(TBB_FOUND AND GAPP_LINK_TBB AND NOT MSVC)
target_link_libraries(gapp PUBLIC "TBB::tbb")
Expand Down
6 changes: 3 additions & 3 deletions build/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ BUILD_DIR=$(dirname $(realpath "$0"))
echo -e "\nThe build directory is ${BUILD_DIR}.\n"

echo -e "Installing Debug configuration.\n"
cmake $BUILD_DIR/.. -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF "$@"
cmake -S $BUILD_DIR/.. -B $BUILD_DIR -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF "$@"
cmake --build $BUILD_DIR --config Debug --parallel
cmake --install $BUILD_DIR --config Debug

echo -e "Installing RelWithDebInfo configuration.\n"
cmake $BUILD_DIR/.. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=OFF "$@"
cmake -S $BUILD_DIR/.. -B $BUILD_DIR -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=OFF "$@"
cmake --build $BUILD_DIR --config RelWithDebInfo --parallel
cmake --install $BUILD_DIR --config RelWithDebInfo

echo -e "Installing Release configuration.\n"
cmake $BUILD_DIR/.. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF "$@"
cmake -S $BUILD_DIR/.. -B $BUILD_DIR -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF "$@"
cmake --build $BUILD_DIR --config Release --parallel
cmake --install $BUILD_DIR --config Release
32 changes: 24 additions & 8 deletions build/install_catch.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
#!/bin/sh

git clone https://github.com/catchorg/Catch2.git
cd Catch2
git checkout tags/v3.3.0
cmake -Bbuild -S. -DBUILD_TESTING=OFF
cmake --build build/ --target install --config Debug
cmake --build build/ --target install --config Release
cmake --build build/ --target install --config RelWithDebInfo
cd ..
echo -e "Installing Catch2...\n"

git clone -b v3.3.0 https://github.com/catchorg/Catch2.git
mkdir Catch2/build

cmake --version

BUILD_DIR=$(dirname $(realpath "$0"))/Catch2/build
echo -e "\nThe build directory is ${BUILD_DIR}.\n"

echo -e "Installing Debug configuration.\n"
cmake -S $BUILD_DIR/.. -B $BUILD_DIR -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF "$@"
cmake --build $BUILD_DIR --config Debug --parallel
cmake --install $BUILD_DIR --config Debug

echo -e "Installing RelWithDebInfo configuration.\n"
cmake -S $BUILD_DIR/.. -B $BUILD_DIR -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=OFF "$@"
cmake --build $BUILD_DIR --config RelWithDebInfo --parallel
cmake --install $BUILD_DIR --config RelWithDebInfo

echo -e "Installing Release configuration.\n"
cmake -S $BUILD_DIR/.. -B $BUILD_DIR -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF "$@"
cmake --build $BUILD_DIR --config Release --parallel
cmake --install $BUILD_DIR --config Release
2 changes: 1 addition & 1 deletion docs/api/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PROJECT_NAME = gapp
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 0.1
PROJECT_NUMBER = 0.1.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion docs/install-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Include(FetchContent)
FetchContent_Declare(
gapp
GIT_REPOSITORY https://github.com/KRM7/gapp.git
GIT_TAG v0.1
GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(gapp)

Expand Down
2 changes: 1 addition & 1 deletion src/utility/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ namespace gapp::math
return integral;
}

} // namespace gapp::math
} // namespace gapp::math
33 changes: 16 additions & 17 deletions src/utility/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
/** Math utility classes and functions. */
namespace gapp::math
{
template<typename T>
inline constexpr T inf = std::numeric_limits<T>::infinity();

template<typename T>
inline constexpr T eps = std::numeric_limits<T>::epsilon();

template<typename T>
inline constexpr T small = std::numeric_limits<T>::min();

template<typename T>
inline constexpr T large = std::numeric_limits<T>::max();

using Point = std::vector<double>;


/**
* This class contains the global absolute and relative tolerance values used
* for comparing floating-point values in the GAs.
Expand All @@ -36,7 +51,7 @@ namespace gapp::math

private:
GAPP_API inline constinit static std::atomic<double> absolute_tolerance = 1E-12;
GAPP_API inline constinit static std::atomic<double> relative_tolerance = 10 * std::numeric_limits<double>::epsilon();
GAPP_API inline constinit static std::atomic<double> relative_tolerance = 10 * eps<double>;

friend class ScopedTolerances;
};
Expand Down Expand Up @@ -84,22 +99,6 @@ namespace gapp::math
double old_absolute_tolerance;
double old_relative_tolerance;
};


template<typename T>
inline constexpr T inf = std::numeric_limits<T>::infinity();

template<typename T>
inline constexpr T eps = std::numeric_limits<T>::epsilon();

template<typename T>
inline constexpr T small = std::numeric_limits<T>::min();

template<typename T>
inline constexpr T large = std::numeric_limits<T>::max();


using Point = std::vector<double>;


/* Comparison function for floating point numbers. Returns -1 if (lhs < rhs), +1 if (lhs > rhs), and 0 if (lhs == rhs). */
Expand Down
22 changes: 6 additions & 16 deletions src/utility/rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,9 @@ namespace gapp::rng
template<std::floating_point RealType = double>
inline RealType randomReal(RealType lbound, RealType ubound);

/** Generate a random floating-point value from a standard normal distribution. */
template<std::floating_point RealType = double>
inline RealType randomNormal();

/** Generate a random floating-point value from a normal distribution with the specified mean and std deviation. */
template<std::floating_point RealType = double>
inline RealType randomNormal(RealType mean, RealType SD);
inline RealType randomNormal(RealType mean = 0.0, RealType SD = 1.0);

/** Generate a random integer value from a binomial distribution with the parameters n and p. */
template<std::integral IntType = int>
Expand Down Expand Up @@ -192,21 +188,15 @@ namespace gapp::rng
return std::uniform_real_distribution{ lbound, ubound }(rng::prng);
}

template<std::floating_point RealType>
RealType randomNormal()
{
// keep the distribution for the state
thread_local std::normal_distribution<RealType> dist{ 0.0, 1.0 };

return dist(rng::prng);
}

template<std::floating_point RealType>
RealType randomNormal(RealType mean, RealType SD)
{
GAPP_ASSERT(SD >= 0.0);

return (SD == 0.0) ? mean : std::normal_distribution{ mean, SD }(rng::prng);
// keep the distribution for the state
thread_local std::normal_distribution<RealType> dist;

return SD * dist(rng::prng) + mean;
}

template<std::integral IntType>
Expand Down Expand Up @@ -298,7 +288,7 @@ namespace gapp::rng
GAPP_ASSERT(range_len >= count);

const bool select_many = (count > 0.6 * range_len);
const bool huge_range = range_len >= (1ull << 20);
const bool huge_range = (range_len >= 65536);

if (huge_range) [[unlikely]] return rng::sampleUniqueSet(lbound, ubound, count);

Expand Down
27 changes: 9 additions & 18 deletions src/utility/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,16 @@ namespace gapp::detail



namespace _
{
template<typename Derived, template<typename...> class BaseTempl>
struct is_derived_from_spec_impl
{
private:
template<typename... TArgs>
static std::true_type f(BaseTempl<TArgs...>*);

static std::false_type f(...);

public:
using type = decltype(f(static_cast<Derived*>(nullptr)));
};

} // namespace _

template<typename Derived, template<typename...> class BaseTempl>
using is_derived_from_spec_of = typename _::is_derived_from_spec_impl<Derived, BaseTempl>::type;
struct is_derived_from_spec_of
{
private:
template<typename... TArgs>
static std::true_type f(BaseTempl<TArgs...>*);
static std::false_type f(...);
public:
inline constexpr static bool value = decltype( f(static_cast<Derived*>(nullptr)) )::value;
};

template<typename Derived, template<typename...> class BaseTempl>
inline constexpr bool is_derived_from_spec_of_v = is_derived_from_spec_of<Derived, BaseTempl>::value;
Expand Down
8 changes: 2 additions & 6 deletions src/utility/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
#endif


#ifndef GAPP_NO_EXCEPTIONS
#if defined(__cpp_exceptions)
# define GAPP_THROW(exception_type, msg) throw exception_type(msg)
#else
# define GAPP_THROW(exception_type, msg) GAPP_UNREACHABLE()
Expand Down Expand Up @@ -157,13 +157,9 @@ namespace gapp::detail
{
return high - low;
}
else if (same_sign(low, high))
{
return high - low;
}
else
{
return static_cast<size_t>(-(low + 1)) + high + 1;
return same_sign(low, high) ? high - low : -(low + 1) + high + 1;
}
}

Expand Down
Loading