Skip to content

Commit

Permalink
Remove asserts in JIT functions (breaks with pytest)
Browse files Browse the repository at this point in the history
  • Loading branch information
thalassemia committed Jan 19, 2024
1 parent 509760f commit e0a99b1
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions reconstruction/ecoli/dataclasses/process/metabolism.py
Original file line number Diff line number Diff line change
Expand Up @@ -2203,22 +2203,24 @@ def _is_transport_rxn(self, stoich):

@njit
def np_apply_along_axis(func1d, axis, arr):
assert arr.ndim == 2
assert axis in [0, 1]
if axis == 0:
result = np.empty(arr.shape[1])
for i in range(len(result)):
result[i] = func1d(arr[:, i])
else:
result = np.empty(arr.shape[0])
for i in range(len(result)):
result[i] = func1d(arr[i, :])
return result
if arr.ndim != 2:
raise RuntimeError("Array must have 2 dimensions.")
if axis not in [0, 1]:
raise RuntimeError("Axis must be 0 or 1.")
if axis == 0:
result = np.empty(arr.shape[1])
for i in range(len(result)):
result[i] = func1d(arr[:, i])
else:
result = np.empty(arr.shape[0])
for i in range(len(result)):
result[i] = func1d(arr[i, :])
return result


@njit
def np_prod(array, axis):
return np_apply_along_axis(np.prod, axis, array)
return np_apply_along_axis(np.prod, axis, array)


@njit
Expand Down

0 comments on commit e0a99b1

Please sign in to comment.