File: make-numerical-json.py

package info (click to toggle)
python-awkward 2.8.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,140 kB
  • sloc: python: 182,845; cpp: 33,828; sh: 432; makefile: 21; javascript: 8
file content (23 lines) | stat: -rw-r--r-- 1,054 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import numpy

maxbytes = 4*1024**3   # 4 GB

content = numpy.empty(maxbytes // numpy.dtype(numpy.float32).itemsize, dtype=numpy.float32)
for i in range(0, len(content), len(content) // 8):
    content[i : i + len(content) // 8] = numpy.random.normal(0, 1, len(content) // 8)
content.tofile(open("sample-content.float32", "wb"))

offsets1 = numpy.arange(0, len(content) + 8, 8, dtype=numpy.int64)
offsets1[1:-1] += numpy.random.randint(0, 8, len(offsets1) - 2)
offsets1.tofile(open("sample-offsets1.int64", "wb"))

offsets2 = numpy.arange(0, len(offsets1) - 1 + 8, 8, dtype=numpy.int64)
offsets2[1:-1] += numpy.random.randint(0, 8, len(offsets2) - 2)
offsets2.tofile(open("sample-offsets2.int64", "wb"))

offsets3 = numpy.arange(0, len(offsets2) - 1 + 8, 8, dtype=numpy.int64)
offsets3[1:-1] += numpy.random.randint(0, 8, len(offsets3) - 2)
offsets3.tofile(open("sample-offsets3.int64", "wb"))

# import awkward
# a = awkward.JaggedArray.fromoffsets(offsets3, awkward.JaggedArray.fromoffsets(offsets2, awkward.JaggedArray.fromoffsets(offsets1, content)))