Skip to content

Commit

Permalink
better iteration for fs
Browse files Browse the repository at this point in the history
  • Loading branch information
CreRecombinase committed Aug 22, 2018
1 parent b7a90c6 commit f63865f
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 8 deletions.
16 changes: 16 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ create_file_h5 <- function(filename) {
invisible(.Call(`_EigenH5_create_file_h5`, filename))
}

par_path <- function(filename) {
.Call(`_EigenH5_par_path`, filename)
}

par_iter_path <- function(filename) {
.Call(`_EigenH5_par_iter_path`, filename)
}

exp_par_iter_path <- function(filename) {
.Call(`_EigenH5_exp_par_iter_path`, filename)
}

exp_par_path <- function(filename) {
.Call(`_EigenH5_exp_par_path`, filename)
}

dataset_chunks <- function(filename, datapath) {
.Call(`_EigenH5_dataset_chunks`, filename, datapath)
}
Expand Down
4 changes: 2 additions & 2 deletions inst/include/EigenH5.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#if __has_include(<filesystem>)

//#include <filesystem>
# include <experimental/filesystem>
# include <filesystem>
namespace stdx {
using namespace ::std;
using namespace ::std::experimental;
//using namespace ::std::experimental;
}
#elif __has_include(<experimental/filesystem>)
# include <experimental/filesystem>
Expand Down
84 changes: 84 additions & 0 deletions inst/include/EigenH5_RcppExports.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,90 @@ namespace EigenH5 {
throw Rcpp::exception(Rcpp::as<std::string>(rcpp_result_gen).c_str());
}

inline Rcpp::StringVector par_path(const std::string filename) {
typedef SEXP(*Ptr_par_path)(SEXP);
static Ptr_par_path p_par_path = NULL;
if (p_par_path == NULL) {
validateSignature("Rcpp::StringVector(*par_path)(const std::string)");
p_par_path = (Ptr_par_path)R_GetCCallable("EigenH5", "_EigenH5_par_path");
}
RObject rcpp_result_gen;
{
RNGScope RCPP_rngScope_gen;
rcpp_result_gen = p_par_path(Shield<SEXP>(Rcpp::wrap(filename)));
}
if (rcpp_result_gen.inherits("interrupted-error"))
throw Rcpp::internal::InterruptedException();
if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen))
throw Rcpp::LongjumpException(rcpp_result_gen);
if (rcpp_result_gen.inherits("try-error"))
throw Rcpp::exception(Rcpp::as<std::string>(rcpp_result_gen).c_str());
return Rcpp::as<Rcpp::StringVector >(rcpp_result_gen);
}

inline Rcpp::StringVector par_iter_path(const std::string filename) {
typedef SEXP(*Ptr_par_iter_path)(SEXP);
static Ptr_par_iter_path p_par_iter_path = NULL;
if (p_par_iter_path == NULL) {
validateSignature("Rcpp::StringVector(*par_iter_path)(const std::string)");
p_par_iter_path = (Ptr_par_iter_path)R_GetCCallable("EigenH5", "_EigenH5_par_iter_path");
}
RObject rcpp_result_gen;
{
RNGScope RCPP_rngScope_gen;
rcpp_result_gen = p_par_iter_path(Shield<SEXP>(Rcpp::wrap(filename)));
}
if (rcpp_result_gen.inherits("interrupted-error"))
throw Rcpp::internal::InterruptedException();
if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen))
throw Rcpp::LongjumpException(rcpp_result_gen);
if (rcpp_result_gen.inherits("try-error"))
throw Rcpp::exception(Rcpp::as<std::string>(rcpp_result_gen).c_str());
return Rcpp::as<Rcpp::StringVector >(rcpp_result_gen);
}

