metatensor-operations 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {metatensor_operations-0.2.2/metatensor_operations.egg-info → metatensor_operations-0.2.4}/PKG-INFO +4 -4
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/__init__.py +8 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/_dispatch.py +70 -0
- metatensor_operations-0.2.4/metatensor/operations/block_from_array.py +165 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/drop_blocks.py +16 -29
- metatensor_operations-0.2.4/metatensor/operations/is_contiguous.py +46 -0
- metatensor_operations-0.2.4/metatensor/operations/make_contiguous.py +49 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/slice.py +23 -38
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/split.py +8 -8
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4/metatensor_operations.egg-info}/PKG-INFO +4 -4
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor_operations.egg-info/SOURCES.txt +2 -0
- metatensor_operations-0.2.4/metatensor_operations.egg-info/requires.txt +1 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/pyproject.toml +2 -2
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/setup.py +2 -2
- metatensor_operations-0.2.2/metatensor/operations/block_from_array.py +0 -76
- metatensor_operations-0.2.2/metatensor_operations.egg-info/requires.txt +0 -1
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/AUTHORS +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/LICENSE +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/MANIFEST.in +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/README.rst +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/_backend.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/_checks.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/_utils.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/abs.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/add.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/allclose.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/detach.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/divide.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/dot.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/empty_like.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/equal.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/equal_metadata.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/join.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/lstsq.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/manipulate_dimension.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/multiply.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/one_hot.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/ones_like.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/pow.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/random_like.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/reduce_over_samples.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/remove_gradients.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/requires_grad.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/solve.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/sort.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/subtract.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/unique_metadata.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/zeros_like.py +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor_operations.egg-info/dependency_links.txt +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor_operations.egg-info/top_level.txt +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor_operations.egg-info/zip-safe +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/n_commits_since_last_tag +0 -0
- {metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/setup.cfg +0 -0
{metatensor_operations-0.2.2/metatensor_operations.egg-info → metatensor_operations-0.2.4}/PKG-INFO
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: metatensor-operations
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Operations to manipulate metatensor data types
|
|
5
5
|
Author: Guillaume Fraux, Davide Tisi, Philip Loche, Joseph W. Abbott, Jigyasa Nigam, Chiheb Ben Mahmoud
|
|
6
6
|
License: BSD-3-Clause
|
|
7
7
|
Project-URL: homepage, https://docs.metatensor.org/latest/
|
|
8
8
|
Project-URL: documentation, https://docs.metatensor.org/latest/
|
|
9
|
-
Project-URL: repository, https://github.com/
|
|
9
|
+
Project-URL: repository, https://github.com/metatensor/metatensor
|
|
10
10
|
Project-URL: changelog, https://docs.metatensor.org/latest/operations/CHANGELOG.html
|
|
11
11
|
Keywords: machine learning,molecular modeling
|
|
12
12
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -23,11 +23,11 @@ Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
|
23
23
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
24
24
|
Classifier: Topic :: Software Development :: Libraries
|
|
25
25
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
-
Requires-Python: >=3.
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
27
|
Description-Content-Type: text/x-rst
|
|
28
28
|
License-File: LICENSE
|
|
29
29
|
License-File: AUTHORS
|
|
30
|
-
Requires-Dist: metatensor-core<0.2.0,>=0.1.
|
|
30
|
+
Requires-Dist: metatensor-core<0.2.0,>=0.1.10
|
|
31
31
|
|
|
32
32
|
metatensor-operations
|
|
33
33
|
=====================
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/__init__.py
RENAMED
|
@@ -27,8 +27,16 @@ from .equal_metadata import ( # noqa
|
|
|
27
27
|
equal_metadata_raise,
|
|
28
28
|
equal_metadata_block_raise,
|
|
29
29
|
)
|
|
30
|
+
from .is_contiguous import ( # noqa: F401
|
|
31
|
+
is_contiguous,
|
|
32
|
+
is_contiguous_block,
|
|
33
|
+
)
|
|
30
34
|
from .join import join # noqa
|
|
31
35
|
from .lstsq import lstsq # noqa
|
|
36
|
+
from .make_contiguous import ( # noqa: F401
|
|
37
|
+
make_contiguous,
|
|
38
|
+
make_contiguous_block,
|
|
39
|
+
)
|
|
32
40
|
from .manipulate_dimension import ( # noqa
|
|
33
41
|
append_dimension,
|
|
34
42
|
insert_dimension,
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/_dispatch.py
RENAMED
|
@@ -58,6 +58,20 @@ def _check_all_np_ndarray(arrays):
|
|
|
58
58
|
)
|
|
59
59
|
|
|
60
60
|
|
|
61
|
+
def sum(array, axis: Optional[int] = None):
|
|
62
|
+
"""
|
|
63
|
+
Returns the sum of the elements in the array at the axis.
|
|
64
|
+
|
|
65
|
+
It is equivalent of np.sum(array, axis=axis) and torch.sum(tensor, dim=axis)
|
|
66
|
+
"""
|
|
67
|
+
if isinstance(array, TorchTensor):
|
|
68
|
+
return torch.sum(array, dim=axis)
|
|
69
|
+
elif isinstance(array, np.ndarray):
|
|
70
|
+
return np.sum(array, axis=axis).astype(array.dtype)
|
|
71
|
+
else:
|
|
72
|
+
raise TypeError(UNKNOWN_ARRAY_TYPE)
|
|
73
|
+
|
|
74
|
+
|
|
61
75
|
def abs(array):
|
|
62
76
|
"""
|
|
63
77
|
Returns the absolute value of the elements in the array.
|
|
@@ -329,6 +343,43 @@ def concatenate(arrays: List[TorchTensor], axis: int):
|
|
|
329
343
|
raise TypeError(UNKNOWN_ARRAY_TYPE)
|
|
330
344
|
|
|
331
345
|
|
|
346
|
+
def is_contiguous(array):
|
|
347
|
+
"""
|
|
348
|
+
Checks if a given array is contiguous.
|
|
349
|
+
|
|
350
|
+
In the case of numpy, C order is used for consistency with torch. As such,
|
|
351
|
+
only C-contiguity is checked.
|
|
352
|
+
"""
|
|
353
|
+
if isinstance(array, TorchTensor):
|
|
354
|
+
return array.is_contiguous()
|
|
355
|
+
|
|
356
|
+
elif isinstance(array, np.ndarray):
|
|
357
|
+
return array.flags["C_CONTIGUOUS"]
|
|
358
|
+
|
|
359
|
+
else:
|
|
360
|
+
raise TypeError(UNKNOWN_ARRAY_TYPE)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def make_contiguous(array):
|
|
364
|
+
"""
|
|
365
|
+
Returns a contiguous array.
|
|
366
|
+
|
|
367
|
+
This is equivalent of ``np.ascontiguousarray(array)`` and ``tensor.contiguous()``.
|
|
368
|
+
In the case of numpy, C order is used for consistency with torch. As such, only
|
|
369
|
+
C-contiguity is checked.
|
|
370
|
+
"""
|
|
371
|
+
if isinstance(array, TorchTensor):
|
|
372
|
+
if array.is_contiguous():
|
|
373
|
+
return array
|
|
374
|
+
return array.contiguous()
|
|
375
|
+
elif isinstance(array, np.ndarray):
|
|
376
|
+
if array.flags["C_CONTIGUOUS"]:
|
|
377
|
+
return array
|
|
378
|
+
return np.ascontiguousarray(array)
|
|
379
|
+
else:
|
|
380
|
+
raise TypeError(UNKNOWN_ARRAY_TYPE)
|
|
381
|
+
|
|
382
|
+
|
|
332
383
|
def copy(array):
|
|
333
384
|
"""Returns a copy of ``array``.
|
|
334
385
|
The new data is not shared with the original array"""
|
|
@@ -476,6 +527,25 @@ def int_array_like(int_list: List[int], like):
|
|
|
476
527
|
raise TypeError(UNKNOWN_ARRAY_TYPE)
|
|
477
528
|
|
|
478
529
|
|
|
530
|
+
def indices_like(shape: List[int], like):
|
|
531
|
+
"""
|
|
532
|
+
Creates a tensor of shape ``shape`` filled with ints that
|
|
533
|
+
enumerate the indices of the entries in the array, e.g.
|
|
534
|
+
``shape = (3,2)`` returns ``[[0,0],[0,1],[1,0],[1,1],[2,0],[2,1]]``.
|
|
535
|
+
"""
|
|
536
|
+
|
|
537
|
+
if isinstance(like, TorchTensor):
|
|
538
|
+
indices = torch.meshgrid(
|
|
539
|
+
[torch.arange(s, dtype=torch.int64, device=like.device) for s in shape],
|
|
540
|
+
indexing="ij",
|
|
541
|
+
)
|
|
542
|
+
return torch.stack(indices, dim=-1).reshape(-1, len(shape))
|
|
543
|
+
elif isinstance(like, np.ndarray):
|
|
544
|
+
return np.indices(shape).reshape(len(shape), -1).T.astype(np.int64)
|
|
545
|
+
else:
|
|
546
|
+
raise TypeError(UNKNOWN_ARRAY_TYPE)
|
|
547
|
+
|
|
548
|
+
|
|
479
549
|
def lstsq(X, Y, rcond: Optional[float], driver: Optional[str] = None):
|
|
480
550
|
"""
|
|
481
551
|
Computes a solution to the least squares problem of a system of linear
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
from typing import List, Optional
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from . import _dispatch
|
|
6
|
+
from ._backend import Labels, TensorBlock, torch_jit_is_scripting, torch_jit_script
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
import torch
|
|
11
|
+
|
|
12
|
+
TorchScriptClass = torch.ScriptClass
|
|
13
|
+
except ImportError:
|
|
14
|
+
|
|
15
|
+
class TorchScriptClass:
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@torch_jit_script
|
|
20
|
+
def block_from_array(
|
|
21
|
+
array,
|
|
22
|
+
sample_names: Optional[List[str]] = None,
|
|
23
|
+
component_names: Optional[List[str]] = None,
|
|
24
|
+
property_names: Optional[List[str]] = None,
|
|
25
|
+
) -> TensorBlock:
|
|
26
|
+
"""
|
|
27
|
+
Creates a simple TensorBlock from an array.
|
|
28
|
+
|
|
29
|
+
The metadata in the resulting :py:class:`TensorBlock` is filled with ranges of
|
|
30
|
+
integers. This function should be seen as a quick way of creating a
|
|
31
|
+
:py:class:`TensorBlock` from arbitrary data. However, the metadata generated in this
|
|
32
|
+
way has little meaning.
|
|
33
|
+
|
|
34
|
+
:param array: An array with two or more dimensions. This can either be a
|
|
35
|
+
:py:class:`numpy.ndarray` or a :py:class:`torch.Tensor`.
|
|
36
|
+
:param sample_names: A list containing ``d_samples`` names for the sample
|
|
37
|
+
dimensions. The first ``d_samples`` dimensions in the array will be interpreted
|
|
38
|
+
as enumerating samples. ``None`` implies a single dimension named ``"sample"``.
|
|
39
|
+
:param property_names: A list containing ``d_properties`` names for the property
|
|
40
|
+
dimensions. The last ``d_properties`` dimensions in the array will be
|
|
41
|
+
interpreted as enumerating properties. ``None`` implies a single dimension named
|
|
42
|
+
``"property"``.
|
|
43
|
+
:param component_names: A list containing ``n_component`` names for the component
|
|
44
|
+
dimensions. The middle ``d_components`` dimensions in the array will be
|
|
45
|
+
interpreted as enumerating components. ``None`` implies that all the middle
|
|
46
|
+
dimensions (after removing any sample and property dimensions) will be
|
|
47
|
+
considered components, named ``"component_xxx"``.
|
|
48
|
+
|
|
49
|
+
:return: A :py:class:`TensorBlock` whose values correspond to the provided
|
|
50
|
+
``array``. If no name options are provided, the metadata names are set to
|
|
51
|
+
``"sample"`` for samples; ``"component_1"``, ``"component_2"``, ... for
|
|
52
|
+
components; and ``property`` for properties. The number of ``component`` labels
|
|
53
|
+
is adapted to the dimensionality of the input array. If axes names are given, as
|
|
54
|
+
indicated in the parameter list, the dimensions of the array will be interpreted
|
|
55
|
+
accordingly, and indices also generated in a similar way. The metadata
|
|
56
|
+
associated with each axis is a range of integers going from 0 to the size of the
|
|
57
|
+
corresponding axis. The returned :py:class:`TensorBlock` has no gradients.
|
|
58
|
+
|
|
59
|
+
>>> import numpy as np
|
|
60
|
+
>>> import metatensor
|
|
61
|
+
>>> # Construct a simple 4D array:
|
|
62
|
+
>>> array = np.linspace(0, 10, 42).reshape((7, 3, 1, 2))
|
|
63
|
+
>>> # Transform it into a TensorBlock:
|
|
64
|
+
>>> tensor_block = metatensor.block_from_array(array)
|
|
65
|
+
>>> print(tensor_block)
|
|
66
|
+
TensorBlock
|
|
67
|
+
samples (7): ['sample']
|
|
68
|
+
components (3, 1): ['component_1', 'component_2']
|
|
69
|
+
properties (2): ['property']
|
|
70
|
+
gradients: None
|
|
71
|
+
>>> # The data inside the TensorBlock will correspond to the provided array:
|
|
72
|
+
>>> print(np.all(array == tensor_block.values))
|
|
73
|
+
True
|
|
74
|
+
>>> # High-dimensional tensor
|
|
75
|
+
>>> array = np.linspace(0, 10, 60).reshape((2, 3, 5, 1, 2))
|
|
76
|
+
>>> # Specify axes names:
|
|
77
|
+
>>> tensor_block = metatensor.block_from_array(
|
|
78
|
+
... array, sample_names=["a", "b"], property_names=["y"]
|
|
79
|
+
... )
|
|
80
|
+
>>> print(tensor_block)
|
|
81
|
+
TensorBlock
|
|
82
|
+
samples (6): ['a', 'b']
|
|
83
|
+
components (5, 1): ['component_1', 'component_2']
|
|
84
|
+
properties (2): ['y']
|
|
85
|
+
gradients: None
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
if torch_jit_is_scripting():
|
|
89
|
+
# we are using metatensor-torch
|
|
90
|
+
labels_array_like = torch.empty(0)
|
|
91
|
+
else:
|
|
92
|
+
if isinstance(Labels, TorchScriptClass):
|
|
93
|
+
# we are using metatensor-torch
|
|
94
|
+
labels_array_like = torch.empty(0)
|
|
95
|
+
else:
|
|
96
|
+
# we are using metatensor-core
|
|
97
|
+
labels_array_like = np.empty(0)
|
|
98
|
+
|
|
99
|
+
shape = array.shape
|
|
100
|
+
n_dimensions = len(shape)
|
|
101
|
+
if n_dimensions < 2:
|
|
102
|
+
raise ValueError(
|
|
103
|
+
f"the array provided to `block_from_array` \
|
|
104
|
+
must have at least two dimensions. Too few provided: {n_dimensions}"
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
# constructs the default label names and counts
|
|
108
|
+
if sample_names is None:
|
|
109
|
+
sample_names = ["sample"]
|
|
110
|
+
d_samples = len(sample_names)
|
|
111
|
+
if property_names is None:
|
|
112
|
+
property_names = ["property"]
|
|
113
|
+
d_properties = len(property_names)
|
|
114
|
+
# guess number of components
|
|
115
|
+
d_components = n_dimensions - d_samples - d_properties
|
|
116
|
+
if d_components < 0:
|
|
117
|
+
raise ValueError(
|
|
118
|
+
f"the array provided to `block_from_array` with shape {shape} "
|
|
119
|
+
+ "does not have enough dimensions to match the sample and property names"
|
|
120
|
+
)
|
|
121
|
+
if component_names is None:
|
|
122
|
+
component_names = [
|
|
123
|
+
f"component_{component_index + 1}"
|
|
124
|
+
for component_index in range(d_components)
|
|
125
|
+
]
|
|
126
|
+
if len(component_names) != d_components:
|
|
127
|
+
raise ValueError(
|
|
128
|
+
f"the array provided to `block_from_array` with shape {shape} "
|
|
129
|
+
+ "does not have enough dimensions to match the given sample, "
|
|
130
|
+
+ "component, and property names"
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
samples = Labels(
|
|
134
|
+
names=sample_names,
|
|
135
|
+
values=_dispatch.indices_like(shape[0:d_samples], labels_array_like),
|
|
136
|
+
)
|
|
137
|
+
components = [
|
|
138
|
+
Labels(
|
|
139
|
+
names=[component_names[component_index]],
|
|
140
|
+
values=_dispatch.int_array_like(
|
|
141
|
+
list(range(axis_size)), labels_array_like
|
|
142
|
+
).reshape(-1, 1),
|
|
143
|
+
)
|
|
144
|
+
for component_index, axis_size in enumerate(shape[d_samples:-d_properties])
|
|
145
|
+
]
|
|
146
|
+
properties = Labels(
|
|
147
|
+
names=property_names,
|
|
148
|
+
values=_dispatch.indices_like(shape[-d_properties:], labels_array_like),
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
device = _dispatch.get_device(array)
|
|
152
|
+
samples = samples.to(device)
|
|
153
|
+
components = [component.to(device) for component in components]
|
|
154
|
+
properties = properties.to(device)
|
|
155
|
+
|
|
156
|
+
# reshape the array if multiple axes of the input array are grouped as samples or
|
|
157
|
+
# properties (i.e. if `len(sample_names) > 1` or `len(property_names) > 1`)
|
|
158
|
+
if d_samples > 1 or d_properties > 1:
|
|
159
|
+
block_shape = [len(samples)]
|
|
160
|
+
for i in range(d_samples, d_samples + d_components):
|
|
161
|
+
block_shape.append(shape[i])
|
|
162
|
+
block_shape.append(len(properties))
|
|
163
|
+
array = array.reshape(block_shape)
|
|
164
|
+
|
|
165
|
+
return TensorBlock(array, samples, components, properties)
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/drop_blocks.py
RENAMED
|
@@ -16,23 +16,16 @@ def drop_blocks(tensor: TensorMap, keys: Labels, copy: bool = False) -> TensorMa
|
|
|
16
16
|
"""
|
|
17
17
|
Drop specified key/block pairs from a TensorMap.
|
|
18
18
|
|
|
19
|
-
:param tensor:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
reference the same data as the input `tensor`. The latter can be useful
|
|
30
|
-
for limiting memory usage, but should be used with caution when
|
|
31
|
-
manipulating the underlying data.
|
|
32
|
-
|
|
33
|
-
:return:
|
|
34
|
-
the input :py:class:`TensorMap` with the specified key/block pairs
|
|
35
|
-
dropped.
|
|
19
|
+
:param tensor: the :py:class:`TensorMap` to drop the key-block pair from.
|
|
20
|
+
|
|
21
|
+
:param keys: selection of keys to remove from the input ``tensor``. This can
|
|
22
|
+
contain any subset of the names of the tensor's keys.
|
|
23
|
+
|
|
24
|
+
:param copy: if :py:obj:`True`, the returned :py:class:`TensorMap` is constructed by
|
|
25
|
+
copying the blocks from the input `tensor`. If :py:obj:`False` (default), the
|
|
26
|
+
values of the blocks in the output :py:class:`TensorMap` reference the same data
|
|
27
|
+
as the input `tensor`. The latter can be useful for limiting memory usage, but
|
|
28
|
+
should be used with caution when manipulating the underlying data.
|
|
36
29
|
"""
|
|
37
30
|
# Check arg types
|
|
38
31
|
if not torch_jit_is_scripting():
|
|
@@ -49,13 +42,7 @@ def drop_blocks(tensor: TensorMap, keys: Labels, copy: bool = False) -> TensorMa
|
|
|
49
42
|
|
|
50
43
|
# Find the indices of keys to remove
|
|
51
44
|
tensor_keys = tensor.keys
|
|
52
|
-
|
|
53
|
-
to_remove_indices: List[int] = (_dispatch.where(to_remove != -1)[0]).tolist()
|
|
54
|
-
|
|
55
|
-
not_present_in_tensor = _dispatch.where(used_in_intersection == -1)[0]
|
|
56
|
-
if len(not_present_in_tensor) != 0:
|
|
57
|
-
key = keys.entry(not_present_in_tensor[0])
|
|
58
|
-
raise ValueError(f"{key.print()} is not present in this tensor")
|
|
45
|
+
to_remove_indices: List[int] = tensor_keys.select(keys).tolist()
|
|
59
46
|
|
|
60
47
|
# Create the new TensorMap
|
|
61
48
|
new_blocks: List[TensorBlock] = []
|
|
@@ -97,13 +84,13 @@ def drop_blocks(tensor: TensorMap, keys: Labels, copy: bool = False) -> TensorMa
|
|
|
97
84
|
new_blocks.append(new_block)
|
|
98
85
|
|
|
99
86
|
if len(new_keys_values) != 0:
|
|
100
|
-
new_keys = Labels(
|
|
87
|
+
new_keys = Labels(tensor_keys.names, _dispatch.stack(new_keys_values, 0))
|
|
101
88
|
else:
|
|
102
|
-
# note: if we're dropping, there must be at least one block
|
|
103
|
-
# otherwise, we will already have raised an error
|
|
104
89
|
new_keys = Labels(
|
|
105
|
-
names=
|
|
106
|
-
values=_dispatch.empty_like(
|
|
90
|
+
names=tensor_keys.names,
|
|
91
|
+
values=_dispatch.empty_like(
|
|
92
|
+
tensor_keys.values, (0, len(tensor_keys.names))
|
|
93
|
+
),
|
|
107
94
|
)
|
|
108
95
|
|
|
109
96
|
return TensorMap(keys=new_keys, blocks=new_blocks)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from . import _dispatch
|
|
2
|
+
from ._backend import TensorBlock, TensorMap, torch_jit_script
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@torch_jit_script
|
|
6
|
+
def is_contiguous_block(block: TensorBlock) -> bool:
|
|
7
|
+
"""
|
|
8
|
+
Checks whether the values array and gradients values arrays (if present) of an input
|
|
9
|
+
:py:class:`TensorBlock` are contiguous.
|
|
10
|
+
|
|
11
|
+
Note that arrays of :py:class:`Labels` objects are not checked for contiguity.
|
|
12
|
+
|
|
13
|
+
:param block: the input :py:class:`TensorBlock`.
|
|
14
|
+
|
|
15
|
+
:return: bool, true if all values arrays contiguous, false otherwise.
|
|
16
|
+
"""
|
|
17
|
+
if not _dispatch.is_contiguous(block.values):
|
|
18
|
+
return False
|
|
19
|
+
|
|
20
|
+
for _parameter, gradient in block.gradients():
|
|
21
|
+
if len(gradient.gradients_list()) != 0:
|
|
22
|
+
raise NotImplementedError("gradients of gradients are not supported")
|
|
23
|
+
|
|
24
|
+
if not _dispatch.is_contiguous(gradient.values):
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
return True
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@torch_jit_script
|
|
31
|
+
def is_contiguous(tensor: TensorMap) -> bool:
|
|
32
|
+
"""
|
|
33
|
+
Checks whether all values arrays and gradients values arrays (if present) in all
|
|
34
|
+
:py:class:`TensorBlock` of an input :py:class:`TensorMap` are contiguous.
|
|
35
|
+
|
|
36
|
+
Note that arrays of :py:class:`Labels` objects are not checked for contiguity.
|
|
37
|
+
|
|
38
|
+
:param tensor: the input :py:class:`TensorMap`.
|
|
39
|
+
|
|
40
|
+
:return: bool, true if all values arrays contiguous, false otherwise.
|
|
41
|
+
"""
|
|
42
|
+
for block in tensor.blocks():
|
|
43
|
+
if not is_contiguous_block(block):
|
|
44
|
+
return False
|
|
45
|
+
|
|
46
|
+
return True
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from . import _dispatch
|
|
4
|
+
from ._backend import TensorBlock, TensorMap, torch_jit_script
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@torch_jit_script
|
|
8
|
+
def make_contiguous_block(block: TensorBlock) -> TensorBlock:
|
|
9
|
+
"""
|
|
10
|
+
Returns a new :py:class:`TensorBlock` where the values and gradient (if present)
|
|
11
|
+
arrays are made to be contiguous.
|
|
12
|
+
|
|
13
|
+
:param block: the input :py:class:`TensorBlock`.
|
|
14
|
+
"""
|
|
15
|
+
new_block = TensorBlock(
|
|
16
|
+
values=_dispatch.make_contiguous(block.values),
|
|
17
|
+
samples=block.samples,
|
|
18
|
+
components=block.components,
|
|
19
|
+
properties=block.properties,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
for parameter, gradient in block.gradients():
|
|
23
|
+
if len(gradient.gradients_list()) != 0:
|
|
24
|
+
raise NotImplementedError("gradients of gradients are not supported")
|
|
25
|
+
|
|
26
|
+
new_gradient = TensorBlock(
|
|
27
|
+
values=_dispatch.make_contiguous(gradient.values),
|
|
28
|
+
samples=gradient.samples,
|
|
29
|
+
components=gradient.components,
|
|
30
|
+
properties=gradient.properties,
|
|
31
|
+
)
|
|
32
|
+
new_block.add_gradient(parameter, new_gradient)
|
|
33
|
+
|
|
34
|
+
return new_block
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@torch_jit_script
|
|
38
|
+
def make_contiguous(tensor: TensorMap) -> TensorMap:
|
|
39
|
+
"""
|
|
40
|
+
Returns a new :py:class:`TensorMap` where all values and gradient values arrays are
|
|
41
|
+
made to be contiguous.
|
|
42
|
+
|
|
43
|
+
:param tensor: the input :py:class:`TensorMap`.
|
|
44
|
+
"""
|
|
45
|
+
new_blocks: List[TensorBlock] = []
|
|
46
|
+
for block in tensor.blocks():
|
|
47
|
+
new_blocks.append(make_contiguous_block(block))
|
|
48
|
+
|
|
49
|
+
return TensorMap(tensor.keys, new_blocks)
|
|
@@ -12,22 +12,15 @@ from ._dispatch import TorchTensor
|
|
|
12
12
|
|
|
13
13
|
def _slice_block(block: TensorBlock, axis: str, labels: Labels) -> TensorBlock:
|
|
14
14
|
if axis == "samples":
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
block.values,
|
|
21
|
-
)
|
|
22
|
-
new_values = _dispatch.mask(block.values, 0, samples_mask)
|
|
23
|
-
new_samples = Labels(
|
|
24
|
-
block.samples.names,
|
|
25
|
-
_dispatch.mask(block.samples.values, 0, samples_mask),
|
|
26
|
-
)
|
|
15
|
+
selected = block.samples.select(labels)
|
|
16
|
+
|
|
17
|
+
bool_array = _dispatch.bool_array_like([], block.properties.values)
|
|
18
|
+
mask = _dispatch.zeros_like(bool_array, [len(block.samples)])
|
|
19
|
+
mask[selected] = True
|
|
27
20
|
|
|
28
21
|
new_block = TensorBlock(
|
|
29
|
-
values=
|
|
30
|
-
samples=
|
|
22
|
+
values=block.values[selected],
|
|
23
|
+
samples=Labels(block.samples.names, block.samples.values[selected]),
|
|
31
24
|
components=block.components,
|
|
32
25
|
properties=block.properties,
|
|
33
26
|
)
|
|
@@ -38,11 +31,11 @@ def _slice_block(block: TensorBlock, axis: str, labels: Labels) -> TensorBlock:
|
|
|
38
31
|
# sample_map contains at position old_sample the index of the
|
|
39
32
|
# corresponding new sample
|
|
40
33
|
sample_map = _dispatch.int_array_like(
|
|
41
|
-
int_list=[-1] * len(
|
|
42
|
-
like=
|
|
34
|
+
int_list=[-1] * len(block.samples),
|
|
35
|
+
like=block.samples.values,
|
|
43
36
|
)
|
|
44
37
|
last = 0
|
|
45
|
-
for i, picked in enumerate(
|
|
38
|
+
for i, picked in enumerate(mask):
|
|
46
39
|
if picked:
|
|
47
40
|
sample_map[i] = last
|
|
48
41
|
last += 1
|
|
@@ -53,7 +46,7 @@ def _slice_block(block: TensorBlock, axis: str, labels: Labels) -> TensorBlock:
|
|
|
53
46
|
|
|
54
47
|
sample_column = gradient.samples.column("sample")
|
|
55
48
|
if not isinstance(gradient.samples.values, TorchTensor) and isinstance(
|
|
56
|
-
|
|
49
|
+
mask, TorchTensor
|
|
57
50
|
):
|
|
58
51
|
# Torch complains if `sample_column` is numpy since it tries to convert
|
|
59
52
|
# it to a Tensor, but the numpy array is read-only. Making a copy
|
|
@@ -61,7 +54,7 @@ def _slice_block(block: TensorBlock, axis: str, labels: Labels) -> TensorBlock:
|
|
|
61
54
|
sample_column = sample_column.copy()
|
|
62
55
|
|
|
63
56
|
# Create a samples filter for the Gradient TensorBlock
|
|
64
|
-
grad_samples_mask =
|
|
57
|
+
grad_samples_mask = mask[_dispatch.to_index_array(sample_column)]
|
|
65
58
|
|
|
66
59
|
new_grad_samples_values = _dispatch.mask(
|
|
67
60
|
gradient.samples.values, 0, grad_samples_mask
|
|
@@ -100,20 +93,14 @@ def _slice_block(block: TensorBlock, axis: str, labels: Labels) -> TensorBlock:
|
|
|
100
93
|
|
|
101
94
|
else:
|
|
102
95
|
assert axis == "properties"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
block.values, len(block.values.shape) - 1, properties_mask
|
|
112
|
-
)
|
|
113
|
-
new_properties = Labels(
|
|
114
|
-
block.properties.names,
|
|
115
|
-
_dispatch.mask(block.properties.values, 0, properties_mask),
|
|
116
|
-
)
|
|
96
|
+
|
|
97
|
+
selected = block.properties.select(labels)
|
|
98
|
+
bool_array = _dispatch.bool_array_like([], block.properties.values)
|
|
99
|
+
mask = _dispatch.zeros_like(bool_array, [len(block.properties)])
|
|
100
|
+
mask[selected] = True
|
|
101
|
+
|
|
102
|
+
new_values = _dispatch.mask(block.values, len(block.values.shape) - 1, mask)
|
|
103
|
+
new_properties = Labels(block.properties.names, block.properties.values[mask])
|
|
117
104
|
|
|
118
105
|
new_block = TensorBlock(
|
|
119
106
|
values=new_values,
|
|
@@ -129,18 +116,16 @@ def _slice_block(block: TensorBlock, axis: str, labels: Labels) -> TensorBlock:
|
|
|
129
116
|
|
|
130
117
|
assert axis == "properties"
|
|
131
118
|
new_grad_values = _dispatch.mask(
|
|
132
|
-
gradient.values, len(gradient.values.shape) - 1,
|
|
119
|
+
gradient.values, len(gradient.values.shape) - 1, mask
|
|
133
120
|
)
|
|
134
|
-
new_grad_samples = gradient.samples
|
|
135
121
|
|
|
136
|
-
# Add sliced gradient to the TensorBlock
|
|
137
122
|
new_block.add_gradient(
|
|
138
123
|
parameter=parameter,
|
|
139
124
|
gradient=TensorBlock(
|
|
140
125
|
values=new_grad_values,
|
|
141
|
-
samples=
|
|
126
|
+
samples=gradient.samples,
|
|
142
127
|
components=gradient.components,
|
|
143
|
-
properties=
|
|
128
|
+
properties=new_properties,
|
|
144
129
|
),
|
|
145
130
|
)
|
|
146
131
|
|
|
@@ -89,10 +89,10 @@ def split(
|
|
|
89
89
|
Split a :py:class:`TensorMap` into multiple :py:class:`TensorMap`.
|
|
90
90
|
|
|
91
91
|
The operation is based on some specified groups of indices, along either the
|
|
92
|
-
"samples" or "properties" ``axis``. The
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
"samples" or "properties" ``axis``. The length of the returned list is equal to the
|
|
93
|
+
number of :py:class:`Labels` objects passed in ``grouped_labels``. Each returned
|
|
94
|
+
:py:class`TensorMap` will have the same keys and number of blocks at the input
|
|
95
|
+
``tensor``, but with the dimensions of the blocks reduced to only contain the
|
|
96
96
|
specified indices for the corresponding group.
|
|
97
97
|
|
|
98
98
|
For example, to split a tensor along the ``"samples"`` axis, according to the
|
|
@@ -198,10 +198,10 @@ def split_block(
|
|
|
198
198
|
"""
|
|
199
199
|
Splits an input :py:class:`TensorBlock` into multiple :py:class:`TensorBlock`
|
|
200
200
|
objects based on some specified ``grouped_labels``, along either the ``"samples"``
|
|
201
|
-
or ``"properties"`` ``axis``. The
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
or ``"properties"`` ``axis``. The length of the returned list is equal to the number
|
|
202
|
+
of :py:class:`Labels` objects passed in ``grouped_labels``. Each returned
|
|
203
|
+
:py:class`TensorBlock` will have the same keys and number of blocks at the input
|
|
204
|
+
``tensor``, but with the dimensions of the blocks reduced to only contain the
|
|
205
205
|
specified indices for the corresponding group.
|
|
206
206
|
|
|
207
207
|
For example, to split a block along the ``"samples"`` axis, according to the
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4/metatensor_operations.egg-info}/PKG-INFO
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: metatensor-operations
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Operations to manipulate metatensor data types
|
|
5
5
|
Author: Guillaume Fraux, Davide Tisi, Philip Loche, Joseph W. Abbott, Jigyasa Nigam, Chiheb Ben Mahmoud
|
|
6
6
|
License: BSD-3-Clause
|
|
7
7
|
Project-URL: homepage, https://docs.metatensor.org/latest/
|
|
8
8
|
Project-URL: documentation, https://docs.metatensor.org/latest/
|
|
9
|
-
Project-URL: repository, https://github.com/
|
|
9
|
+
Project-URL: repository, https://github.com/metatensor/metatensor
|
|
10
10
|
Project-URL: changelog, https://docs.metatensor.org/latest/operations/CHANGELOG.html
|
|
11
11
|
Keywords: machine learning,molecular modeling
|
|
12
12
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -23,11 +23,11 @@ Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
|
23
23
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
24
24
|
Classifier: Topic :: Software Development :: Libraries
|
|
25
25
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
-
Requires-Python: >=3.
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
27
|
Description-Content-Type: text/x-rst
|
|
28
28
|
License-File: LICENSE
|
|
29
29
|
License-File: AUTHORS
|
|
30
|
-
Requires-Dist: metatensor-core<0.2.0,>=0.1.
|
|
30
|
+
Requires-Dist: metatensor-core<0.2.0,>=0.1.10
|
|
31
31
|
|
|
32
32
|
metatensor-operations
|
|
33
33
|
=====================
|
|
@@ -21,8 +21,10 @@ metatensor/operations/drop_blocks.py
|
|
|
21
21
|
metatensor/operations/empty_like.py
|
|
22
22
|
metatensor/operations/equal.py
|
|
23
23
|
metatensor/operations/equal_metadata.py
|
|
24
|
+
metatensor/operations/is_contiguous.py
|
|
24
25
|
metatensor/operations/join.py
|
|
25
26
|
metatensor/operations/lstsq.py
|
|
27
|
+
metatensor/operations/make_contiguous.py
|
|
26
28
|
metatensor/operations/manipulate_dimension.py
|
|
27
29
|
metatensor/operations/multiply.py
|
|
28
30
|
metatensor/operations/one_hot.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
metatensor-core<0.2.0,>=0.1.10
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "metatensor-operations"
|
|
3
3
|
dynamic = ["version", "authors", "dependencies"]
|
|
4
|
-
requires-python = ">=3.
|
|
4
|
+
requires-python = ">=3.9"
|
|
5
5
|
|
|
6
6
|
readme = "README.rst"
|
|
7
7
|
license = {text = "BSD-3-Clause"}
|
|
@@ -28,7 +28,7 @@ classifiers = [
|
|
|
28
28
|
[project.urls]
|
|
29
29
|
homepage = "https://docs.metatensor.org/latest/"
|
|
30
30
|
documentation = "https://docs.metatensor.org/latest/"
|
|
31
|
-
repository = "https://github.com/
|
|
31
|
+
repository = "https://github.com/metatensor/metatensor"
|
|
32
32
|
changelog = "https://docs.metatensor.org/latest/operations/CHANGELOG.html"
|
|
33
33
|
|
|
34
34
|
### ======================================================================== ###
|
|
@@ -12,7 +12,7 @@ from setuptools.command.sdist import sdist
|
|
|
12
12
|
ROOT = os.path.realpath(os.path.dirname(__file__))
|
|
13
13
|
METATENSOR_CORE = os.path.realpath(os.path.join(ROOT, "..", "metatensor-core"))
|
|
14
14
|
|
|
15
|
-
METATENSOR_OPERATIONS_VERSION = "0.2.
|
|
15
|
+
METATENSOR_OPERATIONS_VERSION = "0.2.4"
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class bdist_egg_disabled(bdist_egg):
|
|
@@ -132,7 +132,7 @@ if __name__ == "__main__":
|
|
|
132
132
|
install_requires.append(f"metatensor-core @ file://{METATENSOR_CORE}?{uuid}")
|
|
133
133
|
else:
|
|
134
134
|
# we are building from a sdist/installing from a wheel
|
|
135
|
-
install_requires.append("metatensor-core >=0.1.
|
|
135
|
+
install_requires.append("metatensor-core >=0.1.10,<0.2.0")
|
|
136
136
|
|
|
137
137
|
setup(
|
|
138
138
|
version=create_version_number(METATENSOR_OPERATIONS_VERSION),
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
from . import _dispatch
|
|
2
|
-
from ._backend import Labels, TensorBlock, torch_jit_script
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
@torch_jit_script
|
|
6
|
-
def block_from_array(array) -> TensorBlock:
|
|
7
|
-
"""
|
|
8
|
-
Creates a simple TensorBlock from an array.
|
|
9
|
-
|
|
10
|
-
The metadata in the resulting :py:class:`TensorBlock` is filled with ranges
|
|
11
|
-
of integers. This function should be seen as a quick way of creating a
|
|
12
|
-
:py:class:`TensorBlock` from arbitrary data. However, the metadata generated
|
|
13
|
-
in this way has little meaning.
|
|
14
|
-
|
|
15
|
-
:param array: An array with two or more dimensions. This can either be a
|
|
16
|
-
:py:class:`numpy.ndarray` or a :py:class:`torch.Tensor`.
|
|
17
|
-
|
|
18
|
-
:return: A :py:class:`TensorBlock` whose values correspond to the provided
|
|
19
|
-
``array``. The metadata names are set to ``"sample"`` for samples;
|
|
20
|
-
``"component_1"``, ``"component_2"``, ... for components; and
|
|
21
|
-
``property`` for properties. The number of ``component`` labels is
|
|
22
|
-
adapted to the dimensionality of the input array. The metadata
|
|
23
|
-
associated with each label is a range of integers going from 0 to the
|
|
24
|
-
size of the corresponding axis. The returned :py:class:`TensorBlock` has
|
|
25
|
-
no gradients.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
>>> import numpy as np
|
|
29
|
-
>>> import metatensor
|
|
30
|
-
>>> # Construct a simple 4D array:
|
|
31
|
-
>>> array = np.linspace(0, 10, 42).reshape((7, 3, 1, 2))
|
|
32
|
-
>>> # Transform it into a TensorBlock:
|
|
33
|
-
>>> tensor_block = metatensor.block_from_array(array)
|
|
34
|
-
>>> print(tensor_block)
|
|
35
|
-
TensorBlock
|
|
36
|
-
samples (7): ['sample']
|
|
37
|
-
components (3, 1): ['component_1', 'component_2']
|
|
38
|
-
properties (2): ['property']
|
|
39
|
-
gradients: None
|
|
40
|
-
>>> # The data inside the TensorBlock will correspond to the provided array:
|
|
41
|
-
>>> print(np.all(array == tensor_block.values))
|
|
42
|
-
True
|
|
43
|
-
"""
|
|
44
|
-
|
|
45
|
-
shape = array.shape
|
|
46
|
-
n_dimensions = len(shape)
|
|
47
|
-
if n_dimensions < 2:
|
|
48
|
-
raise ValueError(
|
|
49
|
-
f"the array provided to `block_from_array` \
|
|
50
|
-
must have at least two dimensions. Too few provided: {n_dimensions}"
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
samples = Labels(
|
|
54
|
-
names=["sample"],
|
|
55
|
-
values=_dispatch.int_array_like(list(range(shape[0])), array).reshape(-1, 1),
|
|
56
|
-
)
|
|
57
|
-
components = [
|
|
58
|
-
Labels(
|
|
59
|
-
names=[f"component_{component_index+1}"],
|
|
60
|
-
values=_dispatch.int_array_like(list(range(axis_size)), array).reshape(
|
|
61
|
-
-1, 1
|
|
62
|
-
),
|
|
63
|
-
)
|
|
64
|
-
for component_index, axis_size in enumerate(shape[1:-1])
|
|
65
|
-
]
|
|
66
|
-
properties = Labels(
|
|
67
|
-
names=["property"],
|
|
68
|
-
values=_dispatch.int_array_like(list(range(shape[-1])), array).reshape(-1, 1),
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
device = _dispatch.get_device(array)
|
|
72
|
-
samples = samples.to(device)
|
|
73
|
-
components = [component.to(device) for component in components]
|
|
74
|
-
properties = properties.to(device)
|
|
75
|
-
|
|
76
|
-
return TensorBlock(array, samples, components, properties)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
metatensor-core<0.2.0,>=0.1.0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/_backend.py
RENAMED
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/_checks.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/allclose.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/empty_like.py
RENAMED
|
File without changes
|
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/equal_metadata.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/multiply.py
RENAMED
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/one_hot.py
RENAMED
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/ones_like.py
RENAMED
|
File without changes
|
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/random_like.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/requires_grad.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/subtract.py
RENAMED
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/unique_metadata.py
RENAMED
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor/operations/zeros_like.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metatensor_operations-0.2.2 → metatensor_operations-0.2.4}/metatensor_operations.egg-info/zip-safe
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|