diff --git a/vowpalwabbit/allreduce/src/allreduce_sockets.cc b/vowpalwabbit/allreduce/src/allreduce_sockets.cc index a61e5608a03..aa8f2fbc708 100644 --- a/vowpalwabbit/allreduce/src/allreduce_sockets.cc +++ b/vowpalwabbit/allreduce/src/allreduce_sockets.cc @@ -114,7 +114,7 @@ void VW::all_reduce_sockets::all_reduce_init(VW::io::logger& logger) if (lastError != 0) THROWERRNO("WSAStartup() returned error:" << lastError); #endif - class hostent* master = gethostbyname(_span_server.c_str()); + struct hostent* master = gethostbyname(_span_server.c_str()); if (master == nullptr) THROWERRNO("gethostbyname(" << _span_server << ")"); diff --git a/vowpalwabbit/core/include/vw/core/automl_impl.h b/vowpalwabbit/core/include/vw/core/automl_impl.h index 4a446668609..9cf5a0189e3 100644 --- a/vowpalwabbit/core/include/vw/core/automl_impl.h +++ b/vowpalwabbit/core/include/vw/core/automl_impl.h @@ -257,7 +257,7 @@ class interaction_config_manager bool count_namespaces(const multi_ex& ecs, std::map& ns_counter); void apply_config(example* ec, interaction_vec_t* live_interactions); bool is_allowed_to_remove(const namespace_index ns); -void clear_non_champ_weights(dense_parameters& weights, uint32_t total, uint32_t& feature_width); +//void clear_non_champ_weights(dense_parameters& weights, uint32_t total, uint32_t& feature_width); bool worse(); // all possible states of automl diff --git a/vowpalwabbit/core/include/vw/core/estimators/confidence_sequence_robust.h b/vowpalwabbit/core/include/vw/core/estimators/confidence_sequence_robust.h index 84737b00955..cc482f68220 100644 --- a/vowpalwabbit/core/include/vw/core/estimators/confidence_sequence_robust.h +++ b/vowpalwabbit/core/include/vw/core/estimators/confidence_sequence_robust.h @@ -48,15 +48,15 @@ class countable_discrete_base countable_discrete_base(double tol_x = 1e-6, bool is_brentq = false, double eta = 0.95f, double k = 1.5, double lambda_max = 0.5, double xi = 1.6); double get_ci(double alpha) const; - double get_lam_sqrt_tp1(double j) const; + double get_lam_sqrt_tp1(uint64_t j) const; double get_v_impl(std::map& memo, uint64_t j) const; double log_wealth_mix(double mu, double s, double thres, std::map& memo) const; double root_bisect(double s, double thres, std::map& memo, double min_mu, double max_mu) const; double root_brentq(double s, double thres, std::map& memo, double min_mu, double max_mu) const; double log_sum_exp(const std::vector& combined) const; double lb_log_wealth(double alpha) const; - double get_log_weight(double j) const; - double get_log_remaining_weight(double j) const; + double get_log_weight(uint64_t j) const; + double get_log_remaining_weight(uint64_t j) const; double get_s() const; double get_v(double lam_sqrt_tp1) const; void add_obs(double x); diff --git a/vowpalwabbit/core/include/vw/core/hashstring.h b/vowpalwabbit/core/include/vw/core/hashstring.h index a26d68e5e07..d94b2c9a946 100644 --- a/vowpalwabbit/core/include/vw/core/hashstring.h +++ b/vowpalwabbit/core/include/vw/core/hashstring.h @@ -37,7 +37,7 @@ VW_STD14_CONSTEXPR inline uint32_t hashstring(const char* s, size_t len, uint32_ else { return VW::uniform_hash(front, len, h); } } - return ret + h; + return static_cast(ret + h); } } // namespace details @@ -51,4 +51,4 @@ hash_func_t get_hasher(const std::string& s); using hash_func_t VW_DEPRECATED("Moved into VW namespace") = VW::hash_func_t; VW_DEPRECATED("Moved into VW namespace") -VW::hash_func_t get_hasher(const std::string& s); \ No newline at end of file +VW::hash_func_t get_hasher(const std::string& s); diff --git a/vowpalwabbit/core/include/vw/core/multi_model_utils.h b/vowpalwabbit/core/include/vw/core/multi_model_utils.h index 9aa14e9b861..183e1bf89aa 100644 --- a/vowpalwabbit/core/include/vw/core/multi_model_utils.h +++ b/vowpalwabbit/core/include/vw/core/multi_model_utils.h @@ -112,7 +112,7 @@ inline void reduce_innermost_model_weights(dense_parameters& weights, const size } for (auto weights_it = weights.begin(); weights_it < weights.end(); weights_it += total_feature_width) { - uint32_t cb_ind = weights_it.index() / innermost_feature_width_size; + uint32_t cb_ind = static_cast(weights_it.index() / innermost_feature_width_size); for (size_t outer_offset = 0; outer_offset < overall_without_innermost_feature_width_size; ++outer_offset) { for (size_t stride_offset = 0; stride_offset < weights.stride(); ++stride_offset) @@ -133,4 +133,4 @@ inline void reduce_innermost_model_weights(dense_parameters& weights, const size } } // namespace multi_model } // namespace reductions -} // namespace VW \ No newline at end of file +} // namespace VW diff --git a/vowpalwabbit/core/include/vw/core/vw.h b/vowpalwabbit/core/include/vw/core/vw.h index e82a851519c..8389b2907e4 100644 --- a/vowpalwabbit/core/include/vw/core/vw.h +++ b/vowpalwabbit/core/include/vw/core/vw.h @@ -295,24 +295,24 @@ inline uint64_t hash_space_cstr(VW::workspace& all, const char* fstr) // Then use it as the seed for hashing features. inline uint64_t hash_feature(VW::workspace& all, const std::string& s, uint64_t u) { - return all.parser_runtime.example_parser->hasher(s.data(), s.length(), u) & all.runtime_state.parse_mask; + return all.parser_runtime.example_parser->hasher(s.data(), s.length(), static_cast(u)) & all.runtime_state.parse_mask; } inline uint64_t hash_feature_static(const std::string& s, uint64_t u, const std::string& h, uint32_t num_bits) { size_t parse_mark = (1 << num_bits) - 1; - return get_hasher(h)(s.data(), s.length(), u) & parse_mark; + return get_hasher(h)(s.data(), s.length(), static_cast(u)) & parse_mark; } inline uint64_t hash_feature_cstr(VW::workspace& all, const char* fstr, uint64_t u) { - return all.parser_runtime.example_parser->hasher(fstr, strlen(fstr), u) & all.runtime_state.parse_mask; + return all.parser_runtime.example_parser->hasher(fstr, strlen(fstr), static_cast(u)) & all.runtime_state.parse_mask; } inline uint64_t chain_hash(VW::workspace& all, const std::string& name, const std::string& value, uint64_t u) { // chain hash is hash(feature_value, hash(feature_name, namespace_hash)) & parse_mask return all.parser_runtime.example_parser->hasher( - value.data(), value.length(), all.parser_runtime.example_parser->hasher(name.data(), name.length(), u)) & + value.data(), value.length(), all.parser_runtime.example_parser->hasher(name.data(), name.length(), static_cast(u))) & all.runtime_state.parse_mask; } @@ -320,7 +320,7 @@ inline uint64_t chain_hash_static( const std::string& name, const std::string& value, uint64_t u, hash_func_t hash_func, uint64_t parse_mask) { // chain hash is hash(feature_value, hash(feature_name, namespace_hash)) & parse_mask - return hash_func(value.data(), value.length(), hash_func(name.data(), name.length(), u)) & parse_mask; + return hash_func(value.data(), value.length(), hash_func(name.data(), name.length(), static_cast(u))) & parse_mask; } inline float get_weight(VW::workspace& all, uint32_t index, uint32_t offset) @@ -335,7 +335,7 @@ inline void set_weight(VW::workspace& all, uint32_t index, uint32_t offset, floa inline uint32_t num_weights(VW::workspace& all) { return static_cast(all.length()); } -inline uint32_t get_stride(VW::workspace& all) { return all.weights.stride(); } +inline uint32_t get_stride(VW::workspace& all) { return static_cast(all.weights.stride()); } inline void init_features(primitive_feature_space& fs, size_t features_count) { diff --git a/vowpalwabbit/core/src/confidence_sequence.cc b/vowpalwabbit/core/src/confidence_sequence.cc index fc4b35d91f1..8d932c7660d 100644 --- a/vowpalwabbit/core/src/confidence_sequence.cc +++ b/vowpalwabbit/core/src/confidence_sequence.cc @@ -99,7 +99,7 @@ void confidence_sequence::update(double w, double r, double p_drop, double n_dro double bhigh = t + 1.0; sumxhathighsq += std::pow(ahigh, 2) * (approxpolygammaone(bhigh) - approxpolygammaone(bhigh + n_drop)); - t += n_drop; + t += static_cast(n_drop); } sumXlow = (sumwr - sumw * rmin) / (rmax - rmin); @@ -129,8 +129,8 @@ void confidence_sequence::persist(metric_sink& metrics, const std::string& suffi metrics.set_uint("upcnt" + suffix, update_count); metrics.set_float("lb" + suffix, lower_bound()); metrics.set_float("ub" + suffix, upper_bound()); - metrics.set_float("last_w" + suffix, last_w); - metrics.set_float("last_r" + suffix, last_r); + metrics.set_float("last_w" + suffix, static_cast(last_w)); + metrics.set_float("last_r" + suffix, static_cast(last_r)); } void confidence_sequence::reset_stats() @@ -295,4 +295,4 @@ size_t write_model_field( return bytes; } } // namespace model_utils -} // namespace VW \ No newline at end of file +} // namespace VW diff --git a/vowpalwabbit/core/src/confidence_sequence_robust.cc b/vowpalwabbit/core/src/confidence_sequence_robust.cc index b1b51aafe56..d3c0c602c8f 100644 --- a/vowpalwabbit/core/src/confidence_sequence_robust.cc +++ b/vowpalwabbit/core/src/confidence_sequence_robust.cc @@ -40,7 +40,7 @@ double g_tilde::histo_variance(double lam_sqrt_tp1) const void g_tilde::histo_insert(double x) { - uint64_t n = std::floor(std::log(x) / log_k); + uint64_t n = static_cast(std::floor(std::log(x) / log_k)); double x1 = std::pow(k, n); double alpha = (k * x1 - x) / ((k - 1.0) * x1); // TODO: Kahan summation @@ -107,9 +107,9 @@ countable_discrete_base::countable_discrete_base( double countable_discrete_base::get_ci(double alpha) const { return lb_log_wealth(alpha); } -double countable_discrete_base::get_lam_sqrt_tp1(double j) const +double countable_discrete_base::get_lam_sqrt_tp1(uint64_t j) const { - double log_den = (j + 0.5) * log_xi - 0.5 * std::log(t + 1); + double log_den = (static_cast(j) + 0.5) * log_xi - 0.5 * std::log(t + 1); return lambda_max * std::exp(-log_den); } @@ -282,9 +282,9 @@ double countable_discrete_base::lb_log_wealth(double alpha) const else { return root_bisect(s, thres, memo, min_mu, max_mu); } } -double countable_discrete_base::get_log_weight(double j) const { return log_scale_fac + log_xi_m1 - (1 + j) * log_xi; } +double countable_discrete_base::get_log_weight(size_t j) const { return log_scale_fac + log_xi_m1 - (1 + static_cast(j)) * log_xi; } -double countable_discrete_base::get_log_remaining_weight(double j) const { return log_scale_fac - j * log_xi; } +double countable_discrete_base::get_log_remaining_weight(size_t j) const { return log_scale_fac - static_cast(j) * log_xi; } double countable_discrete_base::get_s() const { return gt.get_s(); } @@ -324,10 +324,10 @@ void confidence_sequence_robust::update(double w, double r) void confidence_sequence_robust::persist(metric_sink& metrics, const std::string& suffix) { metrics.set_uint("upcnt" + suffix, update_count); - metrics.set_float("lb" + suffix, lower_bound()); - metrics.set_float("ub" + suffix, upper_bound()); - metrics.set_float("last_w" + suffix, last_w); - metrics.set_float("last_r" + suffix, last_r); + metrics.set_float("lb" + suffix, static_cast(lower_bound())); + metrics.set_float("ub" + suffix, static_cast(upper_bound())); + metrics.set_float("last_w" + suffix, static_cast(last_w)); + metrics.set_float("last_r" + suffix, static_cast(last_r)); } void confidence_sequence_robust::reset_stats() @@ -408,4 +408,4 @@ size_t write_model_field( return bytes; } } // namespace model_utils -} // namespace VW \ No newline at end of file +} // namespace VW diff --git a/vowpalwabbit/core/src/cressieread.cc b/vowpalwabbit/core/src/cressieread.cc index 827fdea5c0f..a8fe088b90a 100644 --- a/vowpalwabbit/core/src/cressieread.cc +++ b/vowpalwabbit/core/src/cressieread.cc @@ -40,9 +40,9 @@ void cressieread::reset_stats(double alpha, double tau) update_count = 0; } -float cressieread::lower_bound() { return chisq.cressieread_lower_bound(); } +float cressieread::lower_bound() { return static_cast(chisq.cressieread_lower_bound()); } -float cressieread::upper_bound() { return chisq.cressieread_upper_bound(); } +float cressieread::upper_bound() { return static_cast(chisq.cressieread_upper_bound()); } } // namespace estimators namespace model_utils @@ -69,4 +69,4 @@ size_t write_model_field(io_buf& io, const VW::estimators::cressieread& sc, cons return bytes; } } // namespace model_utils -} // namespace VW \ No newline at end of file +} // namespace VW diff --git a/vowpalwabbit/core/src/merge.cc b/vowpalwabbit/core/src/merge.cc index 7425deea09c..8c8911d7fd8 100644 --- a/vowpalwabbit/core/src/merge.cc +++ b/vowpalwabbit/core/src/merge.cc @@ -180,7 +180,7 @@ VW::model_delta merge_deltas(const std::vector& deltas_t // Get example counts and compute weighting of models std::vector example_counts; example_counts.reserve(workspaces_to_merge.size()); - for (const auto* delta : workspaces_to_merge) { example_counts.push_back(delta->sd->weighted_labeled_examples); } + for (const auto* delta : workspaces_to_merge) { example_counts.push_back(static_cast(delta->sd->weighted_labeled_examples)); } const auto per_model_weighting = calc_per_model_weighting(example_counts); // Iterate through learners and merge each one diff --git a/vowpalwabbit/core/src/parse_args.cc b/vowpalwabbit/core/src/parse_args.cc index 3d33bdecd4b..132ba618de2 100644 --- a/vowpalwabbit/core/src/parse_args.cc +++ b/vowpalwabbit/core/src/parse_args.cc @@ -83,7 +83,7 @@ uint64_t hash_file_contents(VW::io::reader* file_reader) bool directory_exists(const std::string& path) { - class stat info; + struct stat info; if (stat(path.c_str(), &info) != 0) { return false; } else { return (info.st_mode & S_IFDIR) > 0; } // boost::filesystem::path p(path); diff --git a/vowpalwabbit/core/src/reductions/automl.cc b/vowpalwabbit/core/src/reductions/automl.cc index 6ef818179b6..1f7b3814e93 100644 --- a/vowpalwabbit/core/src/reductions/automl.cc +++ b/vowpalwabbit/core/src/reductions/automl.cc @@ -17,6 +17,7 @@ #include "vw/core/reductions/gd.h" #include "vw/core/setup_base.h" +#include #include #include @@ -24,6 +25,33 @@ using namespace VW::config; using namespace VW::LEARNER; using namespace VW::reductions::automl; +// Under the Windows VC++ runtime, localtime_s is not available in the C++ standard library; instead +// a pre-standard implementation (which reverses the order of the arguments from the standard) exists. +// Note that if _CRT_USE_CONFORMING_ANNEX_K_TIME is defined and set to 1, localtime_s is available in +// the C++ standard library. +#ifdef _WIN32 + +// If we do not have a standard-compliant localtime_s, we need to define it here. +#if !defined(_CRT_USE_CONFORMING_ANNEX_K_TIME) || _CRT_USE_CONFORMING_ANNEX_K_TIME == 0 +namespace std +{ + errno_t localtime_s(const time_t* _Time, struct tm* _Tm) + { + return ::localtime_s(_Tm, _Time); + } +} // namespace std +#else +// If we do have a standard-compliant localtime_s, we need to forward to it. +namespace std +{ + errno_t localtime_s(const time_t* _Time, struct tm* _Tm) + { + return ::localtime_s(_Time, _Tm); + } +} // namespace std +#endif +#endif + namespace { template @@ -159,11 +187,16 @@ std::shared_ptr make_automl_with_impl(VW::setup_base_i& st if (trace_logging) { + struct tm lc; auto t = std::time(nullptr); - auto lc = *std::localtime(&t); - std::ostringstream oss; - oss << std::put_time(&lc, "%d%m.%H%M%S"); - trace_file_name_prefix = oss.str(); + + if (std::localtime_s(&t, &lc) == 0) + { + std::ostringstream oss; + oss << std::put_time(&lc, "%d%m.%H%M%S"); + trace_file_name_prefix = oss.str(); + } + else { trace_file_name_prefix = "trace"; } } auto cm = VW::make_unique(default_lease, max_live_configs, all.get_random_state(), diff --git a/vowpalwabbit/core/src/reductions/bs.cc b/vowpalwabbit/core/src/reductions/bs.cc index 9ce91479dfe..6cb69a5a88d 100644 --- a/vowpalwabbit/core/src/reductions/bs.cc +++ b/vowpalwabbit/core/src/reductions/bs.cc @@ -163,7 +163,7 @@ void output_example_prediction_bs( const auto min_max = std::minmax_element(data.pred_vec.begin(), data.pred_vec.end()); for (auto& sink : all.output_runtime.final_prediction_sink) { - print_result(sink.get(), ec.pred.scalar, ec.tag, *min_max.first, *min_max.second, logger); + print_result(sink.get(), ec.pred.scalar, ec.tag, float(*min_max.first), float(*min_max.second), logger); } } } diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_large_action_space.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_large_action_space.cc index a90f6580398..cec7da8ed4f 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_large_action_space.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_large_action_space.cc @@ -43,7 +43,7 @@ class A_triplet_constructor { if (feature_value != 0.f) { - _triplets.emplace_back(Eigen::Triplet(_row_index, index & _weights_mask, feature_value)); + _triplets.emplace_back(Eigen::Triplet(static_cast(_row_index), static_cast(index & _weights_mask), feature_value)); if ((index & _weights_mask) > _max_col) { _max_col = (index & _weights_mask); } } } @@ -295,7 +295,7 @@ std::shared_ptr make_las_with_impl(VW::setup_base_i& stack bool apply_shrink_factor, size_t thread_pool_size, size_t block_size, size_t action_cache_slack, bool use_explicit_simd) { - uint64_t seed = (all.get_random_state()->get_random() + 1) * (uint64_t)10; + uint64_t seed = static_cast((all.get_random_state()->get_random() + 1) * 10.f); auto data = VW::make_unique>(d, c, apply_shrink_factor, &all, seed, 1 << all.initial_weights_config.num_bits, thread_pool_size, block_size, action_cache_slack, use_explicit_simd, diff --git a/vowpalwabbit/core/src/reductions/cb/details/large_action/kernel_impl.h b/vowpalwabbit/core/src/reductions/cb/details/large_action/kernel_impl.h index ab2e938cbbf..e5be8738159 100644 --- a/vowpalwabbit/core/src/reductions/cb/details/large_action/kernel_impl.h +++ b/vowpalwabbit/core/src/reductions/cb/details/large_action/kernel_impl.h @@ -22,9 +22,10 @@ inline void kernel_impl(float feature_value, uint64_t index, uint64_t weights_ma constexpr static std::array VALUE_MAP = {0.f, 0.f, 1.f, -1.f}; #ifdef _MSC_VER - int select_sparsity = __popcnt((index & weights_mask) + column_index) & 1; + // TODO: should we be using __popcnt64 here? + int select_sparsity = __popcnt(static_cast((index & weights_mask) + column_index)) & 1; int sparsity_index = INDEX_MAP[select_sparsity]; - int select_sign = __popcnt((index & weights_mask) + column_index + seed) & 1; + int select_sign = __popcnt(static_cast((index & weights_mask) + column_index + seed)) & 1; int value_index = sparsity_index + select_sign; float val = VALUE_MAP[value_index]; #else @@ -35,6 +36,8 @@ inline void kernel_impl(float feature_value, uint64_t index, uint64_t weights_ma float val = VALUE_MAP[value_index]; #endif + + final_dot_product += feature_value * val; } diff --git a/vowpalwabbit/core/src/reductions/cb/details/large_action/one_pass_svd_impl.cc b/vowpalwabbit/core/src/reductions/cb/details/large_action/one_pass_svd_impl.cc index e957d932dfd..ca7353abdc1 100644 --- a/vowpalwabbit/core/src/reductions/cb/details/large_action/one_pass_svd_impl.cc +++ b/vowpalwabbit/core/src/reductions/cb/details/large_action/one_pass_svd_impl.cc @@ -80,7 +80,7 @@ void one_pass_svd_impl::generate_AOmega(const multi_ex& examples, const std::vec } } - const float scaling_factor = 1.f / std::sqrt(p); + const float scaling_factor = static_cast(1.f / std::sqrt(p)); // resize is a no-op if size does not change AOmega.resize(num_actions, p); @@ -194,4 +194,4 @@ one_pass_svd_impl::one_pass_svd_impl(VW::workspace* all, uint64_t d, uint64_t se } } // namespace cb_explore_adf -} // namespace VW \ No newline at end of file +} // namespace VW diff --git a/vowpalwabbit/core/src/reductions/cb/details/large_action/two_pass_svd_impl.cc b/vowpalwabbit/core/src/reductions/cb/details/large_action/two_pass_svd_impl.cc index 3a822fb223b..ee074691123 100644 --- a/vowpalwabbit/core/src/reductions/cb/details/large_action/two_pass_svd_impl.cc +++ b/vowpalwabbit/core/src/reductions/cb/details/large_action/two_pass_svd_impl.cc @@ -38,7 +38,7 @@ class Y_triplet_constructor auto combined_index = _row_index + _column_index + _seed; // index is the equivalent of going over A's rows which turn out to be A.transpose()'s columns auto calc = feature_value * VW::details::merand48_boxmuller(combined_index) * _shrink_factors[_row_index]; - _triplets.emplace_back(Eigen::Triplet(index & _weights_mask, _column_index, calc)); + _triplets.emplace_back(Eigen::Triplet(static_cast(index & _weights_mask), static_cast(_column_index), calc)); if ((index & _weights_mask) > _max_col) { _max_col = (index & _weights_mask); } } } @@ -224,4 +224,4 @@ two_pass_svd_impl::two_pass_svd_impl( } } // namespace cb_explore_adf -} // namespace VW \ No newline at end of file +} // namespace VW diff --git a/vowpalwabbit/core/src/reductions/csoaa_ldf.cc b/vowpalwabbit/core/src/reductions/csoaa_ldf.cc index 3ef8c2094b3..e22aa971897 100644 --- a/vowpalwabbit/core/src/reductions/csoaa_ldf.cc +++ b/vowpalwabbit/core/src/reductions/csoaa_ldf.cc @@ -448,8 +448,8 @@ void csoaa_ldf_multiclass_printline( } } - if (predicted_example) { all.print_by_ref(output, predicted_class, 0, ec->tag, logger); } - else { all.print_by_ref(output, 0, 0, ec->tag, logger); } + if (predicted_example) { all.print_by_ref(output, static_cast(predicted_class), 0.f, ec->tag, logger); } + else { all.print_by_ref(output, 0.f, 0.f, ec->tag, logger); } } } diff --git a/vowpalwabbit/core/src/reductions/details/automl/automl_oracle.cc b/vowpalwabbit/core/src/reductions/details/automl/automl_oracle.cc index 9072b8f3cad..e4a7509bb84 100644 --- a/vowpalwabbit/core/src/reductions/details/automl/automl_oracle.cc +++ b/vowpalwabbit/core/src/reductions/details/automl/automl_oracle.cc @@ -398,15 +398,15 @@ void config_oracle::gen_configs( } } - std::vector indexes(_impl.total_space.size()); + std::vector indexes(_impl.total_space.size()); for (size_t i = 0; i < _impl.total_space.size(); i++) { indexes.push_back(i); } for (size_t i = 0; i < _impl.total_space.size(); i++) { - std::swap(indexes[_impl.random_state->get_and_update_random() * indexes.size()], indexes[i]); + std::swap(indexes[static_cast(_impl.random_state->get_and_update_random() * indexes.size())], indexes[i]); } - for (std::vector::iterator it = indexes.begin(); it != indexes.end(); ++it) + for (std::vector::iterator it = indexes.begin(); it != indexes.end(); ++it) { auto copy_champ = configs[0].elements; _impl.gen_ns_groupings_at(_impl.total_space, *it, copy_champ); diff --git a/vowpalwabbit/core/src/reductions/eigen_memory_tree.cc b/vowpalwabbit/core/src/reductions/eigen_memory_tree.cc index 11da7bbb24b..3b9ba256ec2 100644 --- a/vowpalwabbit/core/src/reductions/eigen_memory_tree.cc +++ b/vowpalwabbit/core/src/reductions/eigen_memory_tree.cc @@ -191,7 +191,7 @@ float emt_median(std::vector& array) const auto v1 = (*nth); std::nth_element(array.begin(), nth - 1, array.end()); const auto v2 = *(nth - 1); - return (v1 + v2) / 2.; + return (v1 + v2) / 2.f; } std::nth_element(array.begin(), nth, array.end()); @@ -381,7 +381,7 @@ emt_feats emt_scale_add(float s1, const emt_feats& f1, float s2, const emt_feats emt_feats emt_router_random(std::vector& exs, VW::rand_state& rng) { - std::set is; + std::set is; emt_feats weights; for (auto& e : exs) @@ -403,7 +403,7 @@ emt_feats emt_router_eigen(std::vector& exs, VW::rand_state& rng) auto weights = emt_router_random(exs, rng); - std::map sums; + std::map sums; emt_feats means; for (auto& ex : exs) @@ -699,18 +699,19 @@ void scorer_learn(emt_tree& b, learner& base, emt_node& cn, const emt_example& e if (b.random_state->get_and_update_random() < .5) { scorer_example(b, ex, *preferred_ex); - scorer_learn(base, *b.ex, int(preferred_error > alternative_error), weight); + + scorer_learn(base, *b.ex, static_cast(preferred_error > alternative_error), weight); scorer_example(b, ex, *alternative_ex); - scorer_learn(base, *b.ex, int(alternative_error > preferred_error), weight); + scorer_learn(base, *b.ex, static_cast(alternative_error > preferred_error), weight); } else { scorer_example(b, ex, *alternative_ex); - scorer_learn(base, *b.ex, int(alternative_error > preferred_error), weight); + scorer_learn(base, *b.ex, static_cast(alternative_error > preferred_error), weight); scorer_example(b, ex, *preferred_ex); - scorer_learn(base, *b.ex, int(preferred_error > alternative_error), weight); + scorer_learn(base, *b.ex, static_cast(preferred_error > alternative_error), weight); } } } diff --git a/vowpalwabbit/core/src/reductions/gd_mf.cc b/vowpalwabbit/core/src/reductions/gd_mf.cc index a4b1b41baa8..85ee8f3500f 100644 --- a/vowpalwabbit/core/src/reductions/gd_mf.cc +++ b/vowpalwabbit/core/src/reductions/gd_mf.cc @@ -265,7 +265,7 @@ void save_load(gdmf& d, VW::io_buf& model_file, bool read, bool text) VW::details::initialize_regressor(all); if (all.initial_weights_config.random_weights) { - uint32_t stride = all.weights.stride(); + uint32_t stride = static_cast(all.weights.stride()); auto weight_initializer = [stride](VW::weight* weights, uint64_t index) { initialize_weights(weights, index, stride); }; diff --git a/vowpalwabbit/core/src/reductions/plt.cc b/vowpalwabbit/core/src/reductions/plt.cc index 0b270764f5f..8310866b902 100644 --- a/vowpalwabbit/core/src/reductions/plt.cc +++ b/vowpalwabbit/core/src/reductions/plt.cc @@ -249,7 +249,7 @@ void predict(plt& p, learner& base, VW::example& ec) if (p.true_labels.size() > 0) { uint32_t tp = 0; - uint32_t pred_size = pred.multilabels.label_v.size(); + uint32_t pred_size = static_cast(pred.multilabels.label_v.size()); for (uint32_t i = 0; i < pred_size; ++i) { diff --git a/vowpalwabbit/explore/include/vw/explore/explore.h b/vowpalwabbit/explore/include/vw/explore/explore.h index 14e15c1c19c..c6f3bc1042b 100644 --- a/vowpalwabbit/explore/include/vw/explore/explore.h +++ b/vowpalwabbit/explore/include/vw/explore/explore.h @@ -154,7 +154,7 @@ namespace exploration { /// Function moved to VW::explore::generate_epsilon_greedy() template -VW_DEPRECATED("Moved to VW::exploration explorece") +VW_DEPRECATED("Moved to VW::exploration namespace") int generate_epsilon_greedy(float epsilon, uint32_t top_action, It pmf_first, It pmf_last) { // call vw version @@ -163,7 +163,7 @@ int generate_epsilon_greedy(float epsilon, uint32_t top_action, It pmf_first, It /// Function moved to VW::explore::generate_softmax() template -VW_DEPRECATED("Moved to VW::exploration explorece") +VW_DEPRECATED("Moved to VW::exploration namespace") int generate_softmax(float lambda, InputIt scores_first, InputIt scores_last, OutputIt pmf_first, OutputIt pmf_last) { // call vw version @@ -172,7 +172,7 @@ int generate_softmax(float lambda, InputIt scores_first, InputIt scores_last, Ou /// Function moved to VW::explore::generate_bag() template -VW_DEPRECATED("Moved to VW::exploration explorece") +VW_DEPRECATED("Moved to VW::exploration namespace") int generate_bag(InputIt top_actions_first, InputIt top_actions_last, OutputIt pmf_first, OutputIt pmf_last) { // call vw version @@ -181,7 +181,7 @@ int generate_bag(InputIt top_actions_first, InputIt top_actions_last, OutputIt p /// Function moved to VW::explore::enforce_minimum_probability() template -VW_DEPRECATED("Moved to VW::exploration explorece") +VW_DEPRECATED("Moved to VW::exploration namespace") int enforce_minimum_probability(float uniform_epsilon, bool consider_zero_valued_elements, It pmf_first, It pmf_last) { // call vw version @@ -190,7 +190,7 @@ int enforce_minimum_probability(float uniform_epsilon, bool consider_zero_valued /// Function moved to VW::explore::mix_with_uniform() template -VW_DEPRECATED("Moved to VW::exploration explorece") +VW_DEPRECATED("Moved to VW::exploration namespace") int mix_with_uniform(float uniform_epsilon, It pmf_first, It pmf_last) { // call vw version @@ -199,7 +199,7 @@ int mix_with_uniform(float uniform_epsilon, It pmf_first, It pmf_last) /// Function moved to VW::explore::sample_after_normalizing() template -VW_DEPRECATED("Moved to VW::exploration explorece") +VW_DEPRECATED("Moved to VW::exploration namespace") int sample_after_normalizing(uint64_t seed, It pmf_first, It pmf_last, uint32_t& chosen_index) { // call vw version @@ -208,7 +208,7 @@ int sample_after_normalizing(uint64_t seed, It pmf_first, It pmf_last, uint32_t& /// Function moved to VW::explore::sample_after_normalizing() template -VW_DEPRECATED("Moved to VW::exploration explorece") +VW_DEPRECATED("Moved to VW::exploration namespace") int sample_after_normalizing(const char* seed, It pmf_first, It pmf_last, uint32_t& chosen_index) { // call vw version @@ -217,7 +217,7 @@ int sample_after_normalizing(const char* seed, It pmf_first, It pmf_last, uint32 /// Function moved to VW::explore::swap_chosen() template -VW_DEPRECATED("Moved to VW::exploration explorece") +VW_DEPRECATED("Moved to VW::exploration namespace") int swap_chosen(ActionIt action_first, ActionIt action_last, uint32_t chosen_index) { // call vw version @@ -226,7 +226,7 @@ int swap_chosen(ActionIt action_first, ActionIt action_last, uint32_t chosen_ind /// Function moved to VW::explore::sample_pdf() template -VW_DEPRECATED("Moved to VW::exploration explorece") +VW_DEPRECATED("Moved to VW::exploration namespace") int sample_pdf(uint64_t* p_seed, It pdf_first, It pdf_last, float& chosen_value, float& pdf_value) { // call vw version diff --git a/vowpalwabbit/json_parser/src/json_utils.h b/vowpalwabbit/json_parser/src/json_utils.h index a087a76c3bb..07fa8f85bbb 100644 --- a/vowpalwabbit/json_parser/src/json_utils.h +++ b/vowpalwabbit/json_parser/src/json_utils.h @@ -40,7 +40,7 @@ class namespace_builder void add_feature(const char* str, hash_func_t hash_func, uint64_t parse_mask) { - auto hashed_feature = hash_func(str, strlen(str), namespace_hash) & parse_mask; + auto hashed_feature = hash_func(str, strlen(str), static_cast(namespace_hash)) & parse_mask; ftrs->push_back(1., hashed_feature); feature_count++; @@ -61,7 +61,7 @@ void push_ns(VW::example* ex, const char* ns, std::vector n; n.feature_group = ns[0]; - n.namespace_hash = hash_func(ns, strlen(ns), hash_seed); + n.namespace_hash = hash_func(ns, strlen(ns), static_cast(hash_seed)); n.ftrs = ex->feature_space.data() + ns[0]; n.feature_count = 0; n.name = ns; diff --git a/vowpalwabbit/json_parser/src/parse_example_json.cc b/vowpalwabbit/json_parser/src/parse_example_json.cc index 1c881cf0c8c..fac83f87ed9 100644 --- a/vowpalwabbit/json_parser/src/parse_example_json.cc +++ b/vowpalwabbit/json_parser/src/parse_example_json.cc @@ -261,7 +261,7 @@ class ArrayToGraphState : public BaseState BaseState* Uint(Context& ctx, unsigned v) override { - if (!_stricmp(ctx.key, "val")) { graph_triplet.val = v; } + if (!_stricmp(ctx.key, "val")) { graph_triplet.val = static_cast(v); } else if (!_stricmp(ctx.key, "row")) { graph_triplet.row = v; } else if (!_stricmp(ctx.key, "col")) { graph_triplet.col = v; } else @@ -1190,7 +1190,7 @@ class DefaultState : public BaseState BaseState* Float(Context& ctx, float f) override { auto& ns = ctx.CurrentNamespace(); - auto hash_index = ctx._hash_func(ctx.key, strlen(ctx.key), ns.namespace_hash) & ctx._parse_mask; + auto hash_index = ctx._hash_func(ctx.key, strlen(ctx.key), static_cast(ns.namespace_hash)) & ctx._parse_mask; ns.add_feature(f, hash_index, ctx.key); return this; } diff --git a/vowpalwabbit/json_parser/src/parse_example_slates_json.cc b/vowpalwabbit/json_parser/src/parse_example_slates_json.cc index 1ae7b3078dc..44dc44b2e15 100644 --- a/vowpalwabbit/json_parser/src/parse_example_slates_json.cc +++ b/vowpalwabbit/json_parser/src/parse_example_slates_json.cc @@ -140,7 +140,7 @@ void handle_features_value(const char* key_namespace, const Value& value, VW::ex { assert(!namespaces.empty()); float number = get_number(value); - auto hash_index = hash_func(key_namespace, strlen(key_namespace), namespaces.back().namespace_hash) & parse_mask; + auto hash_index = hash_func(key_namespace, strlen(key_namespace), static_cast(namespaces.back().namespace_hash)) & parse_mask; namespaces.back().add_feature(number, hash_index, key_namespace); } break; diff --git a/vowpalwabbit/text_parser/src/parse_example_text.cc b/vowpalwabbit/text_parser/src/parse_example_text.cc index 530b6f372c8..368f7f544d8 100644 --- a/vowpalwabbit/text_parser/src/parse_example_text.cc +++ b/vowpalwabbit/text_parser/src/parse_example_text.cc @@ -161,13 +161,13 @@ class tc_parser { // chain hash is hash(feature_value, hash(feature_name, namespace_hash)) & parse_mask word_hash = (_p->hasher(str_feat_value.data(), str_feat_value.length(), - _p->hasher(feature_name.data(), feature_name.length(), _channel_hash)) & + _p->hasher(feature_name.data(), feature_name.length(), static_cast(_channel_hash))) & _parse_mask); } // Case where string:float else if (!feature_name.empty()) { - word_hash = (_p->hasher(feature_name.data(), feature_name.length(), _channel_hash) & _parse_mask); + word_hash = (_p->hasher(feature_name.data(), feature_name.length(), static_cast(_channel_hash)) & _parse_mask); } // Case where :float else { word_hash = _channel_hash + _anon++; } @@ -208,8 +208,12 @@ class tc_parser else { affix_name.remove_prefix(affix_name.size() - len); } } - word_hash = _p->hasher(affix_name.data(), affix_name.length(), (uint64_t)_channel_hash) * - (VW::details::AFFIX_CONSTANT + (affix & 0xF) * VW::details::QUADRATIC_CONSTANT); + word_hash = _p->hasher(affix_name.data(), affix_name.length(), + // TODO: Does this actually fit inside a uint32_t? If not, we should change the hasher to take a uint64_t + // but that will be dangerous because we also need to avoid changing the meanings of hashes with older + // models. Fixing this right is a potential breaking change. + static_cast((uint64_t)_channel_hash) * + (VW::details::AFFIX_CONSTANT + (affix & 0xF) * VW::details::QUADRATIC_CONSTANT)); affix_fs.push_back(_v, word_hash, VW::details::AFFIX_NAMESPACE); if (audit) { @@ -245,7 +249,7 @@ class tc_parser VW::string_view spelling_strview(_spelling.data(), _spelling.size()); word_hash = - VW::details::hashstring(spelling_strview.data(), spelling_strview.length(), (uint64_t)_channel_hash); + VW::details::hashstring(spelling_strview.data(), spelling_strview.length(), static_cast(_channel_hash)); spell_fs.push_back(_v, word_hash, VW::details::SPELLING_NAMESPACE); if (audit) {