assertEquals(112, t2.get(1, 2, 1), 0);
}
@Test
public void testMatrix() {
Matrix m = new Matrix(5, 6);
assertEquals(5, m.getRows(), 0);
assertEquals(6, m.getColumns(), 0);
assertEquals(6, m.getDimensionElementsDistance(0), 0);
assertEquals(1, m.getDimensionElementsDistance(1), 0);
assertEquals(5, m.getDimensionLength(0), 0);
assertEquals(6, m.getDimensionLength(1), 0);
for (int i = 0; i < m.getElements().length; i++) {
m.getElements()[i] = i + 1;
}
assertEquals(2, m.get(0, 1), 0);
assertEquals(15, m.get(2, 2), 0);
m = new Matrix(1, 6);
for (int i = 0; i < m.getElements().length; i++) {
m.getElements()[i] = i + 1;
}
assertEquals(2, m.get(0, 1), 0);
assertEquals(6, m.get(0, 5), 0);
m = new Matrix(6, 1);
for (int i = 0; i < m.getElements().length; i++) {
m.getElements()[i] = i + 1;
}
assertEquals(2, m.get(1, 0), 0);
assertEquals(6, m.get(5, 0), 0);
// submatrix
Tensor t = new Tensor(5, 5, 5);
float[] elements = t.getElements();
for (int i = 0; i < elements.length; i++) {
elements[i] = i + 1;
}
m = new Matrix(t, new int[] {1, 0, 0}, new int[] {1, 4, 4});
assertEquals(26, m.get(0, 0), 0);
assertEquals(27, m.get(0, 1), 0);
assertEquals(36, m.get(2, 0), 0);
assertEquals(38, m.get(2, 2), 0);
m = new Matrix(t, new int[] {1, 0, 0}, new int[] {1, 4, 4});
assertEquals(26, m.get(0, 0), 0);
assertEquals(27, m.get(0, 1), 0);
assertEquals(36, m.get(2, 0), 0);
assertEquals(38, m.get(2, 2), 0);
m = new Matrix(t, new int[] {0, 0, 1}, new int[] {4, 4, 1});
assertEquals(2, m.get(0, 0), 0);
assertEquals(7, m.get(0, 1), 0);
assertEquals(12, m.get(0, 2), 0);
assertEquals(27, m.get(1, 0), 0);
assertEquals(32, m.get(1, 1), 0);
assertEquals(37, m.get(1, 2), 0);
m = new Matrix(t, new int[] {2, 2, 1}, new int[] {3, 3, 1});
assertEquals(62, m.get(0, 0), 0);
assertEquals(67, m.get(0, 1), 0);
assertEquals(92, m.get(1, 1), 0);
m = new Matrix(4, 4);
for (int i = 0; i < m.getElements().length; i++) {
m.getElements()[i] = i + 1;
}
Matrix m2 = new Matrix(m, new int[] {1,1}, new int[] {2, 2});
assertEquals(6, m2.get(0, 0), 0);
assertEquals(7, m2.get(0, 1), 0);
assertEquals(10, m2.get(1, 0), 0);
assertEquals(11, m2.get(1, 1), 0);
}