Skip to content

Update utils.py #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions mnnpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@



@jit(float32[:](float32[:, :]), nogil=True)

def l2_norm(in_matrix):
return np.linalg.norm(x=in_matrix, axis=1)


@jit(float32[:, :](float32[:, :], float32[:, :]), nogil=True)

def scale_rows(in_matrix, scale_vector):
return np.divide(in_matrix, scale_vector)


@jit(float32[:, :](float32[:, :], float32[:, :]))

def kdist(m, n):
dist = np.zeros((m.shape[0], n.shape[0]), dtype=np.float32)
for i in range(m.shape[0]):
Expand Down Expand Up @@ -85,7 +85,7 @@ def transform_input_data(datas, cos_norm_in, cos_norm_out, var_index, var_subset
return in_batches, out_batches, var_sub_index, same_set


@jit((float32[:, :], float32[:, :], int8, int8, int8))

def find_mutual_nn(data1, data2, k1, k2, n_jobs):
k_index_1 = cKDTree(data1).query(x=data2, k=k1, n_jobs=n_jobs)[1]
k_index_2 = cKDTree(data2).query(x=data1, k=k2, n_jobs=n_jobs)[1]
Expand All @@ -99,7 +99,7 @@ def find_mutual_nn(data1, data2, k1, k2, n_jobs):
return mutual_1, mutual_2


@jit(float32[:, :](float32[:, :], float32[:, :], int32[:], int32[:], float32[:, :], float32))

def compute_correction(data1, data2, mnn1, mnn2, data2_or_raw2, sigma):
vect = data1[mnn1] - data2[mnn2]
mnn_index, mnn_count = np.unique(mnn2, return_counts=True)
Expand Down Expand Up @@ -196,7 +196,7 @@ def adjust_shift_variance(data1, data2, correction, sigma, n_jobs, var_subset=No
return correction * scaling[:, None]


@jit(float32(float32[:, :], float32[:, :], float32[:], float32[:], float32), nogil=True)

def adjust_s_variance(data1, data2, curcell, curvect, sigma):
distance1 = np.zeros((data1.shape[0], 2), dtype=np.float32)
l2_norm = np.linalg.norm(curvect)
Expand Down Expand Up @@ -232,7 +232,7 @@ def adjust_s_variance(data1, data2, curcell, curvect, sigma):
return (ref_quan - curproj) / l2_norm


@jit(float32(float32[:], float32[:], float32[:]), nopython=True)

def sq_dist_to_line(ref, grad, point):
working = ref - point
scale = np.dot(working, grad)
Expand Down