numcodecs-combinators 0.1.0__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.
@@ -0,0 +1,53 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - '*'
10
+
11
+ jobs:
12
+ check:
13
+ name: Check
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - name: Checkout the Repository
17
+ uses: actions/checkout@v4
18
+
19
+ - name: Check with ruff
20
+ uses: astral-sh/ruff-action@v3
21
+ with:
22
+ args: check
23
+
24
+ fmt:
25
+ name: Formatting
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - name: Checkout the Repository
29
+ uses: actions/checkout@v4
30
+
31
+ - name: Check with ruff
32
+ uses: astral-sh/ruff-action@v3
33
+ with:
34
+ args: "format --diff --check"
35
+
36
+ test:
37
+ name: Test
38
+ runs-on: ubuntu-latest
39
+ steps:
40
+ - name: Checkout the Repository
41
+ uses: actions/checkout@v4
42
+
43
+ - name: Install uv
44
+ uses: astral-sh/setup-uv@v5
45
+
46
+ - name: Setup Python
47
+ run: uv python install
48
+
49
+ - name: Install numcodecs-combinators
50
+ run: uv sync --all-extras --dev && uv pip install .
51
+
52
+ - name: Run tests
53
+ run: uv run pytest
@@ -0,0 +1,30 @@
1
+ name: Publish
2
+
3
+ on:
4
+ release:
5
+ branch: main
6
+ types: [released]
7
+
8
+ jobs:
9
+ publish:
10
+ name: Publish to PyPi
11
+ runs-on: ubuntu-latest
12
+ environment: publish
13
+ permissions:
14
+ contents: read
15
+ id-token: write
16
+ steps:
17
+ - name: Checkout the Repository
18
+ uses: actions/checkout@v4
19
+
20
+ - name: Install uv
21
+ uses: astral-sh/setup-uv@v5
22
+
23
+ - name: Setup Python
24
+ run: uv python install
25
+
26
+ - name: Build the package
27
+ run: uv build
28
+
29
+ - name: Publish the package to PyPi
30
+ run: uv publish
@@ -0,0 +1,11 @@
1
+ /.venv
2
+ /.python-version
3
+ /.pytest_cache
4
+ /.ruff_cache
5
+ /uv.lock
6
+
7
+ /build
8
+ /site
9
+
10
+ **/__pycache__
11
+ **/*.egg-info
@@ -0,0 +1,15 @@
1
+ version: 2
2
+
3
+ build:
4
+ os: ubuntu-24.04
5
+ tools:
6
+ python: "3.12"
7
+
8
+ mkdocs:
9
+ configuration: mkdocs.yml
10
+
11
+ python:
12
+ install:
13
+ - method: pip
14
+ path: .
15
+ - requirements: docs/requirements.txt
@@ -0,0 +1,375 @@
1
+ Copyright (c) 2024, Juniper Tyree
2
+
3
+ Mozilla Public License Version 2.0
4
+ ==================================
5
+
6
+ 1. Definitions
7
+ --------------
8
+
9
+ 1.1. "Contributor"
10
+ means each individual or legal entity that creates, contributes to
11
+ the creation of, or owns Covered Software.
12
+
13
+ 1.2. "Contributor Version"
14
+ means the combination of the Contributions of others (if any) used
15
+ by a Contributor and that particular Contributor's Contribution.
16
+
17
+ 1.3. "Contribution"
18
+ means Covered Software of a particular Contributor.
19
+
20
+ 1.4. "Covered Software"
21
+ means Source Code Form to which the initial Contributor has attached
22
+ the notice in Exhibit A, the Executable Form of such Source Code
23
+ Form, and Modifications of such Source Code Form, in each case
24
+ including portions thereof.
25
+
26
+ 1.5. "Incompatible With Secondary Licenses"
27
+ means
28
+
29
+ (a) that the initial Contributor has attached the notice described
30
+ in Exhibit B to the Covered Software; or
31
+
32
+ (b) that the Covered Software was made available under the terms of
33
+ version 1.1 or earlier of the License, but not also under the
34
+ terms of a Secondary License.
35
+
36
+ 1.6. "Executable Form"
37
+ means any form of the work other than Source Code Form.
38
+
39
+ 1.7. "Larger Work"
40
+ means a work that combines Covered Software with other material, in
41
+ a separate file or files, that is not Covered Software.
42
+
43
+ 1.8. "License"
44
+ means this document.
45
+
46
+ 1.9. "Licensable"
47
+ means having the right to grant, to the maximum extent possible,
48
+ whether at the time of the initial grant or subsequently, any and
49
+ all of the rights conveyed by this License.
50
+
51
+ 1.10. "Modifications"
52
+ means any of the following:
53
+
54
+ (a) any file in Source Code Form that results from an addition to,
55
+ deletion from, or modification of the contents of Covered
56
+ Software; or
57
+
58
+ (b) any new file in Source Code Form that contains any Covered
59
+ Software.
60
+
61
+ 1.11. "Patent Claims" of a Contributor
62
+ means any patent claim(s), including without limitation, method,
63
+ process, and apparatus claims, in any patent Licensable by such
64
+ Contributor that would be infringed, but for the grant of the
65
+ License, by the making, using, selling, offering for sale, having
66
+ made, import, or transfer of either its Contributions or its
67
+ Contributor Version.
68
+
69
+ 1.12. "Secondary License"
70
+ means either the GNU General Public License, Version 2.0, the GNU
71
+ Lesser General Public License, Version 2.1, the GNU Affero General
72
+ Public License, Version 3.0, or any later versions of those
73
+ licenses.
74
+
75
+ 1.13. "Source Code Form"
76
+ means the form of the work preferred for making modifications.
77
+
78
+ 1.14. "You" (or "Your")
79
+ means an individual or a legal entity exercising rights under this
80
+ License. For legal entities, "You" includes any entity that
81
+ controls, is controlled by, or is under common control with You. For
82
+ purposes of this definition, "control" means (a) the power, direct
83
+ or indirect, to cause the direction or management of such entity,
84
+ whether by contract or otherwise, or (b) ownership of more than
85
+ fifty percent (50%) of the outstanding shares or beneficial
86
+ ownership of such entity.
87
+
88
+ 2. License Grants and Conditions
89
+ --------------------------------
90
+
91
+ 2.1. Grants
92
+
93
+ Each Contributor hereby grants You a world-wide, royalty-free,
94
+ non-exclusive license:
95
+
96
+ (a) under intellectual property rights (other than patent or trademark)
97
+ Licensable by such Contributor to use, reproduce, make available,
98
+ modify, display, perform, distribute, and otherwise exploit its
99
+ Contributions, either on an unmodified basis, with Modifications, or
100
+ as part of a Larger Work; and
101
+
102
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
103
+ for sale, have made, import, and otherwise transfer either its
104
+ Contributions or its Contributor Version.
105
+
106
+ 2.2. Effective Date
107
+
108
+ The licenses granted in Section 2.1 with respect to any Contribution
109
+ become effective for each Contribution on the date the Contributor first
110
+ distributes such Contribution.
111
+
112
+ 2.3. Limitations on Grant Scope
113
+
114
+ The licenses granted in this Section 2 are the only rights granted under
115
+ this License. No additional rights or licenses will be implied from the
116
+ distribution or licensing of Covered Software under this License.
117
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
118
+ Contributor:
119
+
120
+ (a) for any code that a Contributor has removed from Covered Software;
121
+ or
122
+
123
+ (b) for infringements caused by: (i) Your and any other third party's
124
+ modifications of Covered Software, or (ii) the combination of its
125
+ Contributions with other software (except as part of its Contributor
126
+ Version); or
127
+
128
+ (c) under Patent Claims infringed by Covered Software in the absence of
129
+ its Contributions.
130
+
131
+ This License does not grant any rights in the trademarks, service marks,
132
+ or logos of any Contributor (except as may be necessary to comply with
133
+ the notice requirements in Section 3.4).
134
+
135
+ 2.4. Subsequent Licenses
136
+
137
+ No Contributor makes additional grants as a result of Your choice to
138
+ distribute the Covered Software under a subsequent version of this
139
+ License (see Section 10.2) or under the terms of a Secondary License (if
140
+ permitted under the terms of Section 3.3).
141
+
142
+ 2.5. Representation
143
+
144
+ Each Contributor represents that the Contributor believes its
145
+ Contributions are its original creation(s) or it has sufficient rights
146
+ to grant the rights to its Contributions conveyed by this License.
147
+
148
+ 2.6. Fair Use
149
+
150
+ This License is not intended to limit any rights You have under
151
+ applicable copyright doctrines of fair use, fair dealing, or other
152
+ equivalents.
153
+
154
+ 2.7. Conditions
155
+
156
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
157
+ in Section 2.1.
158
+
159
+ 3. Responsibilities
160
+ -------------------
161
+
162
+ 3.1. Distribution of Source Form
163
+
164
+ All distribution of Covered Software in Source Code Form, including any
165
+ Modifications that You create or to which You contribute, must be under
166
+ the terms of this License. You must inform recipients that the Source
167
+ Code Form of the Covered Software is governed by the terms of this
168
+ License, and how they can obtain a copy of this License. You may not
169
+ attempt to alter or restrict the recipients' rights in the Source Code
170
+ Form.
171
+
172
+ 3.2. Distribution of Executable Form
173
+
174
+ If You distribute Covered Software in Executable Form then:
175
+
176
+ (a) such Covered Software must also be made available in Source Code
177
+ Form, as described in Section 3.1, and You must inform recipients of
178
+ the Executable Form how they can obtain a copy of such Source Code
179
+ Form by reasonable means in a timely manner, at a charge no more
180
+ than the cost of distribution to the recipient; and
181
+
182
+ (b) You may distribute such Executable Form under the terms of this
183
+ License, or sublicense it under different terms, provided that the
184
+ license for the Executable Form does not attempt to limit or alter
185
+ the recipients' rights in the Source Code Form under this License.
186
+
187
+ 3.3. Distribution of a Larger Work
188
+
189
+ You may create and distribute a Larger Work under terms of Your choice,
190
+ provided that You also comply with the requirements of this License for
191
+ the Covered Software. If the Larger Work is a combination of Covered
192
+ Software with a work governed by one or more Secondary Licenses, and the
193
+ Covered Software is not Incompatible With Secondary Licenses, this
194
+ License permits You to additionally distribute such Covered Software
195
+ under the terms of such Secondary License(s), so that the recipient of
196
+ the Larger Work may, at their option, further distribute the Covered
197
+ Software under the terms of either this License or such Secondary
198
+ License(s).
199
+
200
+ 3.4. Notices
201
+
202
+ You may not remove or alter the substance of any license notices
203
+ (including copyright notices, patent notices, disclaimers of warranty,
204
+ or limitations of liability) contained within the Source Code Form of
205
+ the Covered Software, except that You may alter any license notices to
206
+ the extent required to remedy known factual inaccuracies.
207
+
208
+ 3.5. Application of Additional Terms
209
+
210
+ You may choose to offer, and to charge a fee for, warranty, support,
211
+ indemnity or liability obligations to one or more recipients of Covered
212
+ Software. However, You may do so only on Your own behalf, and not on
213
+ behalf of any Contributor. You must make it absolutely clear that any
214
+ such warranty, support, indemnity, or liability obligation is offered by
215
+ You alone, and You hereby agree to indemnify every Contributor for any
216
+ liability incurred by such Contributor as a result of warranty, support,
217
+ indemnity or liability terms You offer. You may include additional
218
+ disclaimers of warranty and limitations of liability specific to any
219
+ jurisdiction.
220
+
221
+ 4. Inability to Comply Due to Statute or Regulation
222
+ ---------------------------------------------------
223
+
224
+ If it is impossible for You to comply with any of the terms of this
225
+ License with respect to some or all of the Covered Software due to
226
+ statute, judicial order, or regulation then You must: (a) comply with
227
+ the terms of this License to the maximum extent possible; and (b)
228
+ describe the limitations and the code they affect. Such description must
229
+ be placed in a text file included with all distributions of the Covered
230
+ Software under this License. Except to the extent prohibited by statute
231
+ or regulation, such description must be sufficiently detailed for a
232
+ recipient of ordinary skill to be able to understand it.
233
+
234
+ 5. Termination
235
+ --------------
236
+
237
+ 5.1. The rights granted under this License will terminate automatically
238
+ if You fail to comply with any of its terms. However, if You become
239
+ compliant, then the rights granted under this License from a particular
240
+ Contributor are reinstated (a) provisionally, unless and until such
241
+ Contributor explicitly and finally terminates Your grants, and (b) on an
242
+ ongoing basis, if such Contributor fails to notify You of the
243
+ non-compliance by some reasonable means prior to 60 days after You have
244
+ come back into compliance. Moreover, Your grants from a particular
245
+ Contributor are reinstated on an ongoing basis if such Contributor
246
+ notifies You of the non-compliance by some reasonable means, this is the
247
+ first time You have received notice of non-compliance with this License
248
+ from such Contributor, and You become compliant prior to 30 days after
249
+ Your receipt of the notice.
250
+
251
+ 5.2. If You initiate litigation against any entity by asserting a patent
252
+ infringement claim (excluding declaratory judgment actions,
253
+ counter-claims, and cross-claims) alleging that a Contributor Version
254
+ directly or indirectly infringes any patent, then the rights granted to
255
+ You by any and all Contributors for the Covered Software under Section
256
+ 2.1 of this License shall terminate.
257
+
258
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
259
+ end user license agreements (excluding distributors and resellers) which
260
+ have been validly granted by You or Your distributors under this License
261
+ prior to termination shall survive termination.
262
+
263
+ ************************************************************************
264
+ * *
265
+ * 6. Disclaimer of Warranty *
266
+ * ------------------------- *
267
+ * *
268
+ * Covered Software is provided under this License on an "as is" *
269
+ * basis, without warranty of any kind, either expressed, implied, or *
270
+ * statutory, including, without limitation, warranties that the *
271
+ * Covered Software is free of defects, merchantable, fit for a *
272
+ * particular purpose or non-infringing. The entire risk as to the *
273
+ * quality and performance of the Covered Software is with You. *
274
+ * Should any Covered Software prove defective in any respect, You *
275
+ * (not any Contributor) assume the cost of any necessary servicing, *
276
+ * repair, or correction. This disclaimer of warranty constitutes an *
277
+ * essential part of this License. No use of any Covered Software is *
278
+ * authorized under this License except under this disclaimer. *
279
+ * *
280
+ ************************************************************************
281
+
282
+ ************************************************************************
283
+ * *
284
+ * 7. Limitation of Liability *
285
+ * -------------------------- *
286
+ * *
287
+ * Under no circumstances and under no legal theory, whether tort *
288
+ * (including negligence), contract, or otherwise, shall any *
289
+ * Contributor, or anyone who distributes Covered Software as *
290
+ * permitted above, be liable to You for any direct, indirect, *
291
+ * special, incidental, or consequential damages of any character *
292
+ * including, without limitation, damages for lost profits, loss of *
293
+ * goodwill, work stoppage, computer failure or malfunction, or any *
294
+ * and all other commercial damages or losses, even if such party *
295
+ * shall have been informed of the possibility of such damages. This *
296
+ * limitation of liability shall not apply to liability for death or *
297
+ * personal injury resulting from such party's negligence to the *
298
+ * extent applicable law prohibits such limitation. Some *
299
+ * jurisdictions do not allow the exclusion or limitation of *
300
+ * incidental or consequential damages, so this exclusion and *
301
+ * limitation may not apply to You. *
302
+ * *
303
+ ************************************************************************
304
+
305
+ 8. Litigation
306
+ -------------
307
+
308
+ Any litigation relating to this License may be brought only in the
309
+ courts of a jurisdiction where the defendant maintains its principal
310
+ place of business and such litigation shall be governed by laws of that
311
+ jurisdiction, without reference to its conflict-of-law provisions.
312
+ Nothing in this Section shall prevent a party's ability to bring
313
+ cross-claims or counter-claims.
314
+
315
+ 9. Miscellaneous
316
+ ----------------
317
+
318
+ This License represents the complete agreement concerning the subject
319
+ matter hereof. If any provision of this License is held to be
320
+ unenforceable, such provision shall be reformed only to the extent
321
+ necessary to make it enforceable. Any law or regulation which provides
322
+ that the language of a contract shall be construed against the drafter
323
+ shall not be used to construe this License against a Contributor.
324
+
325
+ 10. Versions of the License
326
+ ---------------------------
327
+
328
+ 10.1. New Versions
329
+
330
+ Mozilla Foundation is the license steward. Except as provided in Section
331
+ 10.3, no one other than the license steward has the right to modify or
332
+ publish new versions of this License. Each version will be given a
333
+ distinguishing version number.
334
+
335
+ 10.2. Effect of New Versions
336
+
337
+ You may distribute the Covered Software under the terms of the version
338
+ of the License under which You originally received the Covered Software,
339
+ or under the terms of any subsequent version published by the license
340
+ steward.
341
+
342
+ 10.3. Modified Versions
343
+
344
+ If you create software not governed by this License, and you want to
345
+ create a new license for such software, you may create and use a
346
+ modified version of this License if you rename the license and remove
347
+ any references to the name of the license steward (except to note that
348
+ such modified license differs from this License).
349
+
350
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
351
+ Licenses
352
+
353
+ If You choose to distribute Source Code Form that is Incompatible With
354
+ Secondary Licenses under the terms of this version of the License, the
355
+ notice described in Exhibit B of this License must be attached.
356
+
357
+ Exhibit A - Source Code Form License Notice
358
+ -------------------------------------------
359
+
360
+ This Source Code Form is subject to the terms of the Mozilla Public
361
+ License, v. 2.0. If a copy of the MPL was not distributed with this
362
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
363
+
364
+ If it is not possible or desirable to put the notice in a particular
365
+ file, then You may include the notice in a location (such as a LICENSE
366
+ file in a relevant directory) where a recipient would be likely to look
367
+ for such a notice.
368
+
369
+ You may add additional accurate notices of copyright ownership.
370
+
371
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
372
+ ---------------------------------------------------------
373
+
374
+ This Source Code Form is "Incompatible With Secondary Licenses", as
375
+ defined by the Mozilla Public License, v. 2.0.
@@ -0,0 +1,409 @@
1
+ Metadata-Version: 2.4
2
+ Name: numcodecs-combinators
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ License: Copyright (c) 2024, Juniper Tyree
6
+
7
+ Mozilla Public License Version 2.0
8
+ ==================================
9
+
10
+ 1. Definitions
11
+ --------------
12
+
13
+ 1.1. "Contributor"
14
+ means each individual or legal entity that creates, contributes to
15
+ the creation of, or owns Covered Software.
16
+
17
+ 1.2. "Contributor Version"
18
+ means the combination of the Contributions of others (if any) used
19
+ by a Contributor and that particular Contributor's Contribution.
20
+
21
+ 1.3. "Contribution"
22
+ means Covered Software of a particular Contributor.
23
+
24
+ 1.4. "Covered Software"
25
+ means Source Code Form to which the initial Contributor has attached
26
+ the notice in Exhibit A, the Executable Form of such Source Code
27
+ Form, and Modifications of such Source Code Form, in each case
28
+ including portions thereof.
29
+
30
+ 1.5. "Incompatible With Secondary Licenses"
31
+ means
32
+
33
+ (a) that the initial Contributor has attached the notice described
34
+ in Exhibit B to the Covered Software; or
35
+
36
+ (b) that the Covered Software was made available under the terms of
37
+ version 1.1 or earlier of the License, but not also under the
38
+ terms of a Secondary License.
39
+
40
+ 1.6. "Executable Form"
41
+ means any form of the work other than Source Code Form.
42
+
43
+ 1.7. "Larger Work"
44
+ means a work that combines Covered Software with other material, in
45
+ a separate file or files, that is not Covered Software.
46
+
47
+ 1.8. "License"
48
+ means this document.
49
+
50
+ 1.9. "Licensable"
51
+ means having the right to grant, to the maximum extent possible,
52
+ whether at the time of the initial grant or subsequently, any and
53
+ all of the rights conveyed by this License.
54
+
55
+ 1.10. "Modifications"
56
+ means any of the following:
57
+
58
+ (a) any file in Source Code Form that results from an addition to,
59
+ deletion from, or modification of the contents of Covered
60
+ Software; or
61
+
62
+ (b) any new file in Source Code Form that contains any Covered
63
+ Software.
64
+
65
+ 1.11. "Patent Claims" of a Contributor
66
+ means any patent claim(s), including without limitation, method,
67
+ process, and apparatus claims, in any patent Licensable by such
68
+ Contributor that would be infringed, but for the grant of the
69
+ License, by the making, using, selling, offering for sale, having
70
+ made, import, or transfer of either its Contributions or its
71
+ Contributor Version.
72
+
73
+ 1.12. "Secondary License"
74
+ means either the GNU General Public License, Version 2.0, the GNU
75
+ Lesser General Public License, Version 2.1, the GNU Affero General
76
+ Public License, Version 3.0, or any later versions of those
77
+ licenses.
78
+
79
+ 1.13. "Source Code Form"
80
+ means the form of the work preferred for making modifications.
81
+
82
+ 1.14. "You" (or "Your")
83
+ means an individual or a legal entity exercising rights under this
84
+ License. For legal entities, "You" includes any entity that
85
+ controls, is controlled by, or is under common control with You. For
86
+ purposes of this definition, "control" means (a) the power, direct
87
+ or indirect, to cause the direction or management of such entity,
88
+ whether by contract or otherwise, or (b) ownership of more than
89
+ fifty percent (50%) of the outstanding shares or beneficial
90
+ ownership of such entity.
91
+
92
+ 2. License Grants and Conditions
93
+ --------------------------------
94
+
95
+ 2.1. Grants
96
+
97
+ Each Contributor hereby grants You a world-wide, royalty-free,
98
+ non-exclusive license:
99
+
100
+ (a) under intellectual property rights (other than patent or trademark)
101
+ Licensable by such Contributor to use, reproduce, make available,
102
+ modify, display, perform, distribute, and otherwise exploit its
103
+ Contributions, either on an unmodified basis, with Modifications, or
104
+ as part of a Larger Work; and
105
+
106
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
107
+ for sale, have made, import, and otherwise transfer either its
108
+ Contributions or its Contributor Version.
109
+
110
+ 2.2. Effective Date
111
+
112
+ The licenses granted in Section 2.1 with respect to any Contribution
113
+ become effective for each Contribution on the date the Contributor first
114
+ distributes such Contribution.
115
+
116
+ 2.3. Limitations on Grant Scope
117
+
118
+ The licenses granted in this Section 2 are the only rights granted under
119
+ this License. No additional rights or licenses will be implied from the
120
+ distribution or licensing of Covered Software under this License.
121
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
122
+ Contributor:
123
+
124
+ (a) for any code that a Contributor has removed from Covered Software;
125
+ or
126
+
127
+ (b) for infringements caused by: (i) Your and any other third party's
128
+ modifications of Covered Software, or (ii) the combination of its
129
+ Contributions with other software (except as part of its Contributor
130
+ Version); or
131
+
132
+ (c) under Patent Claims infringed by Covered Software in the absence of
133
+ its Contributions.
134
+
135
+ This License does not grant any rights in the trademarks, service marks,
136
+ or logos of any Contributor (except as may be necessary to comply with
137
+ the notice requirements in Section 3.4).
138
+
139
+ 2.4. Subsequent Licenses
140
+
141
+ No Contributor makes additional grants as a result of Your choice to
142
+ distribute the Covered Software under a subsequent version of this
143
+ License (see Section 10.2) or under the terms of a Secondary License (if
144
+ permitted under the terms of Section 3.3).
145
+
146
+ 2.5. Representation
147
+
148
+ Each Contributor represents that the Contributor believes its
149
+ Contributions are its original creation(s) or it has sufficient rights
150
+ to grant the rights to its Contributions conveyed by this License.
151
+
152
+ 2.6. Fair Use
153
+
154
+ This License is not intended to limit any rights You have under
155
+ applicable copyright doctrines of fair use, fair dealing, or other
156
+ equivalents.
157
+
158
+ 2.7. Conditions
159
+
160
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
161
+ in Section 2.1.
162
+
163
+ 3. Responsibilities
164
+ -------------------
165
+
166
+ 3.1. Distribution of Source Form
167
+
168
+ All distribution of Covered Software in Source Code Form, including any
169
+ Modifications that You create or to which You contribute, must be under
170
+ the terms of this License. You must inform recipients that the Source
171
+ Code Form of the Covered Software is governed by the terms of this
172
+ License, and how they can obtain a copy of this License. You may not
173
+ attempt to alter or restrict the recipients' rights in the Source Code
174
+ Form.
175
+
176
+ 3.2. Distribution of Executable Form
177
+
178
+ If You distribute Covered Software in Executable Form then:
179
+
180
+ (a) such Covered Software must also be made available in Source Code
181
+ Form, as described in Section 3.1, and You must inform recipients of
182
+ the Executable Form how they can obtain a copy of such Source Code
183
+ Form by reasonable means in a timely manner, at a charge no more
184
+ than the cost of distribution to the recipient; and
185
+
186
+ (b) You may distribute such Executable Form under the terms of this
187
+ License, or sublicense it under different terms, provided that the
188
+ license for the Executable Form does not attempt to limit or alter
189
+ the recipients' rights in the Source Code Form under this License.
190
+
191
+ 3.3. Distribution of a Larger Work
192
+
193
+ You may create and distribute a Larger Work under terms of Your choice,
194
+ provided that You also comply with the requirements of this License for
195
+ the Covered Software. If the Larger Work is a combination of Covered
196
+ Software with a work governed by one or more Secondary Licenses, and the
197
+ Covered Software is not Incompatible With Secondary Licenses, this
198
+ License permits You to additionally distribute such Covered Software
199
+ under the terms of such Secondary License(s), so that the recipient of
200
+ the Larger Work may, at their option, further distribute the Covered
201
+ Software under the terms of either this License or such Secondary
202
+ License(s).
203
+
204
+ 3.4. Notices
205
+
206
+ You may not remove or alter the substance of any license notices
207
+ (including copyright notices, patent notices, disclaimers of warranty,
208
+ or limitations of liability) contained within the Source Code Form of
209
+ the Covered Software, except that You may alter any license notices to
210
+ the extent required to remedy known factual inaccuracies.
211
+
212
+ 3.5. Application of Additional Terms
213
+
214
+ You may choose to offer, and to charge a fee for, warranty, support,
215
+ indemnity or liability obligations to one or more recipients of Covered
216
+ Software. However, You may do so only on Your own behalf, and not on
217
+ behalf of any Contributor. You must make it absolutely clear that any
218
+ such warranty, support, indemnity, or liability obligation is offered by
219
+ You alone, and You hereby agree to indemnify every Contributor for any
220
+ liability incurred by such Contributor as a result of warranty, support,
221
+ indemnity or liability terms You offer. You may include additional
222
+ disclaimers of warranty and limitations of liability specific to any
223
+ jurisdiction.
224
+
225
+ 4. Inability to Comply Due to Statute or Regulation
226
+ ---------------------------------------------------
227
+
228
+ If it is impossible for You to comply with any of the terms of this
229
+ License with respect to some or all of the Covered Software due to
230
+ statute, judicial order, or regulation then You must: (a) comply with
231
+ the terms of this License to the maximum extent possible; and (b)
232
+ describe the limitations and the code they affect. Such description must
233
+ be placed in a text file included with all distributions of the Covered
234
+ Software under this License. Except to the extent prohibited by statute
235
+ or regulation, such description must be sufficiently detailed for a
236
+ recipient of ordinary skill to be able to understand it.
237
+
238
+ 5. Termination
239
+ --------------
240
+
241
+ 5.1. The rights granted under this License will terminate automatically
242
+ if You fail to comply with any of its terms. However, if You become
243
+ compliant, then the rights granted under this License from a particular
244
+ Contributor are reinstated (a) provisionally, unless and until such
245
+ Contributor explicitly and finally terminates Your grants, and (b) on an
246
+ ongoing basis, if such Contributor fails to notify You of the
247
+ non-compliance by some reasonable means prior to 60 days after You have
248
+ come back into compliance. Moreover, Your grants from a particular
249
+ Contributor are reinstated on an ongoing basis if such Contributor
250
+ notifies You of the non-compliance by some reasonable means, this is the
251
+ first time You have received notice of non-compliance with this License
252
+ from such Contributor, and You become compliant prior to 30 days after
253
+ Your receipt of the notice.
254
+
255
+ 5.2. If You initiate litigation against any entity by asserting a patent
256
+ infringement claim (excluding declaratory judgment actions,
257
+ counter-claims, and cross-claims) alleging that a Contributor Version
258
+ directly or indirectly infringes any patent, then the rights granted to
259
+ You by any and all Contributors for the Covered Software under Section
260
+ 2.1 of this License shall terminate.
261
+
262
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
263
+ end user license agreements (excluding distributors and resellers) which
264
+ have been validly granted by You or Your distributors under this License
265
+ prior to termination shall survive termination.
266
+
267
+ ************************************************************************
268
+ * *
269
+ * 6. Disclaimer of Warranty *
270
+ * ------------------------- *
271
+ * *
272
+ * Covered Software is provided under this License on an "as is" *
273
+ * basis, without warranty of any kind, either expressed, implied, or *
274
+ * statutory, including, without limitation, warranties that the *
275
+ * Covered Software is free of defects, merchantable, fit for a *
276
+ * particular purpose or non-infringing. The entire risk as to the *
277
+ * quality and performance of the Covered Software is with You. *
278
+ * Should any Covered Software prove defective in any respect, You *
279
+ * (not any Contributor) assume the cost of any necessary servicing, *
280
+ * repair, or correction. This disclaimer of warranty constitutes an *
281
+ * essential part of this License. No use of any Covered Software is *
282
+ * authorized under this License except under this disclaimer. *
283
+ * *
284
+ ************************************************************************
285
+
286
+ ************************************************************************
287
+ * *
288
+ * 7. Limitation of Liability *
289
+ * -------------------------- *
290
+ * *
291
+ * Under no circumstances and under no legal theory, whether tort *
292
+ * (including negligence), contract, or otherwise, shall any *
293
+ * Contributor, or anyone who distributes Covered Software as *
294
+ * permitted above, be liable to You for any direct, indirect, *
295
+ * special, incidental, or consequential damages of any character *
296
+ * including, without limitation, damages for lost profits, loss of *
297
+ * goodwill, work stoppage, computer failure or malfunction, or any *
298
+ * and all other commercial damages or losses, even if such party *
299
+ * shall have been informed of the possibility of such damages. This *
300
+ * limitation of liability shall not apply to liability for death or *
301
+ * personal injury resulting from such party's negligence to the *
302
+ * extent applicable law prohibits such limitation. Some *
303
+ * jurisdictions do not allow the exclusion or limitation of *
304
+ * incidental or consequential damages, so this exclusion and *
305
+ * limitation may not apply to You. *
306
+ * *
307
+ ************************************************************************
308
+
309
+ 8. Litigation
310
+ -------------
311
+
312
+ Any litigation relating to this License may be brought only in the
313
+ courts of a jurisdiction where the defendant maintains its principal
314
+ place of business and such litigation shall be governed by laws of that
315
+ jurisdiction, without reference to its conflict-of-law provisions.
316
+ Nothing in this Section shall prevent a party's ability to bring
317
+ cross-claims or counter-claims.
318
+
319
+ 9. Miscellaneous
320
+ ----------------
321
+
322
+ This License represents the complete agreement concerning the subject
323
+ matter hereof. If any provision of this License is held to be
324
+ unenforceable, such provision shall be reformed only to the extent
325
+ necessary to make it enforceable. Any law or regulation which provides
326
+ that the language of a contract shall be construed against the drafter
327
+ shall not be used to construe this License against a Contributor.
328
+
329
+ 10. Versions of the License
330
+ ---------------------------
331
+
332
+ 10.1. New Versions
333
+
334
+ Mozilla Foundation is the license steward. Except as provided in Section
335
+ 10.3, no one other than the license steward has the right to modify or
336
+ publish new versions of this License. Each version will be given a
337
+ distinguishing version number.
338
+
339
+ 10.2. Effect of New Versions
340
+
341
+ You may distribute the Covered Software under the terms of the version
342
+ of the License under which You originally received the Covered Software,
343
+ or under the terms of any subsequent version published by the license
344
+ steward.
345
+
346
+ 10.3. Modified Versions
347
+
348
+ If you create software not governed by this License, and you want to
349
+ create a new license for such software, you may create and use a
350
+ modified version of this License if you rename the license and remove
351
+ any references to the name of the license steward (except to note that
352
+ such modified license differs from this License).
353
+
354
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
355
+ Licenses
356
+
357
+ If You choose to distribute Source Code Form that is Incompatible With
358
+ Secondary Licenses under the terms of this version of the License, the
359
+ notice described in Exhibit B of this License must be attached.
360
+
361
+ Exhibit A - Source Code Form License Notice
362
+ -------------------------------------------
363
+
364
+ This Source Code Form is subject to the terms of the Mozilla Public
365
+ License, v. 2.0. If a copy of the MPL was not distributed with this
366
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
367
+
368
+ If it is not possible or desirable to put the notice in a particular
369
+ file, then You may include the notice in a location (such as a LICENSE
370
+ file in a relevant directory) where a recipient would be likely to look
371
+ for such a notice.
372
+
373
+ You may add additional accurate notices of copyright ownership.
374
+
375
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
376
+ ---------------------------------------------------------
377
+
378
+ This Source Code Form is "Incompatible With Secondary Licenses", as
379
+ defined by the Mozilla Public License, v. 2.0.
380
+ License-File: LICENSE
381
+ Requires-Python: >=3.12
382
+ Requires-Dist: numcodecs~=0.13
383
+ Requires-Dist: numpy~=2.2
384
+ Description-Content-Type: text/markdown
385
+
386
+ [![image](https://img.shields.io/github/actions/workflow/status/juntyr/numcodecs-combinators/ci.yml?branch=main)](https://github.com/juntyr/numcodecs-combinators/actions/workflows/ci.yml?query=branch%3Amain)
387
+ [![image](https://img.shields.io/pypi/v/numcodecs-combinators.svg)](https://pypi.python.org/pypi/numcodecs-combinators)
388
+ [![image](https://img.shields.io/pypi/l/numcodecs-combinators.svg)](https://github.com/juntyr/numcodecs-combinators/blob/main/LICENSE)
389
+ [![image](https://img.shields.io/pypi/pyversions/numcodecs-combinators.svg)](https://pypi.python.org/pypi/numcodecs-combinators)
390
+ [![image](https://readthedocs.org/projects/numcodecs-combinators/badge/?version=latest)](https://numcodecs-combinators.readthedocs.io/en/latest/?badge=latest)
391
+
392
+ # numcodecs-combinators
393
+
394
+ Combinator codecs for the [`numcodecs`] buffer compression API.
395
+
396
+ - `CodecStack`: a stack of codecs
397
+
398
+ [`numcodecs`]: https://numcodecs.readthedocs.io/en/stable/
399
+
400
+ ## License
401
+
402
+ Licensed under the Mozilla Public License, Version 2.0 ([LICENSE](LICENSE) or https://www.mozilla.org/en-US/MPL/2.0/).
403
+
404
+
405
+ ## Funding
406
+
407
+ The Online Laboratory for Climate Science and Meteorology has been developed as part of [ESiWACE3](https://www.esiwace.eu), the third phase of the Centre of Excellence in Simulation of Weather and Climate in Europe.
408
+
409
+ Funded by the European Union. This work has received funding from the European High Performance Computing Joint Undertaking (JU) under grant agreement No 101093054.
@@ -0,0 +1,24 @@
1
+ [![image](https://img.shields.io/github/actions/workflow/status/juntyr/numcodecs-combinators/ci.yml?branch=main)](https://github.com/juntyr/numcodecs-combinators/actions/workflows/ci.yml?query=branch%3Amain)
2
+ [![image](https://img.shields.io/pypi/v/numcodecs-combinators.svg)](https://pypi.python.org/pypi/numcodecs-combinators)
3
+ [![image](https://img.shields.io/pypi/l/numcodecs-combinators.svg)](https://github.com/juntyr/numcodecs-combinators/blob/main/LICENSE)
4
+ [![image](https://img.shields.io/pypi/pyversions/numcodecs-combinators.svg)](https://pypi.python.org/pypi/numcodecs-combinators)
5
+ [![image](https://readthedocs.org/projects/numcodecs-combinators/badge/?version=latest)](https://numcodecs-combinators.readthedocs.io/en/latest/?badge=latest)
6
+
7
+ # numcodecs-combinators
8
+
9
+ Combinator codecs for the [`numcodecs`] buffer compression API.
10
+
11
+ - `CodecStack`: a stack of codecs
12
+
13
+ [`numcodecs`]: https://numcodecs.readthedocs.io/en/stable/
14
+
15
+ ## License
16
+
17
+ Licensed under the Mozilla Public License, Version 2.0 ([LICENSE](LICENSE) or https://www.mozilla.org/en-US/MPL/2.0/).
18
+
19
+
20
+ ## Funding
21
+
22
+ The Online Laboratory for Climate Science and Meteorology has been developed as part of [ESiWACE3](https://www.esiwace.eu), the third phase of the Centre of Excellence in Simulation of Weather and Climate in Europe.
23
+
24
+ Funded by the European Union. This work has received funding from the European High Performance Computing Joint Undertaking (JU) under grant agreement No 101093054.
@@ -0,0 +1,46 @@
1
+ """Generate the code reference pages and navigation.
2
+ Adapted from: https://github.com/proxystore/proxystore/blob/main/docs/generate_api.py # noqa: E501
3
+ Licensed under the MIT license
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from pathlib import Path
9
+
10
+ import mkdocs_gen_files
11
+
12
+ nav = mkdocs_gen_files.Nav()
13
+
14
+ src = Path("src")
15
+ root = src / "numcodecs_combinators"
16
+
17
+ for path in sorted(root.rglob("**/*.py")):
18
+ module_path = path.relative_to(src).with_suffix("")
19
+ doc_path = path.relative_to(root).with_suffix(".md")
20
+ full_doc_path = Path("api", doc_path)
21
+
22
+ parts = tuple(module_path.parts)
23
+ parts = tuple(".".join(parts[: i + 1]) for i in range(len(parts)))
24
+
25
+ if parts[-1].endswith("__init__"):
26
+ parts = parts[:-1]
27
+ doc_path = doc_path.with_name("index.md")
28
+ full_doc_path = full_doc_path.with_name("index.md")
29
+ elif parts[-1].endswith("__main__"):
30
+ continue
31
+
32
+ if len(parts) == 1:
33
+ nav_parts = parts
34
+ elif len(parts) == 2:
35
+ nav_parts = (parts[1],)
36
+ else:
37
+ nav_parts = tuple([parts[1]] + [p.split(".")[-1] for p in parts[2:]])
38
+ nav[nav_parts] = doc_path.as_posix()
39
+
40
+ with mkdocs_gen_files.open(full_doc_path, "w") as fd:
41
+ fd.write(f"# {parts[-1]}\n\n::: {parts[-1]}")
42
+
43
+ mkdocs_gen_files.set_edit_path(full_doc_path, path)
44
+
45
+ with mkdocs_gen_files.open("api/SUMMARY.md", "w") as nav_file:
46
+ nav_file.writelines(nav.build_literate_nav())
@@ -0,0 +1,17 @@
1
+ [![image](https://img.shields.io/github/actions/workflow/status/juntyr/numcodecs-combinators/ci.yml?branch=main)](https://github.com/juntyr/numcodecs-combinators/actions/workflows/ci.yml?query=branch%3Amain)
2
+ [![image](https://img.shields.io/pypi/v/numcodecs-combinators.svg)](https://pypi.python.org/pypi/numcodecs-combinators)
3
+ [![image](https://img.shields.io/pypi/l/numcodecs-combinators.svg)](https://github.com/juntyr/numcodecs-combinators/blob/main/LICENSE)
4
+ [![image](https://img.shields.io/pypi/pyversions/numcodecs-combinators.svg)](https://pypi.python.org/pypi/numcodecs-combinators)
5
+ [![image](https://readthedocs.org/projects/numcodecs-combinators/badge/?version=latest)](https://numcodecs-combinators.readthedocs.io/en/latest/?badge=latest)
6
+
7
+ # numcodecs-combinators
8
+
9
+ Combinator codecs for the [`numcodecs`][numcodecs] buffer compression API.
10
+
11
+ - [`CodecStack`][numcodecs_combinators.CodecStack]: a stack of codecs
12
+
13
+ ## Funding
14
+
15
+ The Online Laboratory for Climate Science and Meteorology has been developed as part of [ESiWACE3](https://www.esiwace.eu), the third phase of the Centre of Excellence in Simulation of Weather and Climate in Europe.
16
+
17
+ Funded by the European Union. This work has received funding from the European High Performance Computing Joint Undertaking (JU) under grant agreement No 101093054.
@@ -0,0 +1,8 @@
1
+ mkdocs
2
+ mkdocstrings[python]
3
+ mkdocs-include-markdown-plugin
4
+ mkdocs-gen-files
5
+ mkdocs-literate-nav
6
+ mkdocs-exclude
7
+
8
+ ruff
@@ -0,0 +1,58 @@
1
+ site_name: numcodecs-combinators
2
+
3
+ strict: true
4
+
5
+ markdown_extensions:
6
+ - footnotes
7
+ - pymdownx.superfences
8
+ - toc
9
+ - pymdownx.highlight:
10
+ anchor_linenums: true
11
+ - codehilite
12
+
13
+ theme:
14
+ name: readthedocs
15
+ highlightjs: true
16
+
17
+ nav:
18
+ - Home: index.md
19
+ - Documentation: api/
20
+ - Links:
21
+ - GitHub: https://github.com/juntyr/numcodecs-combinators
22
+ - PyPI: https://pypi.org/project/numcodecs-combinators/
23
+
24
+ plugins:
25
+ - gen-files:
26
+ scripts:
27
+ - docs/generate_api.py
28
+ - literate-nav:
29
+ nav_file: SUMMARY.md
30
+ - exclude:
31
+ glob:
32
+ - generate_api.py
33
+ - mkdocs.yml
34
+ - requirements.txt
35
+ - search
36
+ - include-markdown
37
+ - mkdocstrings:
38
+ enable_inventory: true
39
+ handlers:
40
+ python:
41
+ options:
42
+ docstring_style: numpy
43
+ show_if_no_docstring: true
44
+ filters: [
45
+ "!^_$", "!^_[^_]", "!^__", "__init__"
46
+ ]
47
+ members_order: source
48
+ group_by_category: false
49
+ show_source: false
50
+ separate_signature: true
51
+ show_signature: true
52
+ show_signature_annotations: true
53
+ signature_crossrefs: true
54
+ show_root_toc_entry: false
55
+ merge_init_into_class: true
56
+ import:
57
+ - https://docs.python.org/3.12/objects.inv
58
+ - https://numcodecs.readthedocs.io/en/v0.13.0/objects.inv
@@ -0,0 +1,20 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "numcodecs-combinators"
7
+ version = "0.1.0"
8
+ description = "Add your description here"
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ requires-python = ">=3.12"
12
+ dependencies = [
13
+ "numcodecs~=0.13",
14
+ "numpy~=2.2",
15
+ ]
16
+
17
+ [dependency-groups]
18
+ dev = [
19
+ "pytest~=8.3",
20
+ ]
@@ -0,0 +1,199 @@
1
+ __all__ = ["CodecStack"]
2
+
3
+ from collections.abc import Buffer
4
+ from typing import Optional
5
+
6
+ import numcodecs
7
+ import numcodecs.registry
8
+ import numpy as np
9
+
10
+ from numcodecs.abc import Codec
11
+
12
+
13
+ class CodecStack(Codec, tuple[Codec]):
14
+ """
15
+ A stack of codecs, which makes up a combined codec.
16
+
17
+ On encoding, the codecs are applied to encode from left to right, i.e.
18
+ ```
19
+ CodecStack(a, b, c).encode(buf)
20
+ ```
21
+ computes
22
+ ```
23
+ c.encode(b.encode(a.encode(buf)))
24
+ ```
25
+
26
+ On decoding, the codecs are applied to decode from right to left, i.e.
27
+ ```
28
+ CodecStack(a, b, c).decode(buf)
29
+ ```
30
+ computes
31
+ ```
32
+ a.decode(b.decode(c.decode(buf)))
33
+ ```
34
+
35
+ The [`CodecStack`][numcodecs_combinators.CodecStack] provides the additional
36
+ [`encode_decode(buf)`][numcodecs_combinators.CodecStack.encode_decode]
37
+ method that computes
38
+ ```
39
+ stack.decode(stack.encode(buf))
40
+ ```
41
+ but makes use of knowing the shapes and dtypes of all intermediary encoding
42
+ stages.
43
+ """
44
+
45
+ __slots__ = ()
46
+
47
+ codec_id = "combinators.stack"
48
+
49
+ def __init__(self, *args: tuple[dict | Codec]):
50
+ pass
51
+
52
+ def __new__(cls, *args: tuple[dict | Codec]):
53
+ return super(CodecStack, cls).__new__(
54
+ cls,
55
+ tuple(
56
+ codec
57
+ if isinstance(codec, Codec)
58
+ else numcodecs.registry.get_codec(codec)
59
+ for codec in args
60
+ ),
61
+ )
62
+
63
+ def encode(self, buf: Buffer) -> Buffer:
64
+ """Encode data in `buf`.
65
+
66
+ Parameters
67
+ ----------
68
+ buf : Buffer
69
+ Data to be encoded. May be any object supporting the new-style
70
+ buffer protocol.
71
+
72
+ Returns
73
+ -------
74
+ enc : Buffer
75
+ Encoded data. May be any object supporting the new-style buffer
76
+ protocol.
77
+ """
78
+
79
+ encoded = buf
80
+ for codec in self:
81
+ encoded = codec.encode(
82
+ numcodecs.compat.ensure_contiguous_ndarray_like(encoded, flatten=False)
83
+ )
84
+ return encoded
85
+
86
+ def decode(self, buf: Buffer, out: Optional[Buffer] = None):
87
+ """Decode data in `buf`.
88
+
89
+ Parameters
90
+ ----------
91
+ buf : Buffer
92
+ Encoded data. May be any object supporting the new-style buffer
93
+ protocol.
94
+ out : Buffer, optional
95
+ Writeable buffer to store decoded data. N.B. if provided, this buffer must
96
+ be exactly the right size to store the decoded data.
97
+
98
+ Returns
99
+ -------
100
+ dec : Buffer
101
+ Decoded data. May be any object supporting the new-style
102
+ buffer protocol.
103
+ """
104
+
105
+ decoded = buf
106
+ for codec in reversed(self):
107
+ decoded = codec.decode(
108
+ numcodecs.compat.ensure_contiguous_ndarray_like(decoded, flatten=False),
109
+ out=None,
110
+ )
111
+ return numcodecs.compat.ndarray_copy(decoded, out)
112
+
113
+ def encode_decode(self, buf: Buffer) -> Buffer:
114
+ """
115
+ Encode, then decode the data in `buf`.
116
+
117
+ Parameters
118
+ ----------
119
+ buf : Buffer
120
+ Data to be encoded. May be any object supporting the new-style
121
+ buffer protocol.
122
+
123
+ Returns
124
+ -------
125
+ dec : Buffer
126
+ Decoded data. May be any object supporting the new-style
127
+ buffer protocol.
128
+ """
129
+
130
+ encoded = numcodecs.compat.ensure_contiguous_ndarray_like(buf, flatten=False)
131
+ silhouettes = []
132
+
133
+ for codec in self:
134
+ silhouettes.append((encoded.shape, encoded.dtype))
135
+ encoded = numcodecs.compat.ensure_contiguous_ndarray_like(
136
+ codec.encode((encoded)), flatten=False
137
+ )
138
+
139
+ decoded = encoded
140
+
141
+ for codec in reversed(self):
142
+ shape, dtype = silhouettes.pop()
143
+ out = np.empty(shape=shape, dtype=dtype)
144
+ decoded = codec.decode(decoded, out).reshape(shape)
145
+
146
+ return type(buf)(decoded)
147
+
148
+ def get_config(self) -> dict:
149
+ """
150
+ Returns the configuration of the codec stack.
151
+
152
+ [`numcodecs.registry.get_codec(config)`][numcodecs.registry.get_codec]
153
+ can be used to reconstruct this stack from the returned config.
154
+
155
+ Returns
156
+ -------
157
+ config : dict
158
+ Configuration of the codec stack.
159
+ """
160
+
161
+ return dict(
162
+ id=type(self).codec_id,
163
+ codecs=tuple(codec.get_config() for codec in self),
164
+ )
165
+
166
+ @classmethod
167
+ def from_config(cls, config: dict):
168
+ """
169
+ Instantiate the codec stack from a configuration [`dict`][dict].
170
+
171
+ Parameters
172
+ ----------
173
+ config : dict
174
+ Configuration of the codec stack.
175
+
176
+ Returns
177
+ -------
178
+ stack : CodecStack
179
+ Instantiated codec stack.
180
+ """
181
+
182
+ return cls(*config["codecs"])
183
+
184
+ def __repr__(self):
185
+ repr = ", ".join(f"{codec!r}" for codec in self)
186
+
187
+ return f"{type(self).__name__}({repr})"
188
+
189
+ def __add__(self, other):
190
+ return CodecStack(*tuple.__add__(self, other))
191
+
192
+ def __mul__(self, other):
193
+ return CodecStack(*tuple.__mul__(self, other))
194
+
195
+ def __rmul__(self, other):
196
+ return CodecStack(*tuple.__rmul__(self, other))
197
+
198
+
199
+ numcodecs.registry.register_codec(CodecStack)
@@ -0,0 +1,41 @@
1
+ import numcodecs
2
+ import numpy as np
3
+
4
+ from numcodecs_combinators import CodecStack
5
+
6
+
7
+ def assert_config_roundtrip(codec: numcodecs.abc.Codec):
8
+ config = codec.get_config()
9
+ codec2 = numcodecs.get_codec(config)
10
+ assert codec2 == codec
11
+
12
+
13
+ def test_init_config():
14
+ stack = CodecStack()
15
+ assert len(stack) == 0
16
+ assert_config_roundtrip(stack)
17
+
18
+ stack = CodecStack(dict(id="zlib", level=9))
19
+ assert len(stack) == 1
20
+ assert_config_roundtrip(stack)
21
+
22
+ stack = CodecStack(dict(id="zlib", level=9), numcodecs.CRC32())
23
+ assert len(stack) == 2
24
+ assert_config_roundtrip(stack)
25
+
26
+
27
+ def test_encode_decode():
28
+ stack = CodecStack(numcodecs.Zlib(level=9), numcodecs.CRC32())
29
+
30
+ stack_encoded = stack.encode(b"abc")
31
+ encoded = numcodecs.CRC32().encode(numcodecs.Zlib(level=9).encode(b"abc"))
32
+ assert type(stack_encoded) is type(encoded)
33
+ assert (np.array(stack_encoded) == np.array(encoded)).all()
34
+
35
+ stack_decoded = stack.decode(stack_encoded)
36
+ decoded = numcodecs.Zlib(level=9).decode(numcodecs.CRC32().decode(encoded))
37
+ assert stack_decoded == decoded
38
+ assert stack_decoded == b"abc"
39
+
40
+ encoded_decoded = stack.encode_decode(b"abc")
41
+ assert encoded_decoded == b"abc"