Skip to content

makeEmpty: Overload / Support Zero-Extends #516

Open
@ax3l

Description

@ax3l

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 (openPMD/openPMD-standard#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:

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++

#include <openPMD/openPMD.hpp>

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<float>(),
    {0, 0});
B_x.resetDataset(dataset);

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions