Skip to content

Commit

Permalink
sparse
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Apr 28, 2022
1 parent 9840659 commit b80d997
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion python/amici/ode_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3408,9 +3408,18 @@ def _parallel_applyfunc(
# parallel
from pickle import PicklingError
from multiprocessing import Pool
from sympy.matrices.dense import DenseMatrix
with Pool(n_procs) as p:
try:
return obj._new(obj.rows, obj.cols, p.map(func, obj))
if isinstance(obj, DenseMatrix):
return obj._new(obj.rows, obj.cols, p.map(func, obj))
elif isinstance(obj, sp.SparseMatrix):
dok = obj.todok()
mapped = p.map(func, dok.values())
dok = {k: v for k, v in zip(dok.keys(), mapped) if v != 0}
return obj._new(obj.rows, obj.cols, dok)
else:
raise ValueError(f"Unsupported matrix type {type(obj)}")
except PicklingError as e:
raise ValueError(f"Couldn't pickle {func}. This is likely due "
"that the argument was not a module-level "
Expand Down

0 comments on commit b80d997

Please sign in to comment.