Skip to content

Commit 14dbc77

Browse files
committed
test: DatasetAttributesTest test NestedGrid
1 parent 552d416 commit 14dbc77

1 file changed

Lines changed: 13 additions & 106 deletions

File tree

src/test/java/org/janelia/saalfeldlab/n5/DatasetAttributesTest.java

Lines changed: 13 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,16 @@
2828
*/
2929
package org.janelia.saalfeldlab.n5;
3030

31-
import static org.junit.Assert.assertArrayEquals;
3231
import static org.junit.Assert.assertEquals;
3332
import static org.junit.Assert.assertThrows;
3433
import static org.junit.Assert.assertTrue;
3534

36-
import java.util.Iterator;
37-
import java.util.List;
38-
import java.util.Map;
39-
import java.util.Spliterator;
40-
import java.util.Spliterators;
41-
import java.util.stream.Collectors;
42-
import java.util.stream.Stream;
43-
import java.util.stream.StreamSupport;
44-
45-
import org.janelia.saalfeldlab.n5.codec.CodecInfo;
4635
import org.janelia.saalfeldlab.n5.codec.DataCodecInfo;
47-
import org.janelia.saalfeldlab.n5.codec.DeterministicSizeCodecInfo;
4836
import org.janelia.saalfeldlab.n5.codec.N5BlockCodecInfo;
4937
import org.janelia.saalfeldlab.n5.codec.RawBlockCodecInfo;
5038
import org.janelia.saalfeldlab.n5.shard.DefaultShardCodecInfo;
39+
import org.janelia.saalfeldlab.n5.shard.Nesting.NestedGrid;
5140
import org.janelia.saalfeldlab.n5.shard.ShardIndex.IndexLocation;
52-
import org.janelia.saalfeldlab.n5.util.GridIterator;
53-
import org.janelia.saalfeldlab.n5.util.Position;
5441
import org.junit.Test;
5542

