Python implementation of the Futhark data format
This is a small Python library that implements reading and writing of the textual and binary data format used by Futhark executables and test tools. It is intended to make it easy to write Python scripts that use Python libraries to convert complex formats (e.g. images, audio) into Futhark test data. It provides functions that convert between Numpy values and textual/binary representations in the Futhark formats. Comments are supported. Beware: reading and writing the textual data format is very slow. Use the binary format for all arrays of more than a few hundred elements.
The following Numpy types are supported: np.int8, np.int16,
np.in32, np.int64, np.uint8, np.uint16, np.uint32,
np.uint64, np.float32, np.float64, np.bool_, as well as up to
255-dimensional arrays containing elements of these sizes.
Installation
$ pip install --user futhark-data
API
Serialising
-
dump(v, f, binary=None): Dumpv, which must be a Numpy value, to the file-like objectf. The parameterbinaryindicates whether to use binary data format. IfNone, decide based on the type off. -
dumps(v): Returns the argument in the textual data format. -
dumpb(v): Returns the argument in the binary data format.
Deserialising
-
load(f): Load all values from the file-like objectf. -
loads(s): Load all values from the strings. -
loadb(b): Load all values from the byte sequenceb.
Since a file (or str, or bytes) can contain any number of Futhark
values, the functions above all return generators. Use next if you
know for sure there is just a single value, and you want it (see
example below).
The functions automatically detect whether the data is encoded using the binary or textual format, so there is no need for the caller to specify.
Examples
>>> import futhark_data
>>> for x in futhark_data.loads('[1,2,3] [4,5,6]'):
... print(x)
...
[1 2 3]
[4 5 6]
>>> futhark_data.dumpb(next(futhark_data.loads('[1,2,3]')))
b'b\x02\x01 i32\x03\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00'
Metadata
Release files for futhark-data 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| futhark-data-1.0.3.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| futhark_data-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.5 kB
Release files / futhark-data-1.0.3.tar.gz
| Download URL | futhark-data-1.0.3.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e8c5e48b5edd81d57dcf6667d99a720e8a92de7386dadd591404bb598553cf5
|
|
BLAKE2b-256 checksum How to use checksums |
0bc54148152fe9fe664d30261ba933bb6e88c453d305df8b84b8be92808b275f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / futhark_data-1.0.3-py3-none-any.whl
| Download URL | futhark_data-1.0.3-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0719ba76adf5e0fd2148fd4af2b6cd273a4844a8d78ca7798d39620492efd941
|
|
BLAKE2b-256 checksum How to use checksums |
8fc2fd10a54dae96887b4e4cfa4049dfd25d94f5c90ef0622702e1c5f4a438ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|