1
LIBIQTOOL_API void Hist(std::vector<double>input, std::vector<double> bins, std::vector<double>& histogram)
{
double minY = *std::min_element(std::begin(input), std::end(input));
double maxY = *std::max_element(std::begin(input), std::end(input));
std::vector<double> edges;
edges.push_back(-1 * std::numeric_limits<double>::infinity());
for (int i = 0; i < bins.size() - 1; i++)
{
edges.push_back(bins[i] + 0.0100/2);
}
edges.push_back(std::numeric_limits<double>::infinity());
//histC
histogram.resize(edges.size() - 1);
#pragma omp parallel for
for (int i = 0; i < input.size(); i++)
{
for (int j = 0; j < edges.size() - 1; j++)
{
if ((edges[j] < input[i]) && (input[i] <= edges[j + 1]))
{
histogram[j] = histogram[j] + 1;
break;
}
}
}
histogram[histogram.size() - 1] = histogram[histogram.size() - 1] + histogram[histogram.size() - 2];
histogram.pop_back();
}
輸入向量大小爲3000000 ++,bin數爲7000。
我已經採用了Matlab的Hist()函數並在C++中創建了我需要的代碼。但是它需要很長的時間才能運行,你能看到更多的運行時優化,可以在這裏完成嗎?
我做過:
a。 b。當你發現箱子放置當前編號
b。使用OpenMP的matlab代碼優化直方圖C++
是不是有沒有一種方式來獲得沒有任何搜索的bin索引? – Gilad
只有當您可以找到解析函數以將值與容器匹配時,例如所有容器的寬度相同。 –
它們是相同的width.-INF \t 0.00500000000000000 \t 0.0150000000000000 \t 0.0250000000000000 \t 0.0350000000000000 \t 0.0450000000000000 \t 0.0550000000000000 \t 0.0650000000000000 \t 0.0750000000000000 \t 0.0850000000000000 \t 0.0950000000000000 \t 0.105000000000000 \t 0.115000000000000 \t 0.125000000000000 \t 0.135000000000000 \t 0.145000000000000 \t 0.155000000000000等等,,, – Gilad