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