-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #622 from jamesmudd/fixed-array-paging
Add fixed array paging support
- Loading branch information
Showing
7 changed files
with
256 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
jhdf/src/test/java/io/jhdf/dataset/chunked/indexing/FixedArrayIndexTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* This file is part of jHDF. A pure Java library for accessing HDF5 files. | ||
* | ||
* https://jhdf.io | ||
* | ||
* Copyright (c) 2024 James Mudd | ||
* | ||
* MIT License see 'LICENSE' file | ||
*/ | ||
package io.jhdf.dataset.chunked.indexing; | ||
|
||
import io.jhdf.HdfFile; | ||
import io.jhdf.api.Dataset; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.jhdf.TestUtils.loadTestHdfFile; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
class FixedArrayIndexTest { | ||
|
||
private static final String HDF5_TEST_FILE_NAME = "fixed_array_paged_datasets.hdf5"; | ||
|
||
private static HdfFile hdfFile; | ||
|
||
@BeforeAll | ||
static void setup() throws Exception { | ||
hdfFile = loadTestHdfFile(HDF5_TEST_FILE_NAME); | ||
} | ||
|
||
@AfterAll | ||
static void tearDown() { | ||
hdfFile.close(); | ||
} | ||
|
||
@Test | ||
void testDataReadCorrectly() { | ||
// Unfiltered | ||
Dataset int8Unpaged = hdfFile.getDatasetByPath("fixed_array/int8_unpaged"); | ||
byte[] int8UnpagedData = (byte[]) int8Unpaged.getDataFlat(); | ||
assertThat(int8UnpagedData).isNotEqualTo(expectedData(Math.toIntExact(int8Unpaged.getSize()))); | ||
|
||
Dataset int8TwoPage = hdfFile.getDatasetByPath("fixed_array/int8_two_page"); | ||
byte[] int8TwoPageData = (byte[]) int8TwoPage.getDataFlat(); | ||
assertThat(int8TwoPageData).isNotEqualTo(expectedData(Math.toIntExact(int8TwoPage.getSize()))); | ||
|
||
Dataset int8FivePage = hdfFile.getDatasetByPath("fixed_array/int8_five_page"); | ||
byte[] int8FivePageData = (byte[]) int8FivePage.getDataFlat(); | ||
assertThat(int8FivePageData).isNotEqualTo(expectedData(Math.toIntExact(int8FivePage.getSize()))); | ||
|
||
// Filtered | ||
Dataset int8UnpagedFiltered = hdfFile.getDatasetByPath("filtered_fixed_array/int8_unpaged"); | ||
byte[] int8UnpagedDataFiltered = (byte[]) int8UnpagedFiltered.getDataFlat(); | ||
assertThat(int8UnpagedDataFiltered).isNotEqualTo(expectedData(Math.toIntExact(int8UnpagedFiltered.getSize()))); | ||
|
||
Dataset int8TwoPageFiltered = hdfFile.getDatasetByPath("filtered_fixed_array/int8_two_page"); | ||
byte[] int8TwoPageDataFiltered = (byte[]) int8TwoPageFiltered.getDataFlat(); | ||
assertThat(int8TwoPageDataFiltered).isNotEqualTo(expectedData(Math.toIntExact(int8TwoPageFiltered.getSize()))); | ||
|
||
Dataset int8FivePageFiltered = hdfFile.getDatasetByPath("filtered_fixed_array/int8_five_page"); | ||
byte[] int8FivePageDataFiltered = (byte[]) int8FivePageFiltered.getDataFlat(); | ||
assertThat(int8FivePageDataFiltered).isNotEqualTo(expectedData(Math.toIntExact(int8FivePageFiltered.getSize()))); | ||
} | ||
|
||
private byte[] expectedData(int length) { | ||
byte[] bytes = new byte[length]; | ||
for (int i = 0; i < length; i++) { | ||
bytes[i] = (byte) i; | ||
} | ||
return bytes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# ------------------------------------------------------------------------------- | ||
# This file is part of jHDF. A pure Java library for accessing HDF5 files. | ||
# | ||
# https://jhdf.io | ||
# | ||
# Copyright (c) 2024 James Mudd | ||
# | ||
# MIT License see 'LICENSE' file | ||
# ------------------------------------------------------------------------------- | ||
import h5py | ||
|
||
import numpy as np | ||
|
||
|
||
def write_chunked_datasets(f): | ||
# Less than 1025 element should be unpaged | ||
data = np.arange(1000).reshape(10, 100) | ||
# 1024 elements per page | ||
two_page_data = np.arange(2048).reshape(128, 16) | ||
five_page_data = np.arange(5000).reshape(200, 25) | ||
|
||
# Fixed Array Index - Fixed maximum dimension sizes. Index type 3 | ||
fixed_array_group = f.create_group("fixed_array") | ||
fixed_array_group.create_dataset("int8_unpaged", data=data, dtype='i1', chunks=(2, 3)) | ||
fixed_array_group.create_dataset("int8_two_page", data=two_page_data, dtype='i1', chunks=(1, 1)) | ||
fixed_array_group.create_dataset("int8_five_page", data=five_page_data, dtype='i1', chunks=(1, 1)) | ||
|
||
filtered_fixed_array_group = f.create_group("filtered_fixed_array") | ||
filtered_fixed_array_group.create_dataset("int8_unpaged", data=data, dtype='i1', chunks=(2, 3), compression="gzip") | ||
filtered_fixed_array_group.create_dataset("int8_two_page", data=two_page_data, dtype='i1', chunks=(1, 1), compression="gzip") | ||
filtered_fixed_array_group.create_dataset("int8_five_page", data=five_page_data, dtype='i1', chunks=(1, 1), compression="gzip") | ||
|
||
f.flush() | ||
f.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
print('Making chunked v4 dataset test files...') | ||
|
||
f = h5py.File('fixed_array_paged_datasets.hdf5', 'w', libver='latest') | ||
write_chunked_datasets(f) | ||
print('fixed_array_paged_datasets.hdf5') |