Skip to content

Commit bb70b15

Browse files
jacobfilikPeterC-DLS
authored andcommitted
Fix bug in slicing metadata with broadcasting and a step > 1 (#280)
Signed-off-by: Jacob Filik <[email protected]>
1 parent 8cec54b commit bb70b15

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

org.eclipse.january.test/src/org/eclipse/january/metadata/internal/SliceableMetadataTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.eclipse.january.dataset.Random;
2828
import org.eclipse.january.dataset.ShortDataset;
2929
import org.eclipse.january.dataset.Slice;
30+
import org.eclipse.january.dataset.SliceND;
3031
import org.junit.Test;
3132

3233
public class SliceableMetadataTest {
@@ -149,6 +150,30 @@ public void testSlicingMetadata() {
149150
fail("Should not fail: " + e);
150151
}
151152
}
153+
154+
@Test
155+
public void testStepBroadcasted() {
156+
157+
final int[] bshape = new int[] {1, 5, 1};
158+
final int[] shape = new int[] {4, 5, 6};
159+
ILazyDataset ld = Random.lazyRand(Dataset.INT32, "Metadata1", bshape);
160+
SliceableTestMetadata md = new SliceableTestMetadata(ld, null, null, null, null);
161+
162+
ILazyDataset dataset = Random.lazyRand(Dataset.INT32, "Main", shape);
163+
dataset.addMetadata(md);
164+
165+
try {
166+
SliceND snd = new SliceND(dataset.getShape());
167+
snd.setSlice(1, 0, 5, 2);
168+
ILazyDataset slicedStep = dataset.getSliceView(snd);
169+
SliceableTestMetadata tmd = slicedStep.getFirstMetadata(SliceableTestMetadata.class);
170+
ILazyDataset lazyDataset = tmd.getLazyDataset();
171+
assertEquals(slicedStep.getShape()[1], lazyDataset.getShape()[1]);
172+
173+
} catch (Exception e) {
174+
fail("Should not fail: " + e);
175+
}
176+
}
152177

153178
@Test
154179
public void testSlicingSqueezedMetadata() throws DatasetException {

org.eclipse.january/src/org/eclipse/january/dataset/LazyDatasetBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public ILazyDataset run(ILazyDataset lz) {
423423
if (shape[i] == 1) {
424424
stt[i] = 0;
425425
stp[i] = 1;
426-
ste[1] = 1;
426+
ste[i] = 1;
427427
} else {
428428
throw new IllegalArgumentException("Sliceable dataset has invalid size!");
429429
}

0 commit comments

Comments
 (0)