Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] sort_cpuid_by_max_freq()中的bubble sort代码逻辑错误 #10507

Open
changbindu opened this issue Apr 28, 2024 · 4 comments
Open

[BUG] sort_cpuid_by_max_freq()中的bubble sort代码逻辑错误 #10507

changbindu opened this issue Apr 28, 2024 · 4 comments
Assignees

Comments

@changbindu
Copy link

这段bubble sort代码是错误的,一个冒泡排序却操作了两个数组。

void sort_cpuid_by_max_freq(const std::vector<int>& max_freqs,
                            std::vector<int>* cpu_ids,
                            std::vector<int>* cluster_ids) {
  ...
  // sort cpuid as big core first
  // simple bubble sort
  for (int i = 0; i < cpu_num; i++) {
    for (int j = i + 1; j < cpu_num; j++) {
      if (max_freqs[i] < max_freqs[j]) {
        // swap
        int tmp = cpu_ids->at(i);
        cpu_ids->at(i) = cpu_ids->at(j);
        cpu_ids->at(j) = tmp;
      }
    }
  }
@changbindu changbindu changed the title sort_cpuid_by_max_freq()中的bubble sort代码逻辑错误 [BUG] sort_cpuid_by_max_freq()中的bubble sort代码逻辑错误 Apr 28, 2024
@shentanyue
Copy link
Collaborator

您好,没明白您的意思,贴出的冒泡排序代码只针对 cpu_ids 数组进行了排序,没有操作两个数组。

@changbindu
Copy link
Author

您好,没明白您的意思,贴出的冒泡排序代码只针对 cpu_ids 数组进行了排序,没有操作两个数组。

列几个数据演算一下就明白了。代码调整了cpu_ids数组的元素顺序,但是比较大小确实参考另一个数组的值,但这个数组的元素位置没变动,因此参考的值实际上不匹配了。

@shentanyue
Copy link
Collaborator

好的,我明白您的意思了。 非常感谢您的指出~

@ddchenhao66
Copy link
Collaborator

您好,非常抱歉这么晚才合入您的PR。在这个PR中 #10518 ,我们采纳了您的代码解决了这个问题,合入develop分支后您就可以关闭这个issue了。再次感谢您对Paddle-Lite的关注与贡献!

您好,没明白您的意思,贴出的冒泡排序代码只针对 cpu_ids 数组进行了排序,没有操作两个数组。

列几个数据演算一下就明白了。代码调整了cpu_ids数组的元素顺序,但是比较大小确实参考另一个数组的值,但这个数组的元素位置没变动,因此参考的值实际上不匹配了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants