Added tests, fixed subfunctions (#3)
This commit is contained in:
parent
606078c355
commit
a8cae95c82
4 changed files with 38 additions and 19 deletions
|
|
@ -4,13 +4,12 @@ dec2bitv <- function(d, n) {
|
|||
# n is an optional minimum length on the bit vector.
|
||||
# If d is a vector, each row of the output array will be a bit vector.
|
||||
|
||||
if (nargin() < 2) {
|
||||
if (!exists("n") || n == 0) {
|
||||
n <- 1 # Need at least one digit even for 0.
|
||||
}
|
||||
d <- d[]
|
||||
|
||||
f <- e <- NA
|
||||
c(f, e) %<-% matlab2r::log2(max(d)) # How many digits do we need to represent the numbers?
|
||||
bits <- floor(d * 2 ^ (seq(1 - max(n, e), 0))) %% 2
|
||||
c(f, e) %<-% matlab2r::log2(base::max(d)) # How many digits do we need to represent the numbers?
|
||||
bits <- floor(d * 2 ^ (seq(1 - base::max(n, e), 0))) %% 2
|
||||
return(bits)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,22 +8,22 @@ myintersect <- function(A, B) {
|
|||
if (is.null(A)) {
|
||||
ma <- 0
|
||||
} else {
|
||||
ma <- max(A)
|
||||
ma <- base::max(A)
|
||||
}
|
||||
|
||||
if (is.null(B)) {
|
||||
mb <- 0
|
||||
} else {
|
||||
mb <- max(B)
|
||||
mb <- base::max(B)
|
||||
}
|
||||
|
||||
if (ma == 0 | mb == 0) {
|
||||
if (ma == 0 || mb == 0) {
|
||||
C <- vector()
|
||||
} else {
|
||||
# bits <- sparse(1, max(ma, mb))
|
||||
bits <- zeros(1, max(ma, mb))
|
||||
bits[A] <- 1
|
||||
C <- B[as.logical(bits[B])]
|
||||
bits <- zeros(1, base::max(ma, mb))
|
||||
bits[as.vector(A)] <- 1
|
||||
C <- B[as.logical(bits[as.vector(B)])]
|
||||
}
|
||||
return(C)
|
||||
return(sort(C))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
myisvector <- function(V) {
|
||||
# Kuten isvector(V)
|
||||
V <- as.matrix(V)
|
||||
A <- c(nrow(V), ncol(V))
|
||||
|
||||
A <- size(V)
|
||||
r <- (length(A) == 2) & (min(A) == 1)
|
||||
r <- (base::max(size(A)) == 2) & (base::min(A) == 1)
|
||||
return(r)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue