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
25
namespace
Rcpp
{
26
namespace
sugar{
27
28
template
<
int
RTYPE,
bool
NA,
typename
T,
typename
EXPONENT_TYPE>
29
class
Pow
:
public
Rcpp::VectorBase
< REALSXP ,NA, Pow<RTYPE,NA,T,EXPONENT_TYPE> > {
30
public
:
31
typedef
typename
Rcpp::traits::storage_type<RTYPE>::type
STORAGE
;
32
33
Pow
(
const
T&
object_
,
EXPONENT_TYPE
exponent
) :
object
(
object_
),
op
(
exponent
) {}
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
40
private
:
41
const
T&
object
;
42
EXPONENT_TYPE
op
;
43
} ;
44
45
template
<
bool
NA,
typename
T,
typename
EXPONENT_TYPE>
46
class
Pow
<
INTSXP
,
NA
,T,
EXPONENT_TYPE
> :
public
Rcpp::VectorBase
< REALSXP ,NA, Pow<INTSXP,NA,T,EXPONENT_TYPE> > {
47
public
:
48
Pow
(
const
T&
object_
,
EXPONENT_TYPE
exponent
) :
object
(
object_
),
op
(
exponent
) {}
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
56
private
:
57
const
T&
object
;
58
EXPONENT_TYPE
op
;
59
} ;
60
template
<
typename
T,
typename
EXPONENT_TYPE>
61
class
Pow
<
INTSXP
,
false
,T,
EXPONENT_TYPE
> :
public
Rcpp::VectorBase
< REALSXP ,false, Pow<INTSXP,false,T,EXPONENT_TYPE> > {
62
public
:
63
Pow
(
const
T&
object_
,
EXPONENT_TYPE
exponent
) :
object
(
object_
),
op
(
exponent
) {}
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
70
private
:
71
const
T&
object
;
72
EXPONENT_TYPE
op
;
73
} ;
74
75
76
}
// sugar
77
78
template
<
int
RTYPE,
bool
NA,
typename
T,
typename
EXPONENT_TYPE>
79
inline
sugar::Pow<RTYPE,NA,T,EXPONENT_TYPE>
pow
(
80
const
VectorBase<RTYPE,NA,T>
& t,
81
EXPONENT_TYPE
exponent
82
){
83
return
sugar::Pow<RTYPE,NA,T,EXPONENT_TYPE>
( t.
get_ref
() ,
exponent
) ;
84
}
85
86
87
}
// Rcpp
88
#endif
89
Rcpp::VectorBase
Definition
VectorBase.h:29
Rcpp::VectorBase::get_ref
VECTOR & get_ref()
Definition
VectorBase.h:37
Rcpp::object
Definition
Module.h:65
Rcpp::sugar::Pow< INTSXP, NA, T, EXPONENT_TYPE >::operator[]
double operator[](R_xlen_t i) const
Definition
pow.h:50
Rcpp::sugar::Pow< INTSXP, NA, T, EXPONENT_TYPE >::object
const T & object
Definition
pow.h:57
Rcpp::sugar::Pow< INTSXP, NA, T, EXPONENT_TYPE >::Pow
Pow(const T &object_, EXPONENT_TYPE exponent)
Definition
pow.h:48
Rcpp::sugar::Pow< INTSXP, NA, T, EXPONENT_TYPE >::op
EXPONENT_TYPE op
Definition
pow.h:58
Rcpp::sugar::Pow< INTSXP, NA, T, EXPONENT_TYPE >::size
R_xlen_t size() const
Definition
pow.h:54
Rcpp::sugar::Pow< INTSXP, false, T, EXPONENT_TYPE >::size
R_xlen_t size() const
Definition
pow.h:68
Rcpp::sugar::Pow< INTSXP, false, T, EXPONENT_TYPE >::object
const T & object
Definition
pow.h:71
Rcpp::sugar::Pow< INTSXP, false, T, EXPONENT_TYPE >::operator[]
double operator[](R_xlen_t i) const
Definition
pow.h:65
Rcpp::sugar::Pow< INTSXP, false, T, EXPONENT_TYPE >::Pow
Pow(const T &object_, EXPONENT_TYPE exponent)
Definition
pow.h:63
Rcpp::sugar::Pow< INTSXP, false, T, EXPONENT_TYPE >::op
EXPONENT_TYPE op
Definition
pow.h:72
Rcpp::sugar::Pow
Definition
pow.h:29
Rcpp::sugar::Pow::Pow
Pow(const T &object_, EXPONENT_TYPE exponent)
Definition
pow.h:33
Rcpp::sugar::Pow::STORAGE
Rcpp::traits::storage_type< RTYPE >::type STORAGE
Definition
pow.h:31
Rcpp::sugar::Pow::operator[]
double operator[](R_xlen_t i) const
Definition
pow.h:35
Rcpp::sugar::Pow::object
const T & object
Definition
pow.h:41
Rcpp::sugar::Pow::size
R_xlen_t size() const
Definition
pow.h:38
Rcpp::sugar::Pow::op
EXPONENT_TYPE op
Definition
pow.h:42
Rcpp
Rcpp API.
Definition
algo.h:28
Rcpp::pow
sugar::Pow< RTYPE, NA, T, EXPONENT_TYPE > pow(const VectorBase< RTYPE, NA, T > &t, EXPONENT_TYPE exponent)
Definition
pow.h:79
Rcpp::as
T as(SEXP x)
Definition
as.h:151
Rcpp::NA
static Na_Proxy NA
Definition
Na_Proxy.h:52
Rcpp::traits::storage_type::type
SEXP type
Definition
storage_type.h:36
inst
include
Rcpp
sugar
functions
pow.h
Generated on Sun Jan 12 2025 11:21:43 for Rcpp Version 1.0.14 by
1.9.8