5643
/**
@@ -72,33 +59,37 @@ public void testValidateBlockShardSizesValid() {
7259

7360
// This should not throw any exception
7461
DatasetAttributes attrs = shardDatasetAttributes(dimensions, shardSize, blockSize, dataType);
75-
// assertEquals(shardSize, attrs.getShardSize());
7662
assertEquals(blockSize, attrs.getBlockSize());
77-
// assertArrayEquals(new int[]{1, 1, 1}, attrs.getBlocksPerShard());
63+
NestedGrid grid = attrs.getNestedBlockGrid();
64+
assertEquals(blockSize, grid.getBlockSize(0));
65+
assertEquals(shardSize, grid.getBlockSize(1));
7866

7967
// Test case 2: shard size is a multiple of block size
8068
shardSize = new int[]{128};
8169
blockSize = new int[]{64};
8270
attrs = shardDatasetAttributes(new long[]{128}, shardSize, blockSize, dataType);
83-
// assertEquals(shardSize, attrs.getShardSize());
8471
assertEquals(blockSize, attrs.getBlockSize());
85-
// assertArrayEquals(new int[]{2}, attrs.getBlocksPerShard());
72+
grid = attrs.getNestedBlockGrid();
73+
assertEquals(blockSize, grid.getBlockSize(0));
74+
assertEquals(shardSize, grid.getBlockSize(1));
8675

8776
// Test case 3: different multiples per dimension
8877
shardSize = new int[]{128, 256, 32, 2};
8978
blockSize = new int[]{32, 64, 32, 1};
9079
attrs = shardDatasetAttributes(new long[]{128, 128, 128, 128}, shardSize, blockSize, dataType );
91-
// assertEquals(shardSize, attrs.getShardSize());
9280
assertEquals(blockSize, attrs.getBlockSize());
93-
// assertArrayEquals(new int[]{4, 4, 1, 2}, attrs.getBlocksPerShard());
81+
grid = attrs.getNestedBlockGrid();
82+
assertEquals(blockSize, grid.getBlockSize(0));
83+
assertEquals(shardSize, grid.getBlockSize(1));
9484

9585
// Test case 4: large multiples
9686
shardSize = new int[]{1024, 2048, 512};
9787
blockSize = new int[]{32, 64, 16};
9888
attrs = shardDatasetAttributes(dimensions, shardSize, blockSize, dataType);
99-
// assertEquals(shardSize, attrs.getShardSize());
10089
assertEquals(blockSize, attrs.getBlockSize());
101-
// assertArrayEquals(new int[]{32, 32, 32}, attrs.getBlocksPerShard());
90+
grid = attrs.getNestedBlockGrid();
91+
assertEquals(blockSize, grid.getBlockSize(0));
92+
assertEquals(shardSize, grid.getBlockSize(1));
10293
}
10394

10495
private static DatasetAttributes shardDatasetAttributes(
@@ -160,88 +151,4 @@ public void testValidateBlockShardSizesInvalid() {
160151
() -> shardDatasetAttributes(dimensions, new int[]{0, 64, 64}, new int[]{64, 64, 64}, dataType));
161152
}
162153

163-
// @Test
164-
// public void testShardProperties() {
165-
//
166-
// final long[] arraySize = new long[]{16, 16};
167-
// final int[] shardSize = new int[]{16, 16};
168-
// final long[] shardPosition = new long[]{1, 1};
169-
// final int[] blkSize = new int[]{4, 4};
170-
//
171-
// final DatasetAttributes dsetAttrs = new DatasetAttributes(
172-
// arraySize,
173-
// shardSize,
174-
// blkSize,
175-
// DataType.UINT8,
176-
// new ShardingCodec(
177-
// blkSize,
178-
// new CodecInfo[]{new N5BlockCodecInfo()},
179-
// new DeterministicSizeCodecInfo[]{new RawBlockCodecInfo()},
180-
// IndexLocation.END
181-
// )
182-
// );
183-
//
184-
// final InMemoryShard shard = new InMemoryShard(dsetAttrs, shardPosition, null);
185-
//
186-
// assertArrayEquals(new int[]{4, 4}, shard.getBlockGridSize());
187-
//
188-
// assertArrayEquals(new long[]{0, 0}, dsetAttrs.getShardPositionForBlock(0, 0));
189-
// assertArrayEquals(new long[]{1, 1}, dsetAttrs.getShardPositionForBlock(5, 5));
190-
// assertArrayEquals(new long[]{1, 0}, dsetAttrs.getShardPositionForBlock(5, 0));
191-
// assertArrayEquals(new long[]{0, 1}, dsetAttrs.getShardPositionForBlock(0, 5));
192-
//
193-
// assertArrayEquals(new int[]{0, 0}, shard.getRelativeBlockPosition(4, 4));
194-
// assertArrayEquals(new int[]{1, 1}, shard.getRelativeBlockPosition(5, 5));
195-
// assertArrayEquals(new int[]{2, 2}, shard.getRelativeBlockPosition(6, 6));
196-
// assertArrayEquals(new int[]{3, 3}, shard.getRelativeBlockPosition(7, 7));
197-
// }
198-
199-
// @Test
200-
// public void testShardGrouping() {
201-
//
202-
// final long[] arraySize = new long[]{8, 12};
203-
// final int[] shardSize = new int[]{4, 6};
204-
// final int[] blkSize = new int[]{2, 3};
205-
//
206-
// final DatasetAttributes attrs = new DatasetAttributes(
207-
// arraySize,
208-
// shardSize,
209-
// blkSize,
210-
// DataType.UINT8,
211-
// new ShardingCodec(
212-
// blkSize,
213-
// new CodecInfo[]{ new N5BlockCodecInfo() },
214-
// new DeterministicSizeCodecInfo[]{new RawBlockCodecInfo()},
215-
// IndexLocation.END
216-
// )
217-
// );
218-
//
219-
// List<long[]> blockPositions = blockPositions(attrs).collect(Collectors.toList());
220-
// final Map<Position, List<long[]>> result = attrs.groupBlockPositions(blockPositions);
221-
//
222-
// // there are four shards in this image
223-
// assertEquals(4, result.size());
224-
//
225-
// // there are four blocks per shard in this image
226-
// result.values().forEach(x -> assertEquals(4, x.size()));
227-
// }
228-
229-
// private static Stream<long[]> blockPositions( final DatasetAttributes attrs ) {
230-
//
231-
// final int nd = attrs.getNumDimensions();
232-
// final int[] blocksPerShard = attrs.getBlocksPerShard();
233-
// return toStream( new GridIterator(attrs.shardsPerDataset()))
234-
// .flatMap( shardPosition -> {
235-
// final long[] min = attrs.getBlockPositionFromShardPosition(shardPosition, new int[nd]);
236-
// return toStream(new GridIterator(GridIterator.int2long(blocksPerShard), min));
237-
// });
238-
// }
239-
240-
private static <T> Stream<T> toStream( final Iterator<T> it ) {
241-
242-
return StreamSupport.stream(
243-
Spliterators.spliteratorUnknownSize(it, Spliterator.ORDERED),
244-
false);
245-
}
246-
247154
}

0 commit comments

Comments
 (0)