...
 
Commits (2)
......@@ -33,6 +33,11 @@ public final class HDF5ArrayBlockParams
long[] boundIndexArray;
IndexMap boundIndexMap;
HDF5ArrayBlockParams()
{
// Only HDF5ArrayBlockParamsBuilder can instantiate this class.
}
int[] getBlockDimensions()
{
......
......@@ -21,6 +21,11 @@ package ch.systemsx.cisd.hdf5;
*/
public class HDF5ArrayBlockParamsBuilder
{
private HDF5ArrayBlockParamsBuilder()
{
// Cannot be instantiated.
}
/**
* Creates a parameter that reads the complete array.
*/
......
......@@ -27,12 +27,10 @@ import ch.systemsx.cisd.base.mdarray.MDArray;
/**
* Utilities for working with primitive matrices.
* <p>
* <i>This is an internal API that should not be expected to be stable between releases!</i>
*
* @author Bernd Rinn
*/
final class MatrixUtils
public final class MatrixUtils
{
private MatrixUtils()
......@@ -40,6 +38,30 @@ final class MatrixUtils
// Cannot be instantiated
}
/**
* Helper method for creating <code>int[]</code> array for the block dimensions.
*/
public static int[] dims(int... dim)
{
return dim;
}
/**
* Helper method for creating <code>long[]</code> array for the array dimensions.
*/
public static long[] dims(long... dim)
{
return dim;
}
/**
* Helper method for creating <code>long[]</code> array for the array dimensions.
*/
public static long[] ldims(long... dim)
{
return dim;
}
static void checkMDArrayDimensions(final String name, final int[] dimensions,
final MDAbstractArray<?> array)
{
......
......@@ -18,6 +18,7 @@ package ch.systemsx.cisd.hdf5.examples;
import static ch.systemsx.cisd.hdf5.HDF5ArrayBlockParamsBuilder.slice;
import static ch.systemsx.cisd.hdf5.HDF5ArrayBlockParamsBuilder.blockIndex;
import static ch.systemsx.cisd.hdf5.MatrixUtils.dims;
import java.util.Random;
......@@ -40,13 +41,13 @@ public class BlockwiseMatrixExample
public static void main(String[] args)
{
Random rng = new Random();
MDIntArray mydata = new MDIntArray(new int[] { 10, 10 });
MDIntArray mydata = new MDIntArray(dims(10, 10));
// Write the integer matrix.
try (IHDF5Writer writer = HDF5Factory.open("largeimatrix.h5"))
{
// Define the block size as 10 x 10.
try (HDF5DataSet dataSet = writer.int32().createMDArrayAndOpen("mydata", new int[] { 10, 10 }))
try (HDF5DataSet dataSet = writer.int32().createMDArrayAndOpen("mydata", dims(10, 10)))
{
// Write 5 x 7 blocks.
for (int bx = 0; bx < 5; ++bx)
......
......@@ -17,6 +17,8 @@
package ch.systemsx.cisd.hdf5;
import static ch.systemsx.cisd.hdf5.HDF5ArrayBlockParamsBuilder.*;
import static ch.systemsx.cisd.hdf5.MatrixUtils.dims;
import static ch.systemsx.cisd.hdf5.MatrixUtils.ldims;
import static ch.systemsx.cisd.hdf5.HDF5CompoundMemberMapping.mapping;
import static ch.systemsx.cisd.hdf5.HDF5FloatStorageFeatures.FLOAT_CHUNKED;
import static ch.systemsx.cisd.hdf5.HDF5FloatStorageFeatures.FLOAT_DEFLATE;
......@@ -1003,10 +1005,8 @@ public class HDF5RoundtripTest
final IHDF5Writer writer = HDF5FactoryProvider.get().open(datasetFile);
final String floatDatasetName = "/floatMatrix";
final String floatDatasetName2 = "/floatMatrix2";
final long[] shape = new long[]
{ 10, 10, 10 };
final int[] blockShape = new int[]
{ 5, 5, 5 };
final long[] shape = ldims(10, 10, 10);
final int[] blockShape = dims(5, 5, 5);
writer.float32().createMDArray(floatDatasetName, shape, blockShape);
writer.float32().createMDArray(floatDatasetName2, shape, blockShape);
final float[] flatArray = new float[MDArray.getLength(blockShape)];
......@@ -1034,19 +1034,15 @@ public class HDF5RoundtripTest
}
final MDFloatArray arraySliceWritten1 = new MDFloatArray(new float[]
{ 1000f, 2000f, 3000f, 4000f, 5000f }, new int[]
{ 1, 5 });
final long[] slicedBlock1 = new long[]
{ 4, 1 };
{ 1000f, 2000f, 3000f, 4000f, 5000f }, dims(1, 5));
final long[] slicedBlock1 = ldims(4, 1);
final IndexMap imap1 = new IndexMap().bind(1, 7);
writer.float32().writeSlicedMDArrayBlock(floatDatasetName2, arraySliceWritten1,
slicedBlock1, imap1);
final MDFloatArray arraySliceWritten2 = new MDFloatArray(new float[]
{ -1f, -2f, -3f, -4f, -5f, -6f }, new int[]
{ 3, 2 });
final long[] slicedBlockOffs2 = new long[]
{ 2, 6 };
{ -1f, -2f, -3f, -4f, -5f, -6f }, dims(3, 2));
final long[] slicedBlockOffs2 = ldims(2, 6);
final IndexMap imap2 = new IndexMap().bind(0, 9);
try (HDF5DataSet ds = writer.object().openDataSet(floatDatasetName2))
{
......@@ -1071,9 +1067,8 @@ public class HDF5RoundtripTest
block(blockShape).index(blockIndex));
assertEquals(Arrays.toString(blockIndex), arrayBlockWritten, arrayRead2);
// {0, 1, 1} is the first block we overwrote, { 1, 0, 1} the second block.
if (false == Arrays.equals(new long[]
{ 0, 1, 1 }, blockIndex) && false == Arrays.equals(new long[]
{ 1, 0, 1 }, blockIndex))
if (false == Arrays.equals(ldims(0, 1, 1), blockIndex)
&& false == Arrays.equals(ldims(1, 0, 1), blockIndex))
{
assertEquals(
Arrays.toString(blockIndex),
......