Rcpp Version 0.12.12
upper_tri.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 // upper_tri.h: Rcpp R/C++ interface class library -- upper.tri
4 //
5 // Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois
6 // Copyright (C) 2017 Dirk Eddelbuettel, Romain Francois, and Nathan Russell
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__upper_tri_h
24 #define Rcpp__sugar__upper_tri_h
25 
26 namespace Rcpp {
27 namespace sugar {
28 
29 template <int RTYPE, bool NA, typename T>
30 class UpperTri : public MatrixBase<LGLSXP, false, UpperTri<RTYPE, NA, T> > {
31 public:
33 
34  UpperTri(const T& lhs, bool diag)
35  : nr(lhs.nrow()),
36  nc(lhs.ncol()),
38  {}
39 
40  inline int operator()(int i, int j) const { return get(i, j); }
41 
42  inline R_xlen_t size() const { return static_cast<R_xlen_t>(nr) * nc; }
43  inline int nrow() const { return nr; }
44  inline int ncol() const { return nc; }
45 
46 private:
47  typedef bool (UpperTri::*Method)(int, int) const;
48 
49  int nr, nc;
51 
52  inline bool get_diag_true(int i, int j) const { return i <= j; }
53 
54  inline bool get_diag_false(int i, int j) const { return i < j; }
55 
56  inline bool get(int i, int j) const { return (this->*getter)(i, j); }
57 };
58 
59 } // sugar
60 
61 template <int RTYPE, bool NA, typename T>
63 upper_tri(const Rcpp::MatrixBase<RTYPE, NA, T>& lhs, bool diag = false) {
65 }
66 
67 } // Rcpp
68 
69 #endif // Rcpp__sugar__upper_tri_h
int ncol() const
Definition: upper_tri.h:44
sugar::UpperTri< RTYPE, NA, T > upper_tri(const Rcpp::MatrixBase< RTYPE, NA, T > &lhs, bool diag=false)
Definition: upper_tri.h:63
Rcpp::MatrixBase< RTYPE, NA, T > MatBase
Definition: upper_tri.h:32
R_xlen_t size() const
Definition: upper_tri.h:42
int nrow() const
Definition: upper_tri.h:43
bool get_diag_false(int i, int j) const
Definition: upper_tri.h:54
bool get_diag_true(int i, int j) const
Definition: upper_tri.h:52
UpperTri(const T &lhs, bool diag)
Definition: upper_tri.h:34
sugar::diag_result_type_trait< T >::type diag(const T &t)
Definition: diag.h:83
int operator()(int i, int j) const
Definition: upper_tri.h:40
Rcpp API.
Definition: algo.h:28
bool(UpperTri::* Method)(int, int) const
Definition: upper_tri.h:47