def test_from_offsets(): values = np.array([97, 112, 112, 108, 101], dtype=np.int8) offsets = np.array([0, 1, 2, 3, 4, 5], dtype=np.int32) cat = nvcategory.from_offsets(values, offsets, 5) expected_keys = ['a', 'e', 'l', 'p'] expected_values = [0, 3, 3, 2, 1] assert_eq(cat.keys(), expected_keys) assert_eq(cat.values(), expected_values)
print("values.ctypes.data", hex(values.ctypes.data)) print("offsets.ctypes.data", hex(offsets.ctypes.data)) print("bitmask.ctypes.data", hex(bitmask.ctypes.data)) s = nvstrings.from_offsets(values.ctypes.data, offsets.ctypes.data, 3, bitmask.ctypes.data, 1) print(s) print("------------------") s = nvstrings.to_device(['a', 'p', 'p', 'l', 'e']) values = np.empty(s.size(), dtype=np.int8) offsets = np.empty(s.size() + 1, dtype=np.int32) nulls = np.empty(int(s.size() / 8) + 1, dtype=np.int8) s.to_offsets(values, offsets, nulls) print("values", values.tobytes()) print("offsets", offsets) print("nulls", nulls.tobytes()) print("------------------") import nvcategory values = np.array([97, 112, 112, 108, 101], dtype=np.int8) print("values", values.tobytes()) offsets = np.array([0, 1, 2, 3, 4, 5], dtype=np.int32) print("offsets", offsets) c = nvcategory.from_offsets(values, offsets, 5) print(c.keys(), c.values()) bitmask = np.array([29], dtype=np.int8) print("bitmask", bitmask.tobytes()) c = nvcategory.from_offsets(values, offsets, 5, bitmask, 1) print(c.keys(), c.values())