@@ -38,14 +38,6 @@ import numpy as np
38
38
from scipy.sparse import issparse, csr_matrix
39
39
from ...utils._typedefs import DTYPE, SPARSE_INDEX_TYPE
40
40
41
- # TODO: If possible optimize this routine to efficiently treat cases where
42
- # `n_samples_X << n_samples_Y` met in practise when X_test consists of a
43
- # few samples, and thus when there's a single chunk of X whose number of
44
- # samples is less than the default chunk size.
45
-
46
- # TODO: compare this routine with the similar ones in SciPy, especially
47
- # `csr_matmat` which might implement a better algorithm.
48
- # See: https://github.com/scipy/scipy/blob/e58292e066ba2cb2f3d1e0563ca9314ff1f4f311/scipy/sparse/sparsetools/csr.h#L603-L669 # noqa
49
41
cdef void _middle_term_sparse_sparse_64(
50
42
const DTYPE_t[:] X_data,
51
43
const SPARSE_INDEX_TYPE_t[:] X_indices,
@@ -66,17 +58,17 @@ cdef void _middle_term_sparse_sparse_64(
66
58
ITYPE_t i, j, k
67
59
ITYPE_t n_X = X_end - X_start
68
60
ITYPE_t n_Y = Y_end - Y_start
69
- ITYPE_t X_i_col_idx, X_i_ptr, Y_j_col_idx, Y_j_ptr
61
+ ITYPE_t x_col, x_ptr, y_col, y_ptr
70
62
71
63
for i in range(n_X):
72
- for X_i_ptr in range(X_indptr[X_start+i], X_indptr[X_start+i+1]):
73
- X_i_col_idx = X_indices[X_i_ptr ]
64
+ for x_ptr in range(X_indptr[X_start+i], X_indptr[X_start+i+1]):
65
+ x_col = X_indices[x_ptr ]
74
66
for j in range(n_Y):
75
67
k = i * n_Y + j
76
- for Y_j_ptr in range(Y_indptr[Y_start+j], Y_indptr[Y_start+j+1]):
77
- Y_j_col_idx = Y_indices[Y_j_ptr ]
78
- if X_i_col_idx == Y_j_col_idx :
79
- D[k] += -2 * X_data[X_i_ptr ] * Y_data[Y_j_ptr ]
68
+ for y_ptr in range(Y_indptr[Y_start+j], Y_indptr[Y_start+j+1]):
69
+ y_col = Y_indices[y_ptr ]
70
+ if x_col == y_col :
71
+ D[k] += -2 * X_data[x_ptr ] * Y_data[y_ptr ]
80
72
81
73
82
74
{{for name_suffix, upcast_to_float64, INPUT_DTYPE_t, INPUT_DTYPE in implementation_specific_values}}
0 commit comments