diff --git a/DESCRIPTION b/DESCRIPTION index 6095205..35c2a4b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rBAPS Title: Bayesian Analysis of Population Structure -Version: 0.0.0.9018 +Version: 0.0.0.9019 Date: 2020-11-09 Authors@R: c( diff --git a/R/dec2bitv.R b/R/dec2bitv.R index abe5169..a5f929e 100644 --- a/R/dec2bitv.R +++ b/R/dec2bitv.R @@ -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) } diff --git a/R/myintersect.R b/R/myintersect.R index e2e8f26..7c9ce61 100644 --- a/R/myintersect.R +++ b/R/myintersect.R @@ -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)) } diff --git a/R/myisvector.R b/R/myisvector.R index 498e97b..400089b 100644 --- a/R/myisvector.R +++ b/R/myisvector.R @@ -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) } diff --git a/tests/testthat/test-spatialMixture.R b/tests/testthat/test-spatialMixture.R index 82f2689..47c63ca 100644 --- a/tests/testthat/test-spatialMixture.R +++ b/tests/testthat/test-spatialMixture.R @@ -35,19 +35,38 @@ test_that("testaaKoordinaatit works as expected", { }) test_that("lakseKlitik() and subfunctions produce expected output", { + expect_equal(neighbors(matrix(c(11, 22, 33, 44), 2), 2), c(1, 2)) + expect_equal(myintersect(matrix(1:4, 2), matrix(2:5, 2)), 2:4) + expect_equal(myintersect(matrix(1:4, 2), matrix(5:8, 2)), integer(0)) + expect_equal(myintersect(matrix(1:4, 2), matrix(4:7, 2)), 4) + expect_true(myisvector(runif(1))) + expect_true(myisvector(matrix(runif(1)))) + expect_true(myisvector(runif(2))) + expect_true(myisvector(matrix(runif(2)))) + expect_true(myisvector(rand(2, 1))) + expect_true(myisvector(rand(1, 2))) + expect_false(myisvector(rand(2, 2))) + expect_equal(mysize(rand(1, 1)), 1) + expect_equal(mysize(rand(2, 1)), 2) + expect_equal(mysize(rand(1, 2)), 2) + expect_equal(mysize(rand(2, 2)), c(2, 2)) + expect_equal(dec2bitv(1, 2), c(0, 1)) + expect_equal(dec2bitv(5, 2), c(1, 0, 1)) + expect_equal(dec2bitv(5, 5), c(0, 0, 1, 0, 1)) + expect_equal(dec2bitv(5, 1), c(1, 0, 1)) + expect_equal(dec2bitv(5, 0), c(1, 0, 1)) + expect_equal(dec2bitv(10, 1), c(1, 0, 1, 0)) + expect_equal(dec2bitv(10, 5), c(0, 1, 0, 1, 0)) + expect_equal(dec2bitv(10, 10), c(0, 0, 0, 0, 0, 0, 1, 0, 1, 0)) + # TODO: test ind2subv() + # TODO: test argmin() # TODO: test elim_order() # TODO: test triangulate() - # TODO: test neighbors() - # TODO: test myintersect() # TODO: test mysubset() # TODO: test findCliques() # TODO: test cliques_to_jtree() # TODO: test minimum_spanning_tree() # TODO: test myunion() - # TODO: test argmin() - # TODO: test mysize() - # TODO: test ind2subv() - # TODO: test myisvector() # TODO: ... and anythin left from findCliques.m # TODO: test lakseKlitik() })