def test_build_matrix_one_by_one(): dtype = [ ("row_index", np.int32), ("col_index", np.int32), ("amount", np.float32), ("flip", np.bool), ] array = np.array([(0, 0, 10, False)], dtype=dtype) matrix = build_matrix(array, 1, 1) assert matrix.shape == (1, 1) assert matrix.sum() == 10
def test_build_matrix_zero_by_zero(): dtype = [ ("row_index", np.int32), ("col_index", np.int32), ("amount", np.float32), ("flip", np.bool), ] array = np.array([], dtype=dtype) matrix = build_matrix(array, 0, 0) assert matrix is not None assert matrix.shape == (0, 0) assert not matrix.sum()
def test_build_matrix_no_flip(): dtype = [ ("row_index", np.int32), ("col_index", np.int32), ("amount", np.float32), ("flip", np.bool), ] array = np.array( [ (0, 0, 1, True), (1, 1, 2, True), (1, 0, 10, False), (1, 2, 11, False), ], dtype=dtype, ) matrix = build_matrix(array, 2, 3, flip=False) assert matrix.shape == (2, 3) assert matrix.sum() == 24
def test_build_matrix_custom_labels(): dtype = [ ("ri", np.int32), ("ci", np.int32), ("amount", np.float32), ("flip", np.bool), ] array = np.array( [ (0, 0, 1, True), (1, 1, 2, True), (1, 0, 10, False), (1, 2, 11, False), ], dtype=dtype, ) matrix = build_matrix(array, 2, 3, "ri", "ci") assert matrix.shape == (2, 3) assert matrix.sum() == 18
def test_build_matrix_empty_rows_cols(): dtype = [ ("row_index", np.int32), ("col_index", np.int32), ("amount", np.float32), ("flip", np.bool), ] array = np.array( [ (0, 0, 1, True), (1, 1, 2, True), (1, 0, 10, False), (1, 2, 11, False), ], dtype=dtype, ) matrix = build_matrix(array, 10, 11) assert matrix.shape == (10, 11) assert matrix.sum() == 18
def test_build_matrix(): dtype = [ ("row_index", np.int32), ("col_index", np.int32), ("amount", np.float32), ("flip", np.bool), ] array = np.array( [ (0, 0, 1, True), (1, 1, 2, True), (1, 0, 10, False), (1, 2, 11, False), ], dtype=dtype, ) matrix = build_matrix(array, 2, 3) expected = np.array([(-1, 0, 0), (10, -2, 11)]) assert matrix.shape == (2, 3) assert np.allclose(matrix.toarray(), expected)