Skip to content

Instantly share code, notes, and snippets.

View jamesmudd's full-sized avatar

James Mudd jamesmudd

View GitHub Profile
// ignores the higher 16 bits
public static float toFloat( int hbits )
{
int mant = hbits & 0x03ff; // 10 bits mantissa
int exp = hbits & 0x7c00; // 5 bits exponent
if( exp == 0x7c00 ) // NaN/Inf
exp = 0x3fc00; // -> NaN/Inf
else if( exp != 0 ) // normalized value
{
exp += 0x1c000; // exp - 15 + 127
import numpy as np
import h5py
if __name__ == '__main__':
print('Making large attribute test files...')
# Can only work with latest
f = h5py.File('large_attribute.hdf5', 'w', libver='latest')
# Small test dataset with large attributes
@jamesmudd
jamesmudd / bitfield.py
Last active February 4, 2020 23:00
Create a bitfield test datasets with PyTables
from tables import *
import numpy as np
# Open a file in "w"rite mode
file = open_file("bitfield.hdf5", mode ="w")
# Create the last table in group2
data = [bool(i % 2) for i in range(15)]
file.create_array("/", "bitfield", data)
file.create_carray("/", "chnunked_bitfield", chunkshape=(2,), obj=data)
#-------------------------------------------------------------------------------
# This file is part of jHDF. A pure Java library for accessing HDF5 files.
#
# http://jhdf.io
#
# Copyright 2019 James Mudd
#
# MIT License see 'LICENSE' file
#-------------------------------------------------------------------------------
import h5py
@jamesmudd
jamesmudd / Hdf5LibBenchmark.java
Created March 14, 2019 08:30
jHDF vs HDF5 group benchmark
package examples.datasets;
import static java.util.stream.Collectors.joining;
import java.io.File;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;