-
Notifications
You must be signed in to change notification settings - Fork 72
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
Separate configuration from algorithms #200
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
53dae04
to
b21c6a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
ec37a4b
to
2e29f49
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
62b33e1
to
030e869
Compare
edf3df4
to
6de65f6
Compare
08b8905
to
1237dd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
bdc91f4
to
20c5069
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
Проба пера. Получилось очень много бойлерплейта, но когда за макросом спрятал, стало терпимо. С |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
827bc8f
to
656f217
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
8d10b21
to
2c4bd78
Compare
Only throw `std::invalid_argument`.
This avoids some unnecessary templates and emphasizes how the class is supposed to be used.
An algorithm's configuration is reset whenever `kwargs` is not empty. Also updated comments to explicitly state the supported Python usage scenarios.
Здесь как будто много кода по типу auto Method(...) {
return configuration.Method(...);
} в алгоритме |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Очень большой пр, логически отдельные части закидывай в будущем пожалуйста разными прами (форматирование pyro тут ни к чему, как минимум) :)
Не очень понимаю логику с передачей объектов опций как rvalue ref везде.
Хорошие тесты, кстати
Option &&SetValueCheck(ValueCheckFunc value_check) { | ||
assert(!value_check_); | ||
value_check_ = std::move(value_check); | ||
return *this; | ||
return std::move(*this); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а зачем?
std::unique_ptr<IOption> MoveToHeap() override { | ||
return std::make_unique<Option>(std::move(*this)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не очень ясно зачем и как этот метод помогает. Как будто вызывающий код сам может сделать std::make_unique<Option>(opt)
, если нужном
load_data = 0, | ||
load_prepared_data, | ||
execute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kLoadData
, kLoadPreparedData
, kExecute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Разве? Это же enum
, а не кучка констант. В остальных enum
ах такие имена.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну enum
это по сути и есть кучка констант с конкретными типом :)
В некоторых enum
ах имена такие только потому что мы хотим строки преобразовывать в значения енама и эти строки получаем от пользователя. Стайлгайд просит их именовать как константы
namespace util::config { | ||
|
||
// clang-format off | ||
BETTER_ENUM(ConfigurationStage, size_t, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а зачем size_t
?
// Options with the same names must have certain semantics. The | ||
// situation where both algorithms have options with the same name but | ||
// one throws an exception for the pair of values while the other does | ||
// not is undefined behaviour. The situation where both algorithms may |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Опять же, предлагаю не использовать "undefined behavior" в коде, кототрый мы контролируем :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так ведь оно сейчас так же работает. Просто здесь это явно написано. "Программистская ошибка", может быть, точнее будет
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так ведь оно сейчас так же работает.
Не очень понял, что так же работает (и как, так же?).
Я просто предлагаю избегать ситуаций в коде, которые нарушают какие-либо инварианты и это никак не отлавливается, а вместо этого говорится, что это "undefined behavior" и разбирайтесь сами. Нам же потом это и дебажить ведь. Стоит как минимум писать ассерты, проверяющие нужные инварианты. Тут такой ассерт уже есть насколько я вижу, поэтому просто предлагаю убрать "undefined behavior", а написать, что это просто ожидания этого кода.
@@ -28,16 +24,21 @@ std::unique_ptr<AlgorithmBase> CreateAlgorithmInstance(AlgorithmType algorithm) | |||
static_cast<size_t>(algorithm), create); | |||
} | |||
|
|||
template <typename AlgorithmBase> | |||
std::vector<AlgorithmType> GetAllDerived() { | |||
template <typename DerivedFrom> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
по-моему Base
лучше, чем DerivedFrom
, такой нейминг путает
if (option_name == kPliRelation) { | ||
throw std::logic_error("You do not manage this option."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
довольно плохо выглядит, но решения лучше я придумать не могу
|
||
TEST_F(ConfigurationTesting, BasicConfiguration) { | ||
int var1; | ||
const int var1val = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: constexpr
using FuncTuple = Configuration::FuncTuple; | ||
using OptionNameSet = Configuration::OptionNameSet; | ||
using AddExternalOptFunc = Configuration::AddExternalOptFunc; | ||
using SetExternalOptFunc = Configuration::SetExternalOptFunc; | ||
using UnsetExternalOptFunc = Configuration::UnsetExternalOptFunc; | ||
using GetExternalTypeIndexFunc = Configuration::GetExternalTypeIndexFunc; | ||
using ResetExternalAlgoConfigFunc = Configuration::ResetExternalAlgoConfigFunc; | ||
|
||
class ConfigurationTesting : public ::testing::Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: anonymous namespace
Splits configuration-related things into a separate
Configuration
class, tests included.TypoMiner's methods are reorganized in accordance with this class's structure.
Solves the problem with
PliBasedFDAlgorithm
's code repetition.Better behavior in Python. More info about the options is provided to Python.