Rcpp Version 1.0.9
outer.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // outer.h: Rcpp R/C++ interface class library -- outer
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__outer_h
23 #define Rcpp__sugar__outer_h
24 
25 namespace Rcpp{
26 namespace sugar{
27 
28 template <int RTYPE,
29  bool LHS_NA, typename LHS_T,
30  bool RHS_NA, typename RHS_T,
31  typename Function >
32 class Outer : public MatrixBase<
33  Rcpp::traits::r_sexptype_traits<
34  typename ::Rcpp::traits::result_of<Function>::type
35  >::rtype ,
36  true ,
37  Outer<RTYPE,LHS_NA,LHS_T,RHS_NA,RHS_T,Function>
38 > {
39 public:
40  typedef typename ::Rcpp::traits::result_of<Function>::type result_type ;
41  const static int RESULT_R_TYPE =
43 
46 
49 
52 
53  Outer( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_, Function fun_ ) :
54  lhs(lhs_), rhs(rhs_), fun(fun_), nr(lhs_.size()), nc(rhs_.size()) {}
55 
56  inline STORAGE operator()( int i, int j ) const {
57  return converter_type::get( fun( lhs[i], rhs[j] ) );
58  }
59 
60  inline R_xlen_t size() const { return static_cast<R_xlen_t>(nr) * nc ; }
61  inline int nrow() const { return nr; }
62  inline int ncol() const { return nc; }
63 
64 private:
65 
68 
70  int nr, nc ;
71 } ;
72 
73 } // sugar
74 
75 template <int RTYPE,
76  bool LHS_NA, typename LHS_T,
77  bool RHS_NA, typename RHS_T,
78  typename Function >
83  Function fun ){
84 
86 }
87 
88 } // Rcpp
89 
90 #endif
static target get(const T &input)
Definition: converter.h:33
LHS_LAZY lhs
Definition: outer.h:66
::Rcpp::traits::result_of< Function >::type result_type
Definition: outer.h:40
Function fun
Definition: outer.h:69
Rcpp::VectorBase< RTYPE, LHS_NA, LHS_T > LHS_TYPE
Definition: outer.h:44
STORAGE operator()(int i, int j) const
Definition: outer.h:56
Rcpp::traits::r_vector_element_converter< RESULT_R_TYPE >::type converter_type
Definition: outer.h:50
Rcpp::traits::storage_type< RESULT_R_TYPE >::type STORAGE
Definition: outer.h:51
Outer(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_, Function fun_)
Definition: outer.h:53
RHS_LAZY rhs
Definition: outer.h:67
int ncol() const
Definition: outer.h:62
int nrow() const
Definition: outer.h:61
Rcpp::internal::LazyVector< RHS_TYPE > RHS_LAZY
Definition: outer.h:48
static const int RESULT_R_TYPE
Definition: outer.h:41
R_xlen_t size() const
Definition: outer.h:60
Rcpp::VectorBase< RTYPE, RHS_NA, RHS_T > RHS_TYPE
Definition: outer.h:45
Rcpp::internal::LazyVector< LHS_TYPE > LHS_LAZY
Definition: outer.h:47
Rcpp API.
Definition: algo.h:28
Function_Impl< PreserveStorage > Function
Definition: Function.h:122
sugar::Outer< RTYPE, LHS_NA, LHS_T, RHS_NA, RHS_T, Function > outer(const Rcpp::VectorBase< RTYPE, LHS_NA, LHS_T > &lhs, const Rcpp::VectorBase< RTYPE, RHS_NA, RHS_T > &rhs, Function fun)
Definition: outer.h:80