-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes for upper_tri and lower_tri with unit tests (closes #641) #642
Merged
eddelbuettel
merged 2 commits into
RcppCore:master
from
nathan-russell:bugfix/upper-lower-tri
Jan 31, 2017
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- | ||
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- | ||
// | ||
// lower_tri.h: Rcpp R/C++ interface class library -- lower.tri | ||
// | ||
// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois | ||
// Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think one usually separates the years, so that would be 2010 - 2016 if the next one 2017 - ... No biggie. |
||
// Copyright (C) 2017 Dirk Eddelbuettel, Romain Francois, and Nathan Russell | ||
// | ||
// This file is part of Rcpp. | ||
// | ||
|
@@ -22,60 +23,47 @@ | |
#ifndef Rcpp__sugar__lower_tri_h | ||
#define Rcpp__sugar__lower_tri_h | ||
|
||
namespace Rcpp{ | ||
namespace sugar{ | ||
namespace Rcpp { | ||
namespace sugar { | ||
|
||
template <int RTYPE, bool LHS_NA, typename LHS_T> | ||
class LowerTri : public VectorBase< | ||
LGLSXP , | ||
false , | ||
LowerTri<RTYPE,LHS_NA,LHS_T> | ||
> { | ||
template <int RTYPE, bool NA, typename T> | ||
class LowerTri : public MatrixBase<LGLSXP, false, LowerTri<RTYPE, NA, T> > { | ||
public: | ||
typedef Rcpp::MatrixBase<RTYPE,LHS_NA,LHS_T> LHS_TYPE ; | ||
typedef Rcpp::MatrixBase<RTYPE, NA, T> MatBase; | ||
|
||
LowerTri( const LHS_TYPE& lhs, bool diag) : | ||
nr( lhs.nrow() ), nc( lhs.ncol() ), | ||
getter( diag ? (&LowerTri::get_diag_true) : (&LowerTri::get_diag_false) ){} | ||
LowerTri(const T& lhs, bool diag) | ||
: nr(lhs.nrow()), | ||
nc(lhs.ncol()), | ||
getter(diag ? (&LowerTri::get_diag_true) : (&LowerTri::get_diag_false)) | ||
{} | ||
|
||
// inline int operator[]( int index ) const { | ||
// int i = Rcpp::internal::get_line( index, nr ) ; | ||
// int j = Rcpp::internal::get_column( index, nr, i ) ; | ||
// return get(i,j) ; | ||
// } | ||
inline int operator()( int i, int j ) const { | ||
return get(i,j) ; | ||
} | ||
inline int operator()(int i, int j) const { return get(i, j); } | ||
|
||
inline R_xlen_t size() const { return static_cast<R_xlen_t>(nr) * nc ; } | ||
inline int nrow() const { return nr; } | ||
inline int ncol() const { return nc; } | ||
inline R_xlen_t size() const { return static_cast<R_xlen_t>(nr) * nc; } | ||
inline int nrow() const { return nr; } | ||
inline int ncol() const { return nc; } | ||
|
||
private: | ||
int nr, nc ; | ||
typedef bool (LowerTri::*Method)(int,int) ; | ||
typedef bool (LowerTri::*Method)(int, int) const; | ||
|
||
Method getter ; | ||
inline bool get_diag_true( int i, int j ){ | ||
return i <= j ; | ||
} | ||
inline bool get_diag_false( int i, int j ){ | ||
return i < j ; | ||
} | ||
inline bool get( int i, int j){ | ||
return (this->*getter)(i, j ) ; | ||
} | ||
int nr, nc; | ||
Method getter; | ||
|
||
} ; | ||
inline bool get_diag_true(int i, int j) const { return i >= j; } | ||
|
||
inline bool get_diag_false(int i, int j) const { return i > j; } | ||
|
||
inline bool get(int i, int j) const { return (this->*getter)(i, j); } | ||
}; | ||
|
||
} // sugar | ||
|
||
template <int RTYPE, bool LHS_NA, typename LHS_T> | ||
inline sugar::LowerTri<RTYPE,LHS_NA,LHS_T> | ||
lower_tri( const Rcpp::MatrixBase<RTYPE,LHS_NA,LHS_T>& lhs, bool diag = false){ | ||
return sugar::LowerTri<RTYPE,LHS_NA,LHS_T>( lhs, diag ) ; | ||
template <int RTYPE, bool NA, typename T> | ||
inline sugar::LowerTri<RTYPE, NA, T> | ||
lower_tri(const Rcpp::MatrixBase<RTYPE, NA, T>& lhs, bool diag = false) { | ||
return sugar::LowerTri<RTYPE, NA, T>(lhs, diag); | ||
} | ||
|
||
} // Rcpp | ||
|
||
#endif | ||
#endif // Rcpp__sugar__lower_tri_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching that here. Slowly changing them myself whenever I see one in a file I use.