Rcpp Version 1.0.14
Loading...
Searching...
No Matches
divides.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// divides.h: Rcpp R/C++ interface class library -- operator-
4//
5// Copyright (C) 2010 - 2011 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__divides_h
23#define Rcpp__sugar__divides_h
24
25namespace Rcpp{
26namespace sugar{
27
28 template <int RTYPE, bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T >
29 class Divides_Vector_Vector : public Rcpp::VectorBase<RTYPE,true, Divides_Vector_Vector<RTYPE,LHS_NA,LHS_T,RHS_NA,RHS_T> > {
30 public:
36
39
40 inline STORAGE operator[]( R_xlen_t i ) const {
41 STORAGE x = lhs[i] ;
42 if( Rcpp::traits::is_na<RTYPE>( x ) ) return x ;
43 STORAGE y = rhs[i] ;
44 return Rcpp::traits::is_na<RTYPE>( y ) ? y : ( x / y ) ;
45 }
46
47 inline R_xlen_t size() const { return lhs.size() ; }
48
49 private:
50 const LHS_EXT& lhs ;
51 const RHS_EXT& rhs ;
52 } ;
53 // RTYPE = REALSXP
54 template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T >
56 public Rcpp::VectorBase<REALSXP,true, Divides_Vector_Vector<REALSXP,LHS_NA,LHS_T,RHS_NA,RHS_T> > {
57 public:
62
65
66 inline double operator[]( R_xlen_t i ) const {
67 return lhs[i] / rhs[i] ;
68 }
69
70 inline R_xlen_t size() const { return lhs.size() ; }
71
72 private:
73 const LHS_EXT& lhs ;
74 const RHS_EXT& rhs ;
75 } ;
76
77
78 template <int RTYPE, typename LHS_T, bool RHS_NA, typename RHS_T >
79 class Divides_Vector_Vector<RTYPE,false,LHS_T,RHS_NA,RHS_T> : public Rcpp::VectorBase<RTYPE,true, Divides_Vector_Vector<RTYPE,false,LHS_T,RHS_NA,RHS_T> > {
80 public:
86
89
90 inline STORAGE operator[]( R_xlen_t i ) const {
91 STORAGE y = rhs[i] ;
92 if( Rcpp::traits::is_na<RTYPE>( y ) ) return y ;
93 return lhs[i] / y ;
94 }
95
96 inline R_xlen_t size() const { return lhs.size() ; }
97
98 private:
99 const LHS_EXT& lhs ;
100 const RHS_EXT& rhs ;
101 } ;
102 // RTYPE = REALSXP
103 template <typename LHS_T, bool RHS_NA, typename RHS_T >
105 public Rcpp::VectorBase<REALSXP,true, Divides_Vector_Vector<REALSXP,false,LHS_T,RHS_NA,RHS_T> > {
106 public:
111
114
115 inline double operator[]( R_xlen_t i ) const {
116 return lhs[i] / rhs[i] ;
117 }
118
119 inline R_xlen_t size() const { return lhs.size() ; }
120
121 private:
122 const LHS_EXT& lhs ;
123 const RHS_EXT& rhs ;
124 } ;
125
126
127 template <int RTYPE, bool LHS_NA, typename LHS_T, typename RHS_T >
129 public Rcpp::VectorBase<RTYPE,true, Divides_Vector_Vector<RTYPE,LHS_NA,LHS_T,false,RHS_T> > {
130 public:
136
139
140 inline STORAGE operator[]( R_xlen_t i ) const {
141 STORAGE x = lhs[i] ;
142 if( Rcpp::traits::is_na<RTYPE>( x ) ) return x ;
143 return x / rhs[i] ;
144 }
145 inline R_xlen_t size() const { return lhs.size() ; }
146
147 private:
148 const LHS_EXT& lhs ;
149 const RHS_EXT& rhs ;
150 } ;
151 // RTYPE = REALSXP
152 template <bool LHS_NA, typename LHS_T, typename RHS_T >
154 public Rcpp::VectorBase<REALSXP,true, Divides_Vector_Vector<REALSXP,LHS_NA,LHS_T,false,RHS_T> > {
155 public:
160
163
164 inline double operator[]( R_xlen_t i ) const {
165 return lhs[i] / rhs[i] ;
166 }
167 inline R_xlen_t size() const { return lhs.size() ; }
168
169 private:
170 const LHS_EXT& lhs ;
171 const RHS_EXT& rhs ;
172 } ;
173
174
175 template <int RTYPE, typename LHS_T, typename RHS_T >
177 public Rcpp::VectorBase<RTYPE,false, Divides_Vector_Vector<RTYPE,false,LHS_T,false,RHS_T> > {
178 public:
184
187
188 inline STORAGE operator[]( R_xlen_t i ) const {
189 return lhs[i] / rhs[i] ;
190 }
191
192 inline R_xlen_t size() const { return lhs.size() ; }
193
194 private:
195 const LHS_EXT& lhs ;
196 const RHS_EXT& rhs ;
197 } ;
198 // RTYPE : REALSXP
199 template <typename LHS_T, typename RHS_T >
201 public Rcpp::VectorBase<REALSXP,false, Divides_Vector_Vector<REALSXP,false,LHS_T,false,RHS_T> > {
202 public:
207
210
211 inline double operator[]( R_xlen_t i ) const {
212 return lhs[i] / rhs[i] ;
213 }
214
215 inline R_xlen_t size() const { return lhs.size() ; }
216
217 private:
218 const LHS_EXT& lhs ;
219 const RHS_EXT& rhs ;
220 } ;
221
222
223
224
225 template <int RTYPE, bool NA, typename T>
227 public Rcpp::VectorBase<RTYPE,true, Divides_Vector_Primitive<RTYPE,NA,T> > {
228 public:
232
234 lhs(lhs_.get_ref()), rhs(rhs_), rhs_na( Rcpp::traits::is_na<RTYPE>(rhs_) ) {
235 }
236
237 inline STORAGE operator[]( R_xlen_t i ) const {
238 if(rhs_na) return rhs ;
239 STORAGE x = lhs[i] ;
240 return Rcpp::traits::is_na<RTYPE>(x) ? x : (x / rhs) ;
241 }
242
243 inline R_xlen_t size() const { return lhs.size() ; }
244
245 private:
246 const VEC_EXT& lhs ;
248 bool rhs_na ;
249 } ;
250 // RTYPE : REALSXP
251 template <bool NA, typename T>
253 public Rcpp::VectorBase<REALSXP,true, Divides_Vector_Primitive<REALSXP,NA,T> > {
254 public:
257
259 lhs(lhs_.get_ref()), rhs(rhs_) {
260 }
261
262 inline double operator[]( R_xlen_t i ) const {
263 return lhs[i] / rhs ;
264 }
265
266 inline R_xlen_t size() const { return lhs.size() ; }
267
268 private:
269 const VEC_EXT& lhs ;
270 double rhs ;
271 } ;
272
273
274
275 template <int RTYPE, typename T>
277 public Rcpp::VectorBase<RTYPE,true, Divides_Vector_Primitive<RTYPE,false,T> > {
278 public:
282
284 lhs(lhs_.get_ref()), rhs(rhs_), rhs_na( Rcpp::traits::is_na<RTYPE>(rhs_) ) {}
285
286 inline STORAGE operator[]( R_xlen_t i ) const {
287 if( rhs_na ) return rhs ;
288 STORAGE x = lhs[i] ;
289 return Rcpp::traits::is_na<RTYPE>(x) ? x : (x / rhs) ;
290 }
291 inline R_xlen_t size() const { return lhs.size() ; }
292
293 private:
294 const VEC_EXT& lhs ;
296 bool rhs_na ;
297 } ;
298 // RTYPE = REALSXP
299 template <typename T>
301 public Rcpp::VectorBase<REALSXP,true, Divides_Vector_Primitive<REALSXP,false,T> > {
302 public:
305
308
309 inline double operator[]( R_xlen_t i ) const {
310 return lhs[i] / rhs ;
311 }
312 inline R_xlen_t size() const { return lhs.size() ; }
313
314 private:
315 const VEC_EXT& lhs ;
316 double rhs ;
317 } ;
318
319
320
321 template <int RTYPE, bool NA, typename T>
323 public Rcpp::VectorBase<RTYPE,true, Divides_Primitive_Vector<RTYPE,NA,T> > {
324 public:
328
330 lhs(lhs_), rhs(rhs_.get_ref()), lhs_na( Rcpp::traits::is_na<RTYPE>(lhs_) ) {}
331
332 inline STORAGE operator[]( R_xlen_t i ) const {
333 if( lhs_na ) return lhs ;
334 STORAGE x = rhs[i] ;
335 return Rcpp::traits::is_na<RTYPE>(x) ? x : (lhs / x) ;
336 }
337 inline R_xlen_t size() const { return rhs.size() ; }
338 private:
340 const VEC_EXT& rhs ;
341 bool lhs_na ;
342 } ;
343 // RTYPE = REALSXP
344 template <bool NA, typename T>
346 public Rcpp::VectorBase<REALSXP,true, Divides_Primitive_Vector<REALSXP,NA,T> > {
347 public:
350
353
354 inline double operator[]( R_xlen_t i ) const {
355 return lhs / rhs[i] ;
356 }
357 inline R_xlen_t size() const { return rhs.size() ; }
358 private:
359 double lhs ;
360 const VEC_EXT& rhs ;
361 } ;
362
363
364
365 template <int RTYPE, typename T>
367 public Rcpp::VectorBase<RTYPE,true, Divides_Primitive_Vector<RTYPE,false,T> > {
368 public:
372
374 lhs(lhs_), rhs(rhs_.get_ref()), lhs_na( Rcpp::traits::is_na<RTYPE>(lhs_) ) {}
375
376 inline STORAGE operator[]( R_xlen_t i ) const {
377 if( lhs_na ) return lhs ;
378 return lhs / rhs[i] ;
379 }
380 inline R_xlen_t size() const { return rhs.size() ; }
381
382 private:
384 const VEC_EXT& rhs ;
385 bool lhs_na ;
386 } ;
387 // RTYPE = REALSXP
388 template <typename T>
390 public Rcpp::VectorBase<REALSXP,true, Divides_Primitive_Vector<REALSXP,false,T> > {
391 public:
394
397
398 inline double operator[]( R_xlen_t i ) const {
399 return lhs / rhs[i] ;
400 }
401 inline R_xlen_t size() const { return rhs.size() ; }
402
403 private:
404 double lhs ;
405 const VEC_EXT& rhs ;
406 } ;
407
408
409}
410
411template <int RTYPE,bool NA, typename T, typename U>
414 const VectorBase<RTYPE,NA,T>& lhs,
415 const U &rhs
416) {
418}
419
420
421template <int RTYPE,bool NA, typename T, typename U>
422inline typename traits::enable_if< traits::is_convertible< typename traits::remove_const_and_reference<U>::type, typename traits::storage_type<RTYPE>::type>::value, sugar::Divides_Primitive_Vector< RTYPE , NA,T> >::type
424 const U &lhs,
425 const VectorBase<RTYPE,NA,T>& rhs
426) {
428}
429
430template <int RTYPE,bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T>
431inline sugar::Divides_Vector_Vector<
432 RTYPE ,
433 LHS_NA, LHS_T,
435 >
439) {
441 RTYPE,
444 >( lhs, rhs ) ;
445}
446
447}
448
449#endif
Divides_Vector_Vector< RTYPE, LHS_NA, LHS_T, RHS_NA, RHS_T > & get_ref()
Definition VectorBase.h:37
Divides_Primitive_Vector(double lhs_, const VEC_TYPE &rhs_)
Definition divides.h:351
Rcpp::traits::Extractor< REALSXP, NA, T >::type VEC_EXT
Definition divides.h:349
Rcpp::VectorBase< REALSXP, NA, T > VEC_TYPE
Definition divides.h:348
Divides_Primitive_Vector(double lhs_, const VEC_TYPE &rhs_)
Definition divides.h:395
Rcpp::traits::Extractor< REALSXP, false, T >::type VEC_EXT
Definition divides.h:393
Rcpp::VectorBase< REALSXP, false, T > VEC_TYPE
Definition divides.h:392
Rcpp::traits::Extractor< RTYPE, false, T >::type VEC_EXT
Definition divides.h:371
Divides_Primitive_Vector(STORAGE lhs_, const VEC_TYPE &rhs_)
Definition divides.h:373
traits::storage_type< RTYPE >::type STORAGE
Definition divides.h:370
Rcpp::VectorBase< RTYPE, false, T > VEC_TYPE
Definition divides.h:369
Rcpp::traits::Extractor< RTYPE, NA, T >::type VEC_EXT
Definition divides.h:326
STORAGE operator[](R_xlen_t i) const
Definition divides.h:332
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition divides.h:325
Divides_Primitive_Vector(STORAGE lhs_, const VEC_TYPE &rhs_)
Definition divides.h:329
traits::storage_type< RTYPE >::type STORAGE
Definition divides.h:327
Rcpp::VectorBase< REALSXP, NA, T > VEC_TYPE
Definition divides.h:255
Divides_Vector_Primitive(const VEC_TYPE &lhs_, double rhs_)
Definition divides.h:258
Rcpp::traits::Extractor< REALSXP, NA, T >::type VEC_EXT
Definition divides.h:256
Divides_Vector_Primitive(const VEC_TYPE &lhs_, double rhs_)
Definition divides.h:306
Rcpp::traits::Extractor< REALSXP, false, T >::type VEC_EXT
Definition divides.h:304
Rcpp::VectorBase< REALSXP, false, T > VEC_TYPE
Definition divides.h:303
Divides_Vector_Primitive(const VEC_TYPE &lhs_, STORAGE rhs_)
Definition divides.h:283
Rcpp::VectorBase< RTYPE, false, T > VEC_TYPE
Definition divides.h:280
Rcpp::traits::Extractor< RTYPE, false, T >::type VEC_EXT
Definition divides.h:281
traits::storage_type< RTYPE >::type STORAGE
Definition divides.h:279
STORAGE operator[](R_xlen_t i) const
Definition divides.h:237
Divides_Vector_Primitive(const VEC_TYPE &lhs_, STORAGE rhs_)
Definition divides.h:233
traits::storage_type< RTYPE >::type STORAGE
Definition divides.h:229
Rcpp::traits::Extractor< RTYPE, NA, T >::type VEC_EXT
Definition divides.h:231
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition divides.h:230
Rcpp::traits::Extractor< REALSXP, LHS_NA, LHS_T >::type LHS_EXT
Definition divides.h:60
Rcpp::traits::Extractor< REALSXP, RHS_NA, RHS_T >::type RHS_EXT
Definition divides.h:61
Divides_Vector_Vector(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition divides.h:63
Rcpp::traits::Extractor< REALSXP, LHS_NA, LHS_T >::type LHS_EXT
Definition divides.h:158
Rcpp::traits::Extractor< REALSXP, false, RHS_T >::type RHS_EXT
Definition divides.h:159
Divides_Vector_Vector(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition divides.h:161
Rcpp::traits::Extractor< REALSXP, false, LHS_T >::type LHS_EXT
Definition divides.h:109
Divides_Vector_Vector(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition divides.h:112
Rcpp::traits::Extractor< REALSXP, RHS_NA, RHS_T >::type RHS_EXT
Definition divides.h:110
Rcpp::traits::Extractor< REALSXP, false, LHS_T >::type LHS_EXT
Definition divides.h:205
Rcpp::traits::Extractor< REALSXP, false, RHS_T >::type RHS_EXT
Definition divides.h:206
Divides_Vector_Vector(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition divides.h:208
Rcpp::traits::Extractor< RTYPE, LHS_NA, LHS_T >::type LHS_EXT
Definition divides.h:134
Divides_Vector_Vector(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition divides.h:137
Rcpp::traits::Extractor< RTYPE, false, RHS_T >::type RHS_EXT
Definition divides.h:135
Divides_Vector_Vector(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition divides.h:87
Rcpp::traits::Extractor< RTYPE, false, LHS_T >::type LHS_EXT
Definition divides.h:84
Rcpp::traits::Extractor< RTYPE, RHS_NA, RHS_T >::type RHS_EXT
Definition divides.h:85
Rcpp::traits::Extractor< RTYPE, false, RHS_T >::type RHS_EXT
Definition divides.h:183
Divides_Vector_Vector(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition divides.h:185
Rcpp::traits::Extractor< RTYPE, false, LHS_T >::type LHS_EXT
Definition divides.h:182
Rcpp::traits::Extractor< RTYPE, RHS_NA, RHS_T >::type RHS_EXT
Definition divides.h:35
Rcpp::VectorBase< RTYPE, LHS_NA, LHS_T > LHS_TYPE
Definition divides.h:31
Divides_Vector_Vector(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition divides.h:37
Rcpp::traits::Extractor< RTYPE, LHS_NA, LHS_T >::type LHS_EXT
Definition divides.h:34
Rcpp::VectorBase< RTYPE, RHS_NA, RHS_T > RHS_TYPE
Definition divides.h:32
STORAGE operator[](R_xlen_t i) const
Definition divides.h:40
traits::storage_type< RTYPE >::type STORAGE
Definition divides.h:33
Rcpp API.
Definition algo.h:28
sugar::IsNa< RTYPE, NA, T > is_na(const Rcpp::VectorBase< RTYPE, NA, T > &t)
Definition is_na.h:91
traits::enable_if< traits::is_convertible< typenametraits::remove_const_and_reference< U >::type, typenametraits::storage_type< RTYPE >::type >::value, sugar::Divides_Vector_Primitive< RTYPE, NA, T > >::type operator/(const VectorBase< RTYPE, NA, T > &lhs, const U &rhs)
Definition divides.h:413
T as(SEXP x)
Definition as.h:151
static Na_Proxy NA
Definition Na_Proxy.h:52