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

unrespected bounds #169

Closed
AdrienCorenflos opened this issue May 5, 2020 · 7 comments · Fixed by #170
Closed

unrespected bounds #169

AdrienCorenflos opened this issue May 5, 2020 · 7 comments · Fixed by #170
Labels

Comments

@AdrienCorenflos
Copy link
Contributor

Hi,

There is a (subtle) bug in EMD_1d: the indices i and j are allowed to reach n and m, therefore these lines have unkown behaviour (the resulting values w_i and w_j are dereferenced from the next memory slot in the machine, therefore it could be any value or even fail depending on compiler).

An easy fix would be to change the while condition to a while True and add break condiditions within the if-else branches.

w_i = u_weights[i]

w_j = v_weights[j]

I'll send a pull request if you are happy with this alternative

@rtavenar
Copy link
Contributor

rtavenar commented May 5, 2020

Hi @AdrienCorenflos

Good catch once again! Another easy fix would be to set w_i and w_j at the beginning of each iteration of the while loop (instead of at the end of the iteration).
You could implement the one you prefer, I guess, and a PR would be very welcome :)

@AdrienCorenflos
Copy link
Contributor Author

I'd rather not change the logic too much to be honest, cython allows for breaks in loops anyway.

(also the only reason why I spotted it is because I use your code as a benchmark, I am implementing something very similar that directly computes Gamma x U :))

@AdrienCorenflos
Copy link
Contributor Author

Btw, there are a few things that could be improved in this cython code, mostly compatibility-wise. You should use fuse types to be able to use float32 or float64 types seemlessly for example

@rtavenar
Copy link
Contributor

rtavenar commented May 5, 2020

I am a newbie in Cython, so any improvement to the code would be welcome, feel free to do that in the PR as well.

@AdrienCorenflos
Copy link
Contributor Author

errr I should have run it locally, tests are failing

@AdrienCorenflos
Copy link
Contributor Author

I am a newbie in Cython, so any improvement to the code would be welcome, feel free to do that in the PR as well.

That's gonna be more work, I'll fix the bug and open a new issue for later on

@AdrienCorenflos
Copy link
Contributor Author

tests are passing

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

Successfully merging a pull request may close this issue.

3 participants