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

style: fix style issues in config #4198

Merged
merged 3 commits into from
Oct 7, 2022
Merged
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
2 changes: 1 addition & 1 deletion python/pylibvw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class OptionManager : VW::config::typed_option_visitor
, m_option_group_dic(options.get_collection_of_options())
, m_py_opt_class(py_class)
{
default_group_name = options.m_default_tint;
default_group_name = options.DEFAULT_TINT;
m_visitor_output_var = nullptr;
}

Expand Down
26 changes: 13 additions & 13 deletions vowpalwabbit/config/include/vw/config/option_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,82 +48,82 @@ template <typename T>
struct option_builder
{
template <typename... Args>
option_builder(Args&&... args) : m_option_obj(std::forward<Args>(args)...)
option_builder(Args&&... args) : _option_obj(std::forward<Args>(args)...)
{
}

option_builder& default_value(const typename T::value_type& value)
{
m_option_obj.set_default_value(value);
_option_obj.set_default_value(value);
return *this;
}

option_builder& short_name(const std::string& short_name)
{
if (short_name.size() != 1) { THROW("short_name must be a single character but got: " << short_name); }
m_option_obj.m_short_name = short_name;
_option_obj.m_short_name = short_name;
return *this;
}

option_builder& short_name(char short_name)
{
m_option_obj.m_short_name = std::string(1, short_name);
_option_obj.m_short_name = std::string(1, short_name);
return *this;
}

option_builder& help(const std::string& help)
{
m_option_obj.m_help = help;
_option_obj.m_help = help;
return *this;
}

/// Hides the option from help output.
option_builder& hidden(bool hidden = true)
{
m_option_obj.m_hidden_from_help = hidden;
_option_obj.m_hidden_from_help = hidden;
return *this;
}

/// Marks this as an experimental option.
option_builder& experimental(bool experimental = true)
{
m_option_obj.m_experimental = experimental;
_option_obj.m_experimental = experimental;
return *this;
}

option_builder& keep(bool keep = true)
{
m_option_obj.m_keep = keep;
_option_obj.m_keep = keep;
return *this;
}

option_builder& necessary(bool necessary = true)
{
m_option_obj.m_necessary = necessary;
_option_obj.m_necessary = necessary;
return *this;
}

option_builder& one_of(std::set<typename T::value_type> args)
{
m_option_obj.set_one_of(args);
_option_obj.set_one_of(args);
return *this;
}

option_builder& allow_override(bool allow_override = true)
{
if (details::is_vector<typename T::value_type>::value)
{ THROW("allow_override can only apply to scalar option types.") }
m_option_obj.m_allow_override = allow_override;
_option_obj.m_allow_override = allow_override;
return *this;
}

static std::shared_ptr<base_option> finalize(option_builder&& option)
{
return std::make_shared<T>(std::move(option.m_option_obj));
return std::make_shared<T>(std::move(option._option_obj));
}

private:
T m_option_obj;
T _option_obj;
};

template <typename T>
Expand Down
12 changes: 6 additions & 6 deletions vowpalwabbit/config/include/vw/config/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ struct options_i
VW_ATTR(nodiscard) virtual std::vector<std::string> check_unregistered() = 0;
virtual ~options_i() = default;

static constexpr const char* m_default_tint = "general";
static constexpr const char* DEFAULT_TINT = "general";

protected:
// Collection that tracks for now
// setup_function_id (str) -> list of option_group_definition
std::map<std::string, std::vector<option_group_definition>> m_option_group_dic;
std::vector<option_group_definition> m_option_group_definitions;
std::string m_current_reduction_tint = m_default_tint;
std::map<std::string, std::shared_ptr<base_option>> m_options;
std::map<char, std::shared_ptr<base_option>> m_short_options;
std::map<std::string, std::vector<option_group_definition>> _option_group_dic;
std::vector<option_group_definition> _option_group_definitions;
std::string _current_reduction_tint = DEFAULT_TINT;
std::map<std::string, std::shared_ptr<base_option>> _options;
std::map<char, std::shared_ptr<base_option>> _short_options;
};
} // namespace config
} // namespace VW
8 changes: 4 additions & 4 deletions vowpalwabbit/config/include/vw/config/options_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ struct options_cli : public options_i
VW_ATTR(nodiscard) std::vector<std::string> get_positional_tokens() const override;

private:
std::vector<std::string> m_command_line;
std::vector<std::string> _command_line;

