def test_transpose(A): # C[:] = A.T rows, cols, vals = A.to_values() result = Matrix.new_from_values(cols, rows, vals) C = Matrix.new_from_type(A.dtype, A.ncols, A.nrows) C[:] = A.T assert C == result C2 = A.T.new() assert C2 == result
def test_extract(A): C = Matrix.new_from_type(A.dtype, 3, 4) result = Matrix.new_from_values([0, 0, 1, 2, 2, 2], [0, 2, 1, 1, 2, 3], [2, 3, 3, 5, 7, 3], nrows=3, ncols=4) C[:] = A.extract[[0, 3, 6], [1, 2, 3, 4]] assert C == result C[:] = A.extract[0::3, 1:5] assert C == result C[:] = A.extract[[0, 3, 6], 1:5:1] assert C == result C2 = A.extract[[0, 3, 6], [1, 2, 3, 4]].new() assert C2 == result
def test_mxm_nonsquare(): A = Matrix.new_from_values([0, 0, 0], [0, 2, 4], [1, 2, 3], nrows=1, ncols=5) B = Matrix.new_from_values([0, 2, 4], [0, 0, 0], [10, 20, 30], nrows=5, ncols=1) C = Matrix.new_from_type(A.dtype, nrows=1, ncols=1) C[:] = A.mxm(B, Semiring.MAX_PLUS) assert C.element[0, 0] == 33 C1 = A.mxm(B, Semiring.MAX_PLUS).new() assert C1 == C C2 = A.T.mxm(B.T, Semiring.MAX_PLUS).new() assert C2.nrows == 5 assert C2.ncols == 5
def test_simple_assignment(A): # C[:] = A C = Matrix.new_from_type(A.dtype, A.nrows, A.ncols) C[:] = A assert C == A
def test_new_from_type(): C = Matrix.new_from_type(dtypes.INT8, 17, 12) assert C.dtype == 'INT8' assert C.nvals == 0 assert C.nrows == 17 assert C.ncols == 12