diff --git a/R/affinity.R b/R/affinity.R index 284d097d..10844495 100644 --- a/R/affinity.R +++ b/R/affinity.R @@ -11,7 +11,8 @@ fuzzy_set_union <- function(X, set_op_mix_ratio = 1) { } else { Matrix::drop0( - set_op_mix_ratio * (X + Matrix::t(X) - XX) + (1 - set_op_mix_ratio) * XX) + set_op_mix_ratio * (X + Matrix::t(X) - XX) + (1 - set_op_mix_ratio) * XX + ) } } @@ -19,8 +20,10 @@ fuzzy_set_union <- function(X, set_op_mix_ratio = 1) { # or not smooth_knn <- function(nn, local_connectivity = 1.0, bandwidth = 1.0, - n_threads = max(1, - RcppParallel::defaultNumThreads() / 2), + n_threads = max( + 1, + RcppParallel::defaultNumThreads() / 2 + ), grain_size = 1, verbose = FALSE) { tsmessage( @@ -52,9 +55,11 @@ smooth_knn <- function(nn, fuzzy_simplicial_set <- function(nn, set_op_mix_ratio = 1.0, local_connectivity = 1.0, bandwidth = 1.0, - n_threads = - max(1, - RcppParallel::defaultNumThreads() / 2), + n_threads = + max( + 1, + RcppParallel::defaultNumThreads() / 2 + ), grain_size = 1, verbose = FALSE) { affinity_matrix <- smooth_knn(nn, @@ -77,9 +82,11 @@ symmetrize <- function(P) { } perplexity_similarities <- function(nn, perplexity = NULL, - n_threads = - max(1, - RcppParallel::defaultNumThreads() / 2), + n_threads = + max( + 1, + RcppParallel::defaultNumThreads() / 2 + ), grain_size = 1, kernel = "gauss", verbose = FALSE) { @@ -118,8 +125,9 @@ perplexity_similarities <- function(nn, perplexity = NULL, # edge has a weight of val (scalar or vector) # return a sparse matrix with dimensions of nrow(nn_idx) x max_nbr_id nn_to_sparse <- function(nn_idx, val = 1, byrow = FALSE, self_nbr = FALSE, - max_nbr_id = ifelse(self_nbr, - nrow(nn_idx), max(nn_idx))) { + max_nbr_id = ifelse(self_nbr, + nrow(nn_idx), max(nn_idx) + )) { nd <- nrow(nn_idx) k <- ncol(nn_idx) diff --git a/R/init.R b/R/init.R index f37ec884..5d27e131 100644 --- a/R/init.R +++ b/R/init.R @@ -30,8 +30,10 @@ laplacian_eigenmap <- function(A, ndim = 2, verbose = FALSE) { ) if (is.null(eig_res) || ncol(eig_res$vectors) < ndim + 1) { - message("Laplacian Eigenmap failed to converge, ", - "using random initialization instead") + message( + "Laplacian Eigenmap failed to converge, ", + "using random initialization instead" + ) return(rand_init(nrow(A), ndim)) } vecs <- eig_res$vectors[, 2:(ndim + 1)] @@ -66,8 +68,10 @@ normalized_laplacian_init <- function(A, ndim = 2, verbose = FALSE) { } ) if (is.null(res) || ncol(res$vectors) < ndim) { - message("Spectral initialization failed to converge, ", - "using random initialization instead") + message( + "Spectral initialization failed to converge, ", + "using random initialization instead" + ) return(rand_init(n, ndim)) } vec_indices <- rev(order(res$values, decreasing = TRUE)[1:ndim]) diff --git a/R/neighbors.R b/R/neighbors.R index a8149e2f..80a7b234 100644 --- a/R/neighbors.R +++ b/R/neighbors.R @@ -225,8 +225,10 @@ sparse_nn <- function(X, k, include_self = TRUE) { is_nonzero <- dists != 0 dist_nonzero <- dists[is_nonzero] if (length(dist_nonzero) < k) { - stop("Row ", i, " of distance matrix has only ", length(dist_nonzero), - " defined distances") + stop( + "Row ", i, " of distance matrix has only ", length(dist_nonzero), + " defined distances" + ) } k_order <- order(dist_nonzero)[1:k] diff --git a/R/supervised.R b/R/supervised.R index 17bdaa94..ff5dbe7d 100644 --- a/R/supervised.R +++ b/R/supervised.R @@ -10,8 +10,8 @@ # Return The resulting intersected fuzzy simplicial set. categorical_simplicial_set_intersection <- function( simplicial_set, target, - unknown_dist = 1.0, - far_dist = 5.0, + unknown_dist = 1.0, + far_dist = 5.0, verbose = FALSE) { # Convert to dgTMatrix to get to the j indices @@ -113,11 +113,11 @@ general_sset_intersection <- function(indptr1, if (left_val > left_min || right_val > right_min) { if (mix_weight < 0.5) { - result_val[idx] <- left_val * + result_val[idx] <- left_val * right_val^(mix_weight / (1.0 - mix_weight)) } else { - result_val[idx] <- right_val * + result_val[idx] <- right_val * left_val^(((1.0 - mix_weight) / mix_weight)) } } diff --git a/R/transform.R b/R/transform.R index b940edeb..ac121827 100644 --- a/R/transform.R +++ b/R/transform.R @@ -42,7 +42,7 @@ umap_transform <- function(X, model, init_weighted = TRUE, search_k = NULL, n_epochs = NULL, - n_threads = + n_threads = max(1, RcppParallel::defaultNumThreads() / 2), grain_size = 1, verbose = FALSE) { @@ -181,7 +181,7 @@ umap_transform <- function(X, model, } init_new_embedding <- function(train_embedding, nn, graph, weighted = TRUE, - n_threads = + n_threads = max(1, RcppParallel::defaultNumThreads() / 2), grain_size = 1, verbose = FALSE) { parallelize <- n_threads > 0 diff --git a/R/uwot.R b/R/uwot.R index a1762071..f58fd13d 100644 --- a/R/uwot.R +++ b/R/uwot.R @@ -365,7 +365,7 @@ tumap <- function(X, n_neighbors = 15, n_components = 2, metric = "euclidean", uwot( X = X, n_neighbors = n_neighbors, n_components = n_components, metric = metric, - n_epochs = n_epochs, alpha = alpha, scale = scale, init = init, + n_epochs = n_epochs, alpha = alpha, scale = scale, init = init, spread = NULL, min_dist = NULL, set_op_mix_ratio = set_op_mix_ratio, local_connectivity = local_connectivity, bandwidth = bandwidth, gamma = gamma, negative_sample_rate = negative_sample_rate, @@ -536,7 +536,7 @@ lvish <- function(X, perplexity = 50, n_neighbors = perplexity * 3, uwot(X, n_neighbors = n_neighbors, n_components = n_components, metric = metric, - n_epochs = n_epochs, alpha = alpha, scale = scale, init = init, + n_epochs = n_epochs, alpha = alpha, scale = scale, init = init, gamma = gamma, negative_sample_rate = negative_sample_rate, nn_method = nn_method, n_trees = n_trees, search_k = search_k, method = "largevis", perplexity = perplexity, @@ -548,7 +548,7 @@ lvish <- function(X, perplexity = 50, n_neighbors = perplexity * 3, # Function that does all the real work uwot <- function(X, n_neighbors = 15, n_components = 2, metric = "euclidean", n_epochs = NULL, - alpha = 1, scale = FALSE, init = "spectral", + alpha = 1, scale = FALSE, init = "spectral", spread = 1, min_dist = 0.01, set_op_mix_ratio = 1.0, local_connectivity = 1.0, bandwidth = 1.0, gamma = 1.0, @@ -556,7 +556,7 @@ uwot <- function(X, n_neighbors = 15, n_components = 2, metric = "euclidean", nn_method = NULL, n_trees = 50, search_k = 2 * n_neighbors * n_trees, method = "umap", perplexity = 50, approx_pow = FALSE, - y = NULL, target_n_neighbors = n_neighbors, + y = NULL, target_n_neighbors = n_neighbors, target_weight = 0.5, n_threads = max(1, RcppParallel::defaultNumThreads() / 2), kernel = "gauss", @@ -651,8 +651,10 @@ uwot <- function(X, n_neighbors = 15, n_components = 2, metric = "euclidean", } nn_method <- match.arg(tolower(nn_method), c("annoy", "fnn")) if (nn_method == "fnn" && metric != "euclidean") { - stop("nn_method = 'FNN' is only compatible with distance metric ", - "'euclidean'") + stop( + "nn_method = 'FNN' is only compatible with distance metric ", + "'euclidean'" + ) } if (nn_method == "fnn" && ret_model) { stop("nn_method = 'FNN' is incompatible with ret_model = TRUE") @@ -949,8 +951,10 @@ scale_input <- function(X, scale_type, ret_model = FALSE, verbose = FALSE) { scale_type <- ifelse(scale_type, "scale", "none") } - scale_type <- match.arg(tolower(scale_type), - c("none", "scale", "range", "maxabs")) + scale_type <- match.arg( + tolower(scale_type), + c("none", "scale", "range", "maxabs") + ) switch(scale_type, range = { tsmessage("Range scaling X") diff --git a/tests/testthat/helper_fuzzy_sets.R b/tests/testthat/helper_fuzzy_sets.R index 13512bbf..6c20bb53 100644 --- a/tests/testthat/helper_fuzzy_sets.R +++ b/tests/testthat/helper_fuzzy_sets.R @@ -3,13 +3,17 @@ # Asymmetric fuzzy set data V_asymm <- sparseMatrix( - i = c(5, 6, 8, 3, 9, 10, 2, 4, 7, 9, 10, 2, 3, 7, 9, 10, 1, 6, 8, 3, 5, 1, - 5, 6, 7, 4, 1, 2, 4, 8), - j = c(1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 7, 7, 8, - 8, 8, 8, 9, 10, 10, 10, 10), + i = c( + 5, 6, 8, 3, 9, 10, 2, 4, 7, 9, 10, 2, 3, 7, 9, 10, 1, 6, 8, 3, 5, 1, + 5, 6, 7, 4, 1, 2, 4, 8 + ), + j = c( + 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 7, 7, 8, + 8, 8, 8, 9, 10, 10, 10, 10 + ), x = c( 1, 1, 1, 0.328, 0.4252, 1, 0.5386, 1, 1, 0.5748, 0.5, 0.4614, 1, 0.6463, - 1, 0.5, 1, 1, 0.6894, 0.672, 0.2807, 0.8381, 0.7193, 5.129e-10, 0.3538, + 1, 0.5, 1, 1, 0.6894, 0.672, 0.2807, 0.8381, 0.7193, 5.129e-10, 0.3538, 0.5447, 0.1619, 1, 0.4553, 0.3106 ) ) @@ -25,9 +29,9 @@ V_union <- sparseMatrix( 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10 ), x = c( - 1, 1, 1, 0.1619, 0.6899, 0.4614, 0.4252, 1, 0.6899, 1, 1, 0.5748, 0.5, + 1, 1, 1, 0.1619, 0.6899, 0.4614, 0.4252, 1, 0.6899, 1, 1, 0.5748, 0.5, 0.4614, 1, 0.6463, 1, 0.7277, 1, 1, 0.2807, 0.9128, 1, 1, 5.129e-10, 1, - 0.6463, 0.2807, 0.3538, 1, 0.9128, 5.129e-10, 0.3538, 0.3106, 0.4252, + 0.6463, 0.2807, 0.3538, 1, 0.9128, 5.129e-10, 0.3538, 0.3106, 0.4252, 0.5748, 1, 0.1619, 1, 0.5, 0.7277, 0.3106 ) ) @@ -43,10 +47,10 @@ V_mix <- sparseMatrix( 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10 ), x = c( - 1, 0.5, 0.919, 0.08095, 0.4333, 0.2307, 0.2126, 1, 0.4333, 1, 0.836, - 0.2874, 0.25, 0.2307, 1, 0.3231, 0.7723, 0.4777, 1, 0.5, 0.1404, 0.7043, - 0.5, 0.5, 2.564e-10, 0.836, 0.3231, 0.1404, 0.1769, 0.919, 0.7043, - 2.564e-10, 0.1769, 0.1553, 0.2126, 0.2874, 0.7723, 0.08095, 1, 0.25, + 1, 0.5, 0.919, 0.08095, 0.4333, 0.2307, 0.2126, 1, 0.4333, 1, 0.836, + 0.2874, 0.25, 0.2307, 1, 0.3231, 0.7723, 0.4777, 1, 0.5, 0.1404, 0.7043, + 0.5, 0.5, 2.564e-10, 0.836, 0.3231, 0.1404, 0.1769, 0.919, 0.7043, + 2.564e-10, 0.1769, 0.1553, 0.2126, 0.2874, 0.7723, 0.08095, 1, 0.25, 0.4777, 0.1553 ) ) @@ -63,10 +67,14 @@ V_intersect <- sparseMatrix( # asymm with local connectivity = 1.5 V_asymm_local <- sparseMatrix( - i = c(5, 6, 8, 3, 9, 10, 2, 4, 7, 9, 10, 2, 3, 7, 9, 10, 1, 6, 8, 3, 5, 1, - 5, 6, 7, 4, 1, 2, 4, 8), - j = c(1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 7, 7, 8, 8, - 8, 8, 9, 10, 10, 10, 10), + i = c( + 5, 6, 8, 3, 9, 10, 2, 4, 7, 9, 10, 2, 3, 7, 9, 10, 1, 6, 8, 3, 5, 1, + 5, 6, 7, 4, 1, 2, 4, 8 + ), + j = c( + 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 7, 7, 8, 8, + 8, 8, 9, 10, 10, 10, 10 + ), x = c( 1, 1, 1, 0.2559, 0.3748, 1, 0.5698, 1, 1, 0.6252, 0.5, 0.4302, 1, 0.7157, 1, 0.5, 1, 1, 0.7622, 0.7441, 0.2084, 0.8925, 0.7916, 5.129e-10, 0.2843, @@ -76,17 +84,17 @@ V_asymm_local <- sparseMatrix( V_union_local <- sparseMatrix( i = c( - 5, 6, 8, 10, 3, 4, 9, 10, 2, 4, 7, 9, 10, 2, 3, 7, 9, 10, 1, 6, 7, 8, 1, + 5, 6, 8, 10, 3, 4, 9, 10, 2, 4, 7, 9, 10, 2, 3, 7, 9, 10, 1, 6, 7, 8, 1, 5, 8, 3, 4, 5, 8, 1, 5, 6, 7, 10, 2, 3, 4, 1, 2, 3, 4, 8 ), j = c( - 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, + 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10 ), x = c( - 1, 1, 1, 0.1075, 0.6799, 0.4302, 0.3748, 1, 0.6799, 1, 1, 0.6252, 0.5, - 0.4302, 1, 0.7157, 1, 0.7102, 1, 1, 0.2084, 0.9504, 1, 1, 5.129e-10, 1, - 0.7157, 0.2084, 0.2843, 1, 0.9504, 5.129e-10, 0.2843, 0.2378, 0.3748, + 1, 1, 1, 0.1075, 0.6799, 0.4302, 0.3748, 1, 0.6799, 1, 1, 0.6252, 0.5, + 0.4302, 1, 0.7157, 1, 0.7102, 1, 1, 0.2084, 0.9504, 1, 1, 5.129e-10, 1, + 0.7157, 0.2084, 0.2843, 1, 0.9504, 5.129e-10, 0.2843, 0.2378, 0.3748, 0.6252, 1, 0.1075, 1, 0.5, 0.7102, 0.2378 ) ) @@ -101,9 +109,9 @@ V_union_bandwidth <- sparseMatrix( 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10 ), x = c( - 1, 1, 1, 0.02621, 0.3664, 0.2129, 0.1808, 1, 0.3664, 1, 1, 0.3304, 0.25, - 0.2129, 1, 0.4176, 1, 0.4055, 1, 1, 0.07881, 0.7467, 1, 1, 2.63e-19, 1, - 0.4176, 0.07881, 0.1251, 1, 0.7467, 2.63e-19, 0.1251, 0.09647, 0.1808, + 1, 1, 1, 0.02621, 0.3664, 0.2129, 0.1808, 1, 0.3664, 1, 1, 0.3304, 0.25, + 0.2129, 1, 0.4176, 1, 0.4055, 1, 1, 0.07881, 0.7467, 1, 1, 2.63e-19, 1, + 0.4176, 0.07881, 0.1251, 1, 0.7467, 2.63e-19, 0.1251, 0.09647, 0.1808, 0.3304, 1, 0.02621, 1, 0.25, 0.4055, 0.09647 ) ) @@ -111,6 +119,8 @@ V_union_bandwidth <- sparseMatrix( V_intersect_local_bandwidth <- sparseMatrix( i = c(5, 8, 3, 10, 2, 4, 7, 3, 9, 10, 1, 8, 3, 1, 5, 4, 2, 4), j = c(1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 7, 8, 8, 9, 10, 10), - x = c(1, 0.7966, 0.02126, 1, 0.02126, 1, 0.5536, 1, 0.336, 0.04417, 1, 0.364, - 0.5536, 0.7966, 0.364, 0.336, 1, 0.04417) + x = c( + 1, 0.7966, 0.02126, 1, 0.02126, 1, 0.5536, 1, 0.336, 0.04417, 1, 0.364, + 0.5536, 0.7966, 0.364, 0.336, 1, 0.04417 + ) ) diff --git a/tests/testthat/test_knn_aff.R b/tests/testthat/test_knn_aff.R index 6b35fe72..358bb0c3 100644 --- a/tests/testthat/test_knn_aff.R +++ b/tests/testthat/test_knn_aff.R @@ -43,5 +43,7 @@ expected_sym_nn_graph[10, c(1, 2, 3, 4, 8)] <- c(o6, o3, o6, o3, o6) expect_equal(sum(res), 10) expect_true(Matrix::isSymmetric(res)) -expect_equal(as.matrix(res), expected_sym_nn_graph, check.attributes = FALSE, - tol = 1e-7) +expect_equal(as.matrix(res), expected_sym_nn_graph, + check.attributes = FALSE, + tol = 1e-7 +) diff --git a/tests/testthat/test_neighbors.R b/tests/testthat/test_neighbors.R index 01a7a703..0b017c6b 100644 --- a/tests/testthat/test_neighbors.R +++ b/tests/testthat/test_neighbors.R @@ -115,8 +115,10 @@ res <- annoy_nn(ui10, k = 4, include_self = TRUE, n_threads = 0) expect_equal(res$idx, self_nn_index4, check.attributes = FALSE) expect_equal(res$dist, self_nn_dist4, check.attributes = FALSE, tol = 1e-6) -res <- annoy_nn(ui10, k = 4, include_self = FALSE, n_threads = 0, - ret_index = TRUE) +res <- annoy_nn(ui10, + k = 4, include_self = FALSE, n_threads = 0, + ret_index = TRUE +) expect_equal(res$idx, nn_index4, check.attributes = FALSE) expect_equal(res$dist, nn_dist4, check.attributes = FALSE, tol = 1e-6) expect_true(!is.null(res$index)) @@ -126,8 +128,10 @@ res <- annoy_nn(ui10, k = 4, include_self = TRUE, n_threads = 1) expect_equal(res$idx, self_nn_index4, check.attributes = FALSE) expect_equal(res$dist, self_nn_dist4, check.attributes = FALSE, tol = 1e-6) -res <- annoy_nn(ui10, k = 4, include_self = FALSE, n_threads = 1, - ret_index = TRUE) +res <- annoy_nn(ui10, + k = 4, include_self = FALSE, n_threads = 1, + ret_index = TRUE +) expect_equal(res$idx, nn_index4, check.attributes = FALSE) expect_equal(res$dist, nn_dist4, check.attributes = FALSE, tol = 1e-6) expect_true(!is.null(res$index)) diff --git a/tests/testthat/test_output.R b/tests/testthat/test_output.R index 50ce414f..434ae096 100644 --- a/tests/testthat/test_output.R +++ b/tests/testthat/test_output.R @@ -29,20 +29,20 @@ expect_ok_matrix(res) # UMAP and cosine metric n_threads = 1 issue #5 res <- umap(iris10, - n_neighbors = 4, n_epochs = 2, alpha = 0.5, metric = "cosine", - init = "spectral", verbose = FALSE, n_threads = 1 + n_neighbors = 4, n_epochs = 2, alpha = 0.5, metric = "cosine", + init = "spectral", verbose = FALSE, n_threads = 1 ) expect_ok_matrix(res) # metric = Manhattan res <- umap(iris10, - n_neighbors = 4, n_epochs = 2, alpha = 0.5, metric = "manhattan", - init = "rand", verbose = FALSE, n_threads = 0 + n_neighbors = 4, n_epochs = 2, alpha = 0.5, metric = "manhattan", + init = "rand", verbose = FALSE, n_threads = 0 ) expect_ok_matrix(res) res <- umap(iris10, - n_neighbors = 4, n_epochs = 2, alpha = 0.5, metric = "manhattan", - init = "spca", verbose = FALSE, n_threads = 1 + n_neighbors = 4, n_epochs = 2, alpha = 0.5, metric = "manhattan", + init = "spca", verbose = FALSE, n_threads = 1 ) expect_ok_matrix(res) diff --git a/tests/testthat/test_smooth_knn_dists.R b/tests/testthat/test_smooth_knn_dists.R index ffd831cd..e90dc320 100644 --- a/tests/testthat/test_smooth_knn_dists.R +++ b/tests/testthat/test_smooth_knn_dists.R @@ -50,16 +50,20 @@ expect_equal(res$P, V_asymm, tol = 1e-4) expect_equal(fuzzy_set_union(res$P), V_union, tol = 1e-4) # mix intersection with union -expect_equal(fuzzy_set_union(res$P, set_op_mix_ratio = 0.5), V_mix, - tol = 1e-4) +expect_equal(fuzzy_set_union(res$P, set_op_mix_ratio = 0.5), V_mix, + tol = 1e-4 +) # intersection -expect_equal(fuzzy_set_union(res$P, set_op_mix_ratio = 0), V_intersect, - tol = 1e-4) +expect_equal(fuzzy_set_union(res$P, set_op_mix_ratio = 0), V_intersect, + tol = 1e-4 +) # local connectivity -res <- smooth_knn_distances(nn_4$dist, nn_4$idx, local_connectivity = 1.5, - ret_extra = TRUE) +res <- smooth_knn_distances(nn_4$dist, nn_4$idx, + local_connectivity = 1.5, + ret_extra = TRUE +) res$P <- nn_to_sparse(nn_4$idx, as.vector(res$P), self_nbr = TRUE) expect_equal(res$P, V_asymm_local, tol = 1e-4) @@ -69,16 +73,18 @@ res_cpp_conn1 <- smooth_knn_distances_parallel(nn_4$dist, nn_4$idx, bandwidth = 1.0, tol = 1e-5, min_k_dist_scale = 1e-3, parallelize = FALSE, verbose = FALSE ) -expect_equal(nn_to_sparse(nn_4$idx, as.vector(res_cpp_conn1), - self_nbr = TRUE), V_asymm, tol = 1e-4) +expect_equal(nn_to_sparse(nn_4$idx, as.vector(res_cpp_conn1), + self_nbr = TRUE +), V_asymm, tol = 1e-4) res_cpp_conn1.5 <- smooth_knn_distances_parallel(nn_4$dist, nn_4$idx, n_iter = 64, local_connectivity = 1.5, bandwidth = 1.0, tol = 1e-5, min_k_dist_scale = 1e-3, parallelize = FALSE, verbose = FALSE ) -expect_equal(nn_to_sparse(nn_4$idx, as.vector(res_cpp_conn1.5), - self_nbr = TRUE), V_asymm_local, tol = 1e-4) +expect_equal(nn_to_sparse(nn_4$idx, as.vector(res_cpp_conn1.5), + self_nbr = TRUE +), V_asymm_local, tol = 1e-4) RcppParallel::setThreadOptions(numThreads = 1) @@ -87,23 +93,27 @@ res_cpp_conn1 <- smooth_knn_distances_parallel(nn_4$dist, nn_4$idx, bandwidth = 1.0, tol = 1e-5, min_k_dist_scale = 1e-3, grain_size = 1, verbose = FALSE ) -expect_equal(nn_to_sparse(nn_4$idx, as.vector(res_cpp_conn1), - self_nbr = TRUE), V_asymm, tol = 1e-4) +expect_equal(nn_to_sparse(nn_4$idx, as.vector(res_cpp_conn1), + self_nbr = TRUE +), V_asymm, tol = 1e-4) res_cpp_conn1.5 <- smooth_knn_distances_parallel(nn_4$dist, nn_4$idx, n_iter = 64, local_connectivity = 1.5, bandwidth = 1.0, tol = 1e-5, min_k_dist_scale = 1e-3, grain_size = 1, verbose = FALSE ) -expect_equal(nn_to_sparse(nn_4$idx, as.vector(res_cpp_conn1.5), - self_nbr = TRUE), V_asymm_local, tol = 1e-4) +expect_equal(nn_to_sparse(nn_4$idx, as.vector(res_cpp_conn1.5), + self_nbr = TRUE +), V_asymm_local, tol = 1e-4) # Test cross-distances V_asymm_local_cross <- V_asymm_local diag(V_asymm_local_cross) <- 1 -V_asymm_local_cross <- cbind(V_asymm_local_cross, - matrix(0, nrow = 10, ncol = 2)) +V_asymm_local_cross <- cbind( + V_asymm_local_cross, + matrix(0, nrow = 10, ncol = 2) +) res_cpp_conn1.5_cross <- smooth_knn_distances_parallel(nn_4$dist, nn_4$idx, n_iter = 64, local_connectivity = 1.5, diff --git a/tests/testthat/test_transform.R b/tests/testthat/test_transform.R index 1c5844ae..c80a5f8d 100644 --- a/tests/testthat/test_transform.R +++ b/tests/testthat/test_transform.R @@ -88,8 +88,10 @@ expect_equal(iris10_scale, iris10_strans, check.attributes = FALSE) iris10_zv_col <- iris10 iris10_zv_col[, 3] <- 10 -iris10zvc_scale <- scale_input(iris10_zv_col, scale_type = "scale", - ret_model = TRUE) +iris10zvc_scale <- scale_input(iris10_zv_col, + scale_type = "scale", + ret_model = TRUE +) # scale the original iris10 here on purpose to check that full-variance column # is correctly removed iris10_zvstrans <- apply_scaling(iris10, attr_to_scale_info(iris10zvc_scale))