From 4403cd32196261ddbb3692a1b8d208f3261854ae Mon Sep 17 00:00:00 2001 From: nwknoblauch Date: Sat, 25 Aug 2018 15:29:37 -0500 Subject: [PATCH] removed future as requirement --- DESCRIPTION | 4 +- R/RcppExports.R | 4 - R/future.R | 29 ---- inst/include/EigenH5.h | 4 + inst/include/highfive/H5DataSpace.hpp | 120 ++++++------- .../highfive/bits/H5Converter_misc.hpp | 53 +++++- .../highfive/bits/H5Dataspace_misc.hpp | 36 ++-- src/RcppExports.cpp | 20 --- src/sexp_io.cpp | 40 ++--- src/sexp_utils.cpp | 16 -- src/singleton.cpp | 26 --- src/split_ld_region.cpp | 158 ------------------ src/test-eigen.cpp | 38 ----- tests/testthat/test_compression.R | 32 ++-- tests/testthat/test_future.R | 36 ---- tests/testthat/test_h5.R | 9 +- tests/testthat/test_vec.R | 18 +- 17 files changed, 184 insertions(+), 459 deletions(-) delete mode 100644 R/future.R delete mode 100644 src/sexp_utils.cpp delete mode 100644 src/singleton.cpp delete mode 100644 src/split_ld_region.cpp delete mode 100644 src/test-eigen.cpp delete mode 100644 tests/testthat/test_future.R diff --git a/DESCRIPTION b/DESCRIPTION index 6a84ac6..1d9fcd5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,9 +7,9 @@ Author: Nicholas Knoblauch Maintainer: Nicholas Knoblauch Description: Read and write R objects using blosc+HDF5. Also contains a C++ interface for using with other packages. The C++ interface can handle the reading/writing/converting between column-major matrices (as in R/fortran) and row-major matrices (as in HDF5) License: What license is it under? -Imports: Rcpp (>= 0.12.12), RcppEigen (>= 0.3.3.3.0),BH,dplyr,progress,tidyr,purrr,magrittr,future +Imports: Rcpp (>= 0.12.12), RcppEigen (>= 0.3.3.3.0),BH,dplyr,progress,tidyr,purrr,magrittr LinkingTo: Rcpp, RcppEigen,BH,RcppProgress,testthat -SystemRequirements: C++11, HDF5 (>= 1.8.13), c-blosc, zstd +SystemRequirements: C++11, HDF5 (>= 1.8.13), blosc, zstd Suggests: testthat, knitr, rmarkdown diff --git a/R/RcppExports.R b/R/RcppExports.R index b12b3b4..bc879d3 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -53,10 +53,6 @@ create_dataset_h5 <- function(filename, datapath, data, options) { .Call(`_EigenH5_create_dataset_h5`, filename, datapath, data, options) } -split_ldd <- function(region_ids) { - .Call(`_EigenH5_split_ldd`, region_ids) -} - create_file_h5 <- function(filename) { invisible(.Call(`_EigenH5_create_file_h5`, filename)) } diff --git a/R/future.R b/R/future.R deleted file mode 100644 index c1170ee..0000000 --- a/R/future.R +++ /dev/null @@ -1,29 +0,0 @@ -# read_mat_col_futures<- function(h5filename,filepath,subset_cols=list(),doTranspose=F){ -# n_futures <- length(subset_cols) -# stopifnot(n_futures>0) -# # retl <- listenv::listenv() -# if(doTranspose){ -# return(purrr::map(subset_cols,~future::future(t(EigenH5::read_matrix(h5filename,filepath,subset_cols=.x)),packages="EigenH5"))) -# }else{ -# return(purrr::map(subset_cols,~future::future(EigenH5::read_matrix(h5filename,filepath,subset_cols=.x),packages="EigenH5"))) -# } -# } -# -# read_df_futures <- function(h5filename,filepath,subcols=character(),filtervec=list()){ -# return(purrr::map(filtervec,~future::future(EigenH5::read_df_h5(h5filename,subcols=subcols,filepath,filtervec=.x)),packages="EigenH5")) -# } -# -# read_mat_row_futures<- function(h5filename,filepath,subset_rows=list(),doTranspose=F){ -# n_futures <- length(subset_rows) -# stopifnot(n_futures>0) -# # retl <- listenv::listenv() -# if(doTranspose){ -# return(purrr::map(subset_rows,~future::future(t(EigenH5::read_matrix(h5filename,filepath,subset_rows=.x)),packages="EigenH5"))) -# }else{ -# return(purrr::map(subset_rows,~future::future(EigenH5::read_matrix(h5filename,filepath,subset_rows=.x),packages="EigenH5"))) -# } -# } -# -# read_vec_futures <- function(h5filename,filepath,subset=list()){ -# return(purrr::map(subset,~future::future(EigenH5::read_vector(h5filename,filepath,subset=.x)),packages="EigenH5")) -# } diff --git a/inst/include/EigenH5.h b/inst/include/EigenH5.h index 8559381..e3fe4b5 100644 --- a/inst/include/EigenH5.h +++ b/inst/include/EigenH5.h @@ -59,6 +59,10 @@ class FileManager{ +inline stdx::filesystem::path root_path(const std::string & input){ + return(stdx::filesystem::path("/") / stdx::filesystem::path(input)); +} + template struct cpp2r{ diff --git a/inst/include/highfive/H5DataSpace.hpp b/inst/include/highfive/H5DataSpace.hpp index 57d1638..aa44d67 100644 --- a/inst/include/highfive/H5DataSpace.hpp +++ b/inst/include/highfive/H5DataSpace.hpp @@ -37,92 +37,92 @@ class DataSpace : public Object { // simple dataspace are handle directly from their dimensions }; - /// create a dataspace of N-dimensions - /// Each dimension is configured this way - /// size(dim1) = vec[0] - /// size(dim2) = vec[1] - /// etc... - explicit DataSpace(const std::vector &dims); + /// create a dataspace of N-dimensions + /// Each dimension is configured this way + /// size(dim1) = vec[0] + /// size(dim2) = vec[1] + /// etc... + explicit DataSpace(const std::vector &dims); /// create a dataspace of N-dimensions , with max dimensions explicit DataSpace(const std::vector &dims,const std::vector &max_dims); - /// - /// \brief DataSpace create a dataspace of a single dimension and of size - /// dim1 - /// \param dim1 - /// - explicit DataSpace(size_t dim1); + /// + /// \brief DataSpace create a dataspace of a single dimension and of size + /// dim1 + /// \param dim1 + /// + explicit DataSpace(size_t dim1); - /// - /// \brief DataSpace create a scalar dataspace or a null dataset - /// - explicit DataSpace(DataspaceType dtype); + /// + /// \brief DataSpace create a scalar dataspace or a null dataset + /// + explicit DataSpace(DataspaceType dtype); - /// Create a new DataSpace - /// with a different id avaiable for modifications - DataSpace clone() const; + /// Create a new DataSpace + /// with a different id avaiable for modifications + DataSpace clone() const; - /// - /// \brief getNumberDimensions - /// \return the number of dimensions in the current dataspace - /// - size_t getNumberDimensions() const; + /// + /// \brief getNumberDimensions + /// \return the number of dimensions in the current dataspace + /// + size_t getNumberDimensions() const; - /// \brief getDimensions - /// \return return a vector of N-element, each element is the size of the - /// associated dataset dimension - std::vector getDimensions() const; + /// \brief getDimensions + /// \return return a vector of N-element, each element is the size of the + /// associated dataset dimension + std::vector getDimensions() const; - std::vector getMaxDimensions() const ; + std::vector getMaxDimensions() const; - /// Create a dataspace matching a single element of a basic type - /// supported type are integrals (int,long), floating points (float,double) - /// and std::string - template - static DataSpace From(const ScalarValue& scalar_value); + /// Create a dataspace matching a single element of a basic type + /// supported type are integrals (int,long), floating points (float,double) + /// and std::string + template + static DataSpace From(const ScalarValue& scalar_value); - template - static DataSpace From(const Eigen::Matrix &mat); + template + static DataSpace From(const Eigen::Matrix &mat); - template - static DataSpace - From(const Eigen::Map > &mat); + template + static DataSpace + From(const Eigen::Map > &mat); - template - static DataSpace - From(const Eigen::Map > &mat); + template + static DataSpace + From(const Eigen::Map > &mat); - /// Create a dataspace matching the container dimensions and size - /// Supported Containers are: - /// - vector of fundamental types - /// - vector of std::string - /// - boost::multi_array - template - static DataSpace From(const std::vector& vec); + /// Create a dataspace matching the container dimensions and size + /// Supported Containers are: + /// - vector of fundamental types + /// - vector of std::string + /// - boost::multi_array + template + static DataSpace From(const std::vector& vec); #ifdef H5_USE_BOOST - template - static DataSpace From(const boost::multi_array& container); + template + static DataSpace From(const boost::multi_array& container); - template - static DataSpace From(const boost::numeric::ublas::matrix& mat); + template + static DataSpace From(const boost::numeric::ublas::matrix& mat); - template - static DataSpace From(const boost::numeric::ublas::matrix& mat); + template + static DataSpace From(const boost::numeric::ublas::matrix& mat); #endif - protected: - explicit DataSpace(); +protected: + explicit DataSpace(); - friend class Attribute; - friend class File; - friend class DataSet; + friend class Attribute; + friend class File; + friend class DataSet; }; } diff --git a/inst/include/highfive/bits/H5Converter_misc.hpp b/inst/include/highfive/bits/H5Converter_misc.hpp index 516bd1d..55bc002 100644 --- a/inst/include/highfive/bits/H5Converter_misc.hpp +++ b/inst/include/highfive/bits/H5Converter_misc.hpp @@ -364,13 +364,6 @@ namespace HighFive { }; - - - - - - - #ifdef H5_USE_BOOST // apply conversion to boost multi array template @@ -587,6 +580,49 @@ namespace HighFive { DataSpace &_space; }; + template <> +struct data_converter, void> { + inline data_converter(std::vector& vec, DataSpace& space) + : _space(space) { + (void)vec; + } + + // create a C vector adapted to HDF5 + // fill last element with NULL to identify end + inline char** transform_read(std::vector& vec) { + (void)vec; + _c_vec.resize(_space.getDimensions()[0], NULL); + return (&_c_vec[0]); + } + + // static inline char* char_converter(const std::string& str) { + // return const_cast(str.c_str()); + // } + + inline char** transform_write(std::vector& vec) { + // _c_vec.resize(vec.size() + 1, NULL); + // std::transform(vec.begin(), vec.end(), _c_vec.begin(), &char_converter); + return (vec.data()); + } + + inline void process_result(std::vector& vec) { + (void)vec; + vec.resize(_c_vec.size()); + for (size_t i = 0; i < vec.size(); ++i) { + vec[i] = _c_vec[i]; + } + + if (_c_vec.empty() == false && _c_vec[0] != NULL) { + AtomicType str_type; + (void)H5Dvlen_reclaim(str_type.getId(), _space.getId(), H5P_DEFAULT, + &(_c_vec[0])); + } + } + + std::vector _c_vec; + DataSpace& _space; + }; + // template<> // struct data_converter, void> { // inline data_converter(std::vector &vec, DataSpace &space,const size_t dim=0) @@ -619,8 +655,7 @@ namespace HighFive { // } // } - // std::vector _c_vec; - // const size_t dim_; + // std::vector _c_vec; // DataSpace &_space; // }; diff --git a/inst/include/highfive/bits/H5Dataspace_misc.hpp b/inst/include/highfive/bits/H5Dataspace_misc.hpp index c99cfab..3616eba 100644 --- a/inst/include/highfive/bits/H5Dataspace_misc.hpp +++ b/inst/include/highfive/bits/H5Dataspace_misc.hpp @@ -145,26 +145,26 @@ inline DataSpace DataSpace::From(const std::vector& container) { return DataSpace(details::get_dim_vector(container)); } - template - inline DataSpace - DataSpace::From(const Eigen::Matrix &mat) { - auto retv = details::get_dim_vector(mat); - return (DataSpace(retv)); - } + template + inline DataSpace + DataSpace::From(const Eigen::Matrix &mat) { + auto retv = details::get_dim_vector(mat); + return (DataSpace(retv)); + } - template - inline DataSpace - DataSpace::From(const Eigen::Map > &mat) { - auto retv = details::get_dim_vector(mat); - return (DataSpace(retv)); - } + template + inline DataSpace + DataSpace::From(const Eigen::Map > &mat) { + auto retv = details::get_dim_vector(mat); + return (DataSpace(retv)); + } - template - inline DataSpace - DataSpace::From(const Eigen::Map > &mat) { - auto retv = details::get_dim_vector(mat); - return (DataSpace(retv)); - } + template + inline DataSpace + DataSpace::From(const Eigen::Map > &mat) { + auto retv = details::get_dim_vector(mat); + return (DataSpace(retv)); + } diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index d9c1851..1614983 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -472,17 +472,6 @@ RcppExport SEXP _EigenH5_create_dataset_h5(SEXP filenameSEXP, SEXP datapathSEXP, UNPROTECT(1); return rcpp_result_gen; } -// split_ldd -Rcpp::IntegerMatrix split_ldd(const std::vector& region_ids); -RcppExport SEXP _EigenH5_split_ldd(SEXP region_idsSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const std::vector& >::type region_ids(region_idsSEXP); - rcpp_result_gen = Rcpp::wrap(split_ldd(region_ids)); - return rcpp_result_gen; -END_RCPP -} // create_file_h5 void create_file_h5(const std::string filename); static SEXP _EigenH5_create_file_h5_try(SEXP filenameSEXP) { @@ -1078,10 +1067,6 @@ RcppExport SEXP _EigenH5_RcppExport_registerCCallable() { return R_NilValue; } -RcppExport SEXP _EigenH5_exp_par_iter_path(SEXP); -RcppExport SEXP _EigenH5_exp_par_path(SEXP); -RcppExport SEXP _EigenH5_par_iter_path(SEXP); -RcppExport SEXP _EigenH5_par_path(SEXP); RcppExport SEXP run_testthat_tests(); static const R_CallMethodDef CallEntries[] = { @@ -1098,7 +1083,6 @@ static const R_CallMethodDef CallEntries[] = { {"_EigenH5_write_attribute_h5", (DL_FUNC) &_EigenH5_write_attribute_h5, 3}, {"_EigenH5_read_attribute_h5", (DL_FUNC) &_EigenH5_read_attribute_h5, 2}, {"_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_dataset_chunks", (DL_FUNC) &_EigenH5_dataset_chunks, 2}, {"_EigenH5_extend_dataset", (DL_FUNC) &_EigenH5_extend_dataset, 3}, @@ -1115,10 +1099,6 @@ static const R_CallMethodDef CallEntries[] = { {"_EigenH5_dim_h5", (DL_FUNC) &_EigenH5_dim_h5, 2}, {"_EigenH5_concat_mats", (DL_FUNC) &_EigenH5_concat_mats, 4}, {"_EigenH5_RcppExport_registerCCallable", (DL_FUNC) &_EigenH5_RcppExport_registerCCallable, 0}, - {"_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_par_iter_path", (DL_FUNC) &_EigenH5_par_iter_path, 1}, - {"_EigenH5_par_path", (DL_FUNC) &_EigenH5_par_path, 1}, {"run_testthat_tests", (DL_FUNC) &run_testthat_tests, 0}, {NULL, NULL, 0} }; diff --git a/src/sexp_io.cpp b/src/sexp_io.cpp index 71b57aa..f6a26b1 100644 --- a/src/sexp_io.cpp +++ b/src/sexp_io.cpp @@ -349,7 +349,7 @@ std::vector dataset_dims(std::string filename, std::string datapath){ namespace fs = stdx::filesystem; - fs::path dp=datapath; + fs::path dp= root_path(datapath); HighFive::File file(filename,HighFive::File::ReadOnly); if(auto grp =file.openGroup(dp.parent_path())){ if(auto dset = grp->openDataSet(dp.filename())){ @@ -368,7 +368,7 @@ SEXP read_vector(std::string filename, Rcpp::List options){ using namespace Rcpp; namespace fs = stdx::filesystem; - fs::path dp=datapath; + fs::path dp=root_path(datapath); HighFive::File file(filename,HighFive::File::ReadOnly); @@ -428,7 +428,8 @@ SEXP read_matrix(std::string filename, namespace fs = stdx::filesystem; HighFive::File file(filename,HighFive::File::ReadOnly); - fs::path dp=datapath; + fs::path dp= root_path(datapath); + auto dset = file.getDataSet(datapath); auto dims = dset.getDataDimensions(); auto datasel = DatasetSelection<2>::ProcessList(options,dims); @@ -470,10 +471,10 @@ bool update_matrix(RObject data, const Rcpp::List &options){ using namespace Rcpp; namespace fs = stdx::filesystem; - fs::path dp=datapath; - if(datapath[0]!='/'){ - datapath="/"+datapath; - } + fs::path dp= root_path(datapath); + // if(datapath[0]!='/'){ + // datapath="/"+datapath; + // } bool write_success=false; HighFive::File file(filename,HighFive::File::ReadWrite); if(auto dset = file.openDataSet(datapath)){ @@ -526,6 +527,7 @@ bool update_vector(RObject data, bool write_success=false; HighFive::File file(filename,HighFive::File::ReadWrite); + if(datapath[0]!='/'){ datapath="/"+datapath; } @@ -631,10 +633,10 @@ bool write_attribute_h5(const std::string &filename, using namespace HighFive; namespace fs = stdx::filesystem; - if(datapath[0]!='/'){ - datapath="/"+datapath; - } - fs::path dp=datapath; + // if(datapath[0]!='/'){ + // datapath="/"+datapath; + // } + fs::path dp= root_path(datapath); // bool create_success=false; HighFive::File file(filename,HighFive::File::Create | HighFive::File::ReadWrite); auto p_obj = file.getObject(dp.parent_path()); @@ -656,10 +658,10 @@ SEXP read_attribute_h5(const std::string &filename, std::string datapath){ using namespace HighFive; namespace fs = stdx::filesystem; - if(datapath[0]!='/'){ - datapath="/"+datapath; - } - fs::path dp=datapath; + // if(datapath[0]!='/'){ + // datapath="/"+datapath; + // } + fs::path dp= root_path(datapath); bool create_success=false; HighFive::File file(filename,HighFive::File::Create | HighFive::File::ReadWrite); auto p_obj = file.getObject(dp.parent_path()); @@ -684,10 +686,10 @@ bool create_dataset_h5(const std::string &filename, Rcpp::List options){ using namespace HighFive; namespace fs = stdx::filesystem; - if(datapath[0]!='/'){ - datapath="/"+datapath; - } - fs::path dp=datapath; + // if(datapath[0]!='/'){ + // datapath="/"+datapath; + // } + fs::path dp=root_path(datapath); bool create_success=false; HighFive::File file(filename,HighFive::File::Create | HighFive::File::ReadWrite); diff --git a/src/sexp_utils.cpp b/src/sexp_utils.cpp deleted file mode 100644 index e2f1563..0000000 --- a/src/sexp_utils.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "EigenH5.h" - - - - - -// std::string get_datapath(const Rcpp::List &list){ -// auto dp = get_list_scalar(list,"datapath"); -// if(dp){ -// return(*dp); -// }else{ -// auto gp = get_list_any(list,{"group","groupname","Group","Groupname","Groups","groups"}).value_or("/"); -// auto dsp =get_list_any(list,{"dataset","dataname","Dataset","Data","Datanames","datanames"}).value_or(""); -// return(stdx::filesystem::path(gp)/stdx::filesystem::path(dsp)); -// } -// } diff --git a/src/singleton.cpp b/src/singleton.cpp deleted file mode 100644 index 620aa3a..0000000 --- a/src/singleton.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "EigenH5.h" -#include "highfive/highfive.hpp" -//[[depends(RcppEigen)]] -//[[Rcpp::plugins(cpp17)]] -// [[Rcpp::interfaces(cpp)]] -#include -#include - - - - -// -// -// -// -// RCPP_MODULE(FileManager) { -// using namespace Rcpp; -// -// class_( "FileManager") -// .default_constructor("Default constructor") // This exposes the default constructor -// .method("print", &FileManager::print) -// .method("get_file", &FileManager::get_file) -// // This exposes the print method -// // .property("Bender", &MyClass::getBender, &MyClass::setBender) // and this shows how we set up a property -// ; -// } diff --git a/src/split_ld_region.cpp b/src/split_ld_region.cpp deleted file mode 100644 index 3789e5a..0000000 --- a/src/split_ld_region.cpp +++ /dev/null @@ -1,158 +0,0 @@ -#include -//[[depends(RcppEigen)]] -//[[Rcpp::plugins(cpp14)]] -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -using selection_tup=std::tuple,std::vector,std::vector >; - -template std::map split_LD(const std::array data_dims, const std::vector ®ion_ids){ - - std::map retmap; - size_t num_SNPs=region_ids.size(); - const bool SNP_first=data_dims[0]==num_SNPs; - constexpr bool is_mat = D==2; - const size_t other_dim = is_mat ? (SNP_first ? data_dims[1] : data_dims[0]) : 0; - if (is_mat){ - if(!SNP_first){ - if(data_dims[1]!=num_SNPs){ - Rcpp::stop("region_id dims don't match data dims"); - } - assert(data_dims[1]==num_SNPs); - } - }else{ - assert(SNP_first); - } - size_t chunksize=0; - size_t offset = 0; - auto ld_region_begin = region_ids.begin(); - auto ld_region_end = region_ids.end(); - T check_reg; - - auto reg_range = std::make_pair(ld_region_begin,ld_region_begin); - while(reg_range.second!=ld_region_end){ - check_reg=*(reg_range.second); - reg_range = std::equal_range(region_ids.begin(),region_ids.end(),check_reg); - if(reg_range.second!=reg_range.first){ - chunksize = reg_range.second-reg_range.first; - offset = reg_range.first-ld_region_begin; - if(is_mat){ - if(SNP_first){ - retmap.emplace(std::make_pair(*(reg_range.first), - std::make_tuple(std::vector({offset,0}),std::vector({chunksize,other_dim}),std::vector({})))); - }else{ - retmap.emplace(std::make_pair(*(reg_range.first), - std::make_tuple(std::vector({0,offset}),std::vector({other_dim,chunksize}),std::vector({})))); - } - }else{ - retmap.emplace(std::make_pair(*(reg_range.first), - std::make_tuple(std::vector({offset}),std::vector({chunksize}),std::vector({})))); - } - - } - } - - return(retmap); -} - -Rcpp::ListOf read_split(const Rcpp::StringVector &matrix_path,const Rcpp::StringVector ®ion_path, const Rcpp::IntegerVector sub_regions=Rcpp::IntegerVector::create()){ - - using namespace HighFive; - using namespace Rcpp; - std::vector region_id_l; - { - File file(as(region_path[0]),File::ReadOnly); - file.getGroup(as(region_path[1])).getDataSet(as(region_path[2])).read(region_id_l); - } - File mat_file(as(matrix_path[0]),File::ReadOnly); - auto mat_dataset = mat_file.getGroup(as(matrix_path[1])).getDataSet(as(matrix_path[2])); - auto dim_v = mat_dataset.getDataDimensions(); - std::array mat_dims; - mat_dims[0]=dim_v[0]; - mat_dims[1]=dim_v[1]; - auto map_t = split_LD(mat_dims,region_id_l); - std::vector check_regions(sub_regions.begin(),sub_regions.end()); - if(check_regions.empty()){ - size_t num_reg=map_t.size(); - Rcpp::ListOf matlist; - int idx=0; - for(auto ldi = map_t.begin(); ldi!=map_t.end();ldi++){ - - //retmat(idx,0)=ldi->first; - auto val= ldi->second; - auto offsetvec = std::get<0>(val); - auto sizevec = std::get<1>(val); - const size_t trows=sizevec[0]; - const size_t tcols=sizevec[1]; - - auto ncvec = std::get<2>(val); - matlist[idx]=Rcpp::NumericMatrix(trows,tcols); - Eigen::Map readmap(&(matlist[idx])(0,0),trows,tcols); - mat_dataset.selectEigen(offsetvec,sizevec,ncvec).read(readmap); - idx++; - } - return(matlist); - }else{ - size_t num_reg=check_regions.size(); - Rcpp::ListOf matlist(num_reg); - int idx=0; - for(auto val:check_regions){ - - auto ldi = map_t.find(val); - if(ldi!=map_t.end()){ - //retmat(idx,0)=ldi->first; - auto valvec= ldi->second; - auto offsetvec = std::get<0>(valvec); - auto sizevec = std::get<1>(valvec); - auto ncvec = std::get<2>(valvec); - const size_t trows=sizevec[0]; - const size_t tcols=sizevec[1]; - - matlist[idx]=Rcpp::NumericMatrix(trows,tcols); - Eigen::Map readmap(&(matlist[idx])(0,0),trows,tcols); - mat_dataset.selectEigen(offsetvec,sizevec,ncvec).read(readmap); - }else{ - Rcpp::stop("ld_region not found:"+std::to_string(val)); - } - idx++; - } - return(matlist); - } - -} - -//[[Rcpp::export]] -Rcpp::IntegerMatrix split_ldd(const std::vector ®ion_ids){ - - const size_t num_SNPs=region_ids.size(); - std::array dims={num_SNPs}; - auto ldres = split_LD(dims,region_ids); - Rcpp::IntegerMatrix retmat(ldres.size(),3); - size_t idx=0; - for(auto ldi = ldres.begin(); ldi!=ldres.end();ldi++){ - retmat(idx,0)=ldi->first; - auto val= ldi->second; - retmat(idx,1)=(std::get<0>(val))[0]; - retmat(idx,2)=(std::get<1>(val))[0]; - idx++; - } - return(retmat); -} - - - - diff --git a/src/test-eigen.cpp b/src/test-eigen.cpp deleted file mode 100644 index 95e1fd6..0000000 --- a/src/test-eigen.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file uses the Catch unit testing library, alongside - * testthat's simple bindings, to test a C++ function. - * - * For your own packages, ensure that your test files are - * placed within the `src/` folder, and that you include -// * `LinkingTo: testthat` within your DESCRIPTION file. -// */ - -// // All test files should include the -// // header file. - -#include -#include "EigenH5.h" -#include -#include -#include -#include - - -//[[depends(RcppEigen)]] - - -context("Matrix Move constructor"){ - using namespace Eigen; - MatrixXd m0 = MatrixXd::Random(9,9); - auto m0m = m0.data(); - MatrixXd em; - test_that("constructor works for simple ranges"){ - expect_true(em.data()!=m0.data()); - em = std::move(m0); - expect_true(em.data()!=m0.data()); - expect_true(em.data()==m0m); - Rcpp::Rcout<<"testing ran"<