def mult_vec_lower_symmetric_by_axpy(self, vec): """ This function implements a matrix vector mult based on AXPY using an upper simmetrix matric :vec: Vector, the vector to work on :returns: Vector """ result = Vector([0] * self.rows()) it = self.full_iterator() vit = result.vector_iterator() for i, data in enumerate(it): #slicing the vector tl, value, bl = vit.next() #computing the diagonal value value = data["a11"] * vec[i] + value tl = data["at10"].axpy(tl, vec[i]) bl = data["a21"].axpy(bl, vec[i]) #merging the result back in vit.merge(tl, value, bl) return result
def mult_vec_lower_triangular_by_axpy(self, vec): """ This function implements a lower triangular matrix vector mult based on AXPY :vec: Vector, the vector to work on :returns: Vector """ result = Vector([0] * self.rows()) it = self.full_iterator() vit = result.vector_iterator() for i, data in enumerate(it): #slicing the vector tl, value, bl = vit.next() #computing the diagonal value value = data["a11"] * vec[i] + value #computing the upper diagonal value, using an axpy #and accumulating in the up vector bl = data["a21"].axpy(bl, vec[i]) #merging the result back in vit.merge(tl, value, bl) return result
def mult_vec_upper_symmetric_by_axpy(self, vec): """ This function implements a matrix vector mult based on AXPY using an upper simmetrix matric :vec: Vector, the vector to work on :returns: Vector """ result = Vector([0] * self.rows()) it = self.full_iterator() vit = result.vector_iterator() for i, data in enumerate(it): #slicing the vector tl, value, bl = vit.next() #computing the diagonal value value = data["a11"] * vec[i] + value #we perform two different axpy and we make up for the missing part #by using the equivalent transposed of the column below the diagonal #aka the row after the diagonal tl = data["a01"].axpy(tl, vec[i]) bl = data["at12"].axpy(bl, vec[i]) #merging the result back in vit.merge(tl, value, bl) return result
def mult_vec_lower_symmetric_by_axpy(self, vec): """ This function implements a matrix vector mult based on AXPY using an upper simmetrix matric :vec: Vector, the vector to work on :returns: Vector """ result = Vector([0]* self.rows()) it = self.full_iterator() vit = result.vector_iterator() for i,data in enumerate(it): #slicing the vector tl, value, bl = vit.next() #computing the diagonal value value = data["a11"] * vec[i] + value tl = data["at10"].axpy(tl,vec[i]) bl = data["a21"].axpy(bl,vec[i]) #merging the result back in vit.merge(tl,value,bl) return result
def mult_vec_upper_symmetric_by_axpy(self, vec): """ This function implements a matrix vector mult based on AXPY using an upper simmetrix matric :vec: Vector, the vector to work on :returns: Vector """ result = Vector([0]* self.rows()) it = self.full_iterator() vit = result.vector_iterator() for i,data in enumerate(it): #slicing the vector tl, value, bl = vit.next() #computing the diagonal value value = data["a11"] * vec[i] + value #we perform two different axpy and we make up for the missing part #by using the equivalent transposed of the column below the diagonal #aka the row after the diagonal tl = data["a01"].axpy(tl,vec[i]) bl = data["at12"].axpy(bl,vec[i]) #merging the result back in vit.merge(tl,value,bl) return result
def mult_vec_lower_triangular_by_axpy(self, vec): """ This function implements a lower triangular matrix vector mult based on AXPY :vec: Vector, the vector to work on :returns: Vector """ result = Vector([0]* self.rows()) it = self.full_iterator() vit = result.vector_iterator() for i,data in enumerate(it): #slicing the vector tl, value, bl = vit.next() #computing the diagonal value value = data["a11"] * vec[i] + value #computing the upper diagonal value, using an axpy #and accumulating in the up vector bl = data["a21"].axpy(bl,vec[i]) #merging the result back in vit.merge(tl,value,bl) return result
def test_solve_upper_triangular_system(self): mat = SquareMatrix.from_list(3, [-2, 0, 0, -1, -3, 0, 1, -2, 1]) vec = Vector([6, 9, 3]) it = vec.vector_iterator(True) res = mat.solve_upper_triangular_system(vec) self.is_vector_equal_to_list(res, [1, -5, 3])
def test_solve_upper_triangular_system(self): mat = SquareMatrix.from_list(3, [-2,0,0,-1,-3,0,1,-2,1]) vec = Vector([6,9,3]) it = vec.vector_iterator(True) res = mat.solve_upper_triangular_system(vec) self.is_vector_equal_to_list(res,[1,-5,3])