Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add split_by operation to split according to one of the Labels dimension #627

Open
Luthaf opened this issue May 22, 2024 · 1 comment
Open
Labels
Operations Related to metatensor-operations in Python

Comments

@Luthaf
Copy link
Member

Luthaf commented May 22, 2024

This would allow to do something like split_by(tensor, axis="samples", dimension="structure") to split along structures

@Luthaf Luthaf added the Operations Related to metatensor-operations in Python label May 22, 2024
@jwa7
Copy link
Contributor

jwa7 commented May 22, 2024

Good idea! The current API equivalent, though certainly more fiddly, is:

import numpy as np
import metatensor as mts

tensor = mts.load("path/to/tensor.npz")
split_by_axis = "samples"
split_by_dimension = "structure"
grouped_labels = [
    mts.Labels(names=split_by_dimension, values=np.array([A]))
    for A in mts.unique_metadata(tensor, axis=split_by_axis, names=split_by_dimension)
]

split_tensor = mts.split(tensor, split_by_axis, grouped_labels)

I guess the easiest way to implement split_by is to wrap the private functions in split.py and using unique_metadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Operations Related to metatensor-operations in Python
Projects
None yet
Development

No branches or pull requests

2 participants