R/diff2.R

Defines functions .difference2

.difference2 <- function(A, B) {

  if (is.numeric(A)) A <- Matrix::Matrix(A, sparse = TRUE)
  if (is.numeric(B)) B <- Matrix::Matrix(B, sparse = TRUE)

  applicable <- (ncol(A) == ncol(B)) || (ncol(B) == 1) || (ncol(A) == 1)
  stopifnot(applicable)

  if (ncol(A) == ncol(B)) {

    A <- set_difference(A@i, A@p, A@x, B@i, B@p, B@x, nrow(A))
    # A[B >= A] <- 0

    return(A)

  }

  if (ncol(B) == 1) {

    n <- ncol(A)

    # newB <- .replicate_col(B, n)

    A <- set_difference_single(A@i, A@p, A@x, B@i, B@p, B@x, nrow(A))

    # A[newB >= A] <- 0

    return(A)

  }

  if (ncol(A) == 1) {

    n <- ncol(B)

    newA <- .replicate_col(A, n)

    newA <- set_difference(newA@i, newA@p, newA@x, B@i, B@p, B@x, nrow(newA))

    # newA[B >= newA] <- 0

    return(newA)

  }

}

Try the fcaR package in your browser

Any scripts or data that you put into this service are public.

fcaR documentation built on June 29, 2021, 1:06 a.m.