R Under development (unstable) (2026-08-17 r90424 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(BIDistances) > > x = matrix( + c(0, 1, 2, 3, + 1, 1, 4, 2, + 2, 0, 1, 5), + nrow = 4, + ncol = 3 + ) > w = c(1, 2, 0.5) > reference = as.matrix(stats::dist(sweep(x, 2, sqrt(w), "*"))) > dimnames(reference) = NULL > > cpu_matrix = EuclideanGPU_Distance( + x, w, backend = "cpu", OutputType = "mat" + ) > stopifnot(isTRUE(all.equal(cpu_matrix, reference))) > > cpu_vector = EuclideanGPU_Distance( + x, w, backend = "cpu", OutputType = "vec" + ) > stopifnot(length(cpu_vector) == length(reference)) > stopifnot(isTRUE(all.equal(cpu_vector, as.vector(reference)))) > > through_wrapper = DistanceMatrix( + x, method = "euclidean", GPU = TRUE, + Weights = w, backend = "cpu" + ) > stopifnot(isTRUE(all.equal(through_wrapper, reference))) > > squared = DistanceMatrix( + x, method = "sqeuclidean", GPU = TRUE, + Weights = w, backend = "cpu" + ) > stopifnot(isTRUE(all.equal(squared, reference^2))) > > unweighted_reference = as.matrix(stats::dist(x)) > dimnames(unweighted_reference) = NULL > one_to_all = DistanceOneToAll(x[1, ], x[-1, , drop = FALSE]) > stopifnot(isTRUE(all.equal( + one_to_all$distToAll, + unweighted_reference[-1, 1] + ))) > > plan0 = calculateMemoryDemandGPU(100, 10, 2) > stopifnot(plan0$Version == 0L, sum(plan0$batchSizes) == 100) > > plan1 = calculateMemoryDemandGPU(20000, 10, 1) > stopifnot(plan1$Version == 1L, sum(plan1$batchSizes) == 20000) > > plan2 = calculateMemoryDemandGPU(10000, 5000, 0.01) > stopifnot(plan2$Version == 2L, sum(plan2$batchSizes) == 10000) > > single = matrix(3, nrow = 1L, ncol = 1L) > single_result = EuclideanGPU_Distance(single, backend = "cpu") > stopifnot(identical(single_result, matrix(0, nrow = 1L, ncol = 1L))) > > zero_weight = EuclideanGPU_Distance( + x, rep.int(0, ncol(x)), backend = "cpu" + ) > stopifnot(isTRUE(all.equal( + zero_weight, matrix(0, nrow(x), nrow(x)) + ))) > > selected = DistanceOneToAll( + x[1, ], x[-1, , drop = FALSE], + SelectFeatures = c(TRUE, FALSE, TRUE) + ) > selected_reference = as.matrix(stats::dist(x[, c(TRUE, FALSE, TRUE)])) > dimnames(selected_reference) = NULL > stopifnot(isTRUE(all.equal(selected$distToAll, selected_reference[-1, 1]))) > > minkowski_weights = c(1, 2, 0.5) > minkowski_reference = as.matrix(parallelDist::parDist( + sweep(x, 2, minkowski_weights^(1 / 3), "*"), + method = "minkowski", + p = 3, + threads = 2 + )) > dimnames(minkowski_reference) = NULL > minkowski_multicore = Minkowski_Distance( + x, + p = 3, + Weights = minkowski_weights, + backend = "multicore", + threads = 2 + ) > stopifnot(isTRUE(all.equal( + minkowski_multicore, + minkowski_reference, + tolerance = 1e-10 + ))) > > minkowski_wrapper = DistanceMatrix( + x, + method = "Minkowski_Distance", + p = 3, + Weights = minkowski_weights, + backend = "multicore", + threads = 2 + ) > stopifnot(isTRUE(all.equal( + minkowski_wrapper, + minkowski_reference, + tolerance = 1e-10 + ))) > > proc.time() user system elapsed 0.50 0.10 0.59