Rcpp Version 1.1.2
Loading...
Searching...
No Matches
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 - 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__outer_h
24#define Rcpp__sugar__outer_h
25
26namespace Rcpp{
27namespace sugar{
28
29template <int RTYPE,
30 bool LHS_NA, typename LHS_T,
31 bool RHS_NA, typename RHS_T,
32 typename Function >
33class Outer : public MatrixBase<
34 Rcpp::traits::r_sexptype_traits<
35 typename ::Rcpp::traits::result_of<Function, LHS_T, RHS_T>::type
36 >::rtype ,
37 true ,
38 Outer<RTYPE,LHS_NA,LHS_T,RHS_NA,RHS_T,Function>
39> {
40public:
41 typedef typename ::Rcpp::traits::result_of<Function, LHS_T, RHS_T>::type result_type ;
42 const static int RESULT_R_TYPE =
44
47
50
53
54 Outer( const LHS_TYPE& lhs_, const RHS_TYPE& rhs_, Function fun_ ) :
55 lhs(lhs_), rhs(rhs_), fun(fun_), nr(lhs_.size()), nc(rhs_.size()) {}
56
57 inline STORAGE operator()( int i, int j ) const {
58 return converter_type::get( fun( lhs[i], rhs[j] ) );
59 }
60
61 inline R_xlen_t size() const { return static_cast<R_xlen_t>(nr) * nc ; }
62 inline int nrow() const { return nr; }
63 inline int ncol() const { return nc; }
64
65private:
66
69
71 int nr, nc ;
72} ;
73
74} // sugar
75
76template <int RTYPE,
77 bool LHS_NA, typename LHS_T,
78 bool RHS_NA, typename RHS_T,
79 typename Function >
88
89} // Rcpp
90
91#endif
static target get(const T &input)
Definition converter.h:33
LHS_LAZY lhs
Definition outer.h:67
Function fun
Definition outer.h:70
Rcpp::VectorBase< RTYPE, LHS_NA, LHS_T > LHS_TYPE
Definition outer.h:45
STORAGE operator()(int i, int j) const
Definition outer.h:57
::Rcpp::traits::result_of< Function, LHS_T, RHS_T >::type result_type
Definition outer.h:41
Rcpp::traits::r_vector_element_converter< RESULT_R_TYPE >::type converter_type
Definition outer.h:51
Rcpp::traits::storage_type< RESULT_R_TYPE >::type STORAGE
Definition outer.h:52
Outer(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_, Function fun_)
Definition outer.h:54
RHS_LAZY rhs
Definition outer.h:68
int ncol() const
Definition outer.h:63
int nrow() const
Definition outer.h:62
Rcpp::internal::LazyVector< RHS_TYPE > RHS_LAZY
Definition outer.h:49
static const int RESULT_R_TYPE
Definition outer.h:42
R_xlen_t size() const
Definition outer.h:61
Rcpp::VectorBase< RTYPE, RHS_NA, RHS_T > RHS_TYPE
Definition outer.h:46
Rcpp::internal::LazyVector< LHS_TYPE > LHS_LAZY
Definition outer.h:48
Rcpp API.
Definition algo.h:28
Function_Impl< PreserveStorage > Function
Definition Function.h:144
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:81
::Rcpp::internal::element_converter< RTYPE > type
Definition converter.h:95