inline Rcpp::StringVector exp_par_iter_path(const std::string filename) {
typedef SEXP(*Ptr_exp_par_iter_path)(SEXP);
static Ptr_exp_par_iter_path p_exp_par_iter_path = NULL;
if (p_exp_par_iter_path == NULL) {
validateSignature("Rcpp::StringVector(*exp_par_iter_path)(const std::string)");
p_exp_par_iter_path = (Ptr_exp_par_iter_path)R_GetCCallable("EigenH5", "_EigenH5_exp_par_iter_path");
}
RObject rcpp_result_gen;
{
RNGScope RCPP_rngScope_gen;
rcpp_result_gen = p_exp_par_iter_path(Shield<SEXP>(Rcpp::wrap(filename)));
}
if (rcpp_result_gen.inherits("interrupted-error"))
throw Rcpp::internal::InterruptedException();
if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen))
throw Rcpp::LongjumpException(rcpp_result_gen);
if (rcpp_result_gen.inherits("try-error"))
throw Rcpp::exception(Rcpp::as<std::string>(rcpp_result_gen).c_str());
return Rcpp::as<Rcpp::StringVector >(rcpp_result_gen);
}

inline Rcpp::StringVector exp_par_path(const std::string filename) {
typedef SEXP(*Ptr_exp_par_path)(SEXP);
static Ptr_exp_par_path p_exp_par_path = NULL;
if (p_exp_par_path == NULL) {
validateSignature("Rcpp::StringVector(*exp_par_path)(const std::string)");
p_exp_par_path = (Ptr_exp_par_path)R_GetCCallable("EigenH5", "_EigenH5_exp_par_path");
}
RObject rcpp_result_gen;
{
RNGScope RCPP_rngScope_gen;
rcpp_result_gen = p_exp_par_path(Shield<SEXP>(Rcpp::wrap(filename)));
}
if (rcpp_result_gen.inherits("interrupted-error"))
throw Rcpp::internal::InterruptedException();
if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen))
throw Rcpp::LongjumpException(rcpp_result_gen);
if (rcpp_result_gen.inherits("try-error"))
throw Rcpp::exception(Rcpp::as<std::string>(rcpp_result_gen).c_str());
return Rcpp::as<Rcpp::StringVector >(rcpp_result_gen);
}

inline Rcpp::IntegerVector dataset_chunks(const std::string filename, const std::string datapath) {
typedef SEXP(*Ptr_dataset_chunks)(SEXP,SEXP);
static Ptr_dataset_chunks p_dataset_chunks = NULL;
Expand Down
14 changes: 8 additions & 6 deletions inst/include/highfive/bits/H5Node_traits_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,19 +366,22 @@ inline bool NodeTraits<Derivate>::exist(fs::path p) const {
return(true);
}
}

if(p==dotp){
return(true);
}

if(p.empty()){
HDF5ErrMapper::ToException<GroupException>(std::string("Cannot check for existence of an empty path"));
}

const auto ttid=static_cast<const Derivate*>(this)->getId();

