pythonic-fp-numpy 0.1.2__py3-none-any.whl → 1.0.0__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.
@@ -1,4 +1,4 @@
1
- # Copyright 2024-2025 Geoffrey R. Scheller
1
+ # Copyright 2024-2026 Geoffrey R. Scheller
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -13,19 +13,14 @@
13
13
  # limitations under the License.
14
14
 
15
15
  """
16
- FP NumPy Tools
17
- ==============
16
+ NumPy Tools
17
+ -----------
18
18
 
19
- Package implementing functional programming tools for NumPy.
19
+ .. admonition:: Functional Tools for Numpy
20
20
 
21
- Modules
22
- -------
21
+ Package implementing functional programming tools for NumPy.
23
22
 
24
- +-------------------------------+--------------------------------------+
25
- | Module | Description |
26
- +===============================+======================================+
27
- | **hashable_wrapped_ndarray** | Make non-writable NDArrays hashable. |
28
- +-------------------------------+--------------------------------------+
23
+ - module **hashable_wrapped_ndarray:** Wrap a non-writable NDArray making result hashable.
29
24
 
30
25
  """
31
26
 
@@ -32,24 +32,26 @@ __all__ = [
32
32
 
33
33
 
34
34
  class DTypes(Enum):
35
- """Enumeration of closed NumPy datatypes.
35
+ """
36
+ .. admonition:: Enumeration of closed NumPy datatypes
36
37
 
37
- .. admonition:: Groups (Unions) of NumPy datatypes closed to NumPy operations.
38
+ Groups (Unions) of NumPy datatypes closed to NumPy operations.
38
39
 
39
40
  - number
40
- - str\_
41
+ - str\\_
41
42
  - bytes
42
43
  - datetime64
43
44
  - timedelta64
44
- - bool\_
45
+ - bool\\_
45
46
  - void
46
- - object\_
47
+ - object\\_
47
48
 
48
- While NumPy types are extensively covariant, the NumPy C internals
49
- are somewhat invariant. NumPy also suffers from what I call "Fortran
50
- Disease", types get "auto-promoted" to compatible "wider types" when
51
- necessary. That is fine when dealing with operators on mixed types,
52
- but NumPy will auto-promote with operations on the same type.
49
+ While NumPy types are extensively covariant, the NumPy
50
+ C internals are somewhat invariant. NumPy also suffers
51
+ from what I call "Fortran Disease", types get "auto-promoted"
52
+ to compatible "wider types" when necessary. That is fine when
53
+ dealing with operators on mixed types, but NumPy will
54
+ auto-promote with operations on the same type.
53
55
 
54
56
  """
55
57
 
@@ -76,6 +78,12 @@ class HWrapNDArray(ABC):
76
78
  __slots__ = '_ndarray', '_type', '_shape', '_hash'
77
79
 
78
80
  def __init__(self, ndarray: npt.NDArray[np.generic]) -> None:
81
+ """
82
+ .. admonition:: init
83
+
84
+ Base class for a hashable wrapped ndarray.
85
+
86
+ """
79
87
  self._ndarray = np.array(ndarray, copy=True)
80
88
  self._ndarray.setflags(write=False)
81
89
 
@@ -103,133 +111,301 @@ class HWrapNDArray(ABC):
103
111
  self._shape = self._ndarray.shape
104
112
  self._hash = hash((self._ndarray.tobytes(), hash((self._shape, self._type))))
105
113
 
106
- @abstractmethod
107
- def __repr__(self) -> str: ...
108
-
109
114
  def __call__(self) -> npt.NDArray[np.number]:
110
- """Return a reference to the stored NDArray.
115
+ """
116
+ .. admonition:: call
111
117
 
112
- .. warning::
118
+ Return a reference to the stored NDArray.
113
119
 
114
- For efficiency this method returns a reference to the
115
- wrapped NDArray.
120
+ .. warning::
116
121
 
117
- - Allows for faster slicing and faster operations.
118
- - Use the copy method if you want a read-write copy.
119
- - Never make the underlying NDArray writable!!!
122
+ For efficiency this method returns a reference to the
123
+ wrapped NDArray, not a copy.
120
124
 
121
- """
125
+ - Allows for faster slicing and faster operations.
126
+ - Use the copy method if you want a read-write copy.
127
+ - Never make the underlying NDArray writable!!!
128
+
129
+ """
122
130
  return np.array(self._ndarray)
123
131
 
124
132
  def __hash__(self) -> int:
133
+ """
134
+ .. admonition:: hash
135
+
136
+ Return hash created during initialization. Hash only
137
+ remains valid if NDArray's flag remains off.
138
+
139
+ """
125
140
  return self._hash
126
141
 
127
142
  def __eq__(self, other: object) -> bool:
128
- if not isinstance(other, HWrapNDArray):
143
+ """
144
+ .. admonition:: equality comparison
145
+
146
+ :param other: The ``object`` being compared to ``self``.
147
+ :returns: ``True`` if ``object`` is another ``HWrapNDArray``
148
+ all whose corresponding components are equal to
149
+ the ones in ``self``.
150
+
151
+ """
152
+ if not isinstance(other, type(self)):
129
153
  return False
130
154
  if self._shape != other._shape or self._type != other._type:
131
155
  return False
132
156
  return np.array_equal(self._ndarray, other._ndarray)
133
157
 
158
+ def _ndarray_repr(self) -> str:
159
+ ndarray = self._ndarray
160
+ repr_str = repr(ndarray)
161
+ repr_str = 'np.' + repr_str.replace('\n', '')
162
+ repr_str = repr_str.replace(' ', '')
163
+ repr_str = repr_str.replace('=', "=np.")
164
+ return repr_str
165
+
166
+ @abstractmethod
167
+ def __repr__(self) -> str: ...
168
+
134
169
  def __str__(self) -> str:
135
- np_array_str = ' ' + str(self._ndarray).replace('\n', '\n ')
136
- return f'hwrap<\n{np_array_str}\n>'
170
+ """
171
+ .. admonition:: user string
137
172
 
138
- def _repr(self) -> str:
139
- stripped_repr = ''.join(repr(self._ndarray).split())
140
- return f'np.{stripped_repr}'
173
+ :returns: String meaningful to an end user.
174
+
175
+ """
176
+ user_str = str(self._ndarray)
177
+ user_str = user_str.replace('\n ', '\n ')
178
+ user_str = '<< ' + user_str + ' >>'
179
+ return user_str
141
180
 
142
181
  def copy(self) -> npt.NDArray[np.number]:
143
- """Return a copy of the wrapped NDArray."""
182
+ """
183
+ .. admonition:: copy
184
+
185
+ Return a copy of the wrapped NDArray.
186
+
187
+ """
144
188
  return np.array(self._ndarray, copy=True)
145
189
 
146
190
 
147
191
  class HWrapNDArrayNumber(HWrapNDArray):
148
- """Wrap NDArrays of arbitrary NumPy numeric types."""
192
+ """
193
+ .. admonition:: wrapped numeric ndarray
194
+
195
+ Class for a hashable wrapped numeric ndarray.
149
196
 
197
+ """
150
198
  def __init__(self, ndarray: npt.NDArray[np.number]) -> None:
199
+ """
200
+ .. admonition:: init
201
+
202
+ Wrap NDArray of arbitrary NumPy numeric types.
203
+
204
+ """
151
205
  super().__init__(ndarray)
152
206
 
153
207
  def __repr__(self) -> str:
154
- return f'HWrapNDArrayNumber({self._repr()})'
208
+ """
209
+ .. admonition:: repr string
210
+
211
+ :returns: String to reproduce the wrapped numeric ndarray.
212
+
213
+ """
214
+ return 'HWrapNDArrayNumber(' + self._ndarray_repr() + ')'
155
215
 
156
216
 
157
217
  class HWrapNDArrayString(HWrapNDArray):
158
- """Wrap NDArrays of Unicode strings."""
218
+ """
219
+ .. admonition:: wrapped string ndarray
220
+
221
+ Class for a hashable wrapped string ndarray.
159
222
 
223
+ """
160
224
  def __init__(self, ndarray: npt.NDArray[np.str_]) -> None:
225
+ """
226
+ .. admonition:: init
227
+
228
+ Wrap NDArray of Unicode strings.
229
+
230
+ """
161
231
  super().__init__(ndarray)
162
232
 
163
233
  def __repr__(self) -> str:
164
- return f'HWrapNDArrayStr({self._repr()})'
234
+ """
235
+ .. admonition:: repr string
236
+
237
+ :returns: String to reproduce the wrapped string ndarray.
238
+
239
+ """
240
+ return 'HWrapNDArrayStr(' + self._ndarray_repr() + ')'
165
241
 
166
242
 
167
243
  class HWrapNDArrayBytes(HWrapNDArray):
168
- """Wrap NDArrays of null-terminated byte sequences."""
244
+ """
245
+ .. admonition:: wrapped byte ndarray
169
246
 
247
+ Class for a hashable wrapped null-terminated
248
+ byte sequence ndarray.
249
+
250
+ """
170
251
  def __init__(self, ndarray: npt.NDArray[np.bytes_]) -> None:
252
+ """
253
+ .. admonition:: init
254
+
255
+ Wrap NDArray of null-terminated byte sequences.
256
+
257
+ """
171
258
  super().__init__(ndarray)
172
259
 
173
260
  def __repr__(self) -> str:
174
- return f'HWrapNDArrayBytes({self._repr()})'
261
+ """
262
+ .. admonition:: repr string
175
263
 
264
+ :returns: String to reproduce the wrapped null-terminated
265
+ byte sequence ndarray.
176
266
 
177
- class HWrapNDArrayDateTime(HWrapNDArray):
178
- """Wrap NDArrays of references to arbitrary Python objects."""
267
+ """
268
+ return 'HWrapNDArrayBytes(' + self._ndarray_repr() + ')'
179
269
 
180
- def __init__(self, ndarray: npt.NDArray[np.datetime64]) -> None:
270
+
271
+ class HWrapNDArrayVoid(HWrapNDArray):
272
+ """
273
+ .. admonition:: wrapped void ndarray
274
+
275
+ Class for a hashable wrapped arbitrary byte
276
+ sequence ndarray.
277
+
278
+ """
279
+ def __init__(self, ndarray: npt.NDArray[np.void]) -> None:
280
+ """
281
+ .. admonition:: init
282
+
283
+ Wrap NDArray of arbitrary byte sequences.
284
+
285
+ """
181
286
  super().__init__(ndarray)
182
287
 
183
288
  def __repr__(self) -> str:
184
- return f'HWrapNDArrayTimeDelta({self._repr()})'
289
+ """
290
+ .. admonition:: repr string
185
291
 
292
+ :returns: String to reproduce the wrapped arbitrary
293
+ byte sequence ndarray.
186
294
 
187
- class HWrapNDArrayTimeDelta(HWrapNDArray):
188
- """Wrap NDArrays of references to arbitrary Python objects."""
295
+ """
296
+ return 'HWrapNDArrayVoid(' + self._ndarray_repr() + ')'
189
297
 
190
- def __init__(self, ndarray: npt.NDArray[np.timedelta64]) -> None:
298
+
299
+ class HWrapNDArrayObject(HWrapNDArray):
300
+ """
301
+ .. admonition:: wrapped object reference ndarray
302
+
303
+ Class for a hashable wrapped object reference ndarray.
304
+
305
+ """
306
+ def __init__(self, ndarray: npt.NDArray[np.object_]) -> None:
307
+ """
308
+ .. admonition:: init
309
+
310
+ Wrap NDArray of references to arbitrary Python objects.
311
+
312
+ """
191
313
  super().__init__(ndarray)
192
314
 
193
315
  def __repr__(self) -> str:
194
- return f'HWrapNDArrayTimeDelta({self._repr()})'
316
+ """
317
+ .. admonition:: repr string
195
318
 
319
+ :returns: String to reproduce the wrapped object
320
+ reference ndarray.
196
321
 
197
- class HWrapNDArrayVoid(HWrapNDArray):
198
- """Wrap NDArrays of arbitrary byte sequences."""
322
+ """
323
+ return 'HWrapNDArrayObject(' + self._ndarray_repr() + ')'
199
324
 
200
- def __init__(self, ndarray: npt.NDArray[np.void]) -> None:
325
+
326
+ class HWrapNDArrayDateTime(HWrapNDArray):
327
+ """
328
+ .. admonition:: wrapped datetime ndarray
329
+
330
+ Class for a hashable wrapped datatime ndarray.
331
+
332
+ """
333
+ def __init__(self, ndarray: npt.NDArray[np.datetime64]) -> None:
334
+ """
335
+ .. admonition:: init
336
+
337
+ Wrap NDArray of datetimes.
338
+
339
+ """
201
340
  super().__init__(ndarray)
202
341
 
203
342
  def __repr__(self) -> str:
204
- return f'HWrapNDArrayVoid({self._repr()})'
343
+ """
344
+ .. admonition:: repr string
205
345
 
346
+ :returns: String to reproduce the wrapped datetime ndarray.
206
347
 
207
- class HWrapNDArrayObject(HWrapNDArray):
208
- """Wrap NDArrays of references to arbitrary Python objects."""
348
+ """
349
+ return 'HWrapNDArrayTimeDelta(' + self._ndarray_repr() + ')'
209
350
 
210
- def __init__(self, ndarray: npt.NDArray[np.object_]) -> None:
351
+
352
+ class HWrapNDArrayTimeDelta(HWrapNDArray):
353
+ """
354
+ .. admonition:: wrapped timedelta ndarray
355
+
356
+ Class for a hashable wrapped timedelta ndarray.
357
+
358
+ """
359
+ def __init__(self, ndarray: npt.NDArray[np.timedelta64]) -> None:
360
+ """
361
+ .. admonition:: init
362
+
363
+ Wrap NDArray of timedeltas.
364
+
365
+ """
211
366
  super().__init__(ndarray)
212
367
 
213
368
  def __repr__(self) -> str:
214
- return f'HWrapNDArrayObject({self._repr()})'
369
+ """
370
+ .. admonition:: repr string
371
+
372
+ :returns: String to reproduce the wrapped timedelta ndarray.
373
+
374
+ """
375
+ return 'HWrapNDArrayTimeDelta(' + self._ndarray_repr() + ')'
215
376
 
216
377
 
217
378
  class HWrapNDArrayBool(HWrapNDArray):
218
- """Wrap NDArrays of Booleans.
379
+ """
380
+ .. admonition:: wrapped Boolean ndarray
381
+
382
+ Class for a hashable wrapped Boolean ndarray.
219
383
 
220
- NumPy Booleans are actual Booleans, unlike Python bools which are
221
- subtypes of int.
384
+ .. note::
222
385
 
223
- .. note::
386
+ NumPy Booleans are actual Booleans, unlike Python bools
387
+ which are subtypes of int.
224
388
 
225
- - ``*`` uses component-wise Boolean **and**
226
- - ``+`` uses component-wise Boolean **or**
227
- - ``@`` does matrix multiplication using **and** then **or**
389
+ - ``*`` uses component-wise Boolean **and**
390
+ - ``+`` uses component-wise Boolean **or**
391
+ - ``@`` matrix multiplication using **and** then **or**
228
392
 
229
393
  """
230
394
 
231
395
  def __init__(self, ndarray: npt.NDArray[np.bool_]) -> None:
396
+ """
397
+ .. admonition:: init
398
+
399
+ Wrap NDArray of Booleans.
400
+
401
+ """
232
402
  super().__init__(ndarray)
233
403
 
234
404
  def __repr__(self) -> str:
235
- return f'HWrapNDArrayBool({self._repr()})'
405
+ """
406
+ .. admonition:: repr string
407
+
408
+ :returns: String to reproduce the wrapped Boolean ndarray.
409
+
410
+ """
411
+ return 'HWrapNDArrayBool(' + self._ndarray_repr() + ')'
@@ -1,29 +1,29 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythonic-fp-numpy
3
- Version: 0.1.2
4
- Summary: FP NumPy Tools
3
+ Version: 1.0.0
4
+ Summary: NumPy Tools
5
5
  Keywords: numpy,ndarray,hashable,wrap
6
6
  Author-email: "Geoffrey R. Scheller" <geoffrey@scheller.com>
7
7
  Requires-Python: >=3.13
8
8
  Description-Content-Type: text/x-rst
9
- Classifier: Development Status :: 4 - Beta
9
+ Classifier: Development Status :: 3 - Alpha
10
10
  Classifier: Framework :: Pytest
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Operating System :: OS Independent
14
- Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
15
  Classifier: Typing :: Typed
16
16
  License-File: LICENSE
17
17
  Requires-Dist: numpy>=2.3.4
18
18
  Requires-Dist: boring-math-abstract-algebra>=1.1.0 ; extra == "test"
19
19
  Requires-Dist: pytest>=8.4.1 ; extra == "test"
20
20
  Project-URL: Changelog, https://github.com/grscheller/pythonic-fp-numpy/blob/main/CHANGELOG.rst
21
- Project-URL: Documentation, https://grscheller.github.io/pythonic-fp/numpy/development/build/html/
22
- Project-URL: Homepage, https://grscheller.github.io/pythonic-fp/homepage/build/html/
21
+ Project-URL: Documentation, https://grscheller.github.io/pythonic-fp/projects/numpy.html
22
+ Project-URL: Homepage, https://grscheller.github.io/pythonic-fp/
23
23
  Project-URL: Source, https://github.com/grscheller/pythonic-fp-numpy
24
24
  Provides-Extra: test
25
25
 
26
- Pythonic FP - FP NumPy
26
+ Pythonic FP - FP Numpy
27
27
  ======================
28
28
 
29
29
  PyPI project
@@ -34,7 +34,7 @@ Python package implementing functional programming for NumPy.
34
34
 
35
35
  Part of the
36
36
  `pythonic-fp
37
- <https://grscheller.github.io/pythonic-fp>`_
37
+ <https://grscheller.github.io/pythonic-fp/>`_
38
38
  PyPI projects.
39
39
 
40
40
  Modules
@@ -50,9 +50,9 @@ Module hashable_wrapped_ndarray
50
50
  Documentation
51
51
  -------------
52
52
 
53
- Documentation for this project is hosted on
53
+ Documentation and other links for this project are hosted on
54
54
  `GitHub Pages
55
- <https://grscheller.github.io/pythonic-fp/numpy>`_.
55
+ <https://grscheller.github.io/pythonic-fp/projects/numpy.html>`_.
56
56
 
57
57
  Copyright and License
58
58
  ---------------------
@@ -0,0 +1,9 @@
1
+ pythonic_fp/numpy/__init__.py,sha256=dL-LF98cK5PId82_PBhTq9iTnfZthQkCq_jBTSKKBN0,964
2
+ pythonic_fp/numpy/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ pythonic_fp/numpy/hashable_wrapped_ndarray.py,sha256=Y8ZKHuD_Rw754fagc1cvTztgAwtt58uu58fY5If8HCI,10798
4
+ pythonic_fp/numpy/hashable_wrapped_ndarray.pyi,sha256=J4jsl5q5Lz15-Amunh824R5JOxZk8hnSUlDuPXa5lcs,1666
5
+ pythonic_fp/numpy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ pythonic_fp_numpy-1.0.0.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
7
+ pythonic_fp_numpy-1.0.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
8
+ pythonic_fp_numpy-1.0.0.dist-info/METADATA,sha256=r_FLuxuoFdJQR9qX3DZbNEBt6kO-lePS5RYgjLMM6DM,1917
9
+ pythonic_fp_numpy-1.0.0.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- pythonic_fp/numpy/__init__.py,sha256=lXFznwyXPi4HeoJDOi0Y-CeMBcMlYgx5x92TZxU001U,1209
2
- pythonic_fp/numpy/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- pythonic_fp/numpy/hashable_wrapped_ndarray.py,sha256=IfZvEwjSHJxCjFdAP_4tO6UGts1WjiBa8clQuFsL9nE,7016
4
- pythonic_fp/numpy/hashable_wrapped_ndarray.pyi,sha256=J4jsl5q5Lz15-Amunh824R5JOxZk8hnSUlDuPXa5lcs,1666
5
- pythonic_fp/numpy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- pythonic_fp_numpy-0.1.2.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
7
- pythonic_fp_numpy-0.1.2.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
8
- pythonic_fp_numpy-0.1.2.dist-info/METADATA,sha256=OIHPnGrhVoPhFrPBi_DGHDSWDDgLoMJyPdrk4waMmno,1917
9
- pythonic_fp_numpy-0.1.2.dist-info/RECORD,,