R Under development (unstable) (2024-07-05 r86875 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. > > library( zonohedra ) Package: zonohedra. Author: Glenn Davis. Version: 0.3-0. Built: R 4.5.0; x86_64-w64-mingw32; 2024-07-07 02:06:25 UTC; windows Attaching package: 'zonohedra' The following object is masked from 'package:base': rank > library( microbenchmark ) > > options( width=120 ) > > testDuplicated <- function() + { + set.seed(0) + + start = 1000 + reps = 10 + A = matrix( rnorm(3*start), 3, start*reps ) + + cat( "A = \n" ) + print( str(A) ) + + + cat( "---------- duplicated (std::set or std::unordered_set) ---------------\n" ) + res = base::duplicated.matrix(A,MARGIN=2) + print( str(res) ) + print( res[ (ncol(A)-10):ncol(A) ] ) + + res = zonohedra::duplicated.matrix(A,MARGIN=2) + print( str(res) ) + print( res[ (ncol(A)-10):ncol(A) ] ) + + print( microbenchmark( base::duplicated.matrix(A,MARGIN=2) ) ) + print( microbenchmark( zonohedra::duplicated.matrix(A,MARGIN=2) ) ) + + return(TRUE) + } > > > testGrpDuplicated <- function( start=1000, reps=10 ) + { + cat( "\n" ) + + A = matrix( rnorm(3*start), 3, start*reps ) + + cat( "---------- group duplicated (std::map or std::unordered_map) ---------------\n" ) + grouptarget = rep( 1:start, reps ) + group = zonohedra::grpDuplicated(A,MARGIN=2) + if( ! all(group==grouptarget) ) + { + cat( "group incorrect:\n" ) + print(group) + return(FALSE) + } + + #print( str(res) ) + #print( res[ (ncol(A)-10):ncol(A) ] ) + print( microbenchmark( zonohedra::grpDuplicated(A,MARGIN=2) ) ) + + return(TRUE) + } > > > > # if( ! testDuplicated() ) stop( "testDuplicated() FAILED ! ERROR" ) > > if( ! testGrpDuplicated() ) stop( "testGrpDuplicated() FAILED ! ERROR" ) ---------- group duplicated (std::map or std::unordered_map) --------------- Unit: milliseconds expr min lq mean median uq max neval zonohedra::grpDuplicated(A, MARGIN = 2) 1.0486 1.6601 1.696476 1.68985 1.74775 1.8744 100 > > > cat( "Passed all duplication tests !\n", file=stderr() ) Passed all duplication tests ! > > proc.time() user system elapsed 0.57 0.10 0.61