36 Rcpp::RObject raw_svt = matrix.slot(
"SVT");
37 if (raw_svt == R_NilValue) {
41 Rcpp::IntegerVector svt_version(matrix.slot(
".svt_version"));
42 if (svt_version.size() != 1) {
43 auto ctype = get_class_name(matrix);
44 throw std::runtime_error(
"'.svt_version' slot of a " + ctype +
" should be an integer scalar");
46 int version = svt_version[0];
47 int index_x = (version == 0 ? 0 : 1);
48 int value_x = (version == 0 ? 1 : 0);
50 Rcpp::List svt(raw_svt);
53 for (
int c = 0; c < NC; ++c) {
54 Rcpp::RObject raw_inner(svt[c]);
55 if (raw_inner == R_NilValue) {
59 Rcpp::List inner(raw_inner);
60 if (inner.size() != 2) {
61 auto ctype = get_class_name(matrix);
62 throw std::runtime_error(
"each entry of the 'SVT' slot of a " + ctype +
" object should be a list of length 2 or NULL");
66 Rcpp::RObject raw_indices = inner[index_x];
67 if (raw_indices.sexp_type() != INTSXP) {
68 auto ctype = get_class_name(matrix);
69 throw std::runtime_error(
"indices of each element of the 'SVT' slot in a " + ctype +
" object should be an integer vector");
71 Rcpp::IntegerVector curindices(raw_indices);
72 auto nnz = curindices.size();
74 Rcpp::RObject raw_values(inner[value_x]);
75 auto vsexp = raw_values.sexp_type();
76 bool has_values = raw_values != R_NilValue;
77 Rcpp::IntegerVector curvalues_i;
78 Rcpp::NumericVector curvalues_n;
79 Rcpp::LogicalVector curvalues_l;
85 curvalues_i = Rcpp::IntegerVector(raw_values);
86 vsize = curvalues_i.size();
89 curvalues_n = Rcpp::NumericVector(raw_values);
90 vsize = curvalues_n.size();
93 curvalues_l = Rcpp::LogicalVector(raw_values);
94 vsize = curvalues_l.size();
98 auto ctype = get_class_name(matrix);
99 throw std::runtime_error(
"value vector of an element of the 'SVT' slot in a " + ctype +
" object is not a numeric or logical type");
104 auto ctype = get_class_name(matrix);
105 throw std::runtime_error(
"both vectors of an element of the 'SVT' slot in a " + ctype +
" object should have the same length");
111 fun(c, curindices, !has_values, curvalues_i);
114 fun(c, curindices, !has_values, curvalues_n);
117 fun(c, curindices, !has_values, curvalues_l);