// Key is either short or long name
std::unordered_map<VW::string_view, std::vector<VW::string_view>> m_prog_parsed_token_map;
std::unordered_map<VW::string_view, std::vector<VW::string_view>> _prog_parsed_token_map;

std::set<std::string> m_reachable_options;
std::unordered_map<std::string, std::vector<std::set<std::string>>> m_dependent_necessary_options;
std::set<std::string> _reachable_options;
std::unordered_map<std::string, std::vector<std::set<std::string>>> _dependent_necessary_options;
};

} // namespace config
Expand Down
34 changes: 17 additions & 17 deletions vowpalwabbit/config/src/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::vector<std::shared_ptr<base_option>> options_i::get_all_options()
{
std::vector<std::shared_ptr<base_option>> output_values;

std::transform(m_options.begin(), m_options.end(), std::back_inserter(output_values),
std::transform(_options.begin(), _options.end(), std::back_inserter(output_values),
[](std::pair<const std::string, std::shared_ptr<base_option>>& kv) { return kv.second; });

return output_values;
Expand All @@ -28,8 +28,8 @@ std::vector<std::shared_ptr<base_option>> options_i::get_all_options()
std::vector<std::shared_ptr<const base_option>> VW::config::options_i::get_all_options() const
{
std::vector<std::shared_ptr<const base_option>> output_values;
output_values.reserve(m_options.size());
for (const auto& kv : m_options) { output_values.push_back(kv.second); }
output_values.reserve(_options.size());
for (const auto& kv : _options) { output_values.push_back(kv.second); }
return output_values;
}

Expand All @@ -46,29 +46,29 @@ std::shared_ptr<base_option> internal_get_option(

std::shared_ptr<base_option> VW::config::options_i::get_option(const std::string& key)
{
return internal_get_option(key, m_options);
return internal_get_option(key, _options);
}

std::shared_ptr<const base_option> VW::config::options_i::get_option(const std::string& key) const
{
// shared_ptr can implicitly upgrade to const from non-const
return internal_get_option(key, m_options);
return internal_get_option(key, _options);
}

void options_i::add_and_parse(const option_group_definition& group)
{
// Add known options before parsing so impl can make use of them.
m_option_group_definitions.push_back(group);
m_option_group_dic[m_current_reduction_tint].push_back(group);
_option_group_definitions.push_back(group);
_option_group_dic[_current_reduction_tint].push_back(group);
for (const auto& option : group.m_options)
{
// The last definition is kept. There was a bug where using .insert at a later pointer changed the command line but
// the previously defined option's default value was serialized into the model. This resolves that state info.
m_options[option->m_name] = option;
_options[option->m_name] = option;
if (!option->m_short_name.empty())
{
assert(option->m_short_name.size() == 1);
m_short_options[option->m_short_name[0]] = option;
_short_options[option->m_short_name[0]] = option;
}
}

Expand All @@ -80,17 +80,17 @@ void options_i::add_and_parse(const option_group_definition& group)
bool options_i::add_parse_and_check_necessary(const option_group_definition& group)
{
// Add known options before parsing so impl can make use of them.
m_option_group_definitions.push_back(group);
m_option_group_dic[m_current_reduction_tint].push_back(group);
_option_group_definitions.push_back(group);
_option_group_dic[_current_reduction_tint].push_back(group);
for (const auto& option : group.m_options)
{
// The last definition is kept. There was a bug where using .insert at a later pointer changed the command line but
// the previously defined option's default value was serialized into the model. This resolves that state info.
m_options[option->m_name] = option;
_options[option->m_name] = option;
if (!option->m_short_name.empty())
{
assert(option->m_short_name.size() == 1);
m_short_options[option->m_short_name[0]] = option;
_short_options[option->m_short_name[0]] = option;
}
}

Expand All @@ -102,14 +102,14 @@ bool options_i::add_parse_and_check_necessary(const option_group_definition& gro
return necessary_enabled;
}

void options_i::tint(const std::string& reduction_name) { m_current_reduction_tint = reduction_name; }
void options_i::reset_tint() { m_current_reduction_tint = m_default_tint; }
void options_i::tint(const std::string& reduction_name) { _current_reduction_tint = reduction_name; }
void options_i::reset_tint() { _current_reduction_tint = DEFAULT_TINT; }

std::map<std::string, std::vector<option_group_definition>> options_i::get_collection_of_options() const
{
return m_option_group_dic;
return _option_group_dic;
}
const std::vector<option_group_definition>& options_i::get_all_option_group_definitions() const
{
return m_option_group_definitions;
return _option_group_definitions;
}
Loading