void pluginLoad() { if (notifyFrequency > 0) { // number of cells on the current CPU for each direction const DataSpace<simDim> nrOfGpuCells = Environment<simDim>::get().SubGrid().getLocalDomain().size; // create as much storage as cells in the direction we are interested in: // on gpu und host sliceDataField = new GridBuffer<float3_X, DIM1 > (DataSpace<DIM1 > (nrOfGpuCells.y())); Environment<>::get().PluginConnector().setNotificationPeriod(this, notifyFrequency); const int rank = Environment<simDim>::get().GridController().getGlobalRank(); // open output file std::stringstream oFileName; oFileName << "lineSliceFields_" << rank << ".txt"; outfile.open(oFileName.str().c_str(), std::ofstream::out | std::ostream::trunc); outfile.precision(8); outfile.setf(std::ios::scientific); } }
// Function to return a selected part of a data frame as a list List ch5ChunkSel(string chunkName, CharacterVector selCols, string filePath) { // Open the file in Read/Write Mode, H5F_ACC_RDONLY H5File *file = new H5File(filePath, H5F_ACC_RDONLY); // Opening the data set DataSet dataset = file->openDataSet((H5std_string)chunkName); // Opening the data space DataSpace dataspace = dataset.getSpace(); // Get the number of dimensions int ndim = dataspace.getSimpleExtentNdims(); // Create a dimension object to be filled with the dimensions of the data set hsize_t dims[ndim]; // Fill the dimension of the dataset dataspace.getSimpleExtentDims(dims, NULL); // Create the return data // Filling the matrix with data form the dataspace SEXP data; // Allocating a matrix of the right size and dimension data = PROTECT(Rf_allocMatrix(REALSXP, dims[0], dims[1])); // Filling the matrix with data form the dataspace dataset.read(REAL(data), PredType::NATIVE_DOUBLE, dataspace); UNPROTECT(1); // converting the R object to a numeric matrix NumericMatrix M = as<NumericMatrix>(data); CharacterVector colNames = ch5ReadCharVector("ColumnNames", filePath); CharacterVector colClasses = ch5ReadCharVector("ColumnClasses", filePath); // Create the output List DF; string colName; string colClass; NumericVector vec; CharacterVector levels; int n = selCols.size(); IntegerVector sel(n); int selN; // First we need to find which of the columns has been selected sel = match(selCols, colNames); for(int i = 0; i < n; i++) { colName = selCols[i]; selN = sel[i] - 1; colClass = colClasses[selN]; if(colClass != "factor") { DF[colName] = M(_, selN); }else{ vec = M(_, selN); levels = (CharacterVector)ch5ReadFactor(colName, filePath); DF[colName] = cCreateFactor(vec, levels); } } dataset.close(); file->close(); return DF; }
void extract_data(std::string const& datafilename, char const* name, double* values, dimension const& dimx, dimension const& dimy, dimension const& dimz) { try { using namespace H5; // Turn off the auto-printing when failure occurs Exception::dontPrint(); H5File file(datafilename, H5F_ACC_RDONLY); DataSet dataset = file.openDataSet(name); DataSpace dataspace = dataset.getSpace(); // Verify number of dimensions. HPX_ASSERT(dataspace.getSimpleExtentNdims() == dimension::dim); // Read the data subset. detail::read_values(dataset, dataspace, dimx, dimy, dimz, values); } catch (H5::Exception const& e) { HPX_THROW_EXCEPTION(hpx::no_success, "sheneos::extract_data", e.getDetailMsg()); } }
int H5PlanckDataManager::getData(string channel, long iStart, int nElements, double* data){ H5File file( DataPath+"_"+channel+".h5", H5F_ACC_RDONLY ); if (iStart < LengthPerChannel) { if (iStart + nElements >= LengthPerChannel) { nElements = LengthPerChannel - iStart; } DataSet dataset = file.openDataSet( channel ); //DATASPACE DataSpace dataspace = dataset.getSpace(); hsize_t offset[1]; // hyperslab offset in memory hsize_t count[1]; // size of the hyperslab in memory offset[0] = GlobalOffset + iStart; count[0] = nElements; dataspace.selectHyperslab( H5S_SELECT_SET, count, offset ); //MEMSPACE hsize_t dimsm[1]; dimsm[0] = nElements; hsize_t offset_out[1]; // hyperslab offset in memory offset_out[0] = 0; hsize_t count_out[1]; // size of the hyperslab in memory count_out[0] = nElements; DataSpace memspace( 1, dimsm ); memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out ); dataset.read( data, PredType::NATIVE_DOUBLE, memspace, dataspace ); } return 0; }
//'@title Function for dummy read //' //'@param chunkName the name of the chunk to be read back //'@param filePath the path to the h5 file //'@return int 0 // [[Rcpp::export]] int h5DummyRead(std::string chunkName, std::string filePath) { // Open the file in Read/Write Mode, H5F_ACC_RDONLY H5File *file = new H5File(filePath, H5F_ACC_RDONLY); // Opening the data set DataSet dataset = file->openDataSet((H5std_string)chunkName); // Opening the data space DataSpace dataspace = dataset.getSpace(); // Get the number of dimensions int ndim = dataspace.getSimpleExtentNdims(); // Create a dimension object to be filled with the dimensions of the data set hsize_t dims[ndim]; // Fill the dimension of the dataset dataspace.getSimpleExtentDims(dims, NULL); // Create the return data SEXP data; // Allocating a matrix of the right size and dimension data = PROTECT(Rf_allocMatrix(REALSXP, dims[0], dims[1])); // Filling the matrix with data form the dataspace dataset.read(REAL(data), PredType::NATIVE_DOUBLE, dataspace); UNPROTECT(1); dataset.close(); file->close(); return 0; }
void read_1darray_vector_of_string_impl (group_or_file f, std::string const & name, ArrayVectorOfStringType & V) { if (!h5::exists(f, name)) TRIQS_RUNTIME_ERROR << "no such dataset : "<<name <<" in file "; try { DataSet ds = f->openDataSet( name.c_str() ); DataSpace dataspace = ds.getSpace(); mini_vector<hsize_t,1> dims_out; int ndims = dataspace.getSimpleExtentDims( &dims_out[0], NULL); if (ndims !=1) TRIQS_RUNTIME_ERROR << "triqs::h5 : Trying to read 1d array/vector . Rank mismatch : the array stored in the hdf5 file has rank = "<<ndims; size_t Len = dims_out[0]; V.resize(Len); size_t size = ds.getStorageSize(); StrType strdatatype(PredType::C_S1, size); std::vector<char> buf(Len*(size+1), 0x00); mini_vector<hsize_t,1> L; L[0]=V.size(); mini_vector<hsize_t,1> S; S[0]=1; auto d_space = dataspace_from_LS<1,false > (L,L,S); ds.read( (void *)(&buf[0]),strdatatype, d_space ); size_t i=0; for (auto & x : V) { x = ""; x.append(&buf[i*(size)]); ++i;} } TRIQS_ARRAYS_H5_CATCH_EXCEPTION; }
DataSet *load_fMRI3D_DS(std::string filename) { std::cout << "Opening file " << filename << std::endl; typedef DataSet DBN_DS; using namespace H5; using H5::DataSet; const H5std_string FILE_NAME(filename); H5File file(FILE_NAME, H5F_ACC_RDONLY); int dims[4]; DataSet datadims = file.openDataSet("dims"); datadims.read(dims, PredType::NATIVE_INT); datadims.close(); DataSet data = file.openDataSet("data"); DataSpace dsp = data.getSpace(); hsize_t dims_out[2]; dsp.getSimpleExtentDims(dims_out, NULL); int volumes = (int)dims_out[0]; int voxels = (int)dims_out[1]; std::cout << "Dataset images are of size " << dims[0] << "x" << dims[1] << "x" << dims[2] << "x" << dims[3] << std::endl; std::cout << "Training set is of size " << volumes << "x" << voxels << std::endl; DBN_DS *dataset = new DBN_DS(AOD, volumes, dims[0], dims[1], dims[2], voxels); dataset->data_path = filename; std::cout << "Reading dataset" << std::endl; float *out_buffer = new float[voxels*volumes]; data.read(out_buffer, PredType::NATIVE_FLOAT); for (int volume = 0; volume < volumes; ++volume) { for (int voxel = 0; voxel < voxels; ++voxel) { float val = out_buffer[volumes*voxel + volume]; dataset->data(volume,voxel) = val; } } data.close(); dsp.close(); #if 0 Vector col = transpose(dataset->data)(9); col.save("/Users/devon/Research/matlab/tocmat2"); exit(1); #endif std::cout << "Reading mask" << std::endl; DataSet mask_data = file.openDataSet("mask"); dsp = mask_data.getSpace(); mask_data.read(dataset->mask.m->data, PredType::NATIVE_FLOAT); mask_data.close(); std::cout << "Done reading mask" << std::endl; dataset->applymask = true; std::cout << "Done loading dataset" << std::endl; return dataset; }
int HdfProcessor::getPointsNumber(const Group& group) const { DataSet dataSet = group.openDataSet(COORDINATES_DATASET_NAMES[Step::X]); DataSpace dataSpace = dataSet.getSpace(); int pointsNumber = dataSpace.getSimpleExtentNpoints(); dataSet.close(); return pointsNumber; }
void extract_data(std::string const& datafilename, double* values, std::size_t offset, std::size_t count) { try { using namespace H5; // Turn off the auto-printing when failure occurs Exception::dontPrint(); H5File file(datafilename, H5F_ACC_RDONLY); DataSet dataset = file.openDataSet("sine"); // name of data to read DataSpace dataspace = dataset.getSpace(); // number of dimensions int numdims = dataspace.getSimpleExtentNdims(); if (numdims != 1) { HPX_THROW_EXCEPTION(hpx::no_success, "extract_data", "number of dimensions was not 1"); } // Get the dimension size of each dimension in the dataspace. hsize_t dims[1]; dataspace.getSimpleExtentDims(dims, nullptr); read_values(dataset, dataspace, offset, count, values); } catch (H5::Exception const& e) { HPX_THROW_EXCEPTION(hpx::no_success, "extract_data", e.getDetailMsg()); } }
int HDF5RecordingData::prepareDataBlock(int xDataSize) { hsize_t dim[3]; DataSpace fSpace; if (dimension > 2) return -4; //We're not going to write rows in datasets bigger than 2d. dim[2] = size[2]; dim[1] = size[1]; dim[0] = xPos + xDataSize; try { dSet->extend(dim); fSpace = dSet->getSpace(); fSpace.getSimpleExtentDims(dim); size[0]=dim[0]; } catch (DataSetIException error) { PROCESS_ERROR; } rowXPos = xPos; rowDataSize = xDataSize; xPos += xDataSize; return 0; }
HINLINE static DataSpace<DIM2> getGridDim(const Base &base, const DataSpace<DIM2> &gBlocks) { return DataSpace<DIM2 > ( gBlocks.x() + gBlocks.y() - 2 * base.getGuardingSuperCells(), 2 * base.getGuardingSuperCells()); }
//-------------------------------------------------------------------------- // Function: DataSet::read ///\brief This is an overloaded member function, provided for convenience. /// It takes a reference to a \c H5std_string for the buffer. ///\param buf - IN: Buffer for read data ///\param mem_type - IN: Memory datatype ///\param mem_space - IN: Memory dataspace ///\param file_space - IN: Dataset's dataspace in the file ///\param xfer_plist - IN: Transfer property list for this I/O operation ///\exception H5::DataSetIException // Programmer Binh-Minh Ribler - 2000 // Modification // Jul 2009 // Follow the change to Attribute::read and use the following // private functions to read datasets with fixed- and // variable-length string: // DataSet::p_read_fixed_len and // DataSet::p_read_variable_len //-------------------------------------------------------------------------- void DataSet::read(H5std_string& strg, const DataType& mem_type, const DataSpace& mem_space, const DataSpace& file_space, const DSetMemXferPropList& xfer_plist) const { // Check if this dataset has variable-len string or fixed-len string and // proceed appropriately. htri_t is_variable_len = H5Tis_variable_str(mem_type.getId()); if (is_variable_len < 0) { throw DataSetIException("DataSet::read", "H5Tis_variable_str failed"); } // Obtain identifiers for C API hid_t mem_type_id = mem_type.getId(); hid_t mem_space_id = mem_space.getId(); hid_t file_space_id = file_space.getId(); hid_t xfer_plist_id = xfer_plist.getId(); if (!is_variable_len) // only allocate for fixed-len string { p_read_fixed_len(mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg); } else { p_read_variable_len(mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg); } }
HDF5HandlerBase::HDF5HandlerBase(const std::string &fileName, const std::string &datasetName) : FILE_NAME(H5std_string(fileName)) , DATASETNAME(H5std_string(datasetName)) { try { Exception::dontPrint(); file = H5File(FILE_NAME, H5F_ACC_TRUNC); hsize_t dims[1] = {0}; hsize_t maxdims[1] = {H5S_UNLIMITED}; hsize_t chunk_dims[1] = {10000}; DataSpace dataspace = DataSpace(1,dims,maxdims); DSetCreatPropList prop; prop.setChunk(1, chunk_dims); dataset = file.createDataSet( DATASETNAME, PredType::STD_I32BE, dataspace, prop); prop.close(); dataspace.close(); } catch (Exception &error) { // Throw FileIException, DataSetIException, DataSpaceIException throw; } }
void extract_data(std::string const& datafilename, char const* name, double* values, hsize_t offset, hsize_t count) { try { using namespace H5; // Turn off auto-printing on failure. Exception::dontPrint(); // Try to open the file. H5File file(datafilename, H5F_ACC_RDONLY); // Try to open the specified dataset. DataSet dataset = file.openDataSet(name); DataSpace dataspace = dataset.getSpace(); // Verify number of dimensions. HPX_ASSERT(dataspace.getSimpleExtentNdims() == 1); // Read the data subset. detail::read_values(dataset, dataspace, offset, count, values); } catch (H5::Exception const& e) { HPX_THROW_EXCEPTION(hpx::no_success, "sheneos::extract_data", e.getDetailMsg()); } }
HDF5RecordingData::HDF5RecordingData(DataSet* data) { DataSpace dSpace; DSetCreatPropList prop; ScopedPointer<DataSet> dataSet = data; hsize_t dims[3], chunk[3]; dSpace = dataSet->getSpace(); prop = dataSet->getCreatePlist(); dimension = dSpace.getSimpleExtentDims(dims); prop.getChunk(dimension,chunk); this->size[0] = dims[0]; if (dimension > 1) this->size[1] = dims[1]; else this->size[1] = 1; if (dimension > 1) this->size[2] = dims[2]; else this->size[2] = 1; this->xChunkSize = chunk[0]; this->xPos = dims[0]; this->dSet = dataSet; this->rowXPos.clear(); this->rowXPos.insertMultiple(0,0,this->size[1]); }
CharacterVector ch5ReadFactor(string charName, string filePath) { H5File *file = new H5File(filePath, H5F_ACC_RDONLY); // Group Meta Group Group* metaGroup = new Group(file->openGroup("/MetaData/Factor")); // Getting the data set from the file DataSet dataset = metaGroup->openDataSet((H5std_string)charName); // Getting the data space from the dataset DataSpace dataspace = dataset.getSpace(); // We know that it is a char vector array so ndim = 1 hsize_t dims[1]; // Getting the length of strings dataspace.getSimpleExtentDims(dims, NULL); // for convenience int dim = dims[0]; // String Type StrType vlst(0, H5T_VARIABLE); // Returning the data char *strRet[dim]; dataset.read(strRet, vlst); CharacterVector out(dim); for(int i = 0; i < dim; i++) { out[i] = strRet[i]; } dataset.close(); //nn metaGroup->close(); file->close(); return out; }
void BlockReader::getBlock(int level, int blkno, uchar* block) { int lod2 = qPow(2, level); int bb = m_blockSize/lod2; int dno = blkno/(m_wblocks*m_hblocks); int wno = (blkno - dno*m_wblocks*m_hblocks)/m_hblocks; int hno = blkno - dno*m_wblocks*m_hblocks - wno*m_hblocks; if (! m_hdf5file) { QString filename; filename = m_baseFilename + ".h5"; m_hdf5file = new H5File(filename.toAscii().data(), H5F_ACC_RDONLY); for(int il=0; il<m_minLevel; il++) { QString dataname = QString("lod-%1").arg(il); m_hdf5dataset[il] = m_hdf5file->openDataSet(dataname.toAscii().data()); } m_dataType.copy(m_hdf5dataset[0]); } DataSpace dataspace = m_hdf5dataset[level].getSpace(); hsize_t offset[3], count[3]; offset[0] = dno*bb; offset[1] = wno*bb; offset[2] = hno*bb; count[0] = count[1] = count[2] = bb; count[0] = qMin(m_blockSize, m_depth -dno*m_blockSize-1)/lod2; count[1] = qMin(m_blockSize, m_width -wno*m_blockSize-1)/lod2; count[2] = qMin(m_blockSize, m_height-hno*m_blockSize-1)/lod2; dataspace.selectHyperslab( H5S_SELECT_SET, count, offset ); hsize_t mdim[3]; mdim[0] = bb; mdim[1] = bb; mdim[2] = bb; hsize_t memoffset[3]; memoffset[0] = 0; memoffset[1] = 0; memoffset[2] = 0; DataSpace memspace( 3, mdim ); memspace.selectHyperslab(H5S_SELECT_SET, count, memoffset); m_hdf5dataset[level].read( block, m_dataType, memspace, dataspace ); }
static std::string dspToStr(DataSpace<DIM3>& dsp) { std::stringstream stream; stream << "(" << dsp.x() << ", " << dsp.y() << ", " << dsp.z() << ")"; return stream.str(); }
int H5PlanckDataManager::getPointing(string channel, long iStart, int nElements, int * pix, double * qw, double * uw){ int NPIX = getNPIX(); if (iStart >= LengthPerChannel) { cout << "istart over " << iStart << endl; } else { //cout << "istart + nELEm " << iStart + nElements << endl; if (iStart + nElements > LengthPerChannel) { nElements = LengthPerChannel - iStart; cout << "istart " << iStart << " new nElem " << nElements << endl; } H5File file( PointingPath+"_pix_"+channel+".h5", H5F_ACC_RDONLY ); DataSet dataset = file.openDataSet( "pix" ); //DATASPACE DataSpace dataspace = dataset.getSpace(); hsize_t offset[1]; // hyperslab offset in memory hsize_t count[1]; // size of the hyperslab in memory offset[0] = GlobalOffset + iStart; count[0] = nElements; dataspace.selectHyperslab( H5S_SELECT_SET, count, offset ); //MEMSPACE hsize_t dimsm[1]; dimsm[0] = nElements; hsize_t offset_out[1]; // hyperslab offset in memory offset_out[0] = 0; hsize_t count_out[1]; // size of the hyperslab in memory count_out[0] = nElements; DataSpace memspace( 1, dimsm ); memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out ); dataset.read(pix, PredType::NATIVE_INT, memspace, dataspace ); file = H5File( PointingPath+"_qw_"+channel+".h5", H5F_ACC_RDONLY ); dataset = file.openDataSet( "qw" ); //DATASPACE dataspace = dataset.getSpace(); dataspace.selectHyperslab( H5S_SELECT_SET, count, offset ); //MEMSPACE memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out ); dataset.read(qw, PredType::NATIVE_DOUBLE, memspace, dataspace ); file = H5File( PointingPath+"_uw_"+channel+".h5", H5F_ACC_RDONLY ); dataset = file.openDataSet( "uw" ); //DATASPACE dataspace = dataset.getSpace(); dataspace.selectHyperslab( H5S_SELECT_SET, count, offset ); //MEMSPACE memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out ); dataset.read(uw, PredType::NATIVE_DOUBLE, memspace, dataspace ); } return 0; }
index_system (DataSpace const & ds, bool is_complex) { int rf = ds.getSimpleExtentNdims(); if ( rf != rank_full + (is_complex ? 1 : 0) ) TRIQS_RUNTIME_ERROR << "H5 : dimension error"; //int ndims = ds.getSimpleExtentDims( &lens_[0], NULL); ds.getSimpleExtentDims( &lens_[0], NULL); for (size_t i =0; i<rank; ++i) { dims[i] = lens_[i]; stri_[i] = 1; off_[i]= 0; } total_lens_=dims; mydomain = domain_type (dims); }
//'@title Legacy function to return a data frame chunk as a list //' //'@description Experimental function not intended for use at all //' //'@param chunkName the name of the chunk to be read //'@param filePath the path to the h5 file //'@return List of the data frame chunk // [[Rcpp::export]] SEXP h5ReadDoubleMat3(std::string chunkName, std::string filePath) { // Open the file in Read/Write Mode, H5F_ACC_RDONLY H5File *file = new H5File(filePath, H5F_ACC_RDONLY); // Opening the data set DataSet dataset = file->openDataSet((H5std_string)chunkName); // Opening the data space DataSpace dataspace = dataset.getSpace(); // Get the number of dimensions int ndim = dataspace.getSimpleExtentNdims(); // Create a dimension object to be filled with the dimensions of the data set hsize_t dims[ndim]; // Fill the dimension of the dataset dataspace.getSimpleExtentDims(dims, NULL); // Create the return data // Filling the matrix with data form the dataspace //double (*buf)[dims[1]]*[dims[0]] = malloc(dims[1]]*[dims[0] * sizeof *buf); //buf[dims[1]][dims[0]] = 0.0; double **buf = (double**) calloc (dims[1]*dims[0], sizeof(double)); buf[dims[1]][dims[0]] = 0.0; //double buf[dims[1]][dims[0]]; dataset.read(buf, PredType::NATIVE_DOUBLE, dataspace); // Attempt tp append the contents to a list List out; NumericVector vec(dims[0]); NumericMatrix M(dims[0], dims[1]); CharacterVector colNames = ch5ReadCharVector("ColumnNames", filePath); CharacterVector colClasses = ch5ReadCharVector("ColumnClasses", filePath); string colName; for(int i = 0; i < dims[1]; i++) { NumericVector vec(dims[0]); for(int j = 0; j < dims[0]; j++) { M(j,i) = buf[i][j]; vec(j) = buf[i][j]; } colName = colNames[i]; if(colClasses[i] == "factor") { CharacterVector levels; levels = h5ReadFactor(colName, filePath); IntegerVector fact(vec.size()); fact = cCreateFactor(vec, levels); out[colName] = fact; }else{ out[colName] = vec; } } free(buf); dataset.close(); //nn file->close(); return wrap(out); }
int HDF5RecordingData::writeDataRow(int yPos, int xDataSize, HDF5FileBase::DataTypes type, void* data) { hsize_t dim[2],offset[2]; DataSpace fSpace; DataType nativeType; if (dimension > 2) return -4; //We're not going to write rows in datasets bigger than 2d. // if (xDataSize != rowDataSize) return -2; if ((yPos < 0) || (yPos >= size[1])) return -2; try { if (rowXPos[yPos]+xDataSize > size[0]) { dim[1] = size[1]; dim[0] = rowXPos[yPos] + xDataSize; dSet->extend(dim); fSpace = dSet->getSpace(); fSpace.getSimpleExtentDims(dim); size[0]=dim[0]; } if (rowXPos[yPos]+xDataSize > xPos) { xPos = rowXPos[yPos]+xDataSize; } dim[0] = xDataSize; dim[1] = 1; DataSpace mSpace(dimension,dim); fSpace = dSet->getSpace(); offset[0] = rowXPos[yPos]; offset[1] = yPos; fSpace.selectHyperslab(H5S_SELECT_SET, dim, offset); nativeType = HDF5FileBase::getNativeType(type); dSet->write(data,nativeType,mSpace,fSpace); rowXPos.set(yPos,rowXPos[yPos] + xDataSize); } catch (DataSetIException error) { PROCESS_ERROR; } catch (DataSpaceIException error) { PROCESS_ERROR; } catch (FileIException error) { PROCESS_ERROR; } return 0; }
void read_feature_size(H5File h5f, Size &size_out, const char *name) { DataSet dataset = h5f.openDataSet(name); DataSpace dspace = dataset.getSpace(); assert (dspace.getSimpleExtentNdims() == 2); hsize_t dims[2]; dspace.getSimpleExtentDims(dims); size_out.height = dims[0]; size_out.width = dims[1]; }
HINLINE static DataSpace<DIM2> getGridDim(const Base &base, const DataSpace<DIM2> &gBlocks) { const uint32_t xOverhead = 2 * (base.getGuardingSuperCells()); const uint32_t yOverhead = xOverhead + 2 * (base.getBorderSuperCells()); return DataSpace<DIM2 > ( gBlocks.x() - xOverhead + gBlocks.y() - yOverhead, 2 * base.getBorderSuperCells()); }
//'@title Legacy function to return a data frame chunk as a list //' //'@description Experimental function not intended for use at all //' //'@param chunkName the name of the chunk to be read //'@param filePath the path to the h5 file //'@return List of the data frame chunk // [[Rcpp::export]] SEXP h5ReadDoubleMat2(std::string chunkName, std::string filePath) { // Open the file in Read/Write Mode, H5F_ACC_RDONLY H5File *file = new H5File(filePath, H5F_ACC_RDONLY); // Opening the data set DataSet dataset = file->openDataSet((H5std_string)chunkName); // Opening the data space DataSpace dataspace = dataset.getSpace(); // Get the number of dimensions int ndim = dataspace.getSimpleExtentNdims(); // Create a dimension object to be filled with the dimensions of the data set hsize_t dims[ndim]; // Fill the dimension of the dataset dataspace.getSimpleExtentDims(dims, NULL); // Create the return data // Filling the matrix with data form the dataspace SEXP data; // Allocating a matrix of the right size and dimension data = PROTECT(Rf_allocMatrix(REALSXP, dims[0], dims[1])); // Filling the matrix with data form the dataspace dataset.read(REAL(data), PredType::NATIVE_DOUBLE, dataspace); UNPROTECT(1); // converting the R object to a numeric matrix NumericMatrix M = as<NumericMatrix>(data); List out; NumericVector vec(dims[0]); CharacterVector colNames = ch5ReadCharVector("ColumnNames", filePath); CharacterVector colClasses = ch5ReadCharVector("ColumnClasses", filePath); string colName; for(int i = 0; i < dims[1]; i++) { NumericVector vec(dims[0]); for(int j = 0; j < dims[0]; j++) { vec(j) = M(j,i); } colName = colNames[i]; if(colClasses[i] == "factor") { CharacterVector levels; levels = ch5ReadFactor(colName, filePath); IntegerVector fact(vec.size()); fact = cCreateFactor(vec, levels); out[colName] = fact; }else{ out[colName] = vec; } } dataset.close(); //nn file->close(); // Returning the data return wrap(out); }
/** constructor * * @param size extent for each dimension (in elements) */ MappedBufferIntern(DataSpace<DIM> size): DeviceBuffer<TYPE, DIM>(size, size), pointer(nullptr), ownPointer(true) { #if( PMACC_CUDA_ENABLED == 1 ) CUDA_CHECK((cuplaError_t)cudaHostAlloc(&pointer, size.productOfComponents() * sizeof (TYPE), cudaHostAllocMapped)); #else pointer = new TYPE[size.productOfComponents()]; #endif reset(false); }
HDINLINE static DataSpace<DIM3> getBlockIndex(const Base &base, const DataSpace<DIM3>& _blockIdx, uint32_t exchangeType) { DataSpace<DIM3> result(_blockIdx); DataSpace<DIM3> directions = Mask::getRelativeDirections<DIM3 > (exchangeType); size_t guardingBlocks = base.getGuardingSuperCells(); size_t borderBlocks = base.getBorderSuperCells(); switch (directions.x()) { case 0: result.x() += guardingBlocks + borderBlocks; break; case -1: result.x() += guardingBlocks; break; case 1: result.x() += base.getGridSuperCells().x() - guardingBlocks - borderBlocks; break; } switch (directions.y()) { case 0: result.y() += guardingBlocks + borderBlocks; break; case -1: result.y() += guardingBlocks; break; case 1: result.y() += base.getGridSuperCells().y() - guardingBlocks - borderBlocks; break; } switch (directions.z()) { case 0: result.z() += guardingBlocks + borderBlocks; break; case -1: result.z() += guardingBlocks; break; case 1: result.z() += base.getGridSuperCells().z() - guardingBlocks - borderBlocks; break; } return result; }
h5_read (h5::group_or_file f, std::string const & name, S & A) { if (!f.exists(name)) TRIQS_RUNTIME_ERROR << "no such dataset : "<<name <<" in file "; try { DataSet ds = f->openDataSet( name.c_str() ); DataSpace dataspace = ds.getSpace(); int rank = dataspace.getSimpleExtentNdims(); if (rank != 0) TRIQS_RUNTIME_ERROR << "triqs::array::h5::read. Rank mismatch : expecting a scalar (rank =0)" <<" while the array stored in the hdf5 file has rank = "<<rank; ds.read( (void *)(&A), data_type_mem_scalar(A), DataSpace() , DataSpace() ); } TRIQS_ARRAYS_H5_CATCH_EXCEPTION; }
HINLINE static DataSpace<DIM3> getGridDim(const Base &base, const DataSpace<DIM3> &gBlocks) { const int x = gBlocks.x(); const int x_ = gBlocks.x() - 2 * base.getGuardingSuperCells(); const int y = gBlocks.y(); const int z_ = gBlocks.z() - 2 * base.getGuardingSuperCells(); return DataSpace<DIM3 > (x * y + z_ * y + x_*z_, 2 * base.getGuardingSuperCells(), 1); }
int HDF5RecordingData::writeDataBlock(int xDataSize, int yDataSize, HDF5FileBase::DataTypes type, void* data) { hsize_t dim[3],offset[3]; DataSpace fSpace; DataType nativeType; dim[2] = size[2]; //only modify y size if new required size is larger than what we had. if (yDataSize > size[1]) dim[1] = yDataSize; else dim[1] = size[1]; dim[0] = xPos + xDataSize; try { //First be sure that we have enough space dSet->extend(dim); fSpace = dSet->getSpace(); fSpace.getSimpleExtentDims(dim); size[0]=dim[0]; if (dimension > 1) size[1]=dim[1]; //Create memory space dim[0]=xDataSize; dim[1]=yDataSize; dim[2] = size[2]; DataSpace mSpace(dimension,dim); //select where to write offset[0]=xPos; offset[1]=0; offset[2]=0; fSpace.selectHyperslab(H5S_SELECT_SET, dim, offset); nativeType = HDF5FileBase::getNativeType(type); dSet->write(data,nativeType,mSpace,fSpace); xPos += xDataSize; } catch (DataSetIException error) { PROCESS_ERROR; } catch (DataSpaceIException error) { PROCESS_ERROR; } return 0; }