Rcpp Version 1.0.14
Loading...
Searching...
No Matches
pow.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// pow.h: Rcpp R/C++ interface class library -- pow
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__pow_h
23#define Rcpp__sugar__pow_h
24
25namespace Rcpp{
26namespace sugar{
27
28template <int RTYPE, bool NA, typename T, typename EXPONENT_TYPE>
29class Pow : public Rcpp::VectorBase< REALSXP ,NA, Pow<RTYPE,NA,T,EXPONENT_TYPE> > {
30public:
32
34
35 inline double operator[]( R_xlen_t i ) const {
36 return ::pow( object[i], op );
37 }
38 inline R_xlen_t size() const { return object.size() ; }
39
40private:
41 const T& object ;
43} ;
44
45template <bool NA, typename T, typename EXPONENT_TYPE>
46class Pow<INTSXP,NA,T,EXPONENT_TYPE> : public Rcpp::VectorBase< REALSXP ,NA, Pow<INTSXP,NA,T,EXPONENT_TYPE> > {
47public:
49
50 inline double operator[]( R_xlen_t i ) const {
51 int x = object[i] ;
52 return x == NA_INTEGER ? NA_INTEGER : ::pow( x, op );
53 }
54 inline R_xlen_t size() const { return object.size() ; }
55
56private:
57 const T& object ;
59} ;
60template <typename T, typename EXPONENT_TYPE>
61class Pow<INTSXP,false,T,EXPONENT_TYPE> : public Rcpp::VectorBase< REALSXP ,false, Pow<INTSXP,false,T,EXPONENT_TYPE> > {
62public:
64
65 inline double operator[]( R_xlen_t i ) const {
66 return ::pow( object[i], op );
67 }
68 inline R_xlen_t size() const { return object.size() ; }
69
70private:
71 const T& object ;
73} ;
74
75
76} // sugar
77
78template <int RTYPE, bool NA, typename T, typename EXPONENT_TYPE>
85
86
87} // Rcpp
88#endif
89
VECTOR & get_ref()
Definition VectorBase.h:37
double operator[](R_xlen_t i) const
Definition pow.h:50
Pow(const T &object_, EXPONENT_TYPE exponent)
Definition pow.h:48
Pow(const T &object_, EXPONENT_TYPE exponent)
Definition pow.h:63
Pow(const T &object_, EXPONENT_TYPE exponent)
Definition pow.h:33
Rcpp::traits::storage_type< RTYPE >::type STORAGE
Definition pow.h:31
double operator[](R_xlen_t i) const
Definition pow.h:35
const T & object
Definition pow.h:41
R_xlen_t size() const
Definition pow.h:38
EXPONENT_TYPE op
Definition pow.h:42
Rcpp API.
Definition algo.h:28
sugar::Pow< RTYPE, NA, T, EXPONENT_TYPE > pow(const VectorBase< RTYPE, NA, T > &t, EXPONENT_TYPE exponent)
Definition pow.h:79
T as(SEXP x)
Definition as.h:151
static Na_Proxy NA
Definition Na_Proxy.h:52