def dot_product(x: LRVector, y: TBVector): alpha = Scalar(0) def kernel(chi: float, psi: float, alpha: float): return chi * psi + alpha return apply(kernel, x, y, alpha)
def linear_transformation_1(A: TBMatrix, x: TBVector): y = generate_tb_vector(0, 0, len(x.value)) def kernel(a: TBVector, psi: Scalar): return dot_product(a, x) + psi return apply(kernel, A, y)
def linear_transformation_2(A: LRMatrix, x: TBVector): y = FixedVector(generate_list(0, 0, len(x.value), False)) def kernel(chi: Scalar, a: TBVector, y: FixedVector): return axpy(Scalar(chi), a, TBVector(y.value)) return apply(kernel, x, A, y)
def axpy(alpha: Scalar, x: TBVector, y: TBVector): def kernel(alpha: float, chi: float, psi: float): return alpha * chi + psi return apply(kernel, alpha, x, y)
def add(x: TBVector, y: TBVector): return apply(lambda chi, psi: chi + psi, x, y)
def scal(alpha: Scalar, x: TBVector): return apply(lambda alpha, x: alpha * x, alpha, x)