def matSet(): A_cop = copy.deepcopy(A) A_col_cop = copy.deepcopy(A_col) A_cop[2] = M.Vector([0, -1, 8]) A_col_cop[2] = M.Vector([0, -1, 8]) if A_cop[2] != M.Vector([0, -1, 8]): probs.append('row matrix setitem') if A_col_cop[2] != M.Vector([0, -1, 8]): probs.append('col matrix setitem')
def vecUnit(): if v1.isUnit(): probs.append('col vector isUnit') if v1_row.isUnit(): probs.append('row vector isUnit') if not M.Vector([.5, .5, .5, .5]).isUnit(): probs.append('R4 col unit not isUnit') if not M.Vector([.5, .5, .5, .5], 'col').isUnit(): probs.append('R4 row unit not isUnit')
def vecCross(): if v1.cross(v2) != M.Vector([4, -4, 12]): probs.append('col vector cross product values') if v1.cross(v2_row) != M.Vector([4, -4, 12]): probs.append('cross orientation vector cross product values') if v1_row.cross(v2_row) != M.Vector([4, -4, 12]): probs.append('row vector cross product values') if v2.cross(v1) != v1.cross(v2) * -1: probs.append('cross product order inversion not changing sign') if v1.cross(v2) * v1 != 0 or v1.cross(v2) * v2 != 0: probs.append('cross product not perpendicular to multiplied vectors')
def vecScalarMul(): if v1 * 5 != M.Vector([15, 30, 5]): probs.append("col vector scalar multiplication values") if (v1 * 5).orientation != v1.orientation: probs.append( "col vector scalar multiplication orientation not preserved") if v1_row * 5 != M.Vector([15, 30, 5]): probs.append("row vector scalar multiplication values") if (v1_row * 5).orientation != v1_row.orientation: probs.append( "row vector scalar multiplication orientation not preserved")
def vecAddition(): if (v1 + v1) != M.Vector([6, 12, 2]): probs.append('row vector addition values') if (v1_row + v1_row) != M.Vector([6, 12, 2]): probs.append('col vector addition values') if (v1 + v1).orientation != 'col': probs.append('col vector addition orientation not retained') if (v1_row + v1_row).orientation != 'row': probs.append('row vector addition orientation not retained') if (v1_row + v1).orientation != v1_row.orientation: probs.append( 'cross orientation vector addition orientation not retained')
def matPop(): A_cop = copy.deepcopy(A) A_col_cop = copy.deepcopy(A_col) if A_cop.pop() != M.Vector([9, 0, 2]): probs.append("row matrix pop without index") if A_col_cop.pop() != M.Vector([9, 0, 2], 'col'): probs.append("col matrix pop without index") if A_cop.pop(0) != M.Vector([1, 2, 3]): probs.append("row matrix pop with index") if A_col_cop.pop(0) != M.Vector([1, 2, 3], 'col'): probs.append("col matrix pop with index")
def vecSubtraction(): if (v1 - v2) != M.Vector([1, -2, -1]): probs.append('row vector subtraction values') if (v1_row - v2_row) != M.Vector([1, -2, -1]): probs.append('col vector subtraction values') if (v1 - v2).orientation != 'col': probs.append('col vector subtraction orientation not retained') if (v1_row - v2_row).orientation != 'row': probs.append('row vector subtraction orientation not retained') if (v1_row - v2).orientation != v1_row.orientation: probs.append( 'cross orientation vector subtraction orientation not retained')
def setGet(): if s1[0] != M.Vector([3, 6, 1]) or s1[1] != M.Vector( [2, 8, 2]) or s1[2] != M.Vector([4, 0, 1]): probs.append("col set getitem") if s1_row[0] != M.Vector([3, 6, 1], 'row') or s1_row[1] != M.Vector( [2, 8, 2], 'row') or s1_row[2] != M.Vector([4, 0, 1], 'row'): probs.append("row set getitem") if s1_m[0] != M.Vector([3, 6, 1]) or s1_m[1] != M.Vector( [2, 8, 2], 'row') or s1_m[2] != M.Vector([4, 0, 1]): probs.append("mixed set getitem")
def matMultiplication(): # orientation tests if (A * 5).orientation != A.orientation: probs.append( 'row matrix scalar multiplication orientation not preserved') if (A_col * 5).orientation != A_col.orientation: probs.append( 'col matrix scalar multiplication orientation not preserved') if (A * A).orientation != 'row': probs.append('row matrix multiplication orientation not preserved') if (A_col * A_col).orientation != 'col': probs.append('col matrix multiplication orientation not preserved') if (A * A_col).orientation != 'row': probs.append( 'cross orientation (r*c) matrix multiplication orientation not preserved' ) if (A_col * A).orientation != 'col': probs.append( 'cross orientation (c*r) matrix multiplication orientation not preserved' ) if (A * v1).orientation != 'col': probs.append('matrix vector (r*c) orientation incorrect') if (A * v1_row).orientation != 'row': probs.append('matrix vector (r*r) orientation incorrect') if (A_col * v1).orientation != 'col': probs.append('matrix vector (c*c) orientation incorrect') if (A_col * v1_row).orientation != 'row': probs.append('matrix vector (c*r) orientation incorrect') # value tests if (A * 5) != M.Matrix([[5, 10, 15], [30, 25, 10], [45, 0, 10]]): probs.append('row matrix scalar multiplication values') if (A_col * 5) != M.Matrix([[5, 30, 45], [10, 25, 0], [15, 10, 10]]): probs.append('col matrix scalar multiplication values') if (A * A) != M.Matrix([[40, 12, 13], [54, 37, 32], [27, 18, 31]]): probs.append('row matrix multiplication values') if (A_col * A_col) != M.Matrix([[40, 12, 13], [54, 37, 32], [27, 18, 31]], 'col'): probs.append('col matrix multiplication values') if (A * C_col) != M.Matrix([[24, 26, 39], [63, 43, 57], [40, 8, 25]]): probs.append('cross orientation (r*c) matrix multiplication values') if (C_col * A) != M.Matrix([[13, 8, 14], [112, 49, 49], [98, 24, 30]]): probs.append('cross orientation (c*r) matrix multiplication values') if (A * v1) != M.Vector([18, 50, 29]): probs.append('row matrix * col vector values') if (A * v1_row) != M.Vector([18, 50, 29]): probs.append('row matrix * row vector values') if (A_col * v1) != M.Vector([48, 36, 23]): probs.append('col matrix * col vector values') if (A_col * v1_row) != M.Vector([48, 36, 23]): probs.append('col matrix * row vector values')
def setDel(): s1_cop = copy.deepcopy(s1) s1_row_cop = copy.deepcopy(s1_row) s1_m_cop = copy.deepcopy(s1_m) del s1_cop[0] del s1_row_cop[0] del s1_m_cop[0] if s1_cop[0] != M.Vector([2, 8, 2]): probs.append("col set delitem") if s1_row_cop[0] != M.Vector([2, 8, 2], 'row'): probs.append("row set delitem") if s1_m_cop[0] != M.Vector([2, 8, 2], 'row'): probs.append("mixed set delitem")
def matDel(): A_cop = copy.deepcopy(A) A_col_cop = copy.deepcopy(A_col) del A_cop[0] if A_cop[0] != M.Vector([6, 5, 2]): probs.append('row matrix delitem') del A_cop[0] if A_cop[0] != M.Vector([9, 0, 2]): probs.append('row matrix delitem') del A_col_cop[0] if A_col_cop[0] != M.Vector([6, 5, 2]): probs.append('col matrix delitem') del A_col_cop[0] if A_col_cop[0] != M.Vector([9, 0, 2]): probs.append('col matrix delitem')
def matGet(): if A[0] != M.Vector([1, 2, 3]) or A[1] != M.Vector( [6, 5, 2]) or A[2] != M.Vector([9, 0, 2]): probs.append('row matrix getitem') if A_col[0] != M.Vector([1, 2, 3]) or A_col[1] != M.Vector( [6, 5, 2]) or A_col[2] != M.Vector([9, 0, 2]): probs.append('col matrix getitem')
def setSet(): s1_cop = copy.deepcopy(s1) s1_row_cop = copy.deepcopy(s1_row) s1_m_cop = copy.deepcopy(s1_m) s1_cop[0] = M.Vector([0, 0, 4]) s1_row_cop[0] = M.Vector([0, 0, 4], 'row') s1_m_cop[0] = M.Vector([0, 0, 4]) if s1_cop[0] != M.Vector([0, 0, 4]): probs.append('col set setitem') if s1_row_cop[0] != M.Vector([0, 0, 4], 'row'): probs.append('row set setitem') if s1_m_cop[0] != M.Vector([0, 0, 4]): probs.append('mixed set setitem')
def vecExtend(): if v1.extend([5]) != M.Vector([3, 6, 1, 5]): probs.append('col vector extend') if v1_row.extend([5]) != M.Vector([3, 6, 1, 5]): probs.append('row vector extend')
def vecNormalize(): if v1.normalize() != M.Vector([3 / (46)**.5, 6 / (46)**.5, 1 / (46)**.5]): probs.append('normalize col vector') if v1_row.normalize() != M.Vector( [3 / (46)**.5, 6 / (46)**.5, 1 / (46)**.5]): probs.append('normalize row vector')
def matSlicing(): if A[0] != M.Vector([1, 2, 3], 'row'): probs.append('row matrix slicing') if A_col[0] != M.Vector([1, 2, 3]): probs.append('col matrix slicing')
import matpy as M import copy v1 = M.Vector([3, 6, 1]) v1_row = M.Vector([3, 6, 1], 'row') v2 = M.Vector([2, 8, 2]) v2_row = M.Vector([2, 8, 2], 'row') v3 = M.Vector([4, 0, 1]) v3_row = M.Vector([4, 0, 1], 'row') s1 = M.Set([v1, v2, v3]) s1_row = M.Set([v1_row, v2_row, v3_row]) s1_m = M.Set([v1, v2_row, v3]) s_dependent = M.Set([v1, v2, v3, M.Vector([6, 12, 2], 'row')]) s_row_dependent = M.Set([v1_row, v2_row, v3_row, M.Vector([6, 12, 2], 'row')]) s_m_dependent = M.Set([v1, v2_row, v3, M.Vector([6, 12, 2], 'row')]) A = M.Matrix([[1, 2, 3], [6, 5, 2], [9, 0, 2]]) A_col = M.Matrix([[1, 2, 3], [6, 5, 2], [9, 0, 2]], 'col') A_alt = M.Matrix([[1, 6, 9], [2, 5, 0], [3, 2, 2]], 'col') B = M.Matrix([[1, 2, 3], [6, 5, 2], [9, 0, 2], [6, 2, 3]]) B_col = M.Matrix([[1, 2, 3], [6, 5, 2], [9, 0, 2], [6, 2, 3]], 'col') C = M.Matrix([[4, 7, 2], [0, 7, 4], [1, 7, 8]]) C_col = M.Matrix([[4, 7, 2], [0, 7, 4], [1, 7, 8]], 'col') M_symmetric = M.Matrix([[1, 4, 3], [4, 3, 0], [3, 0, 1]]) M_col_symmetric = M.Matrix([[1, 4, 3], [4, 3, 0], [3, 0, 1]], 'col') probs = [] '''begin Vector tests'''