R Under development (unstable) (2024-01-07 r85787 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 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. > if (require(RUnit)) { + library(Matrix) + library(FeatureHashing) + contr <- list( + Plant = contrasts(CO2$Plant, contrasts = FALSE), + Type = contrasts(CO2$Type, contrasts = FALSE), + Treatment = contrasts(CO2$Treatment, contrasts = FALSE) + ) + m1 <- sparse.model.matrix(~ ., CO2, contr, transpose = TRUE) + + v <- numeric(dim(m1)[2]) + r1 <- as.vector(m1 %*% v) + r2 <- FeatureHashing:::Xv(m1, v, numeric(dim(m1)[1])) + checkTrue(isTRUE(all.equal(r1, r2)), + "The matrix-vector multiplication is incorrect") + + for(i in 1:ncol(m1)) { + v <- numeric(dim(m1)[2]) + v[i] <- 1 + r1 <- as.vector(m1 %*% v) + r2 <- numeric(dim(m1)[1]) + FeatureHashing:::Xv(m1, v, r2) + checkTrue(isTRUE(all.equal(r1, r2)), + "The result of C++ Xv is incorrect") + r <- as.vector(m1[,i]) + } + + + v <- numeric(dim(m1)[1]) + r1 <- as.vector(v %*% m1) + r2 <- FeatureHashing:::vX(v, m1, numeric(dim(m1)[2])) + checkTrue(isTRUE(all.equal(r1, r2)), + "The result of C++ vX is incorrect") + + for(i in 1:nrow(m1)) { + v <- numeric(dim(m1)[1]) + v[i] <- 1 + r1 <- as.vector(v %*% m1) + r2 <- numeric(dim(m1)[2]) + FeatureHashing:::vX(v, m1, r2) + checkTrue(isTRUE(all.equal(r1, r2)), + "The result of matrix-vector multiplication is incorrect") + } + } Loading required package: RUnit > > proc.time() user system elapsed 1.60 0.14 1.75