Skip to content

Commit 2b255f6

Browse files
Use std::unique_ptr in Span API fallback (#1820)
* Use std::unique_ptr in Span API fallback no reason why we shouldnt * Remove unused string overloads * Remove support for boolean types
1 parent 9b90ba0 commit 2b255f6

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

src/RecordComponent.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,9 +986,10 @@ DynamicMemoryView<T> RecordComponent::storeChunk(Offset offset, Extent extent)
986986
return storeChunk<T>(std::move(offset), std::move(extent), [](size_t size) {
987987
#if (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 11000) || \
988988
(defined(__apple_build_version__) && __clang_major__ < 14)
989-
return std::shared_ptr<T>{new T[size], [](auto *ptr) { delete[] ptr; }};
989+
return UniquePtrWithLambda<T>{
990+
new T[size], [](auto *ptr) { delete[] ptr; }};
990991
#else
991-
return std::shared_ptr< T[] >{ new T[ size ] };
992+
return std::unique_ptr<T[]>{new T[size]};
992993
#endif
993994
});
994995
}
@@ -1045,7 +1046,7 @@ void RecordComponent::verifyChunk(Offset const &o, Extent const &e) const
10451046
OPENPMD_INSTANTIATE_FULLMATRIX(OPENPMD_ARRAY(type)) \
10461047
OPENPMD_INSTANTIATE_FULLMATRIX(type const[])
10471048

1048-
OPENPMD_FOREACH_NONVECTOR_DATATYPE(OPENPMD_INSTANTIATE)
1049+
OPENPMD_FOREACH_DATASET_DATATYPE(OPENPMD_INSTANTIATE)
10491050
#undef OPENPMD_INSTANTIATE
10501051
#undef OPENPMD_INSTANTIATE_FULLMATRIX
10511052
#undef OPENPMD_INSTANTIATE_WITH_AND_WITHOUT_EXTENT

src/binding/python/RecordComponent.cpp

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -584,18 +584,11 @@ struct GetCurrentView
584584

585585
static constexpr char const *errorMsg = "DynamicMemoryView";
586586
};
587-
588-
template <>
589-
pybind11::object
590-
GetCurrentView::call<std::string>(PythonDynamicMemoryView const &)
591-
{
592-
throw std::runtime_error("[DynamicMemoryView] Only PODs allowed.");
593-
}
594587
} // namespace
595588

596589
pybind11::object PythonDynamicMemoryView::currentView() const
597590
{
598-
return switchNonVectorType<GetCurrentView>(m_datatype, *this);
591+
return switchDatasetType<GetCurrentView>(m_datatype, *this);
599592
}
600593

601594
namespace
@@ -628,14 +621,6 @@ struct StoreChunkSpan
628621

629622
static constexpr char const *errorMsg = "RecordComponent.store_chunk()";
630623
};
631-
632-
template <>
633-
PythonDynamicMemoryView StoreChunkSpan::call<std::string>(
634-
RecordComponent &, Offset const &, Extent const &)
635-
{
636-
throw std::runtime_error(
637-
"[RecordComponent.store_chunk()] Only PODs allowed.");
638-
}
639624
} // namespace
640625

641626
inline PythonDynamicMemoryView store_chunk_span(
@@ -656,7 +641,7 @@ inline PythonDynamicMemoryView store_chunk_span(
656641
std::begin(shape),
657642
[&maskIt](std::uint64_t) { return !*(maskIt++); });
658643

659-
return switchNonVectorType<StoreChunkSpan>(
644+
return switchDatasetType<StoreChunkSpan>(
660645
r.getDatatype(), r, offset, extent);
661646
}
662647

@@ -726,7 +711,7 @@ void load_chunk(
726711
}
727712
}
728713

729-
switchNonVectorType<LoadChunkIntoPythonBuffer>(
714+
switchDatasetType<LoadChunkIntoPythonBuffer>(
730715
r.getDatatype(), r, buffer, buffer_info, offset, extent);
731716
}
732717

@@ -910,9 +895,6 @@ void init_RecordComponent(py::module &m)
910895
// std::endl; typestring: encoding + type + number of bytes
911896
switch (dtype)
912897
{
913-
case DT::BOOL:
914-
return rc.makeConstant(*static_cast<bool *>(buf.ptr));
915-
break;
916898
case DT::CHAR:
917899
return rc.makeConstant(*static_cast<char *>(buf.ptr));
918900
break;
@@ -971,6 +953,11 @@ void init_RecordComponent(py::module &m)
971953
return rc.makeConstant(
972954
*static_cast<std::complex<long double> *>(buf.ptr));
973955
break;
956+
case DT::BOOL:
957+
throw std::runtime_error(
958+
"make_constant: "
959+
"Boolean type not supported!");
960+
break;
974961
default:
975962
throw std::runtime_error(
976963
"make_constant: "
@@ -998,10 +985,6 @@ void init_RecordComponent(py::module &m)
998985
"make_constant",
999986
&RecordComponent::makeConstant<double>,
1000987
py::arg("value"))
1001-
.def(
1002-
"make_constant",
1003-
&RecordComponent::makeConstant<bool>,
1004-
py::arg("value"))
1005988
.def(
1006989
"make_empty",
1007990
[](RecordComponent &rc, Datatype dt, uint8_t dimensionality) {

test/SerialIOTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3021,7 +3021,7 @@ TEST_CASE("git_hdf5_legacy_picongpu", "[serial][hdf5]")
30213021
auto radiationMask =
30223022
o.iterations[200]
30233023
.particles["e"]["radiationMask"][RecordComponent::SCALAR];
3024-
switchNonVectorType<LoadDataset>(
3024+
switchDatasetType<LoadDataset>(
30253025
radiationMask.getDatatype(), radiationMask);
30263026

30273027
auto particlePatches = o.iterations[200].particles["e"].particlePatches;

0 commit comments

Comments
 (0)