File: data2fut.py

package info (click to toggle)
haskell-futhark 0.25.32-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,236 kB
  • sloc: haskell: 100,484; ansic: 12,100; python: 3,440; yacc: 785; sh: 561; javascript: 558; lisp: 399; makefile: 277
file content (36 lines) | stat: -rwxr-xr-x 815 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
#
# Convert the contents of a file to a Futhark-compatible binary data
# file.  The file is interpreted as raw binary data corresponding to a
# one-dimensional array.
#
# Takes a single option: the name of the element type.  Only the
# numeric types are supported (no floats).
#
# Usage example:
#
# $ ./data2fut.py f32 INPUT OUTPUT

import futhark_data as fd
import numpy as np
import sys

types = {
    "f16": np.float16,
    "f32": np.float32,
    "f64": np.float64,
    "i8": np.int8,
    "i16": np.int16,
    "i32": np.int32,
    "i64": np.int64,
    "u8": np.uint8,
    "u16": np.uint16,
    "u32": np.uint32,
    "u64": np.uint64,
}

_, type, input, output = sys.argv
dtype = types[type]

v = np.fromfile(open(input, mode="rb"), dtype)
fd.dump(v, open(output, mode="wb"), binary=True)