Skip to content

Commit

Permalink
Merge branch 'mabe-systematics' into sum-distance-sys
Browse files Browse the repository at this point in the history
  • Loading branch information
emilydolson authored Feb 29, 2024
2 parents 1b323cf + ab563bf commit f11a154
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 57 deletions.
14 changes: 7 additions & 7 deletions include/emp/Evolve/Systematics.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* This file is part of Empirical, https://github.com/devosoft/Empirical
* Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* date: 2024
*/
/**
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* @date 2017-2023
*
* @file Systematics.hpp
* @brief Track genotypes, species, clades, or lineages of organisms in a world.
*
* @file
* @brief TODO.
* @todo We should provide an option to back up systematics data to a file so that it doesn't all
* need to be kept in memory, especially if we're only doing post-analysis.
* @todo This inheritance system makes adding new systematics-related data tracking kind of a pain.
Expand Down
42 changes: 21 additions & 21 deletions include/emp/base/_optional_throw.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
* This file is part of Empirical, https://github.com/devosoft/Empirical
* Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* date: 2024
*/
/**
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* @date 2023.
*
* @file _optional_throw.hpp
* @brief Variant of asserts that throws exception
* @note This is useful for writing code that gets wrapped in Python via pybind11
* @file
* @brief TODO.
*/

#ifndef EMP_BASE__OPTIONAL_THROW_TRIGGER_HPP_INCLUDE
#define EMP_BASE__OPTIONAL_THROW_TRIGGER_HPP_INCLUDE
#ifndef EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE
#define EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE

#include <sstream>
#include <string>
Expand All @@ -19,42 +19,42 @@
namespace emp {

/// Base case for assert_print...
inline void assert_print(std::stringstream &) { ; }
inline void assert_print_opt(std::stringstream &) { ; }

/// Print out information about the next variable and recurse...
template <typename T, typename... EXTRA>
void assert_print(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
void assert_print_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
if constexpr ( emp::is_streamable<std::stringstream, T>::value ) {
ss << name << ": [" << val << "]" << std::endl;
} else ss << name << ": (non-streamable type)" << std::endl;
assert_print(ss, std::forward<EXTRA>(extra)...);
assert_print_opt(ss, std::forward<EXTRA>(extra)...);
}

template <typename T, typename... EXTRA>
void assert_print_second(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
assert_print(ss, std::forward<EXTRA>(extra)...);
void assert_print_second_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
assert_print_opt(ss, std::forward<EXTRA>(extra)...);
}

template <typename T>
void assert_print_second(std::stringstream & ss, std::string name, T && val) {;}
void assert_print_second_opt(std::stringstream & ss, std::string name, T && val) {;}

template <typename T, typename... EXTRA>
void assert_print_first(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
void assert_print_first_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
if constexpr ( emp::is_streamable<std::stringstream, T>::value ) {
ss << name << ": [" << val << "]" << std::endl;
} else ss << name << ": (non-streamable type)" << std::endl;
assert_print_second(ss, std::forward<EXTRA>(extra)...);
assert_print_second_opt(ss, std::forward<EXTRA>(extra)...);
}

void assert_print_first(std::stringstream & ss, int placeholder) {;}
void assert_print_first_opt(std::stringstream & ss, int placeholder) {;}

template <typename... EXTRA>
void assert_throw(std::string filename, size_t line, std::string expr, std::string message, EXTRA &&... extra) {
void assert_throw_opt(std::string filename, size_t line, std::string expr, std::string message, EXTRA &&... extra) {
std::stringstream ss;
ss << "Internal Error (in " << filename << " line " << line << "): " << expr << ".\n\n Message: " << message << "\n\n";
assert_print_first(ss, std::forward<EXTRA>(extra)...);
assert_print_first_opt(ss, std::forward<EXTRA>(extra)...);
throw(std::runtime_error(ss.str()));
}
}

#endif // #ifndef EMP_BASE__OPTIONAL_THROW_TRIGGER_HPP_INCLUDE
#endif // #ifndef EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE
2 changes: 1 addition & 1 deletion include/emp/base/always_assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

#define emp_always_assert_impl(TEST) emp_always_assert_msvc_impl(TEST)

#elif defined(IN_PYTHON)
#elif defined(EMP_OPTIONAL_THROW_ON)

#define emp_always_assert_impl(...) \
do { \
Expand Down
18 changes: 9 additions & 9 deletions include/emp/base/optional_throw.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* This file is part of Empirical, https://github.com/devosoft/Empirical
* Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* date: 2024
*/
/**
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* @date 2023.
*
* @file optional_throw.hpp
* @brief Like emp_assert, but throws an exception if in Python
* @note Status: RELEASE
* @file
* @brief TODO.
*
*/

Expand All @@ -20,14 +20,14 @@
#endif


#if defined( IN_PYTHON )
#if defined( EMP_OPTIONAL_THROW_ON )

// #if defined (_MSC_VER )

#define emp_optional_throw(TEST, MESSAGE) \
do { \
if (!(TEST)) { \
emp::assert_throw(__FILE__, __LINE__, #TEST, MESSAGE, 0); \
emp::assert_throw_opt(__FILE__, __LINE__, #TEST, MESSAGE, 0); \
} \
} while(0)

Expand Down
18 changes: 9 additions & 9 deletions tests/Evolve/Systematics.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* This file is part of Empirical, https://github.com/devosoft/Empirical
* Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* date: 2024
*/
/**
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* @date 2021
*
* @file Systematics.cpp
*/

* @file
* @brief TODO.
#include <filesystem>
#include <iostream>
#include <sstream>
*/

#include "third-party/Catch/single_include/catch2/catch.hpp"

Expand Down Expand Up @@ -920,7 +920,7 @@ TEST_CASE("Run world", "[evo]") {
for (size_t i = 0; i < 100; i++) {
EliteSelect(world, 1, 1);
}

for (size_t i = 0; i < world.GetSize(); i++) {
record_fit_sig.Trigger(i, world.CalcFitnessID(i));
record_phen_sig.Trigger(i, phen_fun(world.GetOrg(i)));
Expand Down
20 changes: 10 additions & 10 deletions tests/base/optional_throw.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* This file is part of Empirical, https://github.com/devosoft/Empirical
* Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* date: 2024
*/
/**
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* @date 2023
*
* @file optional_throw.cpp
*/

* @file
* @brief TODO.
#include <iostream>
#include <sstream>
*/

#include "third-party/Catch/single_include/catch2/catch.hpp"

Expand All @@ -19,11 +19,11 @@ TEST_CASE("Optional throw" "[asserts]") {
emp_optional_throw(false);
REQUIRE(emp::assert_last_fail);

#define IN_PYTHON 1
#define EMP_OPTIONAL_THROW_ON 1
try {
emp_optional_throw(false);
}
catch (std::runtime_error & error) {
REQUIRE(std::string(error.what()) == "Internal Error (in always_assert.cpp line 37): false,\nfalse: [0]\n");
}
}
}

0 comments on commit f11a154

Please sign in to comment.