Skip to content

sinkhorn_knopp_largedata should return dense matrix #1

@hsuknowledge

Description

@hsuknowledge

When I tried ConstructDiffusionOperators() with 45k cells, first I encountered this error.

Error in diag(P) : no method for coercing this S4 class to a vector

From the source code, we see that base::diag() is called on a Matrix object which is returned by Doubly_stochastic() function in case matrix columns exceed 10k. If it was < 10k, it returns a dense matrix, otherwise it returns a sparse Matrix produced by sinkhorn_knopp_largedata().

sinkhorn_knopp_largedata = function(A, niter = 100, tol = 1e-8, verb = FALSE) {

At first I thought specifying Matrix::diag() to fix the error solves the problem, but then I found that the self-multiplication P <- P %*% P of the sparse Matrix takes too long after just 2 iterations. Instead, I think P should always be a dense matrix, so that its multiplication takes a fixed amount of time while taking advantage of OpenBLAS multi-threading.

Update:

I think I found another bug. In the tutorial, the next function fast_get_lmd() cannot take rho as a sparse Matrix. You need to coerce it to a dense matrix, otherwise this error happens.

Error: Not compatible with requested type: [type=S4; target=double].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions