From 6b652d7a94cf4f7762d3dbe67d3ab9f5b08440f1 Mon Sep 17 00:00:00 2001 From: ManifoldFR <wilson.jallet@polytechnique.org> Date: Mon, 9 May 2022 10:08:48 +0200 Subject: [PATCH] eigen_ref: test taking a row from a matrix --- unittest/python/test_eigen_ref.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/unittest/python/test_eigen_ref.py b/unittest/python/test_eigen_ref.py index 32a7910..7153ca6 100644 --- a/unittest/python/test_eigen_ref.py +++ b/unittest/python/test_eigen_ref.py @@ -35,17 +35,28 @@ def test(mat): assert np.all(mat[:2, :3] == np.ones((2, 3))) mat.fill(0.0) + mat[:, :] = np.arange(rows * cols).reshape(rows, cols) + printMatrix(mat) + mat0 = mat.copy() mat_as_C_order = np.array(mat, order="F") - getBlock(mat_as_C_order, 0, 0, 3, 2)[:, :] = 1.0 - - assert np.all(mat_as_C_order[:3, :2] == np.ones((3, 2))) + for i, rowsize in ([0, 3], [1, 1]): + print("taking block [{}:{}, {}:{}]".format(i, rowsize+i, 0, 2)) + B = getBlock(mat_as_C_order, i, 0, rowsize, 2) + lhs = mat_as_C_order[i:rowsize + i, :2] + print("should be:\n{}\ngot:\n{}".format(lhs, B)) + assert np.array_equal(lhs, B) + + B[:] = 1.0 + rhs = np.ones((rowsize, 2)) + assert np.array_equal(mat_as_C_order[i:rowsize+i, :2], rhs) + + mat_as_C_order[:, :] = mat0 - mat_as_C_order[:3, :2] = 0.0 mat_copy = mat_as_C_order.copy() editBlock(mat_as_C_order, 0, 0, 3, 2) mat_copy[:3, :2] = np.arange(6).reshape(3, 2) - assert np.all(mat_as_C_order == mat_copy) + assert np.array_equal(mat_as_C_order, mat_copy) class ModifyBlockImpl(modify_block): def __init__(self): -- GitLab