Rcpp Version 1.1.2
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 - 2024 Dirk Eddelbuettel and Romain Francois
6// Copyright (C) 2025 Dirk Eddelbuettel, Romain Francois and IƱaki Ucar
7//
8// This file is part of Rcpp.
9//
10// Rcpp is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 2 of the License, or
13// (at your option) any later version.
14//
15// Rcpp is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
22
23#ifndef Rcpp__sugar__mapply_2_h
24#define Rcpp__sugar__mapply_2_h
25
26namespace Rcpp{
27namespace sugar{
28
29template <int RTYPE,
30 bool NA_1, typename T_1,
31 bool NA_2, typename T_2,
32 typename Function
33>
34class Mapply_2 : public VectorBase<
35 Rcpp::traits::r_sexptype_traits<
36 typename ::Rcpp::traits::result_of<Function, T_1, T_2>::type
37 >::rtype ,
38 true ,
39 Mapply_2<RTYPE,NA_1,T_1,NA_2,T_2,Function>
40> {
41public:
42 typedef typename ::Rcpp::traits::result_of<Function, T_1, T_2>::type result_type ;
43
44 Mapply_2( const T_1& vec_1_, const T_2& vec_2_, Function fun_ ) :
45 vec_1(vec_1_), vec_2(vec_2_), fun(fun_){}
46
47 inline result_type operator[]( R_xlen_t i ) const {
48 return fun( vec_1[i], vec_2[i] );
49 }
50 inline R_xlen_t size() const { return vec_1.size() ; }
51
52private:
53 const T_1& vec_1 ;
54 const T_2& vec_2 ;
56} ;
57
58template <int RTYPE,
59 bool NA_1, typename T_1,
60 typename PRIM_2 ,
61 typename Function
62>
65 Rcpp::traits::r_sexptype_traits<
66 typename ::Rcpp::traits::result_of<Function, T_1>::type
67 >::rtype ,
68 true ,
69 Mapply_2_Vector_Primitive<RTYPE,NA_1,T_1,PRIM_2,Function>
70 >
71{
72public:
73 typedef typename ::Rcpp::traits::result_of<Function, T_1>::type result_type ;
74
75 Mapply_2_Vector_Primitive( const T_1& vec_1_, PRIM_2 prim_2_, Function fun_ ) :
76 vec_1(vec_1_), prim_2(prim_2_), fun(fun_){}
77
78 inline result_type operator[]( R_xlen_t i ) const {
79 return fun( vec_1[i], prim_2 );
80 }
81 inline R_xlen_t size() const { return vec_1.size() ; }
82
83private:
84 const T_1& vec_1 ;
85 PRIM_2 prim_2 ;
87} ;
88
89template <int RTYPE,
90 typename PRIM_1,
91 bool NA_2, typename T_2,
92 typename Function
93>
96 Rcpp::traits::r_sexptype_traits<
97 typename ::Rcpp::traits::result_of<Function, T_2>::type
98 >::rtype ,
99 true ,
100 Mapply_2_Primitive_Vector<RTYPE,PRIM_1,NA_2,T_2,Function>
101 >
102{
103public:
104 typedef typename ::Rcpp::traits::result_of<Function, T_2>::type result_type ;
105
106 Mapply_2_Primitive_Vector( PRIM_1 prim_1_, const T_2& vec_2_, Function fun_ ) :
107 prim_1(prim_1_), vec_2(vec_2_), fun(fun_){}
108
109 inline result_type operator[]( R_xlen_t i ) const {
110 return fun( prim_1, vec_2[i] );
111 }
112 inline R_xlen_t size() const { return vec_2.size() ; }
113
114private:
115 PRIM_1 prim_1 ;
116 const T_2& vec_2 ;
118} ;
119
120
121
122} // sugar
123
124
125template <int RTYPE, bool NA_1, typename T_1, bool NA_2, typename T_2, typename Function >
130
131template <int RTYPE, bool NA_1, typename T_1, typename Function >
132inline sugar::Mapply_2_Vector_Primitive<RTYPE,NA_1,T_1,double,Function>
136
137template <int RTYPE, bool NA_2, typename T_2, typename Function >
138inline sugar::Mapply_2_Primitive_Vector<RTYPE,double, NA_2,T_2,Function>
142
143
144
145} // Rcpp
146
147#endif
VECTOR & get_ref()
Definition VectorBase.h:37
result_type operator[](R_xlen_t i) const
Definition mapply_2.h:109
Mapply_2_Primitive_Vector(PRIM_1 prim_1_, const T_2 &vec_2_, Function fun_)
Definition mapply_2.h:106
::Rcpp::traits::result_of< Function, T_2 >::type result_type
Definition mapply_2.h:104
result_type operator[](R_xlen_t i) const
Definition mapply_2.h:78
::Rcpp::traits::result_of< Function, T_1 >::type result_type
Definition mapply_2.h:73
Mapply_2_Vector_Primitive(const T_1 &vec_1_, PRIM_2 prim_2_, Function fun_)
Definition mapply_2.h:75
::Rcpp::traits::result_of< Function, T_1, T_2 >::type result_type
Definition mapply_2.h:42
const T_1 & vec_1
Definition mapply_2.h:53
result_type operator[](R_xlen_t i) const
Definition mapply_2.h:47
R_xlen_t size() const
Definition mapply_2.h:50
const T_2 & vec_2
Definition mapply_2.h:54
Mapply_2(const T_1 &vec_1_, const T_2 &vec_2_, Function fun_)
Definition mapply_2.h:44
Rcpp API.
Definition algo.h:28
Function_Impl< PreserveStorage > Function
Definition Function.h:144
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:127