This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch cleanup_warnings
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git
The following commit(s) were added to refs/heads/cleanup_warnings by this push:
new 5229c67 types and casts
5229c67 is described below
commit 5229c674f8ff1329cd5ffe1aca5f55b463229ceb
Author: Alexander Saydakov <[email protected]>
AuthorDate: Mon Mar 29 17:22:39 2021 -0700
types and casts
---
common/include/binomial_bounds.hpp | 16 ++++++++--------
common/include/bounds_binomial_proportions.hpp | 17 +++++++----------
theta/include/bounds_on_ratios_in_sampled_sets.hpp | 2 +-
theta/include/theta_jaccard_similarity_base.hpp | 6 +++---
theta/include/theta_sketch_impl.hpp | 14 +++++++-------
theta/include/theta_update_sketch_base_impl.hpp | 22 +++++++++++-----------
6 files changed, 37 insertions(+), 40 deletions(-)
diff --git a/common/include/binomial_bounds.hpp
b/common/include/binomial_bounds.hpp
index 0f0222a..c1243e5 100644
--- a/common/include/binomial_bounds.hpp
+++ b/common/include/binomial_bounds.hpp
@@ -381,7 +381,7 @@ private:
// The following computes an approximation to the lower bound of a
Frequentist
// confidence interval based on the tails of the Binomial distribution.
static double compute_approx_binomial_lower_bound(unsigned long long
num_samples, double theta, unsigned num_std_devs) {
- if (theta == 1) return num_samples;
+ if (theta == 1) return static_cast<double>(num_samples);
if (num_samples == 0) return 0;
if (num_samples == 1) {
const double delta = delta_of_num_std_devs[num_std_devs];
@@ -395,24 +395,24 @@ private:
}
// at this point we know 2 <= num_samples <= 120
if (theta > (1 - 1e-5)) { // empirically-determined threshold
- return num_samples;
+ return static_cast<double>(num_samples);
}
if (theta < (num_samples / 360.0)) { // empirically-determined threshold
// here we use the Gaussian approximation, but with a modified
num_std_devs
- const unsigned index = 3 * num_samples + (num_std_devs - 1);
+ const unsigned index = 3 * static_cast<unsigned>(num_samples) +
(num_std_devs - 1);
const double raw_lb = cont_classic_lb(num_samples, theta,
lb_equiv_table[index]);
return raw_lb - 0.5; // fake round down
}
// This is the most difficult range to approximate; we will compute an
"exact" LB.
// We know that est <= 360, so specialNStar() shouldn't be ridiculously
slow.
const double delta = delta_of_num_std_devs[num_std_devs];
- return special_n_star(num_samples, theta, delta); // no need to round
+ return static_cast<double>(special_n_star(num_samples, theta, delta)); //
no need to round
}
// The following computes an approximation to the upper bound of a
Frequentist
// confidence interval based on the tails of the Binomial distribution.
static double compute_approx_binomial_upper_bound(unsigned long long
num_samples, double theta, unsigned num_std_devs) {
- if (theta == 1) return num_samples;
+ if (theta == 1) return static_cast<double>(num_samples);
if (num_samples == 0) {
const double delta = delta_of_num_std_devs[num_std_devs];
const double raw_ub = std::log(delta) / std::log(1 - theta);
@@ -425,18 +425,18 @@ private:
}
// at this point we know 2 <= num_samples <= 120
if (theta > (1 - 1e-5)) { // empirically-determined threshold
- return num_samples + 1;
+ return static_cast<double>(num_samples + 1);
}
if (theta < (num_samples / 360.0)) { // empirically-determined threshold
// here we use the Gaussian approximation, but with a modified
num_std_devs
- const unsigned index = 3 * num_samples + (num_std_devs - 1);
+ const unsigned index = 3 * static_cast<unsigned>(num_samples) +
(num_std_devs - 1);
const double raw_ub = cont_classic_ub(num_samples, theta,
ub_equiv_table[index]);
return raw_ub + 0.5; // fake round up
}
// This is the most difficult range to approximate; we will compute an
"exact" UB.
// We know that est <= 360, so specialNPrimeF() shouldn't be ridiculously
slow.
const double delta = delta_of_num_std_devs[num_std_devs];
- return special_n_prime_f(num_samples, theta, delta); // no need to round
+ return static_cast<double>(special_n_prime_f(num_samples, theta, delta));
// no need to round
}
static void check_theta(double theta) {
diff --git a/common/include/bounds_binomial_proportions.hpp
b/common/include/bounds_binomial_proportions.hpp
index 06ab484..ffeccb2 100644
--- a/common/include/bounds_binomial_proportions.hpp
+++ b/common/include/bounds_binomial_proportions.hpp
@@ -110,7 +110,7 @@ public:
* @return the lower bound of the approximate Clopper-Pearson confidence
interval for the
* unknown success probability.
*/
- static inline double approximate_lower_bound_on_p(long n, long k, double
num_std_devs) {
+ static inline double approximate_lower_bound_on_p(uint64_t n, uint64_t k,
double num_std_devs) {
check_inputs(n, k);
if (n == 0) { return 0.0; } // the coin was never flipped, so we know
nothing
else if (k == 0) { return 0.0; }
@@ -145,12 +145,12 @@ public:
* @return the upper bound of the approximate Clopper-Pearson confidence
interval for the
* unknown success probability.
*/
- static inline double approximate_upper_bound_on_p(long n, long k, double
num_std_devs) {
+ static inline double approximate_upper_bound_on_p(uint64_t n, uint64_t k,
double num_std_devs) {
check_inputs(n, k);
if (n == 0) { return 1.0; } // the coin was never flipped, so we know
nothing
else if (k == n) { return 1.0; }
else if (k == (n - 1)) {
- return (exactU_upper_bound_on_p_k_eq_minusone(n,
delta_of_num_stdevs(num_std_devs)));
+ return (exact_upper_bound_on_p_k_eq_minusone(n,
delta_of_num_stdevs(num_std_devs)));
}
else if (k == 0) {
return (exact_upper_bound_on_p_k_eq_zero(n,
delta_of_num_stdevs(num_std_devs)));
@@ -167,7 +167,7 @@ public:
* @param k is the number of successes. Must be non-negative, and cannot
exceed n.
* @return the estimate of the unknown binomial proportion.
*/
- static inline double estimate_unknown_p(long n, long k) {
+ static inline double estimate_unknown_p(uint64_t n, uint64_t k) {
check_inputs(n, k);
if (n == 0) { return 0.5; } // the coin was never flipped, so we know
nothing
else { return ((double) k / (double) n); }
@@ -193,9 +193,7 @@ public:
}
private:
- static inline void check_inputs(long n, long k) {
- if (n < 0) { throw std::invalid_argument("N must be non-negative"); }
- if (k < 0) { throw std::invalid_argument("K must be non-negative"); }
+ static inline void check_inputs(uint64_t n, uint64_t k) {
if (k > n) { throw std::invalid_argument("K cannot exceed N"); }
}
@@ -251,8 +249,7 @@ private:
// and it is worth keeping it that way so that it will always be easy to
verify
// that the formula was typed in correctly.
- static inline double abramowitz_stegun_formula_26p5p22(double a, double b,
- double yp) {
+ static inline double abramowitz_stegun_formula_26p5p22(double a, double b,
double yp) {
const double b2m1 = (2.0 * b) - 1.0;
const double a2m1 = (2.0 * a) - 1.0;
const double lambda = ((yp * yp) - 3.0) / 6.0;
@@ -280,7 +277,7 @@ private:
return (1.0 - pow((1.0 - delta), (1.0 / n)));
}
- static inline double exactU_upper_bound_on_p_k_eq_minusone(double n, double
delta) {
+ static inline double exact_upper_bound_on_p_k_eq_minusone(double n, double
delta) {
return (pow((1.0 - delta), (1.0 / n)));
}
diff --git a/theta/include/bounds_on_ratios_in_sampled_sets.hpp
b/theta/include/bounds_on_ratios_in_sampled_sets.hpp
index e2c5433..341319a 100644
--- a/theta/include/bounds_on_ratios_in_sampled_sets.hpp
+++ b/theta/include/bounds_on_ratios_in_sampled_sets.hpp
@@ -90,7 +90,7 @@ public:
* @param f the inclusion probability used to produce the set with size
<i>a</i>.
* @return the approximate lower bound
*/
- static double estimate_of_a(uint64_t a, uint64_t f) {
+ static double estimate_of_a(uint64_t a, double f) {
check_inputs(a, 1, f);
return a / f;
}
diff --git a/theta/include/theta_jaccard_similarity_base.hpp
b/theta/include/theta_jaccard_similarity_base.hpp
index cb18601..783a184 100644
--- a/theta/include/theta_jaccard_similarity_base.hpp
+++ b/theta/include/theta_jaccard_similarity_base.hpp
@@ -131,9 +131,9 @@ private:
template<typename SketchA, typename SketchB>
static typename Union::CompactSketch compute_union(const SketchA& sketch_a,
const SketchB& sketch_b) {
- const unsigned count_a = sketch_a.get_num_retained();
- const unsigned count_b = sketch_b.get_num_retained();
- const unsigned lg_k = std::min(std::max(log2(ceiling_power_of_2(count_a +
count_b)), theta_constants::MIN_LG_K), theta_constants::MAX_LG_K);
+ const auto count_a = sketch_a.get_num_retained();
+ const auto count_b = sketch_b.get_num_retained();
+ const auto lg_k = std::min(std::max(log2(ceiling_power_of_2(count_a +
count_b)), theta_constants::MIN_LG_K), theta_constants::MAX_LG_K);
auto u = typename Union::builder().set_lg_k(lg_k).build();
u.update(sketch_a);
u.update(sketch_b);
diff --git a/theta/include/theta_sketch_impl.hpp
b/theta/include/theta_sketch_impl.hpp
index 774f715..0653a70 100644
--- a/theta/include/theta_sketch_impl.hpp
+++ b/theta/include/theta_sketch_impl.hpp
@@ -290,7 +290,7 @@ uint64_t compact_theta_sketch_alloc<A>::get_theta64() const
{
template<typename A>
uint32_t compact_theta_sketch_alloc<A>::get_num_retained() const {
- return entries_.size();
+ return static_cast<uint32_t>(entries_.size());
}
template<typename A>
@@ -300,22 +300,22 @@ uint16_t compact_theta_sketch_alloc<A>::get_seed_hash()
const {
template<typename A>
auto compact_theta_sketch_alloc<A>::begin() -> iterator {
- return iterator(entries_.data(), entries_.size(), 0);
+ return iterator(entries_.data(), static_cast<uint32_t>(entries_.size()), 0);
}
template<typename A>
auto compact_theta_sketch_alloc<A>::end() -> iterator {
- return iterator(nullptr, 0, entries_.size());
+ return iterator(nullptr, 0, static_cast<uint32_t>(entries_.size()));
}
template<typename A>
auto compact_theta_sketch_alloc<A>::begin() const -> const_iterator {
- return const_iterator(entries_.data(), entries_.size(), 0);
+ return const_iterator(entries_.data(),
static_cast<uint32_t>(entries_.size()), 0);
}
template<typename A>
auto compact_theta_sketch_alloc<A>::end() const -> const_iterator {
- return const_iterator(nullptr, 0, entries_.size());
+ return const_iterator(nullptr, 0, static_cast<uint32_t>(entries_.size()));
}
template<typename A>
@@ -343,7 +343,7 @@ void compact_theta_sketch_alloc<A>::serialize(std::ostream&
os) const {
write(os, seed_hash);
if (!this->is_empty()) {
if (!is_single_item) {
- const uint32_t num_entries = entries_.size();
+ const uint32_t num_entries = static_cast<uint32_t>(entries_.size());
write(os, num_entries);
const uint32_t unused32 = 0;
write(os, unused32);
@@ -381,7 +381,7 @@ auto compact_theta_sketch_alloc<A>::serialize(unsigned
header_size_bytes) const
ptr += copy_to_mem(seed_hash, ptr);
if (!this->is_empty()) {
if (!is_single_item) {
- const uint32_t num_entries = entries_.size();
+ const uint32_t num_entries = static_cast<uint32_t>(entries_.size());
ptr += copy_to_mem(num_entries, ptr);
ptr += sizeof(uint32_t);
if (this->is_estimation_mode()) {
diff --git a/theta/include/theta_update_sketch_base_impl.hpp
b/theta/include/theta_update_sketch_base_impl.hpp
index a343c78..ce577e6 100644
--- a/theta/include/theta_update_sketch_base_impl.hpp
+++ b/theta/include/theta_update_sketch_base_impl.hpp
@@ -39,7 +39,7 @@ seed_(seed),
entries_(nullptr)
{
if (lg_cur_size > 0) {
- const size_t size = 1 << lg_cur_size;
+ const size_t size = 1ULL << lg_cur_size;
entries_ = allocator_.allocate(size);
for (size_t i = 0; i < size; ++i) EK()(entries_[i]) = 0;
}
@@ -58,7 +58,7 @@ seed_(other.seed_),
entries_(nullptr)
{
if (other.entries_ != nullptr) {
- const size_t size = 1 << lg_cur_size_;
+ const size_t size = 1ULL << lg_cur_size_;
entries_ = allocator_.allocate(size);
for (size_t i = 0; i < size; ++i) {
if (EK()(other.entries_[i]) != 0) {
@@ -89,7 +89,7 @@ template<typename EN, typename EK, typename A>
theta_update_sketch_base<EN, EK, A>::~theta_update_sketch_base()
{
if (entries_ != nullptr) {
- const size_t size = 1 << lg_cur_size_;
+ const size_t size = 1ULL << lg_cur_size_;
for (size_t i = 0; i < size; ++i) {
if (EK()(entries_[i]) != 0) entries_[i].~EN();
}
@@ -136,7 +136,7 @@ uint64_t theta_update_sketch_base<EN, EK,
A>::hash_and_screen(const void* data,
template<typename EN, typename EK, typename A>
auto theta_update_sketch_base<EN, EK, A>::find(uint64_t key) const ->
std::pair<iterator, bool> {
- const size_t size = 1 << lg_cur_size_;
+ const size_t size = 1ULL << lg_cur_size_;
const size_t mask = size - 1;
const uint32_t stride = get_stride(key, lg_cur_size_);
uint32_t index = static_cast<uint32_t>(key) & mask;
@@ -175,13 +175,13 @@ auto theta_update_sketch_base<EN, EK, A>::begin() const
-> iterator {
template<typename EN, typename EK, typename A>
auto theta_update_sketch_base<EN, EK, A>::end() const -> iterator {
- return &entries_[1 << lg_cur_size_];
+ return &entries_[1ULL << lg_cur_size_];
}
template<typename EN, typename EK, typename A>
uint32_t theta_update_sketch_base<EN, EK, A>::get_capacity(uint8_t
lg_cur_size, uint8_t lg_nom_size) {
const double fraction = (lg_cur_size <= lg_nom_size) ? RESIZE_THRESHOLD :
REBUILD_THRESHOLD;
- return std::floor(fraction * (1 << lg_cur_size));
+ return static_cast<uint32_t>(std::floor(fraction * (1 << lg_cur_size)));
}
template<typename EN, typename EK, typename A>
@@ -192,11 +192,11 @@ uint32_t theta_update_sketch_base<EN, EK,
A>::get_stride(uint64_t key, uint8_t l
template<typename EN, typename EK, typename A>
void theta_update_sketch_base<EN, EK, A>::resize() {
- const size_t old_size = 1 << lg_cur_size_;
+ const size_t old_size = 1ULL << lg_cur_size_;
const uint8_t lg_tgt_size = lg_nom_size_ + 1;
- const uint8_t factor = std::max(1, std::min(static_cast<int>(rf_),
lg_tgt_size - lg_cur_size_));
+ const uint8_t factor = std::max<uint8_t>(1,
std::min<uint8_t>(static_cast<uint8_t>(rf_), static_cast<uint8_t>(lg_tgt_size -
lg_cur_size_)));
lg_cur_size_ += factor;
- const size_t new_size = 1 << lg_cur_size_;
+ const size_t new_size = 1ULL << lg_cur_size_;
EN* old_entries = entries_;
entries_ = allocator_.allocate(new_size);
for (size_t i = 0; i < new_size; ++i) EK()(entries_[i]) = 0;
@@ -214,7 +214,7 @@ void theta_update_sketch_base<EN, EK, A>::resize() {
// assumes number of entries > nominal size
template<typename EN, typename EK, typename A>
void theta_update_sketch_base<EN, EK, A>::rebuild() {
- const size_t size = 1 << lg_cur_size_;
+ const size_t size = 1ULL << lg_cur_size_;
const uint32_t nominal_size = 1 << lg_nom_size_;
// empty entries have uninitialized payloads
@@ -301,7 +301,7 @@ Derived& theta_base_builder<Derived,
Allocator>::set_seed(uint64_t seed) {
template<typename Derived, typename Allocator>
uint64_t theta_base_builder<Derived, Allocator>::starting_theta() const {
- if (p_ < 1) return theta_constants::MAX_THETA * p_;
+ if (p_ < 1) return static_cast<uint64_t>(theta_constants::MAX_THETA * p_);
return theta_constants::MAX_THETA;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]