{"issue":{"title":"sparse-sparse and sparse-dense dot product with dense output","user":{"login":"mblondel","id":233706,"url":"https://api.github.com/users/mblondel","gravatar_id":"af78619231b186055bdd40c5057af17d","avatar_url":"https://secure.gravatar.com/avatar/af78619231b186055bdd40c5057af17d?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"created_at":"2011-12-25T21:31:49Z","milestone":null,"state":"open","updated_at":"2011-12-26T15:42:17Z","labels":[],"id":2655949,"closed_at":null,"html_url":"https://github.com/scikit-learn/scikit-learn/issues/516","pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"body":"`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.\r\n\r\nUsed in:\r\n- euclidean_distances\r\n- linear_kernel\r\n- ridge regression (n_features > n_samples case)\r\n- NMF\r\n\r\nNecessary functions for sparse-dense:\r\n- dot(X_csr, Y_c, out)\r\n- dot(X_csr, Y_fortran, out)\r\n\r\nNecessary functions for sparse-sparse:\r\n- dot(X_csr, Y_csc, out)\r\n\r\nOther situations can be handled by using:\r\n- dot(a, b) = dot(b.T, a.T).T","number":516,"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/516","comments":4,"assignee":null},"comment":{"user":{"login":"mblondel","id":233706,"url":"https://api.github.com/users/mblondel","gravatar_id":"af78619231b186055bdd40c5057af17d","avatar_url":"https://secure.gravatar.com/avatar/af78619231b186055bdd40c5057af17d?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"created_at":"2011-12-26T15:42:17Z","updated_at":"2011-12-26T15:42:17Z","id":3275157,"body":"@jakevdp: Indeed, we may need them too!\r\n\r\n@ogrisel: Ideally, `safe_sparse_dot` should automatically call the right internal function. When an efficient implementation for a particular setting is not available, we can always use `toarray()` as done in the current implementation.","url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments/3275157"},"action":"created"}