Skip to content

Commit

Permalink
move function around for organization
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Apr 19, 2024
1 parent ce28683 commit e24a9c3
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions src/altrep-sparse-real.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,53 +59,6 @@ const void* altrep_sparse_real_Dataptr_or_null(SEXP vec) {
}
}

// -----------------------------------------------------------------------------
// ALTREP

R_xlen_t altrep_sparse_real_Length(SEXP x) {
double out = Rf_asReal(VECTOR_ELT(R_altrep_data1(x),2));

return out;
}

// What gets printed when .Internal(inspect()) is used
Rboolean altrep_sparse_real_Inspect(SEXP x,
int pre,
int deep,
int pvec,
void (*inspect_subtree)(SEXP, int, int, int)) {
Rprintf("sparsevctrs_altrep_sparse_real (materialized=%s)\n",
R_altrep_data2(x) != R_NilValue ? "T" : "F");
return TRUE;
}

// -----------------------------------------------------------------------------
// ALTREAL

static double altrep_sparse_real_Elt(SEXP x, R_xlen_t i) {

if (i > Rf_asReal(VECTOR_ELT(R_altrep_data1(x), 2))) {
return NA_REAL;
}

SEXP data1 = R_altrep_data1(x);
SEXP val = VECTOR_ELT(data1, 0);
SEXP pos = VECTOR_ELT(data1, 1);

const R_len_t n = Rf_length(val);

double out = 0;

for (int j = 0; j < n; ++j) {
if (INTEGER_ELT(pos, j) == i + 1) {
out = REAL_ELT(val, j);
break;
}
}

return out;
}

static SEXP altrep_sparse_real_Extract_subset(SEXP x, SEXP indx, SEXP call) {

SEXP data1 = R_altrep_data1(x);
Expand Down Expand Up @@ -157,6 +110,53 @@ static SEXP altrep_sparse_real_Extract_subset(SEXP x, SEXP indx, SEXP call) {
return ffi_altrep_new_sparse_real(res);
}

// -----------------------------------------------------------------------------
// ALTREP

R_xlen_t altrep_sparse_real_Length(SEXP x) {
double out = Rf_asReal(VECTOR_ELT(R_altrep_data1(x),2));

return out;
}

// What gets printed when .Internal(inspect()) is used
Rboolean altrep_sparse_real_Inspect(SEXP x,
int pre,
int deep,
int pvec,
void (*inspect_subtree)(SEXP, int, int, int)) {
Rprintf("sparsevctrs_altrep_sparse_real (materialized=%s)\n",
R_altrep_data2(x) != R_NilValue ? "T" : "F");
return TRUE;
}

// -----------------------------------------------------------------------------
// ALTREAL

static double altrep_sparse_real_Elt(SEXP x, R_xlen_t i) {

if (i > Rf_asReal(VECTOR_ELT(R_altrep_data1(x), 2))) {
return NA_REAL;
}

SEXP data1 = R_altrep_data1(x);
SEXP val = VECTOR_ELT(data1, 0);
SEXP pos = VECTOR_ELT(data1, 1);

const R_len_t n = Rf_length(val);

double out = 0;

for (int j = 0; j < n; ++j) {
if (INTEGER_ELT(pos, j) == i + 1) {
out = REAL_ELT(val, j);
break;
}
}

return out;
}

// -----------------------------------------------------------------------------

void sparsevctrs_init_altrep_sparse_real(DllInfo* dll) {
Expand All @@ -165,12 +165,12 @@ void sparsevctrs_init_altrep_sparse_real(DllInfo* dll) {
// ALTVEC
R_set_altvec_Dataptr_method(altrep_sparse_real_class, altrep_sparse_real_Dataptr);
R_set_altvec_Dataptr_or_null_method(altrep_sparse_real_class, altrep_sparse_real_Dataptr_or_null);
R_set_altvec_Extract_subset_method(altrep_sparse_real_class, altrep_sparse_real_Extract_subset);

// ALTREP
R_set_altrep_Length_method(altrep_sparse_real_class, altrep_sparse_real_Length);
R_set_altrep_Inspect_method(altrep_sparse_real_class, altrep_sparse_real_Inspect);

// ALTREAL
R_set_altreal_Elt_method(altrep_sparse_real_class, altrep_sparse_real_Elt);
R_set_altvec_Extract_subset_method(altrep_sparse_real_class, altrep_sparse_real_Extract_subset);
}

0 comments on commit e24a9c3

Please sign in to comment.