Skip to content

Commit 8d6c352

Browse files
committed
Fix detection of empty datasets
1 parent 5c64920 commit 8d6c352

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

include/openPMD/Dataset.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@ class Dataset
5555
uint8_t rank;
5656
std::optional<size_t> joinedDimension;
5757
std::string options = "{}"; //!< backend-dependent JSON configuration
58+
59+
bool empty() const;
5860
};
5961
} // namespace openPMD

src/Dataset.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,17 @@ Dataset &Dataset::extend(Extent newExtents)
4949
extent = newExtents;
5050
return *this;
5151
}
52+
53+
bool Dataset::empty() const
54+
{
55+
for (size_t i = 0; i < extent.size(); ++i)
56+
{
57+
if (extent[i] == 0 &&
58+
(!joinedDimension.has_value() || joinedDimension.value() != i))
59+
{
60+
return true;
61+
}
62+
}
63+
return false;
64+
}
5265
} // namespace openPMD

src/RecordComponent.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ RecordComponent &RecordComponent::resetDataset(Dataset d)
9595
}
9696
// if( d.extent.empty() )
9797
// throw std::runtime_error("Dataset extent must be at least 1D.");
98-
if (std::any_of(
99-
d.extent.begin(), d.extent.end(), [](Extent::value_type const &i) {
100-
return i == 0u;
101-
}))
98+
if (d.empty())
10299
return makeEmpty(std::move(d));
103100

104101
rc.m_isEmpty = false;

src/backend/PatchRecordComponent.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ PatchRecordComponent &PatchRecordComponent::resetDataset(Dataset d)
4848
"written.");
4949
if (d.extent.empty())
5050
throw std::runtime_error("Dataset extent must be at least 1D.");
51-
if (std::any_of(
52-
d.extent.begin(), d.extent.end(), [](Extent::value_type const &i) {
53-
return i == 0u;
54-
}))
51+
if (d.empty())
5552
throw std::runtime_error(
5653
"Dataset extent must not be zero in any dimension.");
5754

test/ParallelIOTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ void joined_dim(std::string const &ext)
17881788

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

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

18021802
auto patchOffset = it.particles["e"].particlePatches["offset"]["x"];
18031803
auto patchExtent = it.particles["e"].particlePatches["extent"]["x"];
1804-
Dataset particlePatchesDS(determineDatatype<float>(), {1});
1804+
Dataset particlePatchesDS(determineDatatype<float>(), {0});
18051805
particlePatchesDS.joinedDimension = 0;
18061806
patchOffset.resetDataset(particlePatchesDS);
18071807
patchExtent.resetDataset(particlePatchesDS);

test/SerialIOTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7229,7 +7229,7 @@ void joined_dim(std::string const &ext)
72297229

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

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

72437243
auto patchOffset = it.particles["e"].particlePatches["offset"]["x"];
72447244
auto patchExtent = it.particles["e"].particlePatches["extent"]["x"];
7245-
Dataset particlePatchesDS(determineDatatype<float>(), {1});
7245+
Dataset particlePatchesDS(determineDatatype<float>(), {0});
72467246
particlePatchesDS.joinedDimension = 0;
72477247
patchOffset.resetDataset(particlePatchesDS);
72487248
patchExtent.resetDataset(particlePatchesDS);

0 commit comments

Comments
 (0)