Skip to content

Commit

Permalink
Merge pull request #31 from EmilHvitfeldt/real-double
Browse files Browse the repository at this point in the history
change functions from _real to _double
  • Loading branch information
EmilHvitfeldt authored May 7, 2024
2 parents 6657162 + d21ea85 commit 4e4ef4d
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 140 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(new_sparse_real)
export(new_sparse_double)
import(rlang)
useDynLib(sparsevctrs, .registration = TRUE)
6 changes: 3 additions & 3 deletions R/altrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' message each time a sparse vector has been forced to materialize.
#'
#' @export
new_sparse_real <- function(value, position, length) {
new_sparse_double <- function(value, position, length) {
check_number_whole(length, min = 0)
if (!is.integer(length)) {
length <- as.integer(length)
Expand Down Expand Up @@ -133,7 +133,7 @@ new_sparse_real <- function(value, position, length) {
len = length
)

.Call(ffi_altrep_new_sparse_real, x)
.Call(ffi_altrep_new_sparse_double, x)
}

is_sparse_vector <- function(x) {
Expand All @@ -144,6 +144,6 @@ is_sparse_vector <- function(x) {

res <- as.character(res[[1]])

res %in% c("altrep_sparse_real")
res %in% c("altrep_sparse_double")
}

6 changes: 3 additions & 3 deletions man/new_sparse_real.Rd → man/new_sparse_double.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 25 additions & 22 deletions src/altrep-sparse-real.c → src/altrep-sparse-double.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include "sparse-utils.h"

// Initialised at load time
R_altrep_class_t altrep_sparse_real_class;

SEXP ffi_altrep_new_sparse_real(SEXP x) {
return R_new_altrep(altrep_sparse_real_class, x, R_NilValue);
R_altrep_class_t altrep_sparse_double_class;

SEXP ffi_altrep_new_sparse_double(SEXP x) {
return R_new_altrep(altrep_sparse_double_class, x, R_NilValue);
}

SEXP alrep_sparse_real_Materialize(SEXP x) {
SEXP alrep_sparse_double_Materialize(SEXP x) {
if (!Rf_isNull(Rf_GetOption1(Rf_install("sparsevctrs.verbose_materialize"))
)) {
Rprintf("sparsevctrs: Sparse vector materialized\n");
Expand Down Expand Up @@ -54,11 +55,11 @@ SEXP alrep_sparse_real_Materialize(SEXP x) {
// -----------------------------------------------------------------------------
// ALTVEC

void* altrep_sparse_real_Dataptr(SEXP x, Rboolean writeable) {
return STDVEC_DATAPTR(alrep_sparse_real_Materialize(x));
void* altrep_sparse_double_Dataptr(SEXP x, Rboolean writeable) {
return STDVEC_DATAPTR(alrep_sparse_double_Materialize(x));
}

const void* altrep_sparse_real_Dataptr_or_null(SEXP x) {
const void* altrep_sparse_double_Dataptr_or_null(SEXP x) {
SEXP out = R_altrep_data2(x);

if (out == R_NilValue) {
Expand All @@ -68,7 +69,7 @@ const void* altrep_sparse_real_Dataptr_or_null(SEXP x) {
}
}

static SEXP altrep_sparse_real_Extract_subset(SEXP x, SEXP indx, SEXP call) {
static SEXP altrep_sparse_double_Extract_subset(SEXP x, SEXP indx, SEXP call) {
if (!is_index_handleable(indx)) {
return NULL;
}
Expand Down Expand Up @@ -163,7 +164,7 @@ static SEXP altrep_sparse_real_Extract_subset(SEXP x, SEXP indx, SEXP call) {
++i_out;
}

SEXP altrep = ffi_altrep_new_sparse_real(out);
SEXP altrep = ffi_altrep_new_sparse_double(out);

UNPROTECT(2);
return altrep;
Expand All @@ -172,22 +173,22 @@ static SEXP altrep_sparse_real_Extract_subset(SEXP x, SEXP indx, SEXP call) {
// -----------------------------------------------------------------------------
// ALTREP

R_xlen_t altrep_sparse_real_Length(SEXP x) {
R_xlen_t altrep_sparse_double_Length(SEXP x) {
R_xlen_t out = extract_len(x);

return out;
}

// What gets printed when .Internal(inspect()) is used
Rboolean altrep_sparse_real_Inspect(
Rboolean altrep_sparse_double_Inspect(
SEXP x,
int pre,
int deep,
int pvec,
void (*inspect_subtree)(SEXP, int, int, int)
) {
Rprintf(
"sparsevctrs_altrep_sparse_real (materialized=%s, length=%i)\n",
"sparsevctrs_altrep_sparse_double (materialized=%s, length=%i)\n",
R_altrep_data2(x) != R_NilValue ? "T" : "F",
(int) extract_len(x)
);
Expand All @@ -197,7 +198,7 @@ Rboolean altrep_sparse_real_Inspect(
// -----------------------------------------------------------------------------
// ALTREAL

static double altrep_sparse_real_Elt(SEXP x, R_xlen_t i) {
static double altrep_sparse_double_Elt(SEXP x, R_xlen_t i) {
SEXP val = extract_val(x);

SEXP pos = extract_pos(x);
Expand Down Expand Up @@ -226,29 +227,31 @@ static double altrep_sparse_real_Elt(SEXP x, R_xlen_t i) {

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

void sparsevctrs_init_altrep_sparse_real(DllInfo* dll) {
altrep_sparse_real_class =
R_make_altreal_class("altrep_sparse_real", "sparsevctrs", dll);
void sparsevctrs_init_altrep_sparse_double(DllInfo* dll) {
altrep_sparse_double_class =
R_make_altreal_class("altrep_sparse_double", "sparsevctrs", dll);

// ALTVEC
R_set_altvec_Dataptr_method(
altrep_sparse_real_class, altrep_sparse_real_Dataptr
altrep_sparse_double_class, altrep_sparse_double_Dataptr
);
R_set_altvec_Dataptr_or_null_method(
altrep_sparse_real_class, altrep_sparse_real_Dataptr_or_null
altrep_sparse_double_class, altrep_sparse_double_Dataptr_or_null
);
R_set_altvec_Extract_subset_method(
altrep_sparse_real_class, altrep_sparse_real_Extract_subset
altrep_sparse_double_class, altrep_sparse_double_Extract_subset
);

// ALTREP
R_set_altrep_Length_method(
altrep_sparse_real_class, altrep_sparse_real_Length
altrep_sparse_double_class, altrep_sparse_double_Length
);
R_set_altrep_Inspect_method(
altrep_sparse_real_class, altrep_sparse_real_Inspect
altrep_sparse_double_class, altrep_sparse_double_Inspect
);

// ALTREAL
R_set_altreal_Elt_method(altrep_sparse_real_class, altrep_sparse_real_Elt);
R_set_altreal_Elt_method(
altrep_sparse_double_class, altrep_sparse_double_Elt
);
}
10 changes: 6 additions & 4 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include "sparse-utils.h"

// Defined in altrep-sparse-real.c
extern SEXP ffi_altrep_new_sparse_real(SEXP);
extern void sparsevctrs_init_altrep_sparse_real(DllInfo*);
extern SEXP ffi_altrep_new_sparse_double(SEXP);
extern void sparsevctrs_init_altrep_sparse_double(DllInfo*);

static const R_CallMethodDef CallEntries[] = {
{"ffi_altrep_new_sparse_real", (DL_FUNC) &ffi_altrep_new_sparse_real, 1},
{"ffi_altrep_new_sparse_double",
(DL_FUNC) &ffi_altrep_new_sparse_double,
1},
{"ffi_altrep_sparse_positions", (DL_FUNC) &ffi_altrep_sparse_positions, 1},
{"ffi_altrep_sparse_values", (DL_FUNC) &ffi_altrep_sparse_values, 1},
{"ffi_extract_altrep_class", (DL_FUNC) &ffi_extract_altrep_class, 1},
Expand All @@ -18,5 +20,5 @@ void R_init_sparsevctrs(DllInfo* dll) {
R_useDynamicSymbols(dll, FALSE);

// altrep classes
sparsevctrs_init_altrep_sparse_real(dll);
sparsevctrs_init_altrep_sparse_double(dll);
}
Loading

0 comments on commit 4e4ef4d

Please sign in to comment.