本文整理汇总了C++中h5::DataSet::getSpace方法的典型用法代码示例。如果您正苦于以下问题:C++ DataSet::getSpace方法的具体用法?C++ DataSet::getSpace怎么用?C++ DataSet::getSpace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类h5::DataSet
的用法示例。
在下文中一共展示了DataSet::getSpace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addrow
void addrow( H5::DataSet& ds, const std::vector<double>& rowtowrite )
{
//Get the space (since it may have grown in length since last time of course )
H5::DataSpace origspace = ds.getSpace();
//get the rank, even though I know it is 2
int rank = origspace.getSimpleExtentNdims();
//Get the actual dimensions of the ranks.
hsize_t dims[rank];
int ndims = origspace.getSimpleExtentDims( dims, NULL);
//Want to ADD a row, so need to offset at row = nrows, and col = 0;
hsize_t offset[rank] = { dims[0], 0 };
hsize_t dims_toadd[rank] = { 1, rowtowrite.size() }; //will write 1 row, ncols columns.
//Compute "new" size (extended by 1 row).
hsize_t size[rank] = { dims[0]+dims_toadd[0], rowtowrite.size() };
//Do the extension.
ds.extend( size );
//Get the new (extended) space, and select the hyperslab to write the row to.
origspace = ds.getSpace();
origspace.selectHyperslab( H5S_SELECT_SET, dims_toadd, offset );
//Make the "memory" data space?
H5::DataSpace toaddspace(rank, dims_toadd);
ds.write( rowtowrite.data(), H5::PredType::NATIVE_DOUBLE, toaddspace, origspace );
//Can close toaddspace/origspace with no effect.
//Can also close/open data set at the beginning of each time with no effect.
}
示例2: compare_datasets
void compare_datasets(H5::DataSet const& ds1, H5::DataSet const& ds2)
{
std::vector<hsize_t> dims(ds1.getSpace().getSimpleExtentNdims());
ds1.getSpace().getSimpleExtentDims(&*dims.begin());
// compare 2 or 3-dimensional list of vectors, e.g., box edges
BOOST_REQUIRE( dims.size() == 2 );
BOOST_REQUIRE( dims[1] == 2 || dims[1] == 3 );
if (dims[1] == 3) {
std::vector<halmd::fixed_vector<double, 3> > array1, array2;
h5xx::read_dataset(ds1, array1);
h5xx::read_dataset(ds2, array2);
BOOST_CHECK_EQUAL_COLLECTIONS(
array1.begin(), array1.end()
, array2.begin(), array2.end()
);
}
else if (dims[1] == 2) {
std::vector<halmd::fixed_vector<double, 2> > array1, array2;
h5xx::read_dataset(ds1, array1);
h5xx::read_dataset(ds2, array2);
BOOST_CHECK_EQUAL_COLLECTIONS(
array1.begin(), array1.end()
, array2.begin(), array2.end()
);
}
}
示例3: loadModel
void FeaturePointsRANSAC::loadModel(std::string modelPath)
{
H5::H5File h5Model;
try {
h5Model = H5::H5File(modelPath, H5F_ACC_RDONLY);
}
catch (H5::Exception& e) {
std::string msg( std::string( "Could not open HDF5 file \n" ) + e.getCDetailMsg() );
throw msg;
}
// Load the Shape
H5::Group modelReconstructive = h5Model.openGroup("/shape/ReconstructiveModel/model");
H5::DataSet dsMean = modelReconstructive.openDataSet("./mean");
hsize_t dims[1];
dsMean.getSpace().getSimpleExtentDims(dims, NULL); // dsMean.getSpace() leaks memory... maybe a hdf5 bug, maybe vlenReclaim(...) could be a fix. No idea.
//H5::DataSpace dsp = dsMean.getSpace();
//dsp.close();
std::cout << "Dims: " << dims[0] << std::endl; // TODO: I guess this whole part could be done A LOT better!
float* testData = new float[dims[0]];
dsMean.read(testData, H5::PredType::NATIVE_FLOAT);
this->modelMeanShp.reserve(dims[0]);
for (unsigned int i=0; i < dims[0]; ++i) {
modelMeanShp.push_back(testData[i]);
}
delete[] testData;
testData = NULL;
dsMean.close();
// // Load the Texture
H5::Group modelReconstructiveTex = h5Model.openGroup("/color/ReconstructiveModel/model");
H5::DataSet dsMeanTex = modelReconstructiveTex.openDataSet("./mean");
hsize_t dimsTex[1];
dsMeanTex.getSpace().getSimpleExtentDims(dimsTex, NULL);
std::cout << "Dims: " << dimsTex[0] << std::endl; // TODO: I guess this whole part could be done A LOT better!
float* testDataTex = new float[dimsTex[0]];
dsMeanTex.read(testDataTex, H5::PredType::NATIVE_FLOAT);
this->modelMeanTex.reserve(dimsTex[0]);
for (unsigned int i=0; i < dimsTex[0]; ++i) {
modelMeanTex.push_back(testDataTex[i]);
}
delete[] testDataTex;
testDataTex = NULL;
dsMeanTex.close();
h5Model.close();
}
示例4: LBTHROW
H5::DataSet CompartmentReportHDF5::_openDataset( const H5::H5File& file,
const uint32_t cellID )
{
std::stringstream cellName;
cellName << "a" << cellID;
const std::string datasetName = "/" + cellName.str() + "/" + _reportName +
"/" + dataDatasetName;
H5::DataSet dataset;
H5E_BEGIN_TRY
dataset = file.openDataSet( datasetName );
H5E_END_TRY
if( !dataset.getId() )
{
LBTHROW(
std::runtime_error( "ReportReaderHDF5: "
"Dataset " + datasetName + " not found "
"in file: " + file.getFileName( )));
}
if( dataset.getSpace().getSimpleExtentNdims() != 2 )
{
LBTHROW(
std::runtime_error("Compartment_Report_HDF5_File_Reader: "
"Error, not 2 dimensional array on " +
datasetName));
}
return dataset;
}
示例5: memspace
arma::Mat<uint16_t> readLUT(const std::string& path)
{
H5::H5File file (path.c_str(), H5F_ACC_RDONLY);
H5::DataSet ds = file.openDataSet("LUT");
H5::DataSpace filespace = ds.getSpace();
int ndims = filespace.getSimpleExtentNdims();
assert(ndims == 2);
hsize_t dims[2] = {1, 1};
filespace.getSimpleExtentDims(dims);
H5::DataSpace memspace (ndims, dims);
arma::Mat<uint16_t> res (dims[0], dims[1]);
ds.read(res.memptr(), H5::PredType::NATIVE_UINT16, memspace, filespace);
filespace.close();
memspace.close();
ds.close();
file.close();
// NOTE: Armadillo stores data in column-major order, while HDF5 uses
// row-major ordering. Above, we read the data directly from HDF5 into
// the arma matrix, so it was implicitly transposed. The next function
// fixes this problem.
arma::inplace_trans(res);
return res;
}
示例6:
/**
* @param variable
* @return
*/
long HDF5FileReader::getNumberOfRecords(const std::string& variable)
{
//std::cout << "reading " << variable << std::endl;
//get variable number
H5::DataSet dataset = this->variableGroup->openDataSet(variable);
H5::DataSpace dataspace = dataset.getSpace();
hsize_t count[1];
// int ndims = dataspace.getSimpleExtentDims(count, NULL);
return (long)count[0];
}
示例7: memspace
/**
* @brief Returns a pointer to a std::vector<float> containing the values of the selected variable
*
* This allocates a new std::vector<float> pointer. Make sure you
* delete the contents when you done using it, or you will have a memory leak.
*
* @param variable
* @return std::vector<float> containing the values of the selected variable.
*/
std::vector<float>* HDF5FileReader::getVariable(const std::string& variable)
{
std::vector<float>* variableData = new std::vector<float>();
if (this->doesVariableExist(variable))
{
//std::cout << "reading " << variable << std::endl;
//get variable number
// long variableNum = this->getVariableID(variable);
//std::cout << "variableNum for " << variable << ": " << variableNum << std::endl;
//get dim sizes
H5::Group group = this->current_file->openGroup("Variables");
//cout << "variable: " << variable << ": " << counts[0] << endl;
H5::DataSet * dataset = new H5::DataSet(group.openDataSet(variable));
H5::DataSpace dataspace = dataset->getSpace();
int rank = dataspace.getSimpleExtentNdims(); //should be 1
hsize_t count[1];
hsize_t offset[1] = {0};
// int ndims = dataspace.getSimpleExtentDims(count, NULL);
//std::cout << "count[0]: " << count[0] << std::endl;
float * buffer = new float[count[0]];
dataspace.selectHyperslab(H5S_SELECT_SET, count, offset);
H5::DataSpace memspace( rank, count);
memspace.selectHyperslab(H5S_SELECT_SET, count, offset);
dataset->read(buffer, H5::PredType::NATIVE_FLOAT, memspace, dataspace);
//std::cout << "after read" << std::endl;
//add data to vector type, and delete original array
variableData->reserve(count[0]);
for (int i = 0; i < count[0]; i++)
{
variableData->push_back(buffer[i]);
}
//std::cout << "after adding to variableData vector" << std::endl;
delete[] buffer;
delete dataset;
//std::cout << "finished reading " << variable << std::endl;
//std::cout << "size of variable: " << variableData.size() << std::endl;
//std::cout << "dimSizes[0]: " << dimSizes[0] << std::endl;
}
return variableData;
}
示例8: runtime_error
const std::vector<hsize_t> TableDims(){
if(flags_ != hdf5::READ)
throw std::runtime_error("TableDims() is only valid in READ mode");
H5::DataSet dSet = file_->openDataSet("T00000000");
H5::DataSpace dSpace = dSet.getSpace();
std::vector<hsize_t> dims(dSpace.getSimpleExtentNdims());
dSpace.getSimpleExtentDims(&dims[0]);
return dims;
}
示例9: range_error
NDArray<T, Nd> NDArray<T,Nd>::ReadFromH5(const H5::DataSet& h5Dset) {
H5::DataSpace dspace = h5Dset.getSpace();
int ndim = dspace.getSimpleExtentNdims();
if (ndim>Nd)
throw std::range_error("Too many dimensions in H5 dataset for NDArray");
hsize_t dimSize[ndim];
dspace.getSimpleExtentDims(dimSize);
std::array<std::size_t, Nd> dimSizeArr;
for (int i=0; i<Nd; ++i) dimSizeArr[i] = dimSize[i];
NDArray<T, Nd> arr(dimSizeArr);
// Read in data here
H5::DataType h5DType = GetH5DataType<T>();
h5Dset.read(arr.mData, h5DType);
return arr;
}
示例10: getGroup
void HDF5IO::loadStdVector(const std::string& GroupName, const std::string& Name,
std::vector<RealType>& V)
{
try{
H5::Group FG = getGroup( GroupName );
H5::DataSet DataSet = FG.openDataSet(Name.c_str());
H5::DataSpace DataSpace = DataSet.getSpace();
if(DataSpace.getSimpleExtentNdims() != 1)
throw(H5::DataSpaceIException("HDF5IO::loadRealVector()","Unexpected multidimentional dataspace."));
V.resize(DataSpace.getSimpleExtentNpoints());
DataSet.read(V.data(),H5::PredType::NATIVE_DOUBLE);
FG.close();
} catch( const H5::Exception err ){
RUNTIME_ERROR("HDF5IO::loadRealStdVector");
}
}
示例11: GetDsDims
/** Retrieves the dimensions of the dataset */
int hdfutil::GetDsDims (const H5::DataSet & dataset, int dims[3]) {
H5::DataSpace dataspace = dataset.getSpace();
bool simple = dataspace.isSimple();
if (!simple)
throw std::runtime_error("complex HDF5 dataspace");
int rank = (int)dataspace.getSimpleExtentNdims();
if (rank > 3)
throw std::runtime_error("unsupported dimensionality");
hsize_t h5_dims[3];
dataspace.getSimpleExtentDims(h5_dims, NULL);
for (int i = 0; i < rank; i++)
dims[i] = (int)h5_dims[i];
for (int i = rank; i < 3; i++)
dims[i] = -1;
return rank;
}
示例12: getNodeType
bool readDataset1D(const H5::H5File &file, const std::string &name, std::vector<_Tp> &data)
{
H5::DataSet dataset = file.openDataSet(name);
H5::DataSpace dataspace = dataset.getSpace();
hsize_t dims_out[1];
int rank = dataspace.getSimpleExtentDims( dims_out, NULL);
int _type;
bool read = getNodeType(dataset, _type);
read &= (_type == StorageNode::SEQ);
read &= (rank == 1);
if (!read)
return read;
data.resize(dims_out[0]);
dataset.read(data.data(), dataset.getDataType());
return true;
}
示例13: strreadbuf
OXSXDataSet
DataSetIO::LoadDataSet(const std::string& filename_){
// Get Data Set
H5::H5File file(filename_, H5F_ACC_RDONLY);
H5::DataSet dataSet = file.openDataSet("observations");
// read meta information
unsigned nObs = 0;
H5::Attribute nameAtt = dataSet.openAttribute("observed_quantities");
H5::Attribute countAtt = dataSet.openAttribute("n_observables");
H5std_string strreadbuf("");
nameAtt.read(nameAtt.getDataType(), strreadbuf);
countAtt.read(countAtt.getDataType(), &nObs);
// Read data out as 1D array
hsize_t nData = 0;
dataSet.getSpace().getSimpleExtentDims(&nData, NULL);
size_t nEntries = nData/nObs;
std::vector<double> flatData(nData, 0);
dataSet.read(&flatData.at(0), H5::PredType::NATIVE_DOUBLE);
assert(nData%nObs == 0); // logic error in writing file (this class!) if assert fails.
// Assemble into an OXSX data set
OXSXDataSet oxsxDataSet;
// Set the variable names
oxsxDataSet.SetObservableNames(UnpackString(strreadbuf, fDelimiter));
// then the data
std::vector<double> oneEventObs(nObs, 0);
for(size_t i = 0; i < nEntries; i++){
for(size_t j = 0; j < nObs; j++)
oneEventObs[j] = flatData.at(i * nObs + j);
oxsxDataSet.AddEntry(EventData(oneEventObs));
}
return oxsxDataSet;
}
示例14: memspace
std::vector<double> readlastrow( H5::DataSet& ds )
{
H5::DataSpace origspace = ds.getSpace();
int rank = origspace.getSimpleExtentNdims();
hsize_t dims[rank];
int ndims = origspace.getSimpleExtentDims( dims, NULL);
hsize_t nrows=dims[0];
hsize_t ncols=dims[1];
std::vector<double> returnvect( ncols );
hsize_t targrowoffset = nrows-1;
hsize_t targcoloffset = 0;
hsize_t dimsmem[rank] = {1, ncols};
H5::DataSpace memspace(rank, dimsmem);
hsize_t offset[rank] = { targrowoffset, targcoloffset };
origspace.selectHyperslab( H5S_SELECT_SET, dimsmem, offset );
ds.read( returnvect.data(), H5::PredType::NATIVE_DOUBLE, memspace, origspace );
return returnvect;
}
示例15: catch
void Hdf5Handler::initialize(
const std::string& filename,
const std::vector<Hdf5ColumnData>& columns)
{
try
{
m_h5File.reset(new H5::H5File(filename, H5F_ACC_RDONLY));
}
catch (const H5::FileIException&)
{
throw hdf5_error("Could not open HDF5 file");
}
try
{
// Open each HDF5 DataSet and its corresponding DataSpace.
for (const auto& col : columns)
{
const std::string dataSetName = col.name;
const H5::PredType predType = col.predType;
const H5::DataSet dataSet = m_h5File->openDataSet(dataSetName);
const H5::DataSpace dataSpace = dataSet.getSpace();
m_columnDataMap.insert(std::make_pair(
dataSetName,
ColumnData(predType, dataSet, dataSpace)));
// Does not check whether all the columns are the same length.
m_numPoints =
std::max((uint64_t)getColumnNumEntries(dataSetName), m_numPoints);
}
}
catch (const H5::Exception&)
{
throw hdf5_error("Could not initialize data set information");
}
}