TRIQS/h5 2.0.0
C++ interface to HDF5
Loading...
Searching...
No Matches
Python interface utilities

Detailed Description

Helper functions used in the Python interface of the h5 library.

Functions

c2py::pyref h5::h5_read_bare (group g, std::string const &name)
 Read a dataset from an HDF5 group and return it as a Python object.
void h5::h5_write_bare (group g, std::string const &name, PyObject *ob)
 Write a Python object to an HDF5 group.

Function Documentation

◆ h5_read_bare()

c2py::pyref h5::h5_read_bare ( group g,
std::string const & name )

#include </Users/runner/work/h5/h5/python/h5/h5py_io.hpp>

Read a dataset from an HDF5 group and return it as a Python object.

The Python type is determined from the dataset's HDF5 type and its rank:

  • Rank 0:
    • H5T_FLOAT \( \rightarrow \) Python float
    • H5T_INTEGER \( \rightarrow \) Python int
    • H5T_STRING \( \rightarrow \) Python str
  • Rank 1 and h5::array_interface::dataset_info has complex attribute \( \rightarrow \) Python complex
  • Rank 0, 1 or 2 and H5T_STRING \( \rightarrow \) Python str or list of (list of) str
  • Otherwise \( \rightarrow \) numpy ndarray
Parameters
gh5::group containing the dataset.
nameName of the dataset from which the object is read.
Returns
c2py::pyref wrapping the Python object (new reference).

Definition at line 170 of file h5py_io.cpp.

◆ h5_write_bare()

void h5::h5_write_bare ( group g,
std::string const & name,
PyObject * ob )

#include </Users/runner/work/h5/h5/python/h5/h5py_io.hpp>

Write a Python object to an HDF5 group.

Only scalars, strings and numpy arrays are supported. They are first converted to a corresponding C++ type and then written to HDF5 using the functionality provided by h5:

  • numpy ndarray \( \rightarrow \) h5::array_interface::array_view
  • numpy scalar \( \rightarrow \) 0-dimensional numpy array \( \rightarrow \) h5::array_interface::array_view
  • Python float \( \rightarrow \) double
  • Python bool \( \rightarrow \) bool
  • Python int \( \rightarrow \) long
  • Python str \( \rightarrow \) const char *
  • Python complex \( \rightarrow \) std::complex<double>
Parameters
gh5::group in which the dataset is created.
nameName of the dataset to which the object is written.
obPython object to be written.

Definition at line 146 of file h5py_io.cpp.