context("init_counts_cpp")
test_that("init_counts_cpp", {
set.seed(4711)
N <- 1000
D <- 17
V <- 31
K <- 10
P <- 3
state_df <- data.frame(doc = sample(1:D, size = N, replace = TRUE),
type = sample(1:V, size = N, replace = TRUE),
topic = sample(1:K, size = N, replace = TRUE),
party = sample(1:P, size = N, replace = TRUE),
perspective = sample(0:1, size = N, replace = TRUE))
constants <- list(D = length(unique(state_df$doc)),
V = length(unique(state_df$type)),
K = length(unique(state_df$topic)),
P = length(unique(state_df$party)),
N = nrow(state_df))
expect_silent(
stopifnot(constants$D == D,
constants$V == V,
constants$K == K,
constants$P == P,
constants$N == N)
)
icr <- PerspectiveTopicModel:::init_counts_r(state_df, constants)
icrcpp <- PerspectiveTopicModel:::init_count_cpp(state_df, constants)
expect_silent(
stopifnot(all(icrcpp$n_dk == icr$n_dk),
all(icrcpp$n_vkpx == icr$n_vkpx),
all(icrcpp$n_kpx == icr$n_kpx))
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.