std::numeric_limits<T>::epsilon

std::numeric_limits<T>::epsilon

声明

static T epsilon() throw();
static constexpr T epsilon() noexcept;

意义

返回及其的epsilon,即1.0 + eps != 1.0这个表达式成立的最小的正双精度浮点数。

应用

当需要除以一个变量时,无法确定该变量是否会为0,那么就将该变量加上epsilon再作为除数。

在vs2015 c++ .h中加入这段代码会报重定义 namespace cv_dnn { namespace { template <typename T> static inline bool SortScorePairDescend(const std::pair<float, T>& pair1, const std::pair<float, T>& pair2) { return pair1.first > pair2.first; } } // namespace inline void GetMaxScoreIndex(const std::vector<float>& scores, const float threshold, const int top_k, std::vector<std::pair<float, int> >& score_index_vec) { for (size_t i = 0; i < scores.size(); ++i) { if (scores[i] > threshold) { score_index_vec.push_back(std::make_pair(scores[i], i)); } } std::stable_sort(score_index_vec.begin(), score_index_vec.end(), SortScorePairDescend<int>); if (top_k > 0 && top_k < (int)score_index_vec.size()) { score_index_vec.resize(top_k); } } template <typename BoxType> inline void NMSFast_(const std::vector<BoxType>& bboxes, const std::vector<float>& scores, const float score_threshold, const float nms_threshold, const float eta, const int top_k, std::vector<int>& indices, float(*computeOverlap)(const BoxType&, const BoxType&)) { CV_Assert(bboxes.size() == scores.size()); std::vector<std::pair<float, int> > score_index_vec; GetMaxScoreIndex(scores, score_threshold, top_k, score_index_vec); // Do nms. float adaptive_threshold = nms_threshold; indices.clear(); for (size_t i = 0; i < score_index_vec.size(); ++i) { const int idx = score_index_vec[i].second; bool keep = true; for (int k = 0; k < (int)indices.size() && keep; ++k) { const int kept_idx = indices[k]; float overlap = computeOverlap(bboxes[idx], bboxes[kept_idx]); keep = overlap <= adaptive_threshold; } if (keep) indices.push_back(idx); if (keep && eta < 1 && adaptive_threshold > 0.5) { adaptive_threshold *= eta; } } } // copied from opencv 3.4, not exist in 3.0 template<typename Tp> static inline double jaccardDistance_(const Rect_<Tp>& a, const Rect<_Tp>& b) { Tp Aa = a.area(); Tp Ab = b.area(); if ((Aa + Ab) <= std::numeric_limits<Tp>::epsilon()) { // jaccard_index = 1 -> distance = 0 return 0.0; } double Aab = (a & b).area(); // distance = 1 - jaccard_index return 1.0 - Aab / (Aa + Ab - Aab); } template <typename T> static inline float rectOverlap(const T& a, const T& b) { return 1.f - static_cast<float>(jaccardDistance(a, b)); } void NMSBoxes(const std::vector<Rect>& bboxes, const std::vector<float>& scores, const float score_threshold, const float nms_threshold, std::vector<int>& indices, const float eta = 1, const int top_k = 0) { NMSFast(bboxes, scores, score_threshold, nms_threshold, eta, top_k, indices, rectOverlap); } }
06-07
Exit code: 1 Errors while compiling: g:\codelearning\C_Breach_of_Faith.cpp: �ں�����void solve_breach_of_faith(int)����: g:\codelearning\C_Breach_of_Faith.cpp:31:107: ���󣺡�accumulate���ڴ�����������δ���� 0LL, [](long long acc, long long val){return acc+pow(-1,val)*val;})); ^ g:\codelearning\C_Breach_of_Faith.cpp:33:95: ���󣺡�LLONG_MAX���ڴ�����������δ���� temp_sequence.insert(next(begin(temp_sequence), static_cast<ptrdiff_t>(pos)), LLONG_MAX); ^~~~~~~~~ g:\codelearning\C_Breach_of_Faith.cpp:38:41: ����������Ϊ��double������ֵ��ʼ������Ϊ��double&���ķdz���������Ч auto& elem = idx >= pos ? temp_sequence[idx-((idx>=pos)?1:0)] : ((idx==pos)?expected_sum-temp_sequence[pos]:temp_sequence[idx]); ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ g:\codelearning\C_Breach_of_Faith.cpp:48:50: ���󣺡�numeric_limits���ڴ�����������δ���� abs(roundl(abs(expected_sum))) < numeric_limits<double>::epsilon()){ ^~~~~~~~~~~~~~ g:\codelearning\C_Breach_of_Faith.cpp:48:65: ����expected primary-expression before ��double�� abs(roundl(abs(expected_sum))) < numeric_limits<double>::epsilon()){ ^~~~~~ g:\codelearning\C_Breach_of_Faith.cpp:48:65: ����expected ��)�� before ��double�� g:\codelearning\C_Breach_of_Faith.cpp:50:29: ���󣺶Գ�Ա��join������������ڡ�" "���У������߾��з������͡�const char [2]�� cout << " ".join(to_string(x) for(auto &x : temp_sequence)); ^~~~ g:\codelearning\C_Breach_of_Faith.cpp:50:44: ���󣺡�x���ڴ�����������δ���� cout << " ".join(to_string(x) for(auto &x : temp_sequence)); ^
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jasmine-Lily

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值