openPMD / openPMD/openPMD-api

makeEmpty: Overload / Support Zero-Extends

Open
#516 0 comments 0 reactions 1 assignee Claimed by @franzpoeschel View on GitHub
api: new feature request frontend: C++17 frontend: Python3
Dominant language
C++
Stars
161
Forks
59
Avg merge
2d 22h
Merged PRs (30d)
7

Description

In some cases, as described in #514, it makes sense to explicitly write a zero-extend record component. We can already express this with constant record components but must allow this in the API properly.

Additionally, we can already add a new API `make_empty` instead of the "value-expecting" `make_constant` and automatically zero-initialize the `value` attribute of a constant record component.

In the future (https://github.com/openPMD/openPMD-standard/issues/211), we might want to allow more complicated types which are not zero-initializable. But for the API, we can keep the `value` with zero for now and expose the functionality already as described.

Python:
```python
import openpmd_api as api
import numpy as np

series = api.Series(
"myOutput/data_%05T.h5",
api.Access_Type.create)
i = series.iterations[42]

B = i.meshes["B"]
B_x = B["x"]

dataset = api.Dataset(
np.double,
[0, 0, 0, ])
B_x.reset_dataset(dataset)

# new (could also be implied if a `reset_dataset()` with zero-size shape is created
B_y.make_empty()

del series
```
or C++
```C++
#include

namespace api = openPMD;

auto series = api::Series(
"myOutput/data_%05T.h5",
api::AccessType::CREATE);
auto i = series.iterations[42];

auto B = i.meshes["B"];
auto B_x = B["x"];

auto dataset = api::Dataset(
api::determineDatatype(),
{0, 0});
B_x.resetDataset(dataset);

// new (could also be implied if a `resetDataset()` with zero-size shape is created
B_y.makeEmpty()
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.