Skip to content

Commit

Permalink
Fix detection of empty datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Apr 12, 2023
1 parent 5c64920 commit 8d6c352
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions include/openPMD/Dataset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ class Dataset
uint8_t rank;
std::optional<size_t> joinedDimension;
std::string options = "{}"; //!< backend-dependent JSON configuration

bool empty() const;
};
} // namespace openPMD
13 changes: 13 additions & 0 deletions src/Dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@ Dataset &Dataset::extend(Extent newExtents)
extent = newExtents;
return *this;
}

bool Dataset::empty() const
{
for (size_t i = 0; i < extent.size(); ++i)
{
if (extent[i] == 0 &&
(!joinedDimension.has_value() || joinedDimension.value() != i))
{
return true;
}
}
return false;
}
} // namespace openPMD
5 changes: 1 addition & 4 deletions src/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ RecordComponent &RecordComponent::resetDataset(Dataset d)
}
// if( d.extent.empty() )
// throw std::runtime_error("Dataset extent must be at least 1D.");
if (std::any_of(
d.extent.begin(), d.extent.end(), [](Extent::value_type const &i) {
return i == 0u;
}))
if (d.empty())
return makeEmpty(std::move(d));

rc.m_isEmpty = false;
Expand Down
5 changes: 1 addition & 4 deletions src/backend/PatchRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ PatchRecordComponent &PatchRecordComponent::resetDataset(Dataset d)
"written.");
if (d.extent.empty())
throw std::runtime_error("Dataset extent must be at least 1D.");
if (std::any_of(
d.extent.begin(), d.extent.end(), [](Extent::value_type const &i) {
return i == 0u;
}))
if (d.empty())
throw std::runtime_error(
"Dataset extent must not be zero in any dimension.");

Expand Down
4 changes: 2 additions & 2 deletions test/ParallelIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,7 @@ void joined_dim(std::string const &ext)

auto it = s.writeIterations()[100];

Dataset numParticlesDS(determineDatatype<patchType>(), {1});
Dataset numParticlesDS(determineDatatype<patchType>(), {0});
numParticlesDS.joinedDimension = 0;
auto numParticles =
it.particles["e"]
Expand All @@ -1801,7 +1801,7 @@ void joined_dim(std::string const &ext)

auto patchOffset = it.particles["e"].particlePatches["offset"]["x"];
auto patchExtent = it.particles["e"].particlePatches["extent"]["x"];
Dataset particlePatchesDS(determineDatatype<float>(), {1});
Dataset particlePatchesDS(determineDatatype<float>(), {0});
particlePatchesDS.joinedDimension = 0;
patchOffset.resetDataset(particlePatchesDS);
patchExtent.resetDataset(particlePatchesDS);
Expand Down
4 changes: 2 additions & 2 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7229,7 +7229,7 @@ void joined_dim(std::string const &ext)

auto it = s.writeIterations()[100];

Dataset numParticlesDS(determineDatatype<patchType>(), {1});
Dataset numParticlesDS(determineDatatype<patchType>(), {0});
numParticlesDS.joinedDimension = 0;
auto numParticles =
it.particles["e"]
Expand All @@ -7242,7 +7242,7 @@ void joined_dim(std::string const &ext)

auto patchOffset = it.particles["e"].particlePatches["offset"]["x"];
auto patchExtent = it.particles["e"].particlePatches["extent"]["x"];
Dataset particlePatchesDS(determineDatatype<float>(), {1});
Dataset particlePatchesDS(determineDatatype<float>(), {0});
particlePatchesDS.joinedDimension = 0;
patchOffset.resetDataset(particlePatchesDS);
patchExtent.resetDataset(particlePatchesDS);
Expand Down

0 comments on commit 8d6c352

Please sign in to comment.