/usr/lib/R/site-library/dplyr/include/dplyr/MatrixColumnVisitor.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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | #ifndef dplyr_MatrixColumnVisitor_H
#define dplyr_MatrixColumnVisitor_H
#include <dplyr/comparisons.h>
namespace dplyr {
template <int RTYPE>
class MatrixColumnVisitor : public VectorVisitor {
public:
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
typedef typename Matrix<RTYPE>::Column Column;
class ColumnVisitor {
public:
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
typedef comparisons<RTYPE> compare;
typedef boost::hash<STORAGE> hasher;
ColumnVisitor(Matrix<RTYPE>& data, int column) :
column(data.column(column)) {}
inline size_t hash(int i) const {
return hash_fun(const_cast<Column&>(column)[i]);
}
inline bool equal(int i, int j) const {
return compare::equal_or_both_na(const_cast<Column&>(column)[i], const_cast<Column&>(column)[j]);
}
inline bool less(int i, int j) const {
return compare::is_less(const_cast<Column&>(column)[i], const_cast<Column&>(column)[j]);
}
inline bool equal_or_both_na(int i, int j) const {
return compare::equal_or_both_na(const_cast<Column&>(column)[i], const_cast<Column&>(column)[j]);
}
inline bool greater(int i, int j) const {
return compare::is_greater(const_cast<Column&>(column)[i], const_cast<Column&>(column)[j]);
}
private:
Column column;
hasher hash_fun;
};
MatrixColumnVisitor(const Matrix<RTYPE>& data_) : data(data_), visitors() {
for (int h = 0; h < data.ncol(); h++) {
visitors.push_back(ColumnVisitor(data, h));
}
}
inline size_t hash(int i) const {
size_t seed = visitors[0].hash(i);
for (size_t h = 1; h < visitors.size(); h++) {
boost::hash_combine(seed, visitors[h].hash(i));
}
return seed;
}
inline bool equal(int i, int j) const {
if (i == j) return true;
for (size_t h = 0; h < visitors.size(); h++) {
if (!visitors[h].equal(i, j)) return false;
}
return true;
}
inline bool equal_or_both_na(int i, int j) const {
if (i == j) return true;
for (size_t h = 0; h < visitors.size(); h++) {
if (!visitors[h].equal_or_both_na(i, j)) return false;
}
return true;
}
inline bool less(int i, int j) const {
if (i == j) return false;
for (size_t h = 0; h < visitors.size(); h++) {
const ColumnVisitor& v = visitors[h];
if (!v.equal(i, j)) {
return v.less(i, j);
}
}
return i < j;
}
inline bool greater(int i, int j) const {
if (i == j) return false;
for (size_t h = 0; h < visitors.size(); h++) {
const ColumnVisitor& v = visitors[h];
if (!v.equal(i, j)) {
return v.greater(i, j);
}
}
return i < j;
}
inline int size() const {
return data.nrow();
}
inline std::string get_r_type() const {
return "matrix";
}
bool is_na(int) const {
return false;
}
private:
Matrix<RTYPE> data;
std::vector<ColumnVisitor> visitors;
};
}
#endif
|