assertEquals(6 / 15f, m.get(2, 1), 0);
}
@Test
public void testTensor() {
Tensor t = new Tensor(2, 2, 2);
float[] elements = t.getElements();
assertEquals(8, elements.length, 0);
t.set(1, 0, 0, 0);
t.set(2, 0, 0, 1);
t.set(3, 0, 1, 0);
t.set(4, 0, 1, 1);
t.set(5, 1, 0, 0);
t.set(6, 1, 0, 1);
t.set(7, 1, 1, 0);
t.set(8, 1, 1, 1);
for (int i = 0; i < elements.length; i++) {
assertEquals(i + 1, elements[i], 0);
}
t = new Tensor(5, 5, 5);
assertEquals(25, t.getDimensionElementsDistance(0), 0);
assertEquals(5, t.getDimensionElementsDistance(1), 0);
assertEquals(1, t.getDimensionElementsDistance(2), 0);
elements = t.getElements();
for (int i = 0; i < elements.length; i++) {
elements[i] = i + 1;
}
Tensor t2 = new Tensor(t, new int[] { 3, 0, 0 }, new int[] { 4, 4, 4 });
assertEquals(75, t2.getStartIndex(), 0);
assertEquals(124, t2.getEndIndex(), 0);
assertEquals(25, t2.getDimensionElementsDistance(0), 0);
assertEquals(5, t2.getDimensionElementsDistance(1), 0);
assertEquals(1, t2.getDimensionElementsDistance(2), 0);
assertEquals(50, t2.getSize(), 0);
assertEquals(76, t2.get(0, 0, 0), 0);
assertEquals(77, t2.get(0, 0, 1), 0);
assertEquals(81, t2.get(0, 1, 0), 0);
assertEquals(101, t2.get(1, 0, 0), 0);
assertEquals(106, t2.get(1, 1, 0), 0);
assertEquals(112, t2.get(1, 2, 1), 0);
}