Skip to content
Snippets Groups Projects
Unverified Commit 70559bc3 authored by Michael Emiel Gevaert's avatar Michael Emiel Gevaert Committed by GitHub
Browse files

test for completely empty datasets (#281)

* test for completely empty datasets

* prevents failures with cryptic error message:
    HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 140737340061504:
    #000: ../../../src/H5Shyper.c line 7057 in H5Sselect_hyperslab(): hyperslab doesn't support H5S_NULL space
parent 5932272a
No related branches found
No related tags found
No related merge requests found
......@@ -29,15 +29,15 @@ namespace sonata {
namespace {
const char* H5_DYNAMICS_PARAMS = "dynamics_params";
const char* H5_LIBRARY = "@library";
constexpr const char* const H5_DYNAMICS_PARAMS = "dynamics_params";
constexpr const char* const H5_LIBRARY = "@library";
std::set<std::string> _listChildren(const HighFive::Group& group,
const std::set<std::string>& ignoreNames = {}) {
std::set<std::string> result;
for (const auto& name : group.listObjectNames()) {
if (ignoreNames.count(name)) {
if (ignoreNames.count(name) > 0) {
continue;
}
result.insert(name);
......@@ -57,7 +57,6 @@ std::set<std::string> _listExplicitEnumerations(const HighFive::Group h5Group,
return names;
}
template <typename T>
std::vector<T> _readChunk(const HighFive::DataSet& dset, const Selection::Range& range) {
std::vector<T> result;
......@@ -70,6 +69,10 @@ std::vector<T> _readChunk(const HighFive::DataSet& dset, const Selection::Range&
template <typename T, typename std::enable_if<!std::is_pod<T>::value>::type* = nullptr>
std::vector<T> _readSelection(const HighFive::DataSet& dset, const Selection& selection) {
if (selection.ranges().empty() || dset.getElementCount() == 0) {
return {};
}
if (selection.ranges().size() == 1) {
return _readChunk<T>(dset, selection.ranges().front());
}
......@@ -89,7 +92,7 @@ std::vector<T> _readSelection(const HighFive::DataSet& dset, const Selection& se
template <typename T, typename std::enable_if<std::is_pod<T>::value>::type* = nullptr>
std::vector<T> _readSelection(const HighFive::DataSet& dset, const Selection& selection) {
if (selection.ranges().empty()) {
if (selection.ranges().empty() || dset.getElementCount() == 0) {
return {};
} else if (selection.ranges().size() == 1) {
return _readChunk<T>(dset, selection.ranges().front());
......
......@@ -163,6 +163,13 @@ TEST_CASE("NodePopulationSelectAll", "[base]") {
TEST_CASE("NodePopulationmatchAttributeValues", "[base]") {
NodePopulation population("./data/nodes1.h5", "", "nodes-A");
SECTION("int") {
const auto sel = population.matchAttributeValues("A-int64", 1);
CHECK(sel.flatSize() == 0);
CHECK_THROWS_AS(population.matchAttributeValues("E-mapping-good", 1), SonataError);
}
SECTION("String") {
auto sel = population.matchAttributeValues<std::string>("attr-Z", "bb");
CHECK(sel.flatSize() == 1);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment