Skip to content

Commit

Permalink
Add H5 attribute functions
Browse files Browse the repository at this point in the history
  • Loading branch information
spinicist committed Feb 7, 2024
1 parent 741cd89 commit 71aea0e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/io/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,23 @@ auto Reader::readMeta() const -> std::map<std::string, float>
return meta;
}

template <>
auto Reader::readAttribute<float>(std::string const &ds_name, std::string const &attr_name) const -> float
{
float val;
CheckedCall(H5LTget_attribute_float(handle_, ds_name.c_str(), attr_name.c_str(), &val),
fmt::format("reading attribute {} from {}", attr_name, ds_name));
return val;
}

template <>
auto Reader::readAttribute<int>(std::string const &ds_name, std::string const &attr_name) const -> int
{
int val;
CheckedCall(H5LTget_attribute_int(handle_, ds_name.c_str(), attr_name.c_str(), &val),
fmt::format("reading attribute {} from {}", attr_name, ds_name));
return val;
}

} // namespace HD5
} // namespace rl
2 changes: 1 addition & 1 deletion src/io/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct Reader
auto readMeta() const -> std::map<std::string, float>; // Read meta-data group

template <typename T>
auto readAttribute(std::string const &dataset, std::string const &attribute) -> T;
auto readAttribute(std::string const &dataset, std::string const &attribute) const -> T;

template <typename T>
auto readTensor(std::string const &label) const -> T;
Expand Down

0 comments on commit 71aea0e

Please sign in to comment.