cast-value-rs 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,355 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "autocfg"
7
+ version = "1.5.0"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
10
+
11
+ [[package]]
12
+ name = "cast-value-rs"
13
+ version = "0.1.0"
14
+ dependencies = [
15
+ "numpy",
16
+ "pyo3",
17
+ "zarr-cast-value",
18
+ ]
19
+
20
+ [[package]]
21
+ name = "heck"
22
+ version = "0.5.0"
23
+ source = "registry+https://github.com/rust-lang/crates.io-index"
24
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
25
+
26
+ [[package]]
27
+ name = "indoc"
28
+ version = "2.0.7"
29
+ source = "registry+https://github.com/rust-lang/crates.io-index"
30
+ checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
31
+ dependencies = [
32
+ "rustversion",
33
+ ]
34
+
35
+ [[package]]
36
+ name = "itoa"
37
+ version = "1.0.17"
38
+ source = "registry+https://github.com/rust-lang/crates.io-index"
39
+ checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
40
+
41
+ [[package]]
42
+ name = "libc"
43
+ version = "0.2.183"
44
+ source = "registry+https://github.com/rust-lang/crates.io-index"
45
+ checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
46
+
47
+ [[package]]
48
+ name = "matrixmultiply"
49
+ version = "0.3.10"
50
+ source = "registry+https://github.com/rust-lang/crates.io-index"
51
+ checksum = "a06de3016e9fae57a36fd14dba131fccf49f74b40b7fbdb472f96e361ec71a08"
52
+ dependencies = [
53
+ "autocfg",
54
+ "rawpointer",
55
+ ]
56
+
57
+ [[package]]
58
+ name = "memchr"
59
+ version = "2.8.0"
60
+ source = "registry+https://github.com/rust-lang/crates.io-index"
61
+ checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
62
+
63
+ [[package]]
64
+ name = "memoffset"
65
+ version = "0.9.1"
66
+ source = "registry+https://github.com/rust-lang/crates.io-index"
67
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
68
+ dependencies = [
69
+ "autocfg",
70
+ ]
71
+
72
+ [[package]]
73
+ name = "ndarray"
74
+ version = "0.16.1"
75
+ source = "registry+https://github.com/rust-lang/crates.io-index"
76
+ checksum = "882ed72dce9365842bf196bdeedf5055305f11fc8c03dee7bb0194a6cad34841"
77
+ dependencies = [
78
+ "matrixmultiply",
79
+ "num-complex",
80
+ "num-integer",
81
+ "num-traits",
82
+ "portable-atomic",
83
+ "portable-atomic-util",
84
+ "rawpointer",
85
+ ]
86
+
87
+ [[package]]
88
+ name = "num-complex"
89
+ version = "0.4.6"
90
+ source = "registry+https://github.com/rust-lang/crates.io-index"
91
+ checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
92
+ dependencies = [
93
+ "num-traits",
94
+ ]
95
+
96
+ [[package]]
97
+ name = "num-integer"
98
+ version = "0.1.46"
99
+ source = "registry+https://github.com/rust-lang/crates.io-index"
100
+ checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
101
+ dependencies = [
102
+ "num-traits",
103
+ ]
104
+
105
+ [[package]]
106
+ name = "num-traits"
107
+ version = "0.2.19"
108
+ source = "registry+https://github.com/rust-lang/crates.io-index"
109
+ checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
110
+ dependencies = [
111
+ "autocfg",
112
+ ]
113
+
114
+ [[package]]
115
+ name = "numpy"
116
+ version = "0.25.0"
117
+ source = "registry+https://github.com/rust-lang/crates.io-index"
118
+ checksum = "29f1dee9aa8d3f6f8e8b9af3803006101bb3653866ef056d530d53ae68587191"
119
+ dependencies = [
120
+ "libc",
121
+ "ndarray",
122
+ "num-complex",
123
+ "num-integer",
124
+ "num-traits",
125
+ "pyo3",
126
+ "pyo3-build-config",
127
+ "rustc-hash",
128
+ ]
129
+
130
+ [[package]]
131
+ name = "once_cell"
132
+ version = "1.21.4"
133
+ source = "registry+https://github.com/rust-lang/crates.io-index"
134
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
135
+
136
+ [[package]]
137
+ name = "portable-atomic"
138
+ version = "1.13.1"
139
+ source = "registry+https://github.com/rust-lang/crates.io-index"
140
+ checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
141
+
142
+ [[package]]
143
+ name = "portable-atomic-util"
144
+ version = "0.2.6"
145
+ source = "registry+https://github.com/rust-lang/crates.io-index"
146
+ checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3"
147
+ dependencies = [
148
+ "portable-atomic",
149
+ ]
150
+
151
+ [[package]]
152
+ name = "proc-macro2"
153
+ version = "1.0.106"
154
+ source = "registry+https://github.com/rust-lang/crates.io-index"
155
+ checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
156
+ dependencies = [
157
+ "unicode-ident",
158
+ ]
159
+
160
+ [[package]]
161
+ name = "pyo3"
162
+ version = "0.25.1"
163
+ source = "registry+https://github.com/rust-lang/crates.io-index"
164
+ checksum = "8970a78afe0628a3e3430376fc5fd76b6b45c4d43360ffd6cdd40bdde72b682a"
165
+ dependencies = [
166
+ "indoc",
167
+ "libc",
168
+ "memoffset",
169
+ "once_cell",
170
+ "portable-atomic",
171
+ "pyo3-build-config",
172
+ "pyo3-ffi",
173
+ "pyo3-macros",
174
+ "unindent",
175
+ ]
176
+
177
+ [[package]]
178
+ name = "pyo3-build-config"
179
+ version = "0.25.1"
180
+ source = "registry+https://github.com/rust-lang/crates.io-index"
181
+ checksum = "458eb0c55e7ece017adeba38f2248ff3ac615e53660d7c71a238d7d2a01c7598"
182
+ dependencies = [
183
+ "once_cell",
184
+ "target-lexicon",
185
+ ]
186
+
187
+ [[package]]
188
+ name = "pyo3-ffi"
189
+ version = "0.25.1"
190
+ source = "registry+https://github.com/rust-lang/crates.io-index"
191
+ checksum = "7114fe5457c61b276ab77c5055f206295b812608083644a5c5b2640c3102565c"
192
+ dependencies = [
193
+ "libc",
194
+ "pyo3-build-config",
195
+ ]
196
+
197
+ [[package]]
198
+ name = "pyo3-macros"
199
+ version = "0.25.1"
200
+ source = "registry+https://github.com/rust-lang/crates.io-index"
201
+ checksum = "a8725c0a622b374d6cb051d11a0983786448f7785336139c3c94f5aa6bef7e50"
202
+ dependencies = [
203
+ "proc-macro2",
204
+ "pyo3-macros-backend",
205
+ "quote",
206
+ "syn",
207
+ ]
208
+
209
+ [[package]]
210
+ name = "pyo3-macros-backend"
211
+ version = "0.25.1"
212
+ source = "registry+https://github.com/rust-lang/crates.io-index"
213
+ checksum = "4109984c22491085343c05b0dbc54ddc405c3cf7b4374fc533f5c3313a572ccc"
214
+ dependencies = [
215
+ "heck",
216
+ "proc-macro2",
217
+ "pyo3-build-config",
218
+ "quote",
219
+ "syn",
220
+ ]
221
+
222
+ [[package]]
223
+ name = "quote"
224
+ version = "1.0.45"
225
+ source = "registry+https://github.com/rust-lang/crates.io-index"
226
+ checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
227
+ dependencies = [
228
+ "proc-macro2",
229
+ ]
230
+
231
+ [[package]]
232
+ name = "rawpointer"
233
+ version = "0.2.1"
234
+ source = "registry+https://github.com/rust-lang/crates.io-index"
235
+ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
236
+
237
+ [[package]]
238
+ name = "rustc-hash"
239
+ version = "2.1.1"
240
+ source = "registry+https://github.com/rust-lang/crates.io-index"
241
+ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
242
+
243
+ [[package]]
244
+ name = "rustversion"
245
+ version = "1.0.22"
246
+ source = "registry+https://github.com/rust-lang/crates.io-index"
247
+ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
248
+
249
+ [[package]]
250
+ name = "serde"
251
+ version = "1.0.228"
252
+ source = "registry+https://github.com/rust-lang/crates.io-index"
253
+ checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
254
+ dependencies = [
255
+ "serde_core",
256
+ "serde_derive",
257
+ ]
258
+
259
+ [[package]]
260
+ name = "serde_core"
261
+ version = "1.0.228"
262
+ source = "registry+https://github.com/rust-lang/crates.io-index"
263
+ checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
264
+ dependencies = [
265
+ "serde_derive",
266
+ ]
267
+
268
+ [[package]]
269
+ name = "serde_derive"
270
+ version = "1.0.228"
271
+ source = "registry+https://github.com/rust-lang/crates.io-index"
272
+ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
273
+ dependencies = [
274
+ "proc-macro2",
275
+ "quote",
276
+ "syn",
277
+ ]
278
+
279
+ [[package]]
280
+ name = "serde_json"
281
+ version = "1.0.149"
282
+ source = "registry+https://github.com/rust-lang/crates.io-index"
283
+ checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
284
+ dependencies = [
285
+ "itoa",
286
+ "memchr",
287
+ "serde",
288
+ "serde_core",
289
+ "zmij",
290
+ ]
291
+
292
+ [[package]]
293
+ name = "syn"
294
+ version = "2.0.117"
295
+ source = "registry+https://github.com/rust-lang/crates.io-index"
296
+ checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
297
+ dependencies = [
298
+ "proc-macro2",
299
+ "quote",
300
+ "unicode-ident",
301
+ ]
302
+
303
+ [[package]]
304
+ name = "target-lexicon"
305
+ version = "0.13.5"
306
+ source = "registry+https://github.com/rust-lang/crates.io-index"
307
+ checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
308
+
309
+ [[package]]
310
+ name = "thiserror"
311
+ version = "2.0.18"
312
+ source = "registry+https://github.com/rust-lang/crates.io-index"
313
+ checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
314
+ dependencies = [
315
+ "thiserror-impl",
316
+ ]
317
+
318
+ [[package]]
319
+ name = "thiserror-impl"
320
+ version = "2.0.18"
321
+ source = "registry+https://github.com/rust-lang/crates.io-index"
322
+ checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
323
+ dependencies = [
324
+ "proc-macro2",
325
+ "quote",
326
+ "syn",
327
+ ]
328
+
329
+ [[package]]
330
+ name = "unicode-ident"
331
+ version = "1.0.24"
332
+ source = "registry+https://github.com/rust-lang/crates.io-index"
333
+ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
334
+
335
+ [[package]]
336
+ name = "unindent"
337
+ version = "0.2.4"
338
+ source = "registry+https://github.com/rust-lang/crates.io-index"
339
+ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
340
+
341
+ [[package]]
342
+ name = "zarr-cast-value"
343
+ version = "0.1.0"
344
+ dependencies = [
345
+ "num-traits",
346
+ "serde",
347
+ "serde_json",
348
+ "thiserror",
349
+ ]
350
+
351
+ [[package]]
352
+ name = "zmij"
353
+ version = "1.0.21"
354
+ source = "registry+https://github.com/rust-lang/crates.io-index"
355
+ checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
@@ -0,0 +1,3 @@
1
+ [workspace]
2
+ members = ["core", "python"]
3
+ resolver = "2"
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: cast-value-rs
3
+ Version: 0.1.0
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
7
+ Summary: Python bindings for the Zarr cast_value codec
8
+ License: MIT OR Apache-2.0
9
+ Requires-Python: >=3.9
@@ -0,0 +1,3 @@
1
+ from cast_value_rs._cast_value_rs import cast_array, cast_array_into
2
+
3
+ __all__ = ["cast_array", "cast_array_into"]
@@ -0,0 +1,7 @@
1
+ from cast_value_rs._cast_value_rs import (
2
+ DTypeName as DTypeName,
3
+ OutOfRangeMode as OutOfRangeMode,
4
+ RoundingMode as RoundingMode,
5
+ cast_array as cast_array,
6
+ cast_array_into as cast_array_into,
7
+ )
@@ -0,0 +1,105 @@
1
+ from collections.abc import Iterable
2
+ from typing import Literal
3
+
4
+ import numpy as np
5
+ import numpy.typing as npt
6
+
7
+ RoundingMode = Literal[
8
+ "nearest-even",
9
+ "towards-zero",
10
+ "towards-positive",
11
+ "towards-negative",
12
+ "nearest-away",
13
+ ]
14
+
15
+ OutOfRangeMode = Literal["clamp", "wrap"]
16
+
17
+ DTypeName = Literal[
18
+ "int8",
19
+ "int16",
20
+ "int32",
21
+ "int64",
22
+ "uint8",
23
+ "uint16",
24
+ "uint32",
25
+ "uint64",
26
+ "float32",
27
+ "float64",
28
+ ]
29
+
30
+ def cast_array(
31
+ arr: npt.NDArray[np.generic],
32
+ *,
33
+ target_dtype: DTypeName,
34
+ rounding_mode: RoundingMode,
35
+ out_of_range_mode: OutOfRangeMode | None = None,
36
+ scalar_map_entries: dict[float, float] | Iterable[tuple[float, float]] | None = None,
37
+ ) -> npt.NDArray[np.generic]:
38
+ """Cast a numpy array to a new dtype, allocating a new output array.
39
+
40
+ Parameters
41
+ ----------
42
+ arr
43
+ Input numpy array.
44
+ target_dtype
45
+ Target dtype name (e.g. ``"uint8"``, ``"float32"``).
46
+ rounding_mode
47
+ How to round values during conversion.
48
+ out_of_range_mode
49
+ How to handle values outside the target type's range.
50
+ ``None`` means out-of-range values raise an error.
51
+ scalar_map_entries
52
+ Mapping of special source values to target values, applied before
53
+ any other conversion logic. Accepts a dict or any iterable of
54
+ ``(source, target)`` pairs (tuples, lists, etc.). Useful for
55
+ mapping ``NaN`` or ``Inf`` to sentinel integer values.
56
+
57
+ Returns
58
+ -------
59
+ npt.NDArray[np.generic]
60
+ A new numpy array with the target dtype.
61
+
62
+ Raises
63
+ ------
64
+ ValueError
65
+ If a value cannot be converted (e.g. NaN to int without a
66
+ scalar_map entry, or out-of-range without a mode set).
67
+ TypeError
68
+ If the source or target dtype is unsupported.
69
+ """
70
+ ...
71
+
72
+ def cast_array_into(
73
+ arr: npt.NDArray[np.generic],
74
+ out: npt.NDArray[np.generic],
75
+ *,
76
+ rounding_mode: RoundingMode,
77
+ out_of_range_mode: OutOfRangeMode | None = None,
78
+ scalar_map_entries: dict[float, float] | Iterable[tuple[float, float]] | None = None,
79
+ ) -> None:
80
+ """Cast a numpy array into a pre-allocated output array.
81
+
82
+ Parameters
83
+ ----------
84
+ arr
85
+ Input numpy array.
86
+ out
87
+ Pre-allocated output numpy array. Must have the same shape as
88
+ ``arr``.
89
+ rounding_mode
90
+ How to round values during conversion.
91
+ out_of_range_mode
92
+ How to handle values outside the target type's range.
93
+ ``None`` means out-of-range values raise an error.
94
+ scalar_map_entries
95
+ Mapping of special source values to target values. Accepts a dict
96
+ or any iterable of ``(source, target)`` pairs.
97
+
98
+ Raises
99
+ ------
100
+ ValueError
101
+ If shapes don't match, or a value cannot be converted.
102
+ TypeError
103
+ If the source or target dtype is unsupported.
104
+ """
105
+ ...
File without changes
@@ -0,0 +1,16 @@
1
+ [package]
2
+ name = "zarr-cast-value"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ license = "MIT OR Apache-2.0"
6
+ description = "Core casting logic for the Zarr cast_value codec"
7
+ repository = "https://github.com/zarr-developers/cast-value.rs"
8
+ readme = "README.md"
9
+
10
+ [dependencies]
11
+ num-traits = "0.2"
12
+ serde = { version = "1", features = ["derive"] }
13
+ thiserror = "2"
14
+
15
+ [dev-dependencies]
16
+ serde_json = "1"
@@ -0,0 +1,3 @@
1
+ # cast-value.rs
2
+
3
+ Rust implementation of the [`cast_value` Zarr codec](https://github.com/zarr-developers/zarr-extensions/tree/main/codecs/cast_value) with Python bindings.