Skip to content

MAINT PairwiseDistancesReduction: Do not slice memoryviews in _compute_dist_middle_terms #24715

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

Merged
merged 5 commits into from
Nov 22, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,6 @@ cdef class DenseDenseMiddleTermComputer{{name_suffix}}(MiddleTermComputer{{name_
ITYPE_t thread_num,
) nogil:
cdef:
const {{INPUT_DTYPE_t}}[:, ::1] X_c = self.X[X_start:X_end, :]
const {{INPUT_DTYPE_t}}[:, ::1] Y_c = self.Y[Y_start:Y_end, :]
DTYPE_t *dist_middle_terms = self.dist_middle_terms_chunks[thread_num].data()

# Careful: LDA, LDB and LDC are given for F-ordered arrays
Expand All @@ -380,9 +378,9 @@ cdef class DenseDenseMiddleTermComputer{{name_suffix}}(MiddleTermComputer{{name_
BLAS_Order order = RowMajor
BLAS_Trans ta = NoTrans
BLAS_Trans tb = Trans
ITYPE_t m = X_c.shape[0]
ITYPE_t n = Y_c.shape[0]
ITYPE_t K = X_c.shape[1]
ITYPE_t m = X_end - X_start
ITYPE_t n = Y_end - Y_start
ITYPE_t K = self.n_features
DTYPE_t alpha = - 2.
{{if upcast_to_float64}}
DTYPE_t * A = self.X_c_upcast[thread_num].data()
Expand All @@ -391,15 +389,15 @@ cdef class DenseDenseMiddleTermComputer{{name_suffix}}(MiddleTermComputer{{name_
# Casting for A and B to remove the const is needed because APIs exposed via
# scipy.linalg.cython_blas aren't reflecting the arguments' const qualifier.
# See: https://github.com/scipy/scipy/issues/14262
DTYPE_t * A = <DTYPE_t *> &X_c[0, 0]
DTYPE_t * B = <DTYPE_t *> &Y_c[0, 0]
DTYPE_t * A = <DTYPE_t *> &self.X[X_start, 0]
DTYPE_t * B = <DTYPE_t *> &self.Y[Y_start, 0]
{{endif}}
ITYPE_t lda = X_c.shape[1]
ITYPE_t ldb = X_c.shape[1]
ITYPE_t lda = self.n_features
ITYPE_t ldb = self.n_features
DTYPE_t beta = 0.
ITYPE_t ldc = Y_c.shape[0]
ITYPE_t ldc = Y_end - Y_start

# dist_middle_terms = `-2 * X_c @ Y_c.T`
# dist_middle_terms = `-2 * X[X_start:X_end] @ Y[Y_start:Y_end].T`
_gemm(order, ta, tb, m, n, K, alpha, A, lda, B, ldb, beta, dist_middle_terms, ldc)

return dist_middle_terms
Expand Down