1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309
|
// sugar.cpp: Rcpp R/C++ interface class library -- sugar unit tests
//
// Copyright (C) 2012 - 2025 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2025 Dirk Eddelbuettel, Romain Francois and IƱaki Ucar
//
// This file is part of Rcpp.
//
// Rcpp is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// Rcpp is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
#include <Rcpp.h>
using namespace Rcpp ;
template <typename T>
class square : public std::function<T(T)> {
public:
T operator()( T t) const { return t*t ; }
} ;
double raw_square( double x){ return x*x; }
// [[Rcpp::export]]
List runit_abs( NumericVector xx, IntegerVector yy ){
return List::create( abs(xx), abs(yy) ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_one_less( NumericVector xx ){
return all( xx < 5.0 ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_one_greater( NumericVector xx ){
return all( xx > 5.0 ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_one_less_or_equal( NumericVector xx ){
return all( xx <= 5.0 ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_one_greater_or_equal( NumericVector xx ){
return all( xx >= 5.0 ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_one_equal( NumericVector xx ){
return all( xx == 5.0 ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_not_equal_one( NumericVector xx ){
return all( xx != 5.0 ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_less( NumericVector xx, NumericVector yy){
return all( xx < yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_greater( NumericVector xx, NumericVector yy ){
return all( xx > yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_less_or_equal( NumericVector xx, NumericVector yy){
return all( xx <= yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_greater_or_equal( NumericVector xx, NumericVector yy){
return all( xx >= yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_equal( NumericVector xx, NumericVector yy){
return all( xx == yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_all_not_equal( NumericVector xx, NumericVector yy){
return all( xx != yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_any_less( NumericVector xx, NumericVector yy){
return any( xx < yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_any_greater( NumericVector xx, NumericVector yy ){
return any( xx > yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_any_less_or_equal( NumericVector xx, NumericVector yy ){
return any( xx <= yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_any_greater_or_equal( NumericVector xx, NumericVector yy){
return any( xx >= yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_any_equal( NumericVector xx, NumericVector yy){
return any( xx == yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_any_not_equal( NumericVector xx, NumericVector yy){
return any( xx != yy ) ;
}
// [[Rcpp::export]]
LogicalVector runit_constructor( NumericVector xx, NumericVector yy ){
LogicalVector res( xx < yy ) ;
return res ;
}
// [[Rcpp::export]]
LogicalVector runit_assignment( NumericVector xx, NumericVector yy ){
LogicalVector res;
res = xx < yy ;
return res ;
}
// [[Rcpp::export]]
NumericVector runit_diff( NumericVector xx){
NumericVector res = diff( xx );
return res ;
}
// [[Rcpp::export]]
IntegerVector runit_diff_int(IntegerVector xx) {
IntegerVector res = diff(xx);
return res;
}
// [[Rcpp::export]]
NumericVector runit_diff_ifelse( LogicalVector pred, NumericVector xx, NumericVector yy){
NumericVector res = ifelse( pred, diff(xx), diff(yy) );
return res ;
}
// [[Rcpp::export]]
List runit_exp( NumericVector xx, IntegerVector yy ){
return List::create( exp(xx), exp(yy) ) ;
}
// [[Rcpp::export]]
List runit_floor( NumericVector xx, IntegerVector yy ){
return List::create( floor(xx), floor(yy) ) ;
}
// [[Rcpp::export]]
List runit_ceil( NumericVector xx, IntegerVector yy){
return List::create( ceil(xx), ceil(yy) ) ;
}
// [[Rcpp::export]]
List runit_pow( NumericVector xx, IntegerVector yy){
return List::create( pow(xx, 3), pow(yy, 2.3) ) ;
}
// [[Rcpp::export]]
List runit_ifelse( NumericVector xx, NumericVector yy){
return List::create(
_["vec_vec" ] = ifelse( xx < yy, xx*xx, -(yy*yy) ),
_["vec_prim"] = ifelse( xx < yy, 1.0 , -(yy*yy) ),
_["prim_vec"] = ifelse( xx < yy, xx*xx, 1.0 ),
_["prim_prim"] = ifelse( xx < yy, 1.0, 2.0 )
) ;
}
// [[Rcpp::export]]
LogicalVector runit_isna( NumericVector xx){
return wrap( is_na( xx ) ) ;
}
// [[Rcpp::export]]
LogicalVector runit_isfinite( NumericVector xx){
return is_finite(xx) ;
}
// [[Rcpp::export]]
LogicalVector runit_isinfinite( NumericVector xx){
return is_infinite(xx) ;
}
// [[Rcpp::export]]
LogicalVector runit_isnan( NumericVector xx){
return is_nan(xx) ;
}
// [[Rcpp::export]]
LogicalVector runit_isna_isna( NumericVector xx ){
return is_na( is_na( xx ) ) ;
}
// [[Rcpp::export]]
LogicalVector runit_any_isna( NumericVector xx){
return any( is_na( xx ) ) ;
}
// [[Rcpp::export]]
NumericVector runit_na_omit( NumericVector xx ){
return na_omit( xx ) ;
}
// [[Rcpp::export]]
List runit_lapply( NumericVector xx ){
List res = lapply( xx, square<double>() );
return res ;
}
// [[Rcpp::export]]
List runit_lapply_rawfun( NumericVector xx){
List res = lapply( xx, raw_square );
return res ;
}
// [[Rcpp::export]]
List runit_lapply_lambda(NumericVector xx){
List res = lapply(xx, [](double x) { return x*x; });
return res;
}
// [[Rcpp::export]]
List runit_lapply_seq( IntegerVector xx){
List res = lapply( xx, seq_len );
return res ;
}
// [[Rcpp::export]]
NumericVector runit_mapply2(NumericVector xx, NumericVector yy){
NumericVector res = mapply(xx, yy, std::plus<double>());
return res;
}
// [[Rcpp::export]]
NumericVector runit_mapply2_lambda(NumericVector xx, NumericVector yy){
NumericVector res = mapply(xx, yy, [](double x, double y) { return x+y; });
return res;
}
// [[Rcpp::export]]
NumericVector runit_mapply3_lambda(NumericVector xx, NumericVector yy, NumericVector zz){
NumericVector res = mapply(xx, yy, zz, [](double x, double y, double z) { return x+y+z; });
return res;
}
// [[Rcpp::export]]
LogicalVector runit_mapply2_logical(NumericVector xx, NumericVector yy){
return all(mapply(xx, yy, std::plus<double>()) < 100.0);
}
// [[Rcpp::export]]
List runit_mapply2_list(IntegerVector xx, IntegerVector yy){
List res = mapply(xx, yy, seq);
return res ;
}
// [[Rcpp::export]]
List runit_minus( IntegerVector xx ){
return List::create(
xx - 10,
10 - xx,
xx - xx,
noNA( xx ) - 10,
10 - noNA( xx )
) ;
}
// [[Rcpp::export]]
LogicalVector runit_any_equal_not( NumericVector xx, NumericVector yy){
return any( !( xx == yy) ) ;
}
// [[Rcpp::export]]
List runit_plus( IntegerVector xx ){
return List::create(
xx + 10,
10 + xx,
xx + xx,
xx + xx + xx
) ;
}
// [[Rcpp::export]]
List runit_plus_seqlen(){
return List::create(
seq_len(10) + 10,
10 + seq_len(10),
seq_len(10) + seq_len(10)
) ;
}
// [[Rcpp::export]]
LogicalVector runit_plus_all( IntegerVector xx ){
return all( (xx+xx) < 10 ) ;
}
// [[Rcpp::export]]
NumericVector runit_pmin( NumericVector xx, NumericVector yy ){
NumericVector res = pmin( xx, yy );
return res ;
}
// [[Rcpp::export]]
List runit_pmin_one( NumericVector xx ){
return List::create(
pmin( xx, 5),
pmin( 5, xx)
) ;
}
// [[Rcpp::export]]
NumericVector runit_pmax( NumericVector xx, NumericVector yy ){
NumericVector res = pmax( xx, yy );
return res ;
}
// [[Rcpp::export]]
List runit_pmax_one( NumericVector xx ){
return List::create(
pmax( xx, 5),
pmax( 5, xx)
) ;
}
// [[Rcpp::export]]
NumericVector runit_Range(){
NumericVector xx(8) ;
xx[ Range(0,3) ] = exp( seq_len(4) ) ;
xx[ Range(4,7) ] = exp( - seq_len(4) ) ;
return xx ;
}
// [[Rcpp::export]]
IntegerVector runit_range_plus(int start, int end, int n) {
IntegerVector vec = Range(start, end) + n;
return vec;
}
// [[Rcpp::export]]
IntegerVector runit_range_minus(int start, int end, int n) {
IntegerVector vec = Range(start, end) - n;
return vec;
}
// [[Rcpp::export]]
NumericVector runit_sapply( NumericVector xx ){
NumericVector res = sapply( xx, square<double>() );
return res ;
}
// [[Rcpp::export]]
NumericVector runit_sapply_rawfun( NumericVector xx){
NumericVector res = sapply( xx, raw_square );
return res ;
}
// [[Rcpp::export]]
NumericVector runit_sapply_lambda(NumericVector xx){
NumericVector res = sapply(xx, [](double x) { return x*x; });
return res;
}
// [[Rcpp::export]]
LogicalVector runit_sapply_square( NumericVector xx){
return all( sapply( xx * xx , square<double>() ) < 10.0 );
}
// [[Rcpp::export]]
List runit_sapply_list( IntegerVector xx){
List res = sapply( xx, seq_len );
return res ;
}
// [[Rcpp::export]]
IntegerVector runit_seqalong( NumericVector xx ){
IntegerVector res = seq_along( xx );
return res ;
}
// [[Rcpp::export]]
IntegerVector runit_seqlen(){
IntegerVector res = seq_len( 10 );
return res ;
}
// [[Rcpp::export]]
List runit_sign( NumericVector xx, IntegerVector yy ){
return List::create(
sign( xx ),
sign( yy )
) ;
}
// [[Rcpp::export]]
List runit_times( IntegerVector xx ){
IntegerVector yy = clone<IntegerVector>( xx ) ;
yy[0] = NA_INTEGER ;
return List::create(
xx * 10,
10 * xx,
xx * xx,
xx * xx * xx,
xx * yy,
yy * 10,
10 * yy,
NA_INTEGER * xx
) ;
}
// [[Rcpp::export]]
List runit_divides( NumericVector xx ){
return List::create(
xx / 10,
10 / xx,
xx / xx
) ;
}
// [[Rcpp::export]]
NumericVector runit_unary_minus( NumericVector xx){
NumericVector yy = - xx ;
return yy ;
}
// [[Rcpp::export]]
void runit_wrap( NumericVector xx, NumericVector yy, Environment e ){
e["foo"] = xx < yy ;
}
// [[Rcpp::export]]
List runit_complex( ComplexVector cx ){
return List::create(
_["Re"] = Re( cx ),
_["Im"] = Im( cx ),
_["Conj"] = Conj( cx ),
_["Mod"] = Mod( cx ),
_["Arg"] = Arg( cx ),
_["exp"] = exp( cx ),
_["log"] = log( cx ),
_["sqrt"] = sqrt( cx ),
_["cos"] = cos( cx ),
_["sin"] = sin( cx ),
_["tan"] = tan( cx ),
_["acos"] = acos( cx ),
_["asin"] = asin( cx ),
_["atan"] = atan( cx ),
// _["acosh"] = acosh( cx ),
_["asinh"] = asinh( cx ),
_["atanh"] = atanh( cx ),
_["cosh"] = cosh( cx ),
_["sinh"] = sinh( cx ),
_["tanh"] = tanh( cx )
) ;
}
// [[Rcpp::export]]
List runit_rep( IntegerVector xx ){
List res = List::create(
_["rep"] = rep( xx, 3 ),
_["rep_each"] = rep_each( xx, 3 ),
_["rep_len"] = rep_len( xx, 12 ),
_["rep_prim_double"] = rep( 0.0, 10 )
) ;
return res ;
}
// [[Rcpp::export]]
IntegerVector runit_rev( IntegerVector xx ){
IntegerVector yy = rev( xx * xx );
return yy ;
}
// [[Rcpp::export]]
NumericMatrix runit_outer( NumericVector xx, NumericVector yy){
NumericMatrix m = outer( xx, yy, std::plus<double>() ) ;
return m ;
}
// [[Rcpp::export]]
NumericMatrix runit_outer_lambda(NumericVector xx, NumericVector yy){
NumericMatrix m = outer(xx, yy, [](double x, double y) { return x + y; });
return m ;
}
// [[Rcpp::export]]
List runit_row( NumericMatrix xx ){
return List::create(
_["row"] = row( xx ),
_["col"] = col( xx )
) ;
}
// [[Rcpp::export]]
List runit_head( NumericVector xx ){
return List::create(
_["pos"] = head( xx, 5 ),
_["neg"] = head( xx, -5 )
) ;
}
// [[Rcpp::export]]
List runit_tail( NumericVector xx ){
return List::create(
_["pos"] = tail( xx, 5 ),
_["neg"] = tail( xx, -5 )
) ;
}
// [[Rcpp::export]]
List runit_diag( NumericVector xx, NumericMatrix mm ){
return List::create(
diag( xx ) ,
diag( mm ),
diag( outer( xx, xx, std::plus<double>() ) )
) ;
}
// [[Rcpp::export]]
List runit_gamma( NumericVector xx ){
return List::create(
_["gamma"] = gamma(xx),
_["lgamma"] = lgamma(xx),
_["digamma"] = digamma(xx),
_["trigamma"] = trigamma(xx),
_["tetragamma"] = tetragamma(xx),
_["pentagamma"] = pentagamma(xx),
_["factorial"] = factorial(xx),
_["lfactorial"] = lfactorial(xx)
) ;
}
// [[Rcpp::export]]
List runit_choose( NumericVector nn, NumericVector kk ){
return List::create(
_["VV"] = choose(nn,kk),
_["PV"] = choose(10.0, kk ),
_["VP"] = choose(nn, 5.0 )
) ;
}
// [[Rcpp::export]]
List runit_lchoose( NumericVector nn, NumericVector kk){
return List::create(
_["VV"] = lchoose(nn,kk),
_["PV"] = lchoose(10.0, kk ),
_["VP"] = lchoose(nn, 5.0 )
) ;
}
// [[Rcpp::export]]
List runit_beta( NumericVector nn, NumericVector kk){
return List::create(
_["VV"] = beta(nn,kk),
_["PV"] = beta(10.0, kk ),
_["VP"] = beta(nn, 5.0 )
) ;
}
// [[Rcpp::export]]
List runit_psigamma( NumericVector nn, NumericVector kk){
return List::create(
_["VV"] = psigamma(nn,kk),
_["PV"] = psigamma(10.0, kk ),
_["VP"] = psigamma(nn, 5.0 )
) ;
}
// [[Rcpp::export]]
List runit_lbeta( NumericVector nn, NumericVector kk){
return List::create(
_["VV"] = lbeta(nn,kk),
_["PV"] = lbeta(10.0, kk ),
_["VP"] = lbeta(nn, 5.0 )
) ;
}
// [[Rcpp::export]]
List runit_log1p( NumericVector xx){
return List::create(
_["log1p"] = log1p(xx),
_["expm1"] = expm1(xx)
) ;
}
// [[Rcpp::export]]
double runit_sum( NumericVector xx){
return sum( xx ) ;
}
// [[Rcpp::export]]
NumericVector runit_cumsum( NumericVector xx ){
NumericVector res = cumsum( xx ) ;
return res ;
}
// [[Rcpp::export]]
List runit_asvector( NumericMatrix z, NumericVector x, NumericVector y){
return List::create(
as_vector( z ),
as_vector( outer( x , y , std::plus<double>() ) )
) ;
}
// [[Rcpp::export]]
NumericVector runit_diff_REALSXP_NA( NumericVector x ){
NumericVector res= diff(x) ;
return res ;
}
// [[Rcpp::export]]
List runit_trunc( NumericVector xx, IntegerVector yy){
return List::create(trunc(xx), trunc(yy)) ;
}
// [[Rcpp::export]]
NumericVector runit_round( NumericVector xx, int d ){
NumericVector res = round(xx, d);
return res ;
}
// [[Rcpp::export]]
NumericVector runit_signif( NumericVector xx, int d ){
NumericVector res = signif(xx, d);
return res ;
}
// [[Rcpp::export]]
double runit_RangeIndexer( NumericVector x ){
return max( x[ seq(0, 4) ] ) ;
}
// [[Rcpp::export]]
IntegerVector runit_self_match( CharacterVector x){
return self_match( x ) ;
}
// [[Rcpp::export]]
Rcpp::IntegerVector runit_unique_int(Rcpp::IntegerVector x) {
return Rcpp::unique(x);
}
// [[Rcpp::export]]
Rcpp::NumericVector runit_unique_dbl(Rcpp::NumericVector x) {
return Rcpp::unique(x);
}
// [[Rcpp::export]]
Rcpp::CharacterVector runit_unique_ch(Rcpp::CharacterVector x) {
return Rcpp::unique(x);
}
// [[Rcpp::export]]
Rcpp::CharacterVector runit_sort_unique_ch(Rcpp::CharacterVector x,
bool decreasing = false) {
return Rcpp::sort_unique(x, decreasing);
}
// [[Rcpp::export]]
IntegerVector runit_table( CharacterVector x){
return table( x ) ;
}
// [[Rcpp::export]]
LogicalVector runit_duplicated( CharacterVector x){
return duplicated( x ) ;
}
// [[Rcpp::export]]
IntegerVector runit_union( IntegerVector x, IntegerVector y){
return union_( x, y) ;
}
// [[Rcpp::export]]
IntegerVector runit_setdiff( IntegerVector x, IntegerVector y){
return setdiff( x, y) ;
}
// [[Rcpp::export]]
bool runit_setequal_integer(IntegerVector x, IntegerVector y) {
return setequal(x, y);
}
// [[Rcpp::export]]
bool runit_setequal_character(CharacterVector x, CharacterVector y) {
return setequal(x, y);
}
// [[Rcpp::export]]
IntegerVector runit_intersect( IntegerVector x, IntegerVector y){
return intersect( x, y ) ;
}
// [[Rcpp::export]]
NumericVector runit_clamp( double a, NumericVector x, double b){
return clamp( a, x, b ) ;
}
// [[Rcpp::export]]
List vector_scalar_ops( NumericVector xx ){
NumericVector y1 = xx + 2.0; // NB does not work with ints as eg "+ 2L"
NumericVector y2 = 2 - xx;
NumericVector y3 = xx * 2.0;
NumericVector y4 = 2.0 / xx;
return List::create(y1, y2, y3, y4);
}
// [[Rcpp::export]]
List vector_scalar_logical( NumericVector xx ){
LogicalVector y1 = xx < 2;
LogicalVector y2 = 2 > xx;
LogicalVector y3 = xx <= 2;
LogicalVector y4 = 2 != xx;
return List::create(y1, y2, y3, y4);
}
// [[Rcpp::export]]
List vector_vector_ops( NumericVector xx, NumericVector yy){
NumericVector y1 = xx + yy;
NumericVector y2 = yy - xx;
NumericVector y3 = xx * yy;
NumericVector y4 = yy / xx;
return List::create(y1, y2, y3, y4);
}
// [[Rcpp::export]]
List vector_vector_logical( NumericVector xx, NumericVector yy){
LogicalVector y1 = xx < yy;
LogicalVector y2 = xx > yy;
LogicalVector y3 = xx <= yy;
LogicalVector y4 = xx >= yy;
LogicalVector y5 = xx == yy;
LogicalVector y6 = xx != yy;
return List::create(y1, y2, y3, y4, y5, y6);
}
// Additions made 1 Jan 2015
// [[Rcpp::export]]
double meanInteger(Rcpp::IntegerVector x) { return Rcpp::mean(x); }
// [[Rcpp::export]]
double meanNumeric(Rcpp::NumericVector x) { return(Rcpp::mean(x)); }
// [[Rcpp::export]]
double meanLogical(Rcpp::LogicalVector x) { return(Rcpp::mean(x)); }
// [[Rcpp::export]]
Rcomplex meanComplex(Rcpp::ComplexVector x) { return(Rcpp::mean(x)); }
// 30 Oct 2015: cumprod, cummin, cummax
// [[Rcpp::export]]
NumericVector runit_cumprod_nv(NumericVector xx){
NumericVector res = cumprod(xx) ;
return res ;
}
// [[Rcpp::export]]
IntegerVector runit_cumprod_iv(IntegerVector xx){
IntegerVector res = cumprod(xx) ;
return res ;
}
// [[Rcpp::export]]
ComplexVector runit_cumprod_cv(ComplexVector xx){
ComplexVector res = cumprod(xx) ;
return res ;
}
// [[Rcpp::export]]
NumericVector runit_cummin_nv(NumericVector xx){
NumericVector res = cummin(xx) ;
return res ;
}
// [[Rcpp::export]]
IntegerVector runit_cummin_iv(IntegerVector xx){
IntegerVector res = cummin(xx) ;
return res ;
}
// [[Rcpp::export]]
NumericVector runit_cummax_nv(NumericVector xx){
NumericVector res = cummax(xx) ;
return res ;
}
// [[Rcpp::export]]
IntegerVector runit_cummax_iv(IntegerVector xx){
IntegerVector res = cummax(xx) ;
return res ;
}
// 18 January 2016: median
// [[Rcpp::export]]
double median_dbl(Rcpp::NumericVector x, bool na_rm = false) {
return Rcpp::median(x, na_rm);
}
// [[Rcpp::export]]
double median_int(Rcpp::IntegerVector x, bool na_rm = false) {
return Rcpp::median(x, na_rm);
}
// [[Rcpp::export]]
Rcomplex median_cx(Rcpp::ComplexVector x, bool na_rm = false) {
return Rcpp::median(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::String median_ch(Rcpp::CharacterVector x, bool na_rm = false) {
return Rcpp::median(x, na_rm);
}
// 12 March 2016: cbind
// A. Numeric*
// [[Rcpp::export]]
Rcpp::NumericMatrix n_cbind_mm(Rcpp::NumericMatrix m1, Rcpp::NumericMatrix m2) {
return Rcpp::cbind(m1, m2);
}
// [[Rcpp::export]]
Rcpp::NumericMatrix n_cbind_mv(Rcpp::NumericMatrix m1, Rcpp::NumericVector v1) {
return Rcpp::cbind(m1, v1);
}
// [[Rcpp::export]]
Rcpp::NumericMatrix n_cbind_ms(Rcpp::NumericMatrix m1, double s1) {
return Rcpp::cbind(m1, s1);
}
// [[Rcpp::export]]
Rcpp::NumericMatrix n_cbind_vv(Rcpp::NumericVector v1, Rcpp::NumericVector v2) {
return Rcpp::cbind(v1, v2);
}
// [[Rcpp::export]]
Rcpp::NumericMatrix n_cbind_vm(Rcpp::NumericVector v1, Rcpp::NumericMatrix m1) {
return Rcpp::cbind(v1, m1);
}
// [[Rcpp::export]]
Rcpp::NumericMatrix n_cbind_vs(Rcpp::NumericVector v1, double s1) {
return Rcpp::cbind(v1, s1);
}
// [[Rcpp::export]]
Rcpp::NumericMatrix n_cbind_sm(double s1, Rcpp::NumericMatrix m1) {
return Rcpp::cbind(s1, m1);
}
// [[Rcpp::export]]
Rcpp::NumericMatrix n_cbind_sv(double s1, Rcpp::NumericVector v1) {
return Rcpp::cbind(s1, v1);
}
// [[Rcpp::export]]
Rcpp::NumericMatrix n_cbind_ss(double s1, double s2) {
return Rcpp::cbind(s1, s2);
}
// [[Rcpp::export]]
Rcpp::NumericMatrix
n_cbind9(Rcpp::NumericMatrix m1, Rcpp::NumericVector v1, double s1,
Rcpp::NumericMatrix m2, Rcpp::NumericVector v2, double s2,
Rcpp::NumericMatrix m3, Rcpp::NumericVector v3, double s3) {
return Rcpp::cbind(m1, v1, s1, m2, v2, s2, m3, v3, s3);
}
// B. Integer*
// [[Rcpp::export]]
Rcpp::IntegerMatrix
i_cbind_mm(Rcpp::IntegerMatrix m1, Rcpp::IntegerMatrix m2) {
return Rcpp::cbind(m1, m2);
}
// [[Rcpp::export]]
Rcpp::IntegerMatrix
i_cbind_mv(Rcpp::IntegerMatrix m1, Rcpp::IntegerVector v1) {
return Rcpp::cbind(m1, v1);
}
// [[Rcpp::export]]
Rcpp::IntegerMatrix
i_cbind_ms(Rcpp::IntegerMatrix m1, int s1) {
return Rcpp::cbind(m1, s1);
}
// [[Rcpp::export]]
Rcpp::IntegerMatrix
i_cbind_vv(Rcpp::IntegerVector v1, Rcpp::IntegerVector v2) {
return Rcpp::cbind(v1, v2);
}
// [[Rcpp::export]]
Rcpp::IntegerMatrix
i_cbind_vm(Rcpp::IntegerVector v1, Rcpp::IntegerMatrix m1) {
return Rcpp::cbind(v1, m1);
}
// [[Rcpp::export]]
Rcpp::IntegerMatrix
i_cbind_vs(Rcpp::IntegerVector v1, int s1) {
return Rcpp::cbind(v1, s1);
}
// [[Rcpp::export]]
Rcpp::IntegerMatrix
i_cbind_sm(int s1, Rcpp::IntegerMatrix m1) {
return Rcpp::cbind(s1, m1);
}
// [[Rcpp::export]]
Rcpp::IntegerMatrix
i_cbind_sv(int s1, Rcpp::IntegerVector v1) {
return Rcpp::cbind(s1, v1);
}
// [[Rcpp::export]]
Rcpp::IntegerMatrix
i_cbind_ss(int s1, int s2) {
return Rcpp::cbind(s1, s2);
}
// [[Rcpp::export]]
Rcpp::IntegerMatrix
i_cbind9(Rcpp::IntegerMatrix m1, Rcpp::IntegerVector v1, int s1,
Rcpp::IntegerMatrix m2, Rcpp::IntegerVector v2, int s2,
Rcpp::IntegerMatrix m3, Rcpp::IntegerVector v3, int s3) {
return Rcpp::cbind(m1, v1, s1, m2, v2, s2, m3, v3, s3);
}
// C. Complex*
// [[Rcpp::export]]
Rcpp::ComplexMatrix
cx_cbind_mm(Rcpp::ComplexMatrix m1, Rcpp::ComplexMatrix m2) {
return Rcpp::cbind(m1, m2);
}
// [[Rcpp::export]]
Rcpp::ComplexMatrix
cx_cbind_mv(Rcpp::ComplexMatrix m1, Rcpp::ComplexVector v1) {
return Rcpp::cbind(m1, v1);
}
// [[Rcpp::export]]
Rcpp::ComplexMatrix
cx_cbind_ms(Rcpp::ComplexMatrix m1, Rcomplex s1) {
return Rcpp::cbind(m1, s1);
}
// [[Rcpp::export]]
Rcpp::ComplexMatrix
cx_cbind_vv(Rcpp::ComplexVector v1, Rcpp::ComplexVector v2) {
return Rcpp::cbind(v1, v2);
}
// [[Rcpp::export]]
Rcpp::ComplexMatrix
cx_cbind_vm(Rcpp::ComplexVector v1, Rcpp::ComplexMatrix m1) {
return Rcpp::cbind(v1, m1);
}
// [[Rcpp::export]]
Rcpp::ComplexMatrix
cx_cbind_vs(Rcpp::ComplexVector v1, Rcomplex s1) {
return Rcpp::cbind(v1, s1);
}
// [[Rcpp::export]]
Rcpp::ComplexMatrix
cx_cbind_sm(Rcomplex s1, Rcpp::ComplexMatrix m1) {
return Rcpp::cbind(s1, m1);
}
// [[Rcpp::export]]
Rcpp::ComplexMatrix
cx_cbind_sv(Rcomplex s1, Rcpp::ComplexVector v1) {
return Rcpp::cbind(s1, v1);
}
// [[Rcpp::export]]
Rcpp::ComplexMatrix
cx_cbind_ss(Rcomplex s1, Rcomplex s2) {
return Rcpp::cbind(s1, s2);
}
// [[Rcpp::export]]
Rcpp::ComplexMatrix
cx_cbind9(Rcpp::ComplexMatrix m1, Rcpp::ComplexVector v1, Rcomplex s1,
Rcpp::ComplexMatrix m2, Rcpp::ComplexVector v2, Rcomplex s2,
Rcpp::ComplexMatrix m3, Rcpp::ComplexVector v3, Rcomplex s3) {
return Rcpp::cbind(m1, v1, s1, m2, v2, s2, m3, v3, s3);
}
// D. Logical*
// [[Rcpp::export]]
Rcpp::LogicalMatrix
l_cbind_mm(Rcpp::LogicalMatrix m1, Rcpp::LogicalMatrix m2) {
return Rcpp::cbind(m1, m2);
}
// [[Rcpp::export]]
Rcpp::LogicalMatrix
l_cbind_mv(Rcpp::LogicalMatrix m1, Rcpp::LogicalVector v1) {
return Rcpp::cbind(m1, v1);
}
// [[Rcpp::export]]
Rcpp::LogicalMatrix
l_cbind_ms(Rcpp::LogicalMatrix m1, bool s1) {
return Rcpp::cbind(m1, s1);
}
// [[Rcpp::export]]
Rcpp::LogicalMatrix
l_cbind_vv(Rcpp::LogicalVector v1, Rcpp::LogicalVector v2) {
return Rcpp::cbind(v1, v2);
}
// [[Rcpp::export]]
Rcpp::LogicalMatrix
l_cbind_vm(Rcpp::LogicalVector v1, Rcpp::LogicalMatrix m1) {
return Rcpp::cbind(v1, m1);
}
// [[Rcpp::export]]
Rcpp::LogicalMatrix
l_cbind_vs(Rcpp::LogicalVector v1, bool s1) {
return Rcpp::cbind(v1, s1);
}
// [[Rcpp::export]]
Rcpp::LogicalMatrix
l_cbind_sm(bool s1, Rcpp::LogicalMatrix m1) {
return Rcpp::cbind(s1, m1);
}
// [[Rcpp::export]]
Rcpp::LogicalMatrix
l_cbind_sv(bool s1, Rcpp::LogicalVector v1) {
return Rcpp::cbind(s1, v1);
}
// [[Rcpp::export]]
Rcpp::LogicalMatrix
l_cbind_ss(bool s1, bool s2) {
return Rcpp::cbind(s1, s2);
}
// [[Rcpp::export]]
Rcpp::LogicalMatrix
l_cbind9(Rcpp::LogicalMatrix m1, Rcpp::LogicalVector v1, bool s1,
Rcpp::LogicalMatrix m2, Rcpp::LogicalVector v2, bool s2,
Rcpp::LogicalMatrix m3, Rcpp::LogicalVector v3, bool s3) {
return Rcpp::cbind(m1, v1, s1, m2, v2, s2, m3, v3, s3);
}
// E. Character*
// [[Rcpp::export]]
Rcpp::CharacterMatrix
c_cbind_mm(Rcpp::CharacterMatrix m1, Rcpp::CharacterMatrix m2) {
return Rcpp::cbind(m1, m2);
}
// [[Rcpp::export]]
Rcpp::CharacterMatrix
c_cbind_mv(Rcpp::CharacterMatrix m1, Rcpp::CharacterVector v1) {
return Rcpp::cbind(m1, v1);
}
// [[Rcpp::export]]
Rcpp::CharacterMatrix
c_cbind_vv(Rcpp::CharacterVector v1, Rcpp::CharacterVector v2) {
return Rcpp::cbind(v1, v2);
}
// [[Rcpp::export]]
Rcpp::CharacterMatrix
c_cbind_vm(Rcpp::CharacterVector v1, Rcpp::CharacterMatrix m1) {
return Rcpp::cbind(v1, m1);
}
// [[Rcpp::export]]
Rcpp::CharacterMatrix
c_cbind6(Rcpp::CharacterMatrix m1, Rcpp::CharacterVector v1,
Rcpp::CharacterMatrix m2, Rcpp::CharacterVector v2,
Rcpp::CharacterMatrix m3, Rcpp::CharacterVector v3) {
return Rcpp::cbind(m1, v1, m2, v2, m3, v3);
}
// 04 September 2016: rowSums, colSums, rowMeans, colMeans
// [[Rcpp::export]]
Rcpp::NumericVector dbl_row_sums(Rcpp::NumericMatrix x, bool na_rm = false) {
return rowSums(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::IntegerVector int_row_sums(Rcpp::IntegerMatrix x, bool na_rm = false) {
return rowSums(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::IntegerVector lgl_row_sums(Rcpp::LogicalMatrix x, bool na_rm = false) {
return rowSums(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::ComplexVector cx_row_sums(Rcpp::ComplexMatrix x, bool na_rm = false) {
return rowSums(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::NumericVector dbl_col_sums(Rcpp::NumericMatrix x, bool na_rm = false) {
return colSums(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::IntegerVector int_col_sums(Rcpp::IntegerMatrix x, bool na_rm = false) {
return colSums(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::IntegerVector lgl_col_sums(Rcpp::LogicalMatrix x, bool na_rm = false) {
return colSums(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::ComplexVector cx_col_sums(Rcpp::ComplexMatrix x, bool na_rm = false) {
return colSums(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::NumericVector dbl_row_means(Rcpp::NumericMatrix x, bool na_rm = false) {
return rowMeans(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::NumericVector int_row_means(Rcpp::IntegerMatrix x, bool na_rm = false) {
return rowMeans(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::NumericVector lgl_row_means(Rcpp::LogicalMatrix x, bool na_rm = false) {
return rowMeans(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::ComplexVector cx_row_means(Rcpp::ComplexMatrix x, bool na_rm = false) {
return rowMeans(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::NumericVector dbl_col_means(Rcpp::NumericMatrix x, bool na_rm = false) {
return colMeans(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::NumericVector int_col_means(Rcpp::IntegerMatrix x, bool na_rm = false) {
return colMeans(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::NumericVector lgl_col_means(Rcpp::LogicalMatrix x, bool na_rm = false) {
return colMeans(x, na_rm);
}
// [[Rcpp::export]]
Rcpp::ComplexVector cx_col_means(Rcpp::ComplexMatrix x, bool na_rm = false) {
return colMeans(x, na_rm);
}
// 10 December 2016: sample
// [[Rcpp::export]]
IntegerVector sample_dot_int(int n, int sz, bool rep = false, sugar::probs_t p = R_NilValue, bool one_based = true)
{
return sample(n, sz, rep, p, one_based);
}
// [[Rcpp::export]]
IntegerVector sample_int(IntegerVector x, int sz, bool rep = false, sugar::probs_t p = R_NilValue)
{
return sample(x, sz, rep, p);
}
// [[Rcpp::export]]
NumericVector sample_dbl(NumericVector x, int sz, bool rep = false, sugar::probs_t p = R_NilValue)
{
return sample(x, sz, rep, p);
}
// [[Rcpp::export]]
CharacterVector sample_chr(CharacterVector x, int sz, bool rep = false, sugar::probs_t p = R_NilValue)
{
return sample(x, sz, rep, p);
}
// [[Rcpp::export]]
ComplexVector sample_cx(ComplexVector x, int sz, bool rep = false, sugar::probs_t p = R_NilValue)
{
return sample(x, sz, rep, p);
}
// [[Rcpp::export]]
LogicalVector sample_lgl(LogicalVector x, int sz, bool rep = false, sugar::probs_t p = R_NilValue)
{
return sample(x, sz, rep, p);
}
// [[Rcpp::export]]
List sample_list(List x, int sz, bool rep = false, sugar::probs_t p = R_NilValue)
{
return sample(x, sz, rep, p);
}
// 31 January 2017: upper_tri, lower_tri
// [[Rcpp::export]]
LogicalMatrix UpperTri(NumericMatrix x, bool diag = false) {
return upper_tri(x, diag);
}
// [[Rcpp::export]]
LogicalMatrix LowerTri(NumericMatrix x, bool diag = false) {
return lower_tri(x, diag);
}
// 22 April 2017: trimws
// [[Rcpp::export]]
CharacterVector vtrimws(CharacterVector x, const char* which = "both") {
return trimws(x, which);
}
// [[Rcpp::export]]
CharacterMatrix mtrimws(CharacterMatrix x, const char* which = "both") {
return trimws(x, which);
}
// [[Rcpp::export]]
String strimws(String x, const char* which = "both") {
return trimws(x, which);
}
// 21 Jul 2018 min/max tests for int and double
// [[Rcpp::export]]
int intmin(IntegerVector v) {
return min(v);
}
// [[Rcpp::export]]
int intmax(IntegerVector v) {
return max(v);
}
// [[Rcpp::export]]
double doublemin(NumericVector v) {
return min(v);
}
// [[Rcpp::export]]
double doublemax(NumericVector v) {
return max(v);
}
|