Giter Site home page Giter Site logo

Register C Callable about geodist HOT 5 OPEN

dcooley avatar dcooley commented on June 11, 2024 1
Register C Callable

from geodist.

Comments (5)

mpadge avatar mpadge commented on June 11, 2024 1

I'm happy to leave this issue open for a while. I'll attend to some others first, and then slowly come around to this. Thanks for the impetus!

from geodist.

mpadge avatar mpadge commented on June 11, 2024

All grand by me, but with one caveat: The number of exposed functions is actually pretty huge: geodist_init.c lists them all:

extern SEXP R_cheap(SEXP);
extern SEXP R_cheap_paired(SEXP, SEXP);
extern SEXP R_cheap_paired_vec(SEXP, SEXP, SEXP, SEXP);
extern SEXP R_cheap_range(SEXP);
extern SEXP R_cheap_seq(SEXP);
extern SEXP R_cheap_seq_range(SEXP);
extern SEXP R_cheap_seq_vec(SEXP, SEXP);
extern SEXP R_cheap_vec(SEXP, SEXP);
extern SEXP R_cheap_xy(SEXP, SEXP);
extern SEXP R_cheap_xy_range(SEXP, SEXP);
extern SEXP R_cheap_xy_vec(SEXP, SEXP, SEXP, SEXP);
extern SEXP R_geodesic(SEXP);
extern SEXP R_geodesic_paired(SEXP, SEXP);
extern SEXP R_geodesic_paired_vec(SEXP, SEXP, SEXP, SEXP);
extern SEXP R_geodesic_range(SEXP);
extern SEXP R_geodesic_seq(SEXP);
extern SEXP R_geodesic_seq_range(SEXP);
extern SEXP R_geodesic_seq_vec(SEXP, SEXP);
extern SEXP R_geodesic_vec(SEXP, SEXP);
extern SEXP R_geodesic_xy(SEXP, SEXP);
extern SEXP R_geodesic_xy_range(SEXP, SEXP);
extern SEXP R_geodesic_xy_vec(SEXP, SEXP, SEXP, SEXP);
extern SEXP R_haversine(SEXP);
extern SEXP R_haversine_paired(SEXP, SEXP);
extern SEXP R_haversine_paired_vec(SEXP, SEXP, SEXP, SEXP);
extern SEXP R_haversine_range(SEXP);
extern SEXP R_haversine_seq(SEXP);
extern SEXP R_haversine_seq_range(SEXP);
extern SEXP R_haversine_seq_vec(SEXP, SEXP);
extern SEXP R_haversine_vec(SEXP, SEXP);
extern SEXP R_haversine_xy(SEXP, SEXP);
extern SEXP R_haversine_xy_range(SEXP, SEXP);
extern SEXP R_haversine_xy_vec(SEXP, SEXP, SEXP, SEXP);
extern SEXP R_vincenty(SEXP);
extern SEXP R_vincenty_paired(SEXP, SEXP);
extern SEXP R_vincenty_paired_vec(SEXP, SEXP, SEXP, SEXP);
extern SEXP R_vincenty_range(SEXP);
extern SEXP R_vincenty_seq(SEXP);
extern SEXP R_vincenty_seq_range(SEXP);
extern SEXP R_vincenty_seq_vec(SEXP, SEXP);
extern SEXP R_vincenty_vec(SEXP, SEXP);
extern SEXP R_vincenty_xy(SEXP, SEXP);
extern SEXP R_vincenty_xy_range(SEXP, SEXP);
extern SEXP R_vincenty_xy_vec(SEXP, SEXP, SEXP, SEXP);

Each one is a particular combination of input params. Exposing those would induce some safety compromises, as the code currently relies very strongly on the R-side per-processing to ensure the appropriate C routine is called. That means the code does no checking of arguments at all in any C routine. Direct passing of arbitrary inputs would almost certainly raise problems, and at the least, I'd first have to implement a bunch of C-level code to ensure sane inputs, and doing that would likely slow calculations down somewhat, so there would also be potential disadvantages there. Note also that some SEXPs are assumed to be vectors, while others are assumed to be stored as matrices. R knows no difference between these, but the geodist code sometimes assumes indexing into vectors-as-2-column-matrices, and other times not. All of that would have to be controlled, and there may well be cases where such checking at the C-level might just not be possible.

I don't mean to be obstructive here, and i definitely do think this is a good idea, but would be interested to first have your insights into some of these concerns?

from geodist.

mdsumner avatar mdsumner commented on June 11, 2024

(All interesting stuff for me, just went through my first example and learnt heaps thanks both)

from geodist.

mpadge avatar mpadge commented on June 11, 2024

An alternative would be for me to write a C-level meta-wrapper around all of those internal functions. The latter could then be left so, and the exposed bit used to funnel the right combinations of SEXP elements to the right internal calls, just as the current R code does. That should be fairly straightforward.

from geodist.

dcooley avatar dcooley commented on June 11, 2024

You bring up some valid concerns for sure. And I think your suggested C-level API would be an easier solution. But, having brought up this issue, I have no real need for it yet, so don't feel like you're required to do this :)

from geodist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.