pelutils 3.8.4__tar.gz → 3.8.5__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 (47) hide show
  1. {pelutils-3.8.4 → pelutils-3.8.5}/PKG-INFO +2 -2
  2. {pelutils-3.8.4 → pelutils-3.8.5}/README.md +1 -1
  3. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/__init__.py +0 -1
  4. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/__version__.py +1 -1
  5. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/datastorage2/_pretty_json.py +11 -0
  6. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/types.py +2 -0
  7. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils.egg-info/PKG-INFO +2 -2
  8. {pelutils-3.8.4 → pelutils-3.8.5}/tests/test_types.py +8 -4
  9. {pelutils-3.8.4 → pelutils-3.8.5}/MANIFEST.in +0 -0
  10. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/_c/__init__.py +0 -0
  11. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/_c/ds.c +0 -0
  12. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/_c/hashmap.c/LICENSE +0 -0
  13. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/_c/hashmap.c/hashmap.c +0 -0
  14. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/_c/hashmap.c/hashmap.h +0 -0
  15. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/_entry_points/__init__.py +0 -0
  16. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/_entry_points/linecounter.py +0 -0
  17. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/datastorage.py +0 -0
  18. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/datastorage2/__init__.py +0 -0
  19. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/ds/__init__.py +0 -0
  20. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/ds/distributions.py +0 -0
  21. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/ds/plots.py +0 -0
  22. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/ds/stats.py +0 -0
  23. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/format.py +0 -0
  24. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/jsonl.py +0 -0
  25. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/logging/__init__.py +0 -0
  26. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/logging/_rotate.py +0 -0
  27. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/logging/_utils.py +0 -0
  28. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/parser.py +0 -0
  29. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/pretty_json.py +0 -0
  30. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/py.typed +0 -0
  31. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/tests.py +0 -0
  32. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils/ticktock.py +0 -0
  33. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils.egg-info/SOURCES.txt +0 -0
  34. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils.egg-info/dependency_links.txt +0 -0
  35. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils.egg-info/entry_points.txt +0 -0
  36. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils.egg-info/requires.txt +0 -0
  37. {pelutils-3.8.4 → pelutils-3.8.5}/pelutils.egg-info/top_level.txt +0 -0
  38. {pelutils-3.8.4 → pelutils-3.8.5}/setup.cfg +0 -0
  39. {pelutils-3.8.4 → pelutils-3.8.5}/setup.py +0 -0
  40. {pelutils-3.8.4 → pelutils-3.8.5}/tests/test_datastorage.py +0 -0
  41. {pelutils-3.8.4 → pelutils-3.8.5}/tests/test_format.py +0 -0
  42. {pelutils-3.8.4 → pelutils-3.8.5}/tests/test_init.py +0 -0
  43. {pelutils-3.8.4 → pelutils-3.8.5}/tests/test_jsonl.py +0 -0
  44. {pelutils-3.8.4 → pelutils-3.8.5}/tests/test_parser.py +0 -0
  45. {pelutils-3.8.4 → pelutils-3.8.5}/tests/test_pretty_json.py +0 -0
  46. {pelutils-3.8.4 → pelutils-3.8.5}/tests/test_tests.py +0 -0
  47. {pelutils-3.8.4 → pelutils-3.8.5}/tests/test_ticktock.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pelutils
3
- Version: 3.8.4
3
+ Version: 3.8.5
4
4
  Summary: The Swiss army knife of Python projects.
5
5
  Home-page: https://github.com/peleiden/pelutils
6
6
  Download-URL: https://pypi.org/project/pelutils/
@@ -275,7 +275,7 @@ log2.configure("path/to/save/log2.log")
275
275
 
276
276
  A few different numpy types are defined for the convenience of not having to remember what data types your arrays are - and also to satisfy your nasty type checkers.
277
277
  ```py
278
- from pelutils.types import AnyArray, FloatArray, IntArray
278
+ from pelutils.types import AnyArray, BoolArray, ComplexArray, FloatArray, IntArray
279
279
 
280
280
 
281
281
  def function_which_takes_np_types(
@@ -250,7 +250,7 @@ log2.configure("path/to/save/log2.log")
250
250
 
251
251
  A few different numpy types are defined for the convenience of not having to remember what data types your arrays are - and also to satisfy your nasty type checkers.
252
252
  ```py
253
- from pelutils.types import AnyArray, FloatArray, IntArray
253
+ from pelutils.types import AnyArray, BoolArray, ComplexArray, FloatArray, IntArray
254
254
 
255
255
 
