Skip to content

Commit

Permalink
Fix a memory leak in fluidimage/calcul/subpix.py
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed Apr 20, 2024
1 parent 35d1a19 commit 13520f6
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/fluidimage/calcul/subpix.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@

@boost
def compute_subpix_2d_gaussian2(correl: "float32[][]", ix: int, iy: int):
correl_crop = correl[iy - 1 : iy + 2, ix - 1 : ix + 2]
# hoops, pythran crashes because of this line
# correl_crop[correl_crop < 0] = 1e-6

# we write it like this to please pythran
tmp = np.where(correl_crop < 0)
for i0, i1 in zip(tmp[0], tmp[1]):
correl_crop[i0, i1] = 1e-6
# without np.ascontiguousarray => memory leak
correl_crop = np.ascontiguousarray(correl[iy - 1 : iy + 2, ix - 1 : ix + 2])

correl_crop_ravel = correl_crop.ravel()

correl_min = correl_crop.min()
for idx in range(9):
correl_crop_ravel[idx] -= correl_min

correl_max = correl_crop.max()
for idx in range(9):
correl_crop_ravel[idx] /= correl_max

for idx in range(9):
if correl_crop_ravel[idx] == 0:
correl_crop_ravel[idx] = 1e-8

c10 = 0
c01 = 0
Expand Down

0 comments on commit 13520f6

Please sign in to comment.