metatensor-operations 0.2.2__tar.gz → 0.2.3__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.
Files changed (52) hide show
  1. {metatensor_operations-0.2.2/metatensor_operations.egg-info → metatensor_operations-0.2.3}/PKG-INFO +3 -3
  2. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/__init__.py +8 -0
  3. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/_dispatch.py +51 -0
  4. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/block_from_array.py +33 -6
  5. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/drop_blocks.py +16 -29
  6. metatensor_operations-0.2.3/metatensor/operations/is_contiguous.py +46 -0
  7. metatensor_operations-0.2.3/metatensor/operations/make_contiguous.py +49 -0
  8. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/slice.py +23 -38
  9. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/split.py +8 -8
  10. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3/metatensor_operations.egg-info}/PKG-INFO +3 -3
  11. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor_operations.egg-info/SOURCES.txt +2 -0
  12. metatensor_operations-0.2.3/metatensor_operations.egg-info/requires.txt +1 -0
  13. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/pyproject.toml +1 -1
  14. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/setup.py +2 -2
  15. metatensor_operations-0.2.2/metatensor_operations.egg-info/requires.txt +0 -1
  16. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/AUTHORS +0 -0
  17. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/LICENSE +0 -0
  18. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/MANIFEST.in +0 -0
  19. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/README.rst +0 -0
  20. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/_backend.py +0 -0
  21. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/_checks.py +0 -0
  22. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/_utils.py +0 -0
  23. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/abs.py +0 -0
  24. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/add.py +0 -0
  25. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/allclose.py +0 -0
  26. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/detach.py +0 -0
  27. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/divide.py +0 -0
  28. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/dot.py +0 -0
  29. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/empty_like.py +0 -0
  30. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/equal.py +0 -0
  31. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/equal_metadata.py +0 -0
  32. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/join.py +0 -0
  33. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/lstsq.py +0 -0
  34. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/manipulate_dimension.py +0 -0
  35. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/multiply.py +0 -0
  36. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/one_hot.py +0 -0
  37. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/ones_like.py +0 -0
  38. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/pow.py +0 -0
  39. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/random_like.py +0 -0
  40. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/reduce_over_samples.py +0 -0
  41. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/remove_gradients.py +0 -0
  42. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/requires_grad.py +0 -0
  43. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/solve.py +0 -0
  44. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/sort.py +0 -0
  45. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/subtract.py +0 -0
  46. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/unique_metadata.py +0 -0
  47. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor/operations/zeros_like.py +0 -0
  48. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor_operations.egg-info/dependency_links.txt +0 -0
  49. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor_operations.egg-info/top_level.txt +0 -0
  50. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/metatensor_operations.egg-info/zip-safe +0 -0
  51. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/n_commits_since_last_tag +0 -0
  52. {metatensor_operations-0.2.2 → metatensor_operations-0.2.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: metatensor-operations
3
- Version: 0.2.2
3
+ Version: 0.2.3
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
@@ -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.8
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.0
30
+ Requires-Dist: metatensor-core<0.2.0,>=0.1.10
31
31
 
32
32
  metatensor-operations
33
33
  =====================
@@ -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,
@@ -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"""
@@ -1,5 +1,17 @@
1
+ import numpy as np
2
+
1
3
  from . import _dispatch
2
- from ._backend import Labels, TensorBlock, torch_jit_script
4
+ from ._backend import Labels, TensorBlock, torch_jit_is_scripting, torch_jit_script
5
+
6
+
7
+ try:
8
+ import torch
9
+
10
+ TorchScriptClass = torch.ScriptClass
11
+ except ImportError:
12
+
13
+ class TorchScriptClass:
14
+ pass
3
15
 
4
16
 
5
17
  @torch_jit_script
@@ -50,22 +62,37 @@ def block_from_array(array) -> TensorBlock:
50
62
  must have at least two dimensions. Too few provided: {n_dimensions}"
51
63
  )
52
64
 
65
+ if torch_jit_is_scripting():
66
+ # we are using metatensor-torch
67
+ labels_array_like = torch.empty(0)
68
+ else:
69
+ if isinstance(Labels, TorchScriptClass):
70
+ # we are using metatensor-torch
71
+ labels_array_like = torch.empty(0)
72
+ else:
73
+ # we are using metatensor-core
74
+ labels_array_like = np.empty(0)
75
+
53
76
  samples = Labels(
54
77
  names=["sample"],
55
- values=_dispatch.int_array_like(list(range(shape[0])), array).reshape(-1, 1),
78
+ values=_dispatch.int_array_like(
79
+ list(range(shape[0])), labels_array_like
80
+ ).reshape(-1, 1),
56
81
  )
57
82
  components = [
58
83
  Labels(
59
84
  names=[f"component_{component_index+1}"],
60
- values=_dispatch.int_array_like(list(range(axis_size)), array).reshape(
61
- -1, 1
62
- ),
85
+ values=_dispatch.int_array_like(
86
+ list(range(axis_size)), labels_array_like
87
+ ).reshape(-1, 1),
63
88
  )
64
89
  for component_index, axis_size in enumerate(shape[1:-1])
65
90
  ]
66
91
  properties = Labels(
67
92
  names=["property"],
68
- values=_dispatch.int_array_like(list(range(shape[-1])), array).reshape(-1, 1),
93
+ values=_dispatch.int_array_like(
94
+ list(range(shape[-1])), labels_array_like
95
+ ).reshape(-1, 1),
69
96
  )
70
97
 
71
98
  device = _dispatch.get_device(array)
@@ -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
- the TensorMap to drop the key-block pair from.
21
-
22
- :param keys:
23
- a :py:class:`Labels` object containing the keys of the blocks to drop
24
-
25
- :param copy:
26
- if :py:obj:`True`, the returned :py:class:`TensorMap` is constructed by
27
- copying the blocks from the input `tensor`. If :py:obj:`False`
28
- (default), the values of the blocks in the output :py:class:`TensorMap`
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
- _, to_remove, used_in_intersection = tensor_keys.intersection_and_mapping(keys)
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(keys.names, _dispatch.stack(new_keys_values, 0))
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=keys.names,
106
- values=_dispatch.empty_like(tensor.block(0).values, (0, len(keys.names))),
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
- # only keep the same names as `labels`
16
- all_samples = block.samples.view(labels.names)
17
- # create an arrays of bools indicating which samples indices to keep
18
- samples_mask = _dispatch.bool_array_like(
19
- [all_samples.entry(i) in labels for i in range(len(all_samples))],
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=new_values,
30
- samples=new_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(samples_mask),
42
- like=samples_mask,
34
+ int_list=[-1] * len(block.samples),
35
+ like=block.samples.values,
43
36
  )
44
37
  last = 0
45
- for i, picked in enumerate(samples_mask):
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
- samples_mask, TorchTensor
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 = samples_mask[_dispatch.to_index_array(sample_column)]
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
- # only keep the same names as `labels`
104
- all_properties = block.properties.view(list(labels.names))
105
- # create an arrays of bools indicating which samples indices to keep
106
- properties_mask = _dispatch.bool_array_like(
107
- [all_properties.entry(i) in labels for i in range(len(all_properties))],
108
- block.values,
109
- )
110
- new_values = _dispatch.mask(
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, properties_mask
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=new_grad_samples,
126
+ samples=gradient.samples,
142
127
  components=gradient.components,
143
- properties=new_block.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 number of returned :py:class:`TensorMap`s is
93
- equal to the number of :py:class:`Labels` objects passed in ``grouped_labels``. Each
94
- returned :py:class`TensorMap` will have the same keys and number of blocks at the
95
- input ``tensor``, but with the dimensions of the blocks reduced to only contain the
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 number of returned :py:class:`TensorBlock` is
202
- equal to the number of :py:class:`Labels` objects passed in ``grouped_labels``. Each
203
- returned :py:class`TensorBlock` will have the same keys and number of blocks at the
204
- input ``tensor``, but with the dimensions of the blocks reduced to only contain the
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: metatensor-operations
3
- Version: 0.2.2
3
+ Version: 0.2.3
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
@@ -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.8
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.0
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.8"
4
+ requires-python = ">=3.9"
5
5
 
6
6
  readme = "README.rst"
7
7
  license = {text = "BSD-3-Clause"}
@@ -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.2"
15
+ METATENSOR_OPERATIONS_VERSION = "0.2.3"
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.0,<0.2.0")
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 +0,0 @@
1
- metatensor-core<0.2.0,>=0.1.0