/usr/lib/R/site-library/dplyr/include/dplyr/MatrixColumnSubsetVectorVisitor.h is in r-cran-dplyr 0.7.4-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | #ifndef dplyr_MatrixColumnSubsetVisitor_H
#define dplyr_MatrixColumnSubsetVisitor_H
namespace dplyr {
template <int RTYPE>
class MatrixColumnSubsetVisitor : public SubsetVectorVisitor {
public:
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
typedef typename Matrix<RTYPE>::Column Column;
MatrixColumnSubsetVisitor(const Matrix<RTYPE>& data_) : data(data_) {}
inline SEXP subset(const Rcpp::IntegerVector& index) const {
return subset_int(index);
}
inline SEXP subset(const std::vector<int>& index) const {
return subset_int(index);
}
inline SEXP subset(const SlicingIndex& index) const {
return subset_int(index);
}
inline SEXP subset(const ChunkIndexMap& index) const {
int n = index.size();
int nc = data.ncol();
Matrix<RTYPE> res(n, data.ncol());
for (int h = 0; h < nc; h++) {
ChunkIndexMap::const_iterator it = index.begin();
Column column = res.column(h);
Column source_column = const_cast<Matrix<RTYPE>&>(data).column(h);
for (int i = 0; i < n; i++, ++it) {
column[i] = source_column[ it->first ];
}
}
return res;
}
inline SEXP subset(EmptySubset) const {
return Matrix<RTYPE>(0, data.ncol());
}
inline int size() const {
return data.nrow();
}
inline std::string get_r_type() const {
return "matrix";
}
inline bool is_compatible(SubsetVectorVisitor* other, std::stringstream&, const SymbolString&) const {
return is_same_typeid(other);
}
private:
template <typename Container>
inline SEXP subset_int(const Container& index) const {
int n = index.size(), nc = data.ncol();
Matrix<RTYPE> res(n, nc);
for (int h = 0; h < nc; h++) {
Column column = res.column(h);
Column source_column = const_cast<Matrix<RTYPE>&>(data).column(h);
for (int k = 0; k < n; k++) {
int idx = index[k];
if (idx < 0) {
column[k] = Vector<RTYPE>::get_na();
} else {
column[k] = source_column[ index[k] ];
}
}
}
return res;
}
Matrix<RTYPE> data;
};
}
#endif
|