Skip to content

Commit

Permalink
Fix dummy guvectorize
Browse files Browse the repository at this point in the history
  • Loading branch information
pablormier committed Sep 18, 2024
1 parent bc95cb0 commit d2f0ddb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions corneto/extensions/_numba.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from functools import wraps

import numpy as np

from corneto.extensions._optional import OptionalModule


Expand All @@ -12,5 +16,34 @@ def _create_dummy(self, name): # type: ignore
return float
if name == "prange":
return range
if name == "guvectorize":
# Dummy guvectorize decorator for simulation purposes
def dummy_guvectorize(signature, layout):
def decorator(func):
@wraps(func)
def wrapped_func(*args, **kwargs):
# Extract input arrays
a = args[0] # The input array `a`
window_arr = args[1] # Scalar `window_arr`

# Allocate the output array if not provided
if len(args) < 3:
out = np.zeros_like(a)
else:
out = args[2] # Output array

# Iterate over the first axis (rows)
for i in range(a.shape[0]):
func(
a[i], window_arr, out[i]
) # Call the function for each row

return out

return wrapped_func

return decorator

return dummy_guvectorize

return super()._create_dummy(name)

0 comments on commit d2f0ddb

Please sign in to comment.