purem 3.0.1__py3-none-any.whl → 3.0.2__py3-none-any.whl
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.
- purem/__init__.py +1 -2
- purem/core.py +52 -28
- purem/logger.py +2 -2
- {purem-3.0.1.dist-info → purem-3.0.2.dist-info}/METADATA +3 -2
- purem-3.0.2.dist-info/RECORD +12 -0
- purem-3.0.1.dist-info/RECORD +0 -12
- {purem-3.0.1.dist-info → purem-3.0.2.dist-info}/WHEEL +0 -0
- {purem-3.0.1.dist-info → purem-3.0.2.dist-info}/licenses/LICENSE +0 -0
- {purem-3.0.1.dist-info → purem-3.0.2.dist-info}/top_level.txt +0 -0
purem/__init__.py
CHANGED
purem/core.py
CHANGED
@@ -11,7 +11,6 @@ Additional Use Grant: Free for personal and non-commercial research use only.
|
|
11
11
|
SPDX-License-Identifier: BUSL-1.1
|
12
12
|
"""
|
13
13
|
|
14
|
-
import base64
|
15
14
|
import ctypes
|
16
15
|
import json
|
17
16
|
import os
|
@@ -19,17 +18,16 @@ import shutil
|
|
19
18
|
import ssl
|
20
19
|
import urllib.request
|
21
20
|
import zipfile
|
22
|
-
from
|
21
|
+
from pathlib import Path
|
22
|
+
from typing import Optional, Dict
|
23
23
|
|
24
24
|
import certifi as certifi
|
25
|
-
import numpy as np
|
26
25
|
from numpy import ndarray
|
27
26
|
|
28
|
-
from purem.env_config import load_env_config
|
27
|
+
from purem.env_config import load_env_config, EnvConfig
|
29
28
|
from purem.file_structure import FileStructure
|
30
29
|
from purem.loader import Loader
|
31
30
|
from purem.logger import Logger
|
32
|
-
from purem.utils import _compute_shifted_jit
|
33
31
|
|
34
32
|
|
35
33
|
class Purem:
|
@@ -68,7 +66,7 @@ class Purem:
|
|
68
66
|
:type _log: Logger
|
69
67
|
"""
|
70
68
|
|
71
|
-
def __init__(self
|
69
|
+
def __init__(self):
|
72
70
|
"""
|
73
71
|
Represents the initialization and configuration of an environment, license key,
|
74
72
|
and file structure required for the system's binary operations.
|
@@ -76,26 +74,30 @@ class Purem:
|
|
76
74
|
:param licenced_key: Optional license key string for initializing the system.
|
77
75
|
:type licenced_key: Optional[str]
|
78
76
|
"""
|
79
|
-
self.
|
80
|
-
self.
|
81
|
-
self._download_binary_url = None
|
77
|
+
self._lib: Optional[ctypes.CDLL] = None
|
78
|
+
self._download_binary_url: Optional[str] = None
|
82
79
|
self._ctx = ssl.create_default_context(cafile=certifi.where())
|
83
80
|
self._file_structure = FileStructure()
|
84
|
-
self._binary_path = self._file_structure.get_binary_path()
|
85
|
-
self._binary_project_root_path = (
|
81
|
+
self._binary_path: Path = self._file_structure.get_binary_path()
|
82
|
+
self._binary_project_root_path: Path = (
|
86
83
|
self._file_structure.get_binary_project_root_path()
|
87
84
|
)
|
88
|
-
self._binary_archive_path = self._file_structure.get_binary_archive_path()
|
89
|
-
self._binary_archive_path_tmp = (
|
85
|
+
self._binary_archive_path: Path = self._file_structure.get_binary_archive_path()
|
86
|
+
self._binary_archive_path_tmp: Path = (
|
90
87
|
self._file_structure.get_binary_archive_path_tmp()
|
91
88
|
)
|
92
|
-
self._env = load_env_config()
|
93
|
-
self.
|
94
|
-
|
95
|
-
|
89
|
+
self._env: EnvConfig = load_env_config()
|
90
|
+
self._license_key: Optional[str] = self._env.PUREM_LICENSE_KEY or None
|
91
|
+
self._config_url: str = (
|
92
|
+
self._env.PUREM_CONFIG_URL
|
93
|
+
or "https://api.worktif.com/v2/portal/products/purem/config"
|
96
94
|
)
|
97
|
-
self._loader = Loader()
|
98
|
-
self._log = Logger()
|
95
|
+
self._loader: Loader = Loader()
|
96
|
+
self._log: Logger = Logger()
|
97
|
+
print('self._license_key: ', self._license_key)
|
98
|
+
|
99
|
+
if self._license_key is not None:
|
100
|
+
self.configure(license_key=self._license_key)
|
99
101
|
|
100
102
|
def configure(self, license_key: Optional[str] = None) -> None:
|
101
103
|
"""
|
@@ -125,9 +127,18 @@ class Purem:
|
|
125
127
|
self._set_binary()
|
126
128
|
|
127
129
|
def softmax(self, array: ndarray) -> ndarray:
|
128
|
-
|
129
|
-
|
130
|
-
|
130
|
+
try:
|
131
|
+
ptr = array.ctypes.data_as(ctypes.POINTER(ctypes.c_float))
|
132
|
+
self._lib.purem(ptr, array.size)
|
133
|
+
return array
|
134
|
+
except Exception as e:
|
135
|
+
raise ValueError(
|
136
|
+
self._log.info(
|
137
|
+
"Purem requires a valid license key to initialize.\n"
|
138
|
+
"You can obtain your key at https://worktif.com or through your enterprise deployment.",
|
139
|
+
verbose=True
|
140
|
+
)
|
141
|
+
)
|
131
142
|
|
132
143
|
def softmax_pure(self, ptr, size) -> None:
|
133
144
|
"""
|
@@ -168,7 +179,7 @@ class Purem:
|
|
168
179
|
binary_url = f"{protocol}://{base}/{path}{self._license_key}"
|
169
180
|
return binary_url
|
170
181
|
|
171
|
-
def _tune_binary(self):
|
182
|
+
def _tune_binary(self) -> None:
|
172
183
|
"""
|
173
184
|
Tunes the binary by loading the specified binary file as a shared library
|
174
185
|
and setting up its function signatures for further use.
|
@@ -185,7 +196,7 @@ class Purem:
|
|
185
196
|
self._lib.purem.argtypes = [ctypes.POINTER(ctypes.c_float), ctypes.c_size_t]
|
186
197
|
self._lib.purem.restype = None
|
187
198
|
|
188
|
-
def _tune_project_root_binary(self):
|
199
|
+
def _tune_project_root_binary(self) -> None:
|
189
200
|
"""
|
190
201
|
Tuning the project root binary configuration.
|
191
202
|
|
@@ -228,7 +239,7 @@ class Purem:
|
|
228
239
|
except Exception:
|
229
240
|
return None
|
230
241
|
|
231
|
-
def _set_binary(self):
|
242
|
+
def _set_binary(self) -> None:
|
232
243
|
"""
|
233
244
|
Sets and initializes the binary for the Purem runtime environment. The method ensures that a valid binary
|
234
245
|
is available and properly configured. If a valid license key or binary is not found, the method will attempt
|
@@ -262,8 +273,8 @@ class Purem:
|
|
262
273
|
)
|
263
274
|
self._loader.start()
|
264
275
|
self._download_binary_url = (
|
265
|
-
|
266
|
-
|
276
|
+
self._build_url(self._load_from_latest_cdn_index())
|
277
|
+
or f"{self._env.PUREM_DOWNLOAD_BINARY_URL}{self._license_key}"
|
267
278
|
)
|
268
279
|
self._download_and_extract_binary()
|
269
280
|
self._loader.stop()
|
@@ -288,7 +299,7 @@ class Purem:
|
|
288
299
|
)
|
289
300
|
)
|
290
301
|
|
291
|
-
def _download_and_extract_binary(self):
|
302
|
+
def _download_and_extract_binary(self) -> None:
|
292
303
|
"""
|
293
304
|
Downloads a binary file from a given URL, saves it temporarily, and extracts its
|
294
305
|
contents to a specific directory. Handles errors related to incomplete or
|
@@ -337,3 +348,16 @@ class Purem:
|
|
337
348
|
)
|
338
349
|
|
339
350
|
self._binary_archive_path.unlink()
|
351
|
+
|
352
|
+
def has_license_key(self) -> bool:
|
353
|
+
"""
|
354
|
+
Checks if an object has a valid license key.
|
355
|
+
|
356
|
+
This method evaluates whether the `_license_key` attribute of
|
357
|
+
the object is not `None`, implying the presence of a license key.
|
358
|
+
|
359
|
+
:return: Returns `True` if the `_license_key` attribute is not
|
360
|
+
`None`, otherwise returns `False`.
|
361
|
+
:rtype: bool
|
362
|
+
"""
|
363
|
+
return self._license_key is not None
|
purem/logger.py
CHANGED
@@ -19,8 +19,8 @@ class Logger:
|
|
19
19
|
self._env = load_env_config()
|
20
20
|
self._default_info_message = f"Something went wrong"
|
21
21
|
|
22
|
-
def info(self, message: str) -> str:
|
23
|
-
if self._env.PUREM_VERBOSE is True:
|
22
|
+
def info(self, message: str, verbose: bool = False) -> str:
|
23
|
+
if self._env.PUREM_VERBOSE is True or verbose is True:
|
24
24
|
return f"[purem]: {message}\n"
|
25
25
|
else:
|
26
26
|
return f"[purem]: {self._default_info_message}\n"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: purem
|
3
|
-
Version: 3.0.
|
3
|
+
Version: 3.0.2
|
4
4
|
Summary: The official high-performance mapping function for mixed-type arrays powered by Work TIF Ltd.
|
5
5
|
Author-email: Raman Marozau <raman@worktif.com>
|
6
6
|
License-Expression: BUSL-1.1
|
@@ -25,7 +25,6 @@ Requires-Python: >=3.11
|
|
25
25
|
Description-Content-Type: text/x-rst
|
26
26
|
License-File: LICENSE
|
27
27
|
Requires-Dist: numpy~=2.1.3
|
28
|
-
Requires-Dist: pytest~=8.3.5
|
29
28
|
Requires-Dist: numba~=0.61.0
|
30
29
|
Requires-Dist: certifi~=2025.1.31
|
31
30
|
Requires-Dist: pydantic~=2.10.6
|
@@ -33,6 +32,8 @@ Requires-Dist: dotenv~=0.9.9
|
|
33
32
|
Requires-Dist: python-dotenv~=1.1.0
|
34
33
|
Requires-Dist: setuptools~=65.5.1
|
35
34
|
Requires-Dist: requests~=2.32.3
|
35
|
+
Requires-Dist: pytest~=8.3.5
|
36
|
+
Requires-Dist: pytest-env~=1.1.5
|
36
37
|
Provides-Extra: dev
|
37
38
|
Requires-Dist: pytest; extra == "dev"
|
38
39
|
Requires-Dist: flake8; extra == "dev"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
purem/__init__.py,sha256=of-z4lRvk7cmLLsCbiXHIPXVjP0FHBCByndtPgINfT0,92
|
2
|
+
purem/core.py,sha256=kGhCPlSwyTlmjsv970H_DSCBrvMCL6TA2-EHmwsgQ3c,15830
|
3
|
+
purem/env_config.py,sha256=o1VujOYEH0XXVHbM0j84BEbO2FqlWVQ088DxlSfsvRU,2663
|
4
|
+
purem/file_structure.py,sha256=nYTSj74gDsnVAYAwkb5NGE1QHXvlkaYuaafB_FIAMaI,3337
|
5
|
+
purem/loader.py,sha256=GDeuiqZcKvZQEDaUg2TO5rC-WwVcjIgKqNEpF602mmg,3610
|
6
|
+
purem/logger.py,sha256=vZHUGwL-MXJPNBoHIxqLf26KOF9qk4xj2qdgUhRas8c,1281
|
7
|
+
purem/utils.py,sha256=wjLHukHROX3GKJoEwXCR9X6CfqT70M1Mj6FcLtFUxJ8,923
|
8
|
+
purem-3.0.2.dist-info/licenses/LICENSE,sha256=5WFXHK6Xc_wj2EtvzVtd9TIC4cWEZJS8ECNTuvutsiE,1636
|
9
|
+
purem-3.0.2.dist-info/METADATA,sha256=fuDQr3LQrympk6wCLUqEbqb-Raxb5qxrAmrnH1BQZJg,5677
|
10
|
+
purem-3.0.2.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
11
|
+
purem-3.0.2.dist-info/top_level.txt,sha256=EjS75KEpZUEKSV2TFGW6w5aLqY9nUyO6Gq2ATz-KeZM,6
|
12
|
+
purem-3.0.2.dist-info/RECORD,,
|
purem-3.0.1.dist-info/RECORD
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
purem/__init__.py,sha256=zF_hOKYn8X3jeoBxQ9X1irDi6HCPQ-HRcMP5fcocaNw,141
|
2
|
-
purem/core.py,sha256=fAWRKSzPp4x0YNKm_HrHWV9j38gISl2fLU6XyYIK33U,14772
|
3
|
-
purem/env_config.py,sha256=o1VujOYEH0XXVHbM0j84BEbO2FqlWVQ088DxlSfsvRU,2663
|
4
|
-
purem/file_structure.py,sha256=nYTSj74gDsnVAYAwkb5NGE1QHXvlkaYuaafB_FIAMaI,3337
|
5
|
-
purem/loader.py,sha256=GDeuiqZcKvZQEDaUg2TO5rC-WwVcjIgKqNEpF602mmg,3610
|
6
|
-
purem/logger.py,sha256=56pSIjyQal4IvaFzRpKBaQ8oMAdt-u638QK6uex-cRQ,1239
|
7
|
-
purem/utils.py,sha256=wjLHukHROX3GKJoEwXCR9X6CfqT70M1Mj6FcLtFUxJ8,923
|
8
|
-
purem-3.0.1.dist-info/licenses/LICENSE,sha256=5WFXHK6Xc_wj2EtvzVtd9TIC4cWEZJS8ECNTuvutsiE,1636
|
9
|
-
purem-3.0.1.dist-info/METADATA,sha256=qe1GhJoHEKQyjhJH7NR4c4XVhNlPhifKA-H_bY8HITg,5644
|
10
|
-
purem-3.0.1.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
11
|
-
purem-3.0.1.dist-info/top_level.txt,sha256=EjS75KEpZUEKSV2TFGW6w5aLqY9nUyO6Gq2ATz-KeZM,6
|
12
|
-
purem-3.0.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|