File tree Expand file tree Collapse file tree 6 files changed +21
-12
lines changed
Expand file tree Collapse file tree 6 files changed +21
-12
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -1887,7 +1887,7 @@ void joined_dim(std::string const &ext)
18871887
18881888 auto it = s.writeIterations ()[100 ];
18891889
1890- Dataset numParticlesDS (determineDatatype<patchType>(), {1 });
1890+ Dataset numParticlesDS (determineDatatype<patchType>(), {0 });
18911891 numParticlesDS.joinedDimension = 0 ;
18921892 auto numParticles =
18931893 it.particles [" e" ]
@@ -1900,7 +1900,7 @@ void joined_dim(std::string const &ext)
19001900
19011901 auto patchOffset = it.particles [" e" ].particlePatches [" offset" ][" x" ];
19021902 auto patchExtent = it.particles [" e" ].particlePatches [" extent" ][" x" ];
1903- Dataset particlePatchesDS (determineDatatype<float >(), {1 });
1903+ Dataset particlePatchesDS (determineDatatype<float >(), {0 });
19041904 particlePatchesDS.joinedDimension = 0 ;
19051905 patchOffset.resetDataset (particlePatchesDS);
19061906 patchExtent.resetDataset (particlePatchesDS);
Original file line number Diff line number Diff line change @@ -7263,7 +7263,7 @@ void joined_dim(std::string const &ext)
72637263
72647264 auto it = s.writeIterations ()[100 ];
72657265
7266- Dataset numParticlesDS (determineDatatype<patchType>(), {1 });
7266+ Dataset numParticlesDS (determineDatatype<patchType>(), {0 });
72677267 numParticlesDS.joinedDimension = 0 ;
72687268 auto numParticles =
72697269 it.particles [" e" ]
@@ -7276,7 +7276,7 @@ void joined_dim(std::string const &ext)
72767276
72777277 auto patchOffset = it.particles [" e" ].particlePatches [" offset" ][" x" ];
72787278 auto patchExtent = it.particles [" e" ].particlePatches [" extent" ][" x" ];
7279- Dataset particlePatchesDS (determineDatatype<float >(), {1 });
7279+ Dataset particlePatchesDS (determineDatatype<float >(), {0 });
72807280 particlePatchesDS.joinedDimension = 0 ;
72817281 patchOffset.resetDataset (particlePatchesDS);
72827282 patchExtent.resetDataset (particlePatchesDS);
You can’t perform that action at this time.
0 commit comments