Skip to content

Commit

Permalink
Rename ResizePolicy enum members to more compact ones
Browse files Browse the repository at this point in the history
* RESIZE_TO_FIT    ---> FIT
* RESIZE_GROW_ONLY ---> GROW
* DO_NOT_RESIZE    ---> OFF
  • Loading branch information
DavidAce committed Apr 24, 2021
1 parent 163de06 commit ac5e3b6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
12 changes: 6 additions & 6 deletions h5pp/include/h5pp/details/h5ppEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ namespace h5pp {
};

enum class ResizePolicy {
RESIZE_TO_FIT, // (Default)
INCREASE_ONLY,
DO_NOT_RESIZE,
FIT, /* Writing over a dataset will shrink or grow existing dimensions to fit new data (default on H5D_CHUNKED) */
GROW, /* Writing over a dataset will may grow existing dimensions, but never shrink, to fit new data (works only on H5D_CHUNKED) */
OFF, /* Writing over a dataset will not modify existing dimensions */
};

enum class LocationMode {
/*
* Some operations, such as h5pp::hdf5::copyLink support copying objects between files.
* However, detecting whether two given location id's are on the same file can become
* a bottleneck when batch processing a large amount of files.
*
* However, detecting whether two given location ids are on the same file can become
* a bottleneck when batch processing a large amount of files. If we know beforehand what it will be, setting
* this flag avoids a costly detection step.
*/

SAME_FILE, /*!< Interpret source and target location id's as being on the same file */
Expand Down
10 changes: 5 additions & 5 deletions h5pp/include/h5pp/details/h5ppFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ namespace h5pp {

/*
*
* Functions for transfering contents between locations or files
* Functions for transferring contents between locations or files
*
*/

Expand Down Expand Up @@ -425,7 +425,7 @@ namespace h5pp {
const OptDimsType & dsetDimsChunk = std::nullopt, /*!< (On create) Chunking dimensions. Only valid for H5D_CHUNKED datasets */
const OptDimsType & dsetDimsMax = std::nullopt, /*!< (On create) Maximum dimensions. Only valid for H5D_CHUNKED datasets */
std::optional<hid::h5t> h5Type = std::nullopt, /*!< (On create) Type of dataset. Override automatic type detection. */
std::optional<ResizePolicy> resizePolicy = std::nullopt, /*!< Type of resizing if needed. Choose INCREASE_ONLY, RESIZE_TO_FIT,DO_NOT_RESIZE */
std::optional<ResizePolicy> resizePolicy = std::nullopt, /*!< Type of resizing if needed. Choose GROW, FIT,OFF */
std::optional<unsigned int> compression = std::nullopt) /*!< (On create) Compression level 0-9, 0 = off, 9 is gives best compression and is slowest */
{
/* clang-format on */
Expand All @@ -451,7 +451,7 @@ namespace h5pp {
std::optional<H5D_layout_t> h5Layout = std::nullopt, /*!< (On create) Layout of dataset. Choose between H5D_CHUNKED,H5D_COMPACT and H5D_CONTIGUOUS */
const OptDimsType & dsetDimsChunk = std::nullopt, /*!< (On create) Chunking dimensions. Only valid for H5D_CHUNKED datasets */
const OptDimsType & dsetDimsMax = std::nullopt, /*!< (On create) Maximum dimensions. Only valid for H5D_CHUNKED datasets */
std::optional<ResizePolicy> resizePolicy = std::nullopt, /*!< Type of resizing if needed. Choose INCREASE_ONLY, RESIZE_TO_FIT,DO_NOT_RESIZE */
std::optional<ResizePolicy> resizePolicy = std::nullopt, /*!< Type of resizing if needed. Choose GROW, FIT, OFF */
std::optional<unsigned int> compression = std::nullopt /*!< (On create) Compression level 0-9, 0 = off, 9 is gives best compression and is slowest */
/* clang-format on */
) {
Expand All @@ -478,7 +478,7 @@ namespace h5pp {
const OptDimsType & dsetDimsChunk = std::nullopt, /*!< (On create) Chunking dimensions. Only valid for H5D_CHUNKED datasets */
const OptDimsType & dsetDimsMax = std::nullopt, /*!< (On create) Maximum dimensions. Only valid for H5D_CHUNKED datasets */
std::optional<hid::h5t> h5Type = std::nullopt, /*!< (On create) Type of dataset. Override automatic type detection. */
std::optional<ResizePolicy> resizePolicy = std::nullopt, /*!< Type of resizing if needed. Choose INCREASE_ONLY, RESIZE_TO_FIT,DO_NOT_RESIZE */
std::optional<ResizePolicy> resizePolicy = std::nullopt, /*!< Type of resizing if needed. Choose GROW, FIT, OFF */
std::optional<unsigned int> compression = std::nullopt /*!< (On create) Compression level 0-9, 0 = off, 9 is gives best compression and is slowest */
/* clang-format on */
) {
Expand Down Expand Up @@ -558,7 +558,7 @@ namespace h5pp {
Options options;
options.linkPath = dsetPath;
options.dsetSlab = hyperslab;
options.resizePolicy = ResizePolicy::DO_NOT_RESIZE;
options.resizePolicy = ResizePolicy::OFF;
auto dsetInfo = h5pp::scan::readDsetInfo(openFileHandle(), options, plists);
if(not dsetInfo.dsetExists or not dsetInfo.dsetExists.value())
throw std::runtime_error(h5pp::format("Could not write hyperslab: dataset [{}] does not exist", dsetPath));
Expand Down
16 changes: 8 additions & 8 deletions h5pp/include/h5pp/details/h5ppHdf5.h
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ namespace h5pp::hdf5 {
dsetInfo.dsetChunk = std::nullopt;
dsetInfo.dsetDimsMax = std::nullopt;
dsetInfo.h5Layout = H5D_CONTIGUOUS; // In case it's a big text
dsetInfo.resizePolicy = h5pp::ResizePolicy::DO_NOT_RESIZE;
dsetInfo.resizePolicy = h5pp::ResizePolicy::OFF;
setProperty_layout(dsetInfo);
return;
}
Expand Down Expand Up @@ -1295,13 +1295,13 @@ namespace h5pp::hdf5 {

inline void
resizeDataset(DsetInfo &info, const std::vector<hsize_t> &newDimensions, std::optional<h5pp::ResizePolicy> policy = std::nullopt) {
if(info.resizePolicy == h5pp::ResizePolicy::DO_NOT_RESIZE) return;
if(info.resizePolicy == h5pp::ResizePolicy::OFF) return;
if(not policy) policy = info.resizePolicy;
if(not policy and info.dsetSlab)
policy = h5pp::ResizePolicy::INCREASE_ONLY; // A hyperslab selection on the dataset has been made. Let's not shrink!
if(not policy) policy = h5pp::ResizePolicy::RESIZE_TO_FIT;
if(policy == h5pp::ResizePolicy::DO_NOT_RESIZE) return;
if(policy == h5pp::ResizePolicy::RESIZE_TO_FIT and info.dsetSlab) {
policy = h5pp::ResizePolicy::GROW; // A hyperslab selection on the dataset has been made. Let's not shrink!
if(not policy) policy = h5pp::ResizePolicy::FIT;
if(policy == h5pp::ResizePolicy::OFF) return;
if(policy == h5pp::ResizePolicy::FIT and info.dsetSlab) {
bool outofbounds = false;
for(size_t idx = 0; idx < newDimensions.size(); idx++) {
if(info.dsetSlab->extent and newDimensions[idx] < info.dsetSlab->extent->at(idx)) {
Expand All @@ -1315,7 +1315,7 @@ namespace h5pp::hdf5 {
}
if(outofbounds)
h5pp::logger::log->warn("A hyperslab selection was made on the dataset [{}{}]. "
"However, resize policy [RESIZE_TO_FIT] will resize this dataset to dimensions {}. "
"However, resize policy [FIT] will resize this dataset to dimensions {}. "
"This is likely an error.",
info.dsetPath.value(),
info.dsetSlab->string(),
Expand Down Expand Up @@ -1347,7 +1347,7 @@ namespace h5pp::hdf5 {
info.dsetPath.value(),
info.dsetDims.value(),
newDimensions));
if(policy == h5pp::ResizePolicy::INCREASE_ONLY) {
if(policy == h5pp::ResizePolicy::GROW) {
bool allDimsAreSmaller = true;
for(size_t idx = 0; idx < newDimensions.size(); idx++)
if(newDimensions[idx] > info.dsetDims.value()[idx]) allDimsAreSmaller = false;
Expand Down
10 changes: 5 additions & 5 deletions h5pp/include/h5pp/details/h5ppInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace h5pp {
std::optional<hid::h5t> h5Type = std::nullopt; /*!< (On create) Type of dataset. Override automatic type detection. */
std::optional<H5D_layout_t> h5Layout = std::nullopt; /*!< (On create) Layout of dataset. Choose between H5D_CHUNKED,H5D_COMPACT and H5D_CONTIGUOUS */
std::optional<unsigned int> compression = std::nullopt; /*!< (On create) Compression level 0-9, 0 = off, 9 is gives best compression and is slowest */
std::optional<h5pp::ResizePolicy> resizePolicy = std::nullopt; /*!< Type of resizing if needed. Choose INCREASE_ONLY, RESIZE_TO_FIT,DO_NOT_RESIZE */
std::optional<h5pp::ResizePolicy> resizePolicy = std::nullopt; /*!< Type of resizing if needed. Choose GROW, TO_FIT,OFF */
/* clang-format on */
[[nodiscard]] std::string string(bool enable = true) const {
std::string msg;
Expand Down Expand Up @@ -266,7 +266,7 @@ namespace h5pp {
/* clang-format off */
if(dsetExists and dsetPath and not dsetExists.value()) error_msg.append(h5pp::format("\t Dataset does not exist [{}]", dsetPath.value()));
else if(dsetExists and not dsetExists.value()) error_msg.append("\t Dataset does not exist");
if(resizePolicy and resizePolicy == h5pp::ResizePolicy::DO_NOT_RESIZE) error_msg.append("\t Resize mode is set to DO_NOT_RESIZE");
if(resizePolicy and resizePolicy == h5pp::ResizePolicy::OFF) error_msg.append("\t Resize policy is [OFF]");
if(not error_msg.empty())
throw std::runtime_error(h5pp::format("Cannot resize dataset.\n{}", error_msg));
if(not dsetPath ) error_msg.append("\t dsetPath\n");
Expand Down Expand Up @@ -359,9 +359,9 @@ namespace h5pp {
if(resizePolicy){
msg.append(" | resize mode ");
switch(resizePolicy.value()){
case ResizePolicy::RESIZE_TO_FIT: msg.append(h5pp::format("RESIZE_TO_FIT")); break;
case ResizePolicy::INCREASE_ONLY: msg.append(h5pp::format("INCREASE_ONLY")); break;
case ResizePolicy::DO_NOT_RESIZE: msg.append(h5pp::format("DO_NOT_RESIZE")); break;
case ResizePolicy::FIT: msg.append(h5pp::format("FIT")); break;
case ResizePolicy::GROW: msg.append(h5pp::format("GROW")); break;
case ResizePolicy::OFF: msg.append(h5pp::format("OFF")); break;
default: break;
}
}
Expand Down
14 changes: 7 additions & 7 deletions h5pp/include/h5pp/details/h5ppScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ namespace h5pp::scan {

if(not info.resizePolicy) info.resizePolicy = options.resizePolicy;
if(not info.resizePolicy) {
if(info.h5Layout != H5D_CHUNKED) info.resizePolicy = h5pp::ResizePolicy::DO_NOT_RESIZE;
else if(info.dsetSlab) info.resizePolicy = h5pp::ResizePolicy::INCREASE_ONLY; // A hyperslab selection on the dataset has been made. Let's not shrink!
else info.resizePolicy = h5pp::ResizePolicy::RESIZE_TO_FIT;
if(info.h5Layout != H5D_CHUNKED) info.resizePolicy = h5pp::ResizePolicy::OFF;
else if(info.dsetSlab) info.resizePolicy = h5pp::ResizePolicy::GROW; // A hyperslab selection on the dataset has been made. Let's not shrink!
else info.resizePolicy = h5pp::ResizePolicy::FIT;
}
if(not info.compression) {
hid::h5p plist = H5Dget_create_plist(info.h5Dset.value());
Expand Down Expand Up @@ -166,9 +166,9 @@ namespace h5pp::scan {
if(not info.compression) info.compression = h5pp::hdf5::getValidCompressionLevel(info.compression);
if(not info.resizePolicy) {
if(info.h5Layout != H5D_CHUNKED)
info.resizePolicy = h5pp::ResizePolicy::DO_NOT_RESIZE;
info.resizePolicy = h5pp::ResizePolicy::OFF;
else
info.resizePolicy = h5pp::ResizePolicy::RESIZE_TO_FIT;
info.resizePolicy = h5pp::ResizePolicy::FIT;
}
if(not info.h5Space) info.h5Space = h5pp::util::getDsetSpace(info.dsetSize.value(), info.dsetDims.value(), info.h5Layout.value(), info.dsetDimsMax);
// Apply hyperslab selection if there is any
Expand Down Expand Up @@ -278,9 +278,9 @@ namespace h5pp::scan {
if(not info.compression) info.compression = h5pp::hdf5::getValidCompressionLevel(info.compression);
if(not info.resizePolicy) {
if(info.h5Layout != H5D_CHUNKED)
info.resizePolicy = h5pp::ResizePolicy::DO_NOT_RESIZE;
info.resizePolicy = h5pp::ResizePolicy::OFF;
else
info.resizePolicy = h5pp::ResizePolicy::RESIZE_TO_FIT;
info.resizePolicy = h5pp::ResizePolicy::FIT;
}

h5pp::hdf5::setStringSize<DataType>(data, info.h5Type.value(), info.dsetSize.value(), info.dsetByte.value(), info.dsetDims.value()); // String size will be H5T_VARIABLE unless explicitly specified
Expand Down
2 changes: 1 addition & 1 deletion tests/test-overWrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main() {
// Now decrease size and overwrite again
vectorComplexDouble = std::vector<std::complex<double>>(1500, {10.0, 5.0});
somestring = "short string";
file.resizeDataset("overWriteGroup_chunked/vectorComplexDouble", 1500, h5pp::ResizePolicy::RESIZE_TO_FIT);
file.resizeDataset("overWriteGroup_chunked/vectorComplexDouble", 1500, h5pp::ResizePolicy::FIT);
file.writeDataset(vectorComplexDouble, "overWriteGroup_chunked/vectorComplexDouble");
file.writeDataset(somestring, "overWriteGroup_chunked/somestring");

Expand Down

0 comments on commit ac5e3b6

Please sign in to comment.