exports_cpp <- function(functions) {
NAME <- get_package_name()
name <- tolower(NAME)
glue_code(
'
// Generated by using torchexport::export() -> do not edit by hand
#include "<<name>>/<<name>>.h"
#include <lantern/types.h>
<<if(has_types_file()) types_file_include() else "">>
void * p_<<name>>_last_error = NULL;
<<NAME>>_API void* <<name>>_last_error()
{
return p_<<name>>_last_error;
}
<<NAME>>_API void <<name>>_last_error_clear()
{
p_<<name>>_last_error = NULL;
}
<<paste(functions, collapse = "\n")>>
'
)
}
exports_h <- function(declarations, wrappers) {
NAME <- get_package_name()
name <- tolower(NAME)
common = "#include \"common.h\""
glue_code(
'
// Generated by using torchexport::export() -> do not edit by hand
#pragma once
<<if (file.exists(paste0("./csrc/include/", name, "/common.h"))) common else "">>
#ifdef _WIN32
#ifndef <<NAME>>_HEADERS_ONLY
#define <<NAME>>_API extern "C" __declspec(dllexport)
#else
#define <<NAME>>_API extern "C" __declspec(dllimport)
#endif
#else
#define <<NAME>>_API extern "C"
#endif
#ifndef <<NAME>>_HANDLE_EXCEPTION
#define <<NAME>>_HANDLE_EXCEPTION \\\\\n
catch(const std::exception& ex) { \\\\\n
p_<<name>>_last_error = make_raw::string(ex.what()); \\\\\n
} catch (std::string& ex) { \\\\\n
p_<<name>>_last_error = make_raw::string(ex); \\\\\n
} catch (...) { \\\\\n
p_<<name>>_last_error = make_raw::string("Unknown error. "); \\\\\n
}
#endif
void host_exception_handler ();
extern void* p_<<name>>_last_error;
<<NAME>>_API void* <<name>>_last_error ();
<<NAME>>_API void <<name>>_last_error_clear();
<<paste(declarations, collapse = "\n")>>
#ifdef RCPP_VERSION
<<paste(wrappers, collapse = "\n")>>
#endif // RCPP_VERSION
'
)
}
exports_rcpp <- function(declarations) {
NAME <- get_package_name()
name <- tolower(NAME)
glue::glue(.open = "[[", .close = "]]",
'
// Generated by using torchexport::export() -> do not edit by hand
#include "exports.h"
#define [[NAME]]_HEADERS_ONLY
#include <[[name]]/[[name]].h>
[[paste(declarations, collapse="\n")]]
')
}
exports_rcpp_h <- function(declarations) {
NAME <- get_package_name()
name <- tolower(NAME)
glue::glue(.open = "[[", .close = "]]",
'
// Generated by using torchexport::export() -> do not edit by hand
#include <Rcpp.h>
#include <torch.h>
[[if (has_types_file(rcpp = TRUE)) types_file_include(rcpp = TRUE) else ""]]
[[paste(declarations, collapse="\n")]]
')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.