scikit-learn/scikit-learn — Issue #516: sparse-sparse and sparse-dense dot product with dense output
Author: mblondel
Created: 2011-12-25 21:31:49+00:00
State: open

`safe_sparse_dot` has an option `dense_output` which allows to specify that the dot product between two sparse matrices or between a sparse matrix and a numpy array should be output to a numpy array. However, scipy currently always return a sparse matrix, therefore `safe_sparse_dot` converts it afterwards with `toarray()`. It would be better if we had Cython utilities that can directly output to a numpy array, thus avoiding needless memory allocation and copying. Those utilities are fairly low level and should probably be contributed to scipy too but I feel we should have them in scikit-learn, until the version of scipy that implements them becomes mainstream.

Used in:
- euclidean_distances
- linear_kernel
- ridge regression (n_features > n_samples case)
- NMF

Necessary functions for sparse-dense:
- dot(X_csr, Y_c, out)
- dot(X_csr, Y_fortran, out)
- dot(X_csc, Y_c, out)
- dot(X_csc, Y_fortran, out)

Necessary functions for sparse-sparse:
- dot(X_csr, Y_csc, out)

Other situations can be handled by using:
- dot(a, b) = dot(b.T, a.T).T