-
Notifications
You must be signed in to change notification settings - Fork 16
Implement serialization support for s2_geometry vectors #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tzakharko
wants to merge
13
commits into
r-spatial:main
Choose a base branch
from
tzakharko:altrep-serialization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
584c036
Implement serialization support for s2_geometry vectors
tzakharko a7e7165
Fix a missing object entry in Makewars.win
tzakharko cece635
New serialization routines that do not lose precision
tzakharko 23ed8aa
Only use ALTREP if building for R 4.3.0 or higher
tzakharko d7f286c
Provide the option `s2.s2.disable_altrep` to turn off ALTREP for s2 g…
tzakharko 5329e60
Restructured the C++ init code, which is now centrally invoked from i…
tzakharko da5e6bc
Move new_s2_geography() back to R, make sure that all constructors us…
tzakharko 0f42347
Fixed the copy-paste typo in package namespace caching code
tzakharko bccd9d9
Creation of s2_geography object using wk_handle moved back to geograp…
tzakharko 8d65bb5
Add missing documentation for `use_altrep` parameter of `s2_geography…
tzakharko 3fbb713
Protect the ALTREP object
tzakharko f3be196
Remove extraneous tests
tzakharko 0a4b054
Minor changes to ALTREP object protection.
tzakharko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
s2_geography_serialize <- function(x) { | ||
wk::wk_handle( | ||
as_s2_geography(x), | ||
wk::wkb_writer(endian = 1L), | ||
s2_projection = NULL | ||
) | ||
} | ||
|
||
s2_geography_unserialize <- function(bytes) { | ||
wk::wk_handle( | ||
bytes, | ||
s2::s2_geography_writer( | ||
oriented = TRUE, | ||
check = FALSE, | ||
projection = NULL | ||
) | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#include <Rcpp.h> | ||
|
||
#include "s2geography.h" | ||
#include "s2-altrep.h" | ||
|
||
class RGeography { | ||
public: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#define R_NO_REMAP | ||
#include <R.h> | ||
#include <Rinternals.h> | ||
#include <Rversion.h> | ||
|
||
#include "s2-altrep.h" | ||
#include "util.h" | ||
|
||
// ALTREP implementation for s2_geography | ||
|
||
#if defined(S2_GEOGRAPHY_ALTREP) | ||
#include "R_ext/Altrep.h" | ||
R_altrep_class_t s2_geography_altrep_cls; | ||
|
||
static R_xlen_t s2_altrep_Length(SEXP obj) { | ||
SEXP data = R_altrep_data1(obj); | ||
return Rf_xlength(data); | ||
} | ||
|
||
static SEXP s2_altrep_Elt(SEXP obj, R_xlen_t i) { | ||
SEXP data = R_altrep_data1(obj); | ||
return VECTOR_ELT(data, i); | ||
} | ||
|
||
static SEXP s2_altrep_Serialized_state(SEXP obj) { | ||
// fetch the pointer to s2::s2_geography_serialize() | ||
SEXP fn = Rf_findFun(Rf_install("s2_geography_serialize"), s2_ns_pkg); | ||
|
||
SEXP call = PROTECT(Rf_lang2(fn, obj)); | ||
SEXP out = Rf_eval(call, s2_ns_pkg); | ||
|
||
UNPROTECT(1); | ||
return out; | ||
} | ||
|
||
static SEXP s2_altrep_Unserialize(SEXP cls, SEXP state) { | ||
// fetch the pointer to s2::s2_geography_unserialize() | ||
SEXP fn = Rf_findFun(Rf_install("s2_geography_unserialize"), s2_ns_pkg); | ||
|
||
SEXP call = PROTECT(Rf_lang2(fn, state)); | ||
SEXP out = Rf_eval(call, s2_ns_pkg); | ||
|
||
UNPROTECT(1); | ||
return out; | ||
} | ||
#endif | ||
|
||
// [[Rcpp::export]] | ||
SEXP make_s2_geography_altrep(SEXP list) { | ||
#if defined(S2_GEOGRAPHY_ALTREP) | ||
return R_new_altrep(s2_geography_altrep_cls, list, R_NilValue); | ||
#else | ||
// nothing to do | ||
return list; | ||
#endif | ||
} | ||
|
||
void s2_init_altrep(DllInfo *dll) { | ||
#if defined(S2_GEOGRAPHY_ALTREP) | ||
s2_geography_altrep_cls = R_make_altlist_class("s2_geography", "s2", dll); | ||
|
||
R_set_altrep_Length_method(s2_geography_altrep_cls, s2_altrep_Length); | ||
R_set_altlist_Elt_method(s2_geography_altrep_cls, s2_altrep_Elt); | ||
R_set_altrep_Serialized_state_method(s2_geography_altrep_cls, s2_altrep_Serialized_state); | ||
R_set_altrep_Unserialize_method(s2_geography_altrep_cls, s2_altrep_Unserialize); | ||
#endif | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef S2_ALTREP_H | ||
#define S2_ALTREP_H | ||
|
||
#include <Rcpp.h> | ||
#include <Rversion.h> | ||
|
||
// ALTREP VECSXP are supported starting from R 4.3.0 | ||
// | ||
// When compiling for an earlier target serialization support is disabled | ||
#if defined(R_VERSION) && R_VERSION >= R_Version(4, 3, 0) | ||
#define S2_GEOGRAPHY_ALTREP | ||
#endif | ||
|
||
void s2_init_altrep(DllInfo *dll); | ||
SEXP make_s2_geography_altrep(SEXP list); | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.