Rcpp Version 1.0.14
Loading...
Searching...
No Matches
mapply_2.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// mapply_2.h: Rcpp R/C++ interface class library -- mapply_2
4//
5// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
6//
7// This file is part of Rcpp.
8//
9// Rcpp is free software: you can redistribute it and/or modify it
10// under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 2 of the License, or
12// (at your option) any later version.
13//
14// Rcpp is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21
22#ifndef Rcpp__sugar__mapply_2_h
23#define Rcpp__sugar__mapply_2_h
24
25namespace Rcpp{
26namespace sugar{
27
28template <int RTYPE,
29 bool NA_1, typename T_1,
30 bool NA_2, typename T_2,
31 typename Function
32>
33class Mapply_2 : public VectorBase<
34 Rcpp::traits::r_sexptype_traits<
35 typename ::Rcpp::traits::result_of<Function>::type
36 >::rtype ,
37 true ,
38 Mapply_2<RTYPE,NA_1,T_1,NA_2,T_2,Function>
39> {
40public:
41 typedef typename ::Rcpp::traits::result_of<Function>::type result_type ;
42
45
46 inline result_type operator[]( R_xlen_t i ) const {
47 return fun( vec_1[i], vec_2[i] );
48 }
49 inline R_xlen_t size() const { return vec_1.size() ; }
50
51private:
52 const T_1& vec_1 ;
53 const T_2& vec_2 ;
55} ;
56
57template <int RTYPE,
58 bool NA_1, typename T_1,
59 typename PRIM_2 ,
60 typename Function
61>
64 Rcpp::traits::r_sexptype_traits<
65 typename ::Rcpp::traits::result_of<Function>::type
66 >::rtype ,
67 true ,
68 Mapply_2_Vector_Primitive<RTYPE,NA_1,T_1,PRIM_2,Function>
69 >
70{
71public:
72 typedef typename ::Rcpp::traits::result_of<Function>::type result_type ;
73
76
77 inline result_type operator[]( R_xlen_t i ) const {
78 return fun( vec_1[i], prim_2 );
79 }
80 inline R_xlen_t size() const { return vec_1.size() ; }
81
82private:
83 const T_1& vec_1 ;
86} ;
87
88template <int RTYPE,
89 typename PRIM_1,
90 bool NA_2, typename T_2,
91 typename Function
92>
95 Rcpp::traits::r_sexptype_traits<
96 typename ::Rcpp::traits::result_of<Function>::type
97 >::rtype ,
98 true ,
99 Mapply_2_Primitive_Vector<RTYPE,PRIM_1,NA_2,T_2,Function>
100 >
101{
102public:
103 typedef typename ::Rcpp::traits::result_of<Function>::type result_type ;
104
107
108 inline result_type operator[]( R_xlen_t i ) const {
109 return fun( prim_1, vec_2[i] );
110 }
111 inline R_xlen_t size() const { return vec_2.size() ; }
112
113private:
115 const T_2& vec_2 ;
117} ;
118
119
120
121} // sugar
122
123
124template <int RTYPE, bool NA_1, typename T_1, bool NA_2, typename T_2, typename Function >
129
130template <int RTYPE, bool NA_1, typename T_1, typename Function >
131inline sugar::Mapply_2_Vector_Primitive<RTYPE,NA_1,T_1,double,Function>
135
136template <int RTYPE, bool NA_2, typename T_2, typename Function >
137inline sugar::Mapply_2_Primitive_Vector<RTYPE,double, NA_2,T_2,Function>
141
142
143
144} // Rcpp
145
146#endif
result_type operator[](R_xlen_t i) const
Definition mapply_2.h:108
Mapply_2_Primitive_Vector(PRIM_1 prim_1_, const T_2 &vec_2_, Function fun_)
Definition mapply_2.h:105
::Rcpp::traits::result_of< Function >::type result_type
Definition mapply_2.h:103
result_type operator[](R_xlen_t i) const
Definition mapply_2.h:77
Mapply_2_Vector_Primitive(const T_1 &vec_1_, PRIM_2 prim_2_, Function fun_)
Definition mapply_2.h:74
::Rcpp::traits::result_of< Function >::type result_type
Definition mapply_2.h:72
::Rcpp::traits::result_of< Function >::type result_type
Definition mapply_2.h:41
const T_1 & vec_1
Definition mapply_2.h:52
result_type operator[](R_xlen_t i) const
Definition mapply_2.h:46
R_xlen_t size() const
Definition mapply_2.h:49
const T_2 & vec_2
Definition mapply_2.h:53
Mapply_2(const T_1 &vec_1_, const T_2 &vec_2_, Function fun_)
Definition mapply_2.h:43
Rcpp API.
Definition algo.h:28
Function_Impl< PreserveStorage > Function
Definition Function.h:131
sugar::Mapply_2< RTYPE, NA_1, T_1, NA_2, T_2, Function > mapply(const Rcpp::VectorBase< RTYPE, NA_1, T_1 > &t1, const Rcpp::VectorBase< RTYPE, NA_2, T_2 > &t2, Function fun)
Definition mapply_2.h:126
T as(SEXP x)
Definition as.h:151