-
-
Notifications
You must be signed in to change notification settings - Fork 209
/
sugar.cpp
1221 lines (1004 loc) · 28 KB
/
sugar.cpp
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
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
//
// sugar.cpp: Rcpp R/C++ interface class library -- sugar unit tests
//
// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
//
// 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::unary_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( IntegerVector xx){
List res = lapply( xx, seq_len );
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]]
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]]
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]]
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]]