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

NumbaPerformanceWarning on KL #1900

Closed
paskino opened this issue Aug 22, 2024 · 0 comments · Fixed by #1901
Closed

NumbaPerformanceWarning on KL #1900

paskino opened this issue Aug 22, 2024 · 0 comments · Fixed by #1901
Assignees
Labels
bug Something isn't working
Milestone

Comments

@paskino
Copy link
Contributor

paskino commented Aug 22, 2024

Description

Unit test shows a numba warning:

NumbaPerformanceWarning: 
prange or pndindex loop will not be executed in parallel due to there being 
more than one entry to or exit from the loop (e.g., an assertion).

File "cil/optimisation/functions/KullbackLeibler.py", line 346:
    def kl_div(x, y, eta):
        <source elided>
        accumulator = numpy.zeros(get_num_threads(), dtype=numpy.float64)
        for i in prange(x.size):
        ^

This is due to the else which returns, I believe.

@njit(parallel=True)
def kl_div(x, y, eta):
accumulator = numpy.zeros(get_num_threads(), dtype=numpy.float64)
for i in prange(x.size):
X = x.flat[i]
Y = y.flat[i] + eta.flat[i]
if X > 0 and Y > 0:
# out.flat[i] = X * numpy.log(X/Y) - X + Y
accumulator[get_thread_id()] += X * numpy.log(X/Y) - X + Y
elif X == 0 and Y >= 0:
# out.flat[i] = Y
accumulator[get_thread_id()] += Y
else:
# out.flat[i] = numpy.inf
return numpy.inf
return sum(accumulator)

@paskino paskino added the bug Something isn't working label Aug 22, 2024
paskino added a commit that referenced this issue Aug 22, 2024
closes #1900 

Signed-off-by: Edoardo Pasca <14138589+paskino@users.noreply.github.com>
@paskino paskino self-assigned this Aug 22, 2024
@paskino paskino added this to CIL work Aug 22, 2024
@github-project-automation github-project-automation bot moved this to Todo in CIL work Aug 22, 2024
@paskino paskino moved this from Todo to Blocked in CIL work Sep 5, 2024
@paskino paskino added this to the v24.2.0 milestone Sep 24, 2024
@gfardell gfardell moved this from Blocked to In Review in CIL work Sep 24, 2024
@gfardell gfardell modified the milestones: v24.2.0, v24.3.0 Oct 16, 2024
@github-project-automation github-project-automation bot moved this from In Review to Done in CIL work Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants