Skip to content

Commit

Permalink
Remove extra copy
Browse files Browse the repository at this point in the history
  • Loading branch information
asistradition committed Feb 28, 2024
1 parent 4888d24 commit 2e6dfb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions inferelator_velocity/denoise.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy as np

from inferelator_velocity.utils.noise2self import (
_dist_to_row_stochastic,
dot
Expand All @@ -24,10 +26,13 @@ def denoise(
f"run global_graph() first"
)

data.layers[output_layer] = dot(
data.layers[output_layer] = np.zeros(lref.shape, dtype=np.float32)

dot(
_dist_to_row_stochastic(data.obsp[graph_key]),
lref,
dense=dense
dense=dense,
out=data.layers[output_layer]
)

return data
8 changes: 6 additions & 2 deletions inferelator_velocity/utils/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
f"{str(err)}"
)

def dot(x, y, dense=False, cast=False):
def dot(x, y, dense=False, cast=False, out=None):

z = x @ y

if dense and sps.issparse(z):
z = z.A

return z
if out is not None:
out[:] = z
return out
else:
return z


def scalar_projection(
Expand Down

0 comments on commit 2e6dfb7

Please sign in to comment.