auto ip = p.begin();
fs::path tp;
do{
if(*ip!=dotp){
tp/=*ip;

for(auto &ip:p){
if(ip!=dotp){
tp/=ip;
if(tp!=rootp){
htri_t val = H5Lexists(ttid,tp.c_str(), H5P_DEFAULT);
if(val<0){
Expand All @@ -388,8 +391,7 @@ inline bool NodeTraits<Derivate>::exist(fs::path p) const {
}
}
}
ip++;
}while(ip!=p.end());
}

return(true);
}
Expand Down
148 changes: 148 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,142 @@ RcppExport SEXP _EigenH5_create_file_h5(SEXP filenameSEXP) {
UNPROTECT(1);
return rcpp_result_gen;
}
// par_path
Rcpp::StringVector par_path(const std::string filename);
static SEXP _EigenH5_par_path_try(SEXP filenameSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::traits::input_parameter< const std::string >::type filename(filenameSEXP);
rcpp_result_gen = Rcpp::wrap(par_path(filename));
return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _EigenH5_par_path(SEXP filenameSEXP) {
SEXP rcpp_result_gen;
{
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = PROTECT(_EigenH5_par_path_try(filenameSEXP));
}
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
if (rcpp_isInterrupt_gen) {
UNPROTECT(1);
Rf_onintr();
}
bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
if (rcpp_isLongjump_gen) {
Rcpp::internal::resumeJump(rcpp_result_gen);
}
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
if (rcpp_isError_gen) {
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
UNPROTECT(1);
Rf_error(CHAR(rcpp_msgSEXP_gen));
}
UNPROTECT(1);
return rcpp_result_gen;
}
// par_iter_path
Rcpp::StringVector par_iter_path(const std::string filename);
static SEXP _EigenH5_par_iter_path_try(SEXP filenameSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::traits::input_parameter< const std::string >::type filename(filenameSEXP);
rcpp_result_gen = Rcpp::wrap(par_iter_path(filename));
return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _EigenH5_par_iter_path(SEXP filenameSEXP) {
SEXP rcpp_result_gen;
{
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = PROTECT(_EigenH5_par_iter_path_try(filenameSEXP));
}
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
if (rcpp_isInterrupt_gen) {
UNPROTECT(1);
Rf_onintr();
}
bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
if (rcpp_isLongjump_gen) {
Rcpp::internal::resumeJump(rcpp_result_gen);
}
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
if (rcpp_isError_gen) {
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
UNPROTECT(1);
Rf_error(CHAR(rcpp_msgSEXP_gen));
}
UNPROTECT(1);
return rcpp_result_gen;
}
// exp_par_iter_path
Rcpp::StringVector exp_par_iter_path(const std::string filename);
static SEXP _EigenH5_exp_par_iter_path_try(SEXP filenameSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::traits::input_parameter< const std::string >::type filename(filenameSEXP);
rcpp_result_gen = Rcpp::wrap(exp_par_iter_path(filename));
return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _EigenH5_exp_par_iter_path(SEXP filenameSEXP) {
SEXP rcpp_result_gen;
{
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = PROTECT(_EigenH5_exp_par_iter_path_try(filenameSEXP));
}
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
if (rcpp_isInterrupt_gen) {
UNPROTECT(1);
Rf_onintr();
}
bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
if (rcpp_isLongjump_gen) {
Rcpp::internal::resumeJump(rcpp_result_gen);
}
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
if (rcpp_isError_gen) {
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
UNPROTECT(1);
Rf_error(CHAR(rcpp_msgSEXP_gen));
}
UNPROTECT(1);
return rcpp_result_gen;
}
// exp_par_path
Rcpp::StringVector exp_par_path(const std::string filename);
static SEXP _EigenH5_exp_par_path_try(SEXP filenameSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::traits::input_parameter< const std::string >::type filename(filenameSEXP);
rcpp_result_gen = Rcpp::wrap(exp_par_path(filename));
return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _EigenH5_exp_par_path(SEXP filenameSEXP) {
SEXP rcpp_result_gen;
{
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = PROTECT(_EigenH5_exp_par_path_try(filenameSEXP));
}
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
if (rcpp_isInterrupt_gen) {
UNPROTECT(1);
Rf_onintr();
}
bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
if (rcpp_isLongjump_gen) {
Rcpp::internal::resumeJump(rcpp_result_gen);
}
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
if (rcpp_isError_gen) {
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
UNPROTECT(1);
Rf_error(CHAR(rcpp_msgSEXP_gen));
}
UNPROTECT(1);
return rcpp_result_gen;
}
// dataset_chunks
Rcpp::IntegerVector dataset_chunks(const std::string filename, const std::string datapath);
static SEXP _EigenH5_dataset_chunks_try(SEXP filenameSEXP, SEXP datapathSEXP) {
Expand Down Expand Up @@ -1026,6 +1162,10 @@ static int _EigenH5_RcppExport_validate(const char* sig) {
signatures.insert("SEXP(*read_attribute_h5)(const std::string&,std::string)");
signatures.insert("bool(*create_dataset_h5)(const std::string&,std::string,const RObject&,Rcpp::List)");
signatures.insert("void(*create_file_h5)(const std::string)");
signatures.insert("Rcpp::StringVector(*par_path)(const std::string)");
signatures.insert("Rcpp::StringVector(*par_iter_path)(const std::string)");
signatures.insert("Rcpp::StringVector(*exp_par_iter_path)(const std::string)");
signatures.insert("Rcpp::StringVector(*exp_par_path)(const std::string)");
signatures.insert("Rcpp::IntegerVector(*dataset_chunks)(const std::string,const std::string)");
signatures.insert("void(*extend_dataset)(const std::string,const std::string,Rcpp::IntegerVector)");
signatures.insert("void(*extend_dataset_by)(const std::string,const std::string,Rcpp::IntegerVector)");
Expand Down Expand Up @@ -1060,6 +1200,10 @@ RcppExport SEXP _EigenH5_RcppExport_registerCCallable() {
R_RegisterCCallable("EigenH5", "_EigenH5_read_attribute_h5", (DL_FUNC)_EigenH5_read_attribute_h5_try);
R_RegisterCCallable("EigenH5", "_EigenH5_create_dataset_h5", (DL_FUNC)_EigenH5_create_dataset_h5_try);
R_RegisterCCallable("EigenH5", "_EigenH5_create_file_h5", (DL_FUNC)_EigenH5_create_file_h5_try);
R_RegisterCCallable("EigenH5", "_EigenH5_par_path", (DL_FUNC)_EigenH5_par_path_try);
R_RegisterCCallable("EigenH5", "_EigenH5_par_iter_path", (DL_FUNC)_EigenH5_par_iter_path_try);
R_RegisterCCallable("EigenH5", "_EigenH5_exp_par_iter_path", (DL_FUNC)_EigenH5_exp_par_iter_path_try);
R_RegisterCCallable("EigenH5", "_EigenH5_exp_par_path", (DL_FUNC)_EigenH5_exp_par_path_try);
R_RegisterCCallable("EigenH5", "_EigenH5_dataset_chunks", (DL_FUNC)_EigenH5_dataset_chunks_try);
R_RegisterCCallable("EigenH5", "_EigenH5_extend_dataset", (DL_FUNC)_EigenH5_extend_dataset_try);
R_RegisterCCallable("EigenH5", "_EigenH5_extend_dataset_by", (DL_FUNC)_EigenH5_extend_dataset_by_try);
Expand Down Expand Up @@ -1096,6 +1240,10 @@ static const R_CallMethodDef CallEntries[] = {
{"_EigenH5_create_dataset_h5", (DL_FUNC) &_EigenH5_create_dataset_h5, 4},
{"_EigenH5_split_ldd", (DL_FUNC) &_EigenH5_split_ldd, 1},
{"_EigenH5_create_file_h5", (DL_FUNC) &_EigenH5_create_file_h5, 1},
{"_EigenH5_par_path", (DL_FUNC) &_EigenH5_par_path, 1},
{"_EigenH5_par_iter_path", (DL_FUNC) &_EigenH5_par_iter_path, 1},
{"_EigenH5_exp_par_iter_path", (DL_FUNC) &_EigenH5_exp_par_iter_path, 1},
{"_EigenH5_exp_par_path", (DL_FUNC) &_EigenH5_exp_par_path, 1},
{"_EigenH5_dataset_chunks", (DL_FUNC) &_EigenH5_dataset_chunks, 2},
{"_EigenH5_extend_dataset", (DL_FUNC) &_EigenH5_extend_dataset, 3},
{"_EigenH5_extend_dataset_by", (DL_FUNC) &_EigenH5_extend_dataset_by, 3},
Expand Down
34 changes: 34 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,42 @@ void create_file_h5(const std::string filename){
HighFive::File file(filename,HighFive::File::Create);
}

//[[Rcpp::export]]
Rcpp::StringVector par_path(const std::string filename){
std::filesystem::path pt(filename);

return(Rcpp::wrap(pt.parent_path().string()));
}

//[[Rcpp::export]]
Rcpp::StringVector par_iter_path(const std::string filename){
std::filesystem::path pt(filename);
std::vector<std::string> retvec;
for(auto it = pt.begin(); it!=pt.end();it++){
retvec.push_back(it->string());
}
return(Rcpp::wrap(retvec));
}

//[[Rcpp::export]]
Rcpp::StringVector exp_par_iter_path(const std::string filename){
std::experimental::filesystem::path pt(filename);
std::vector<std::string> retvec;
for(auto it = pt.begin(); it!=pt.end();it++){
retvec.push_back(it->string());
}
return(Rcpp::wrap(retvec));
}




//[[Rcpp::export]]
Rcpp::StringVector exp_par_path(const std::string filename){
std::experimental::filesystem::path pt(filename);

return(Rcpp::wrap(pt.parent_path().string()));
}

//[[Rcpp::export]]
Rcpp::IntegerVector dataset_chunks(const std::string filename,
Expand Down

0 comments on commit f63865f

Please sign in to comment.