Merge branch 'issue-3' into develop

This commit is contained in:
Waldir Leoncio 2023-02-16 15:30:30 +01:00
commit 449982a083
3 changed files with 11 additions and 4 deletions

View file

@ -1,6 +1,6 @@
Package: rBAPS
Title: Bayesian Analysis of Population Structure
Version: 0.0.0.9019
Version: 0.0.0.9020
Date: 2020-11-09
Authors@R:
c(

View file

@ -21,7 +21,7 @@ ind2subv <- function(siz, ndx) {
}
if (all(siz == 2)) {
sub <- dec2bitv(ndx - 1, n)
sub <- t(vapply(ndx, function(x) dec2bitv(x - 1, n), c(0, 0, 0)))
sub <- sub[, seq(n, 1, - 1)] + 1
return(sub)
}
@ -31,7 +31,7 @@ ind2subv <- function(siz, ndx) {
sub <- zeros(length(ndx), n)
for (i in seq(n, 1, -1)) {# i'th digit
sub[, i] <- floor(ndx / cp[i]) + 1
ndx <- ndx %% cp(i)
ndx <- ndx %% cp[i]
}
return(sub)
}

View file

@ -58,7 +58,14 @@ test_that("lakseKlitik() and subfunctions produce expected output", {
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()
expect_equal(
ind2subv(c(2, 2, 2), 1:8),
matrix(c(rep(1:2, 4), rep(1:2, 2, each = 2), rep(1:2, 1, each = 4)), 8)
)
expect_equal(
ind2subv(c(1, 2, 4, 3), 1:5),
matrix(c(rep(1, 5), 1, 2, 1, 2, 1, 1, 1, 2, 2, 3, rep(1, 5)), ncol = 4)
)
# TODO: test argmin()
# TODO: test elim_order()
# TODO: test triangulate()