256
256
  def function_which_takes_np_types(
@@ -24,7 +24,6 @@ import numpy as np
24
24
  import psutil
25
25
 
26
26
  try:
27
- # torch is only to be installed if pelutils[ds] has been installed
28
27
  import torch
29
28
 
30
29
  _has_torch = True
@@ -1,2 +1,2 @@
1
1
  # Do not put anything else in this file
2
- __version__ = "3.8.4"
2
+ __version__ = "3.8.5"
@@ -9,6 +9,13 @@ import json
9
9
  import pickle
10
10
  from typing import Any
11
11
 
12
+ try:
13
+ import torch
14
+
15
+ _has_torch = True
16
+ except ModuleNotFoundError:
17
+ _has_torch = False
18
+
12
19
  # Sentinel prefix so consumers can detect pickled blobs.
13
20
  _PICKLE_PREFIX = "__pickled_b64__"
14
21
 
@@ -45,6 +52,10 @@ def _get_qualified_type_name(obj: object) -> str:
45
52
 
46
53
  def _pickle_encode(value: object) -> str:
47
54
  """Pickle *value*, base64-encode the bytes, and return a prefixed string."""
55
+ if _has_torch and isinstance(value, torch.Tensor): # pyright: ignore[reportPossiblyUnboundVariable]
56
+ # If a view of torch Tensor is given, the whole tensor is pickled, not just the view
57
+ # Therefore, it is cloned first to ensure that only the view itself is pickled
58
+ value = value.clone()
48
59
  raw = pickle.dumps(value, protocol=pickle.HIGHEST_PROTOCOL)
49
60
  encoded = base64.b64encode(raw).decode("ascii")
50
61
  return f"{_PICKLE_PREFIX}:{_get_qualified_type_name(value)}:{encoded}"
@@ -5,5 +5,7 @@ import numpy.typing as npt
5
5
 
6
6
  # Common numpy types
7
7
  AnyArray = npt.NDArray[Any] # pyright: ignore[reportExplicitAny]
8
+ BoolArray = npt.NDArray[np.bool_]
9
+ ComplexArray = npt.NDArray[np.complexfloating[Any]] # pyright: ignore[reportExplicitAny, reportInvalidTypeArguments]
8
10
  FloatArray = npt.NDArray[np.floating[Any]] # pyright: ignore[reportExplicitAny]
9
11
  IntArray = npt.NDArray[np.integer[Any]] # pyright: ignore[reportExplicitAny]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pelutils
3
- Version: 3.8.4
3
+ Version: 3.8.5
4
4
  Summary: The Swiss army knife of Python projects.
5
5
  Home-page: https://github.com/peleiden/pelutils
6
6
  Download-URL: https://pypi.org/project/pelutils/
@@ -275,7 +275,7 @@ log2.configure("path/to/save/log2.log")
275
275
 
276
276
  A few different numpy types are defined for the convenience of not having to remember what data types your arrays are - and also to satisfy your nasty type checkers.
277
277
  ```py
278
- from pelutils.types import AnyArray, FloatArray, IntArray
278
+ from pelutils.types import AnyArray, BoolArray, ComplexArray, FloatArray, IntArray
279
279
 
280
280
 
281
281
  def function_which_takes_np_types(
@@ -1,14 +1,16 @@
1
1
  import numpy as np
2
2
 
3
- from pelutils.types import AnyArray, FloatArray, IntArray
3
+ from pelutils import AnyArray, BoolArray, ComplexArray, FloatArray, IntArray
4
4
 
5
5
 
6
6
  def function_which_takes_np_types(
7
7
  any_array: AnyArray,
8
+ bool_array: BoolArray,
9
+ complex_array: ComplexArray,
8
10
  float_array: FloatArray,
9
11
  int_array: IntArray,
10
- ) -> FloatArray:
11
- return any_array + float_array + int_array
12
+ ) -> ComplexArray:
13
+ return any_array + bool_array + complex_array + float_array + int_array
12
14
 
13
15
 
14
16
  def test_types():
@@ -17,6 +19,8 @@ def test_types():
17
19
  Just make sure that using the types doesn't break anything silly like function declarations.
18
20
  """
19
21
  any_array = np.arange(5, dtype=np.float16)
22
+ bool_array = np.arange(5).astype(bool)
23
+ complex_array = 1j * np.arange(5)
20
24
  float_array = np.arange(5, dtype=np.float32)
21
25
  int_array = np.arange(5)
22
- function_which_takes_np_types(any_array, float_array, int_array)
26
+ function_which_takes_np_types(any_array, bool_array, complex_array, float_array, int_array)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes