def perform(self, matrix): # linear independent checking with B.NoTape(): rank = T.Rank()(matrix) if rank.to_scalar() != matrix.columns: return None U = [] u_k = matrix[:, 1] u_k_norm = T.L2Norm()(matrix[:, 1]) U.append(u_k / u_k_norm) R = Matrix(np.zeros((matrix.columns, ) * 2), dtype=matrix.dtype) R[1, 1] = u_k_norm for col in range(2, matrix.columns + 1): x_k = matrix[:, col] u_k = B.copy(x_k) for row, u in enumerate(U, 1): c_k = (x_k.T * u).to_scalar() R[row, col] = c_k u_k -= c_k * u u_k_norm = T.L2Norm()(u_k) U.append(u_k / u_k_norm) R[row + 1, col] = u_k_norm return T.Cat(axis=-1)(*U), R
def perform(self, matrix): if isinstance(self.other, Matrix): result = matrix.matrix / self.other.matrix result = B.copy(matrix, result, causal=True) else: with B.NoTape(): result = matrix / Matrix(self.other, dtype=matrix.dtype) return result
def __build(self, *matrixs): return_matrix = [] for matrix in matrixs: if not self.eager: new_matrix = B.copy(matrix, causal=self.causal) else: new_matrix = matrix if self.tape_enabled and self.tape: self.add_tape(new_matrix) return_matrix.append(new_matrix) return return_matrix
def perform(self, matrix): if isinstance(self.other, Matrix): result = matrix.matrix + self.other.matrix result = B.copy(matrix, new_value=matrix.matrix + self.other.matrix, causal=True) # binary operation tape with B.LazyPerform(): self.other + matrix else: with B.NoTape(): result = matrix + Matrix(self.other, matrix.dtype) return result
def perform(self, matrix): if isinstance(self.other, Matrix): if self.other.shape == (1, 1): with B.NoTape(): result = matrix * self.other.to_scalar() result = result.matrix else: result = matrix.matrix @ self.other.matrix # binary operation tape with B.LazyPerform(): self.other * matrix elif isinstance(self.other, (int, float)): result = matrix.matrix * self.other else: with B.NoTape(): result = matrix * Matrix(self.other, dtype=matrix.dtype) result = B.copy(matrix, new_value=result, causal=True) return result
def __build(self, *matrixs): return_matrix = [] for matrix in matrixs: new_matrix = B.copy(matrix) return_matrix.append(new_matrix) return return_matrix
def perform(self, matrix): result = matrix.matrix.reshape(self.shape) return B.copy(matrix, new_value=result, causal=True)
def perform(self, matrix): return B.copy(matrix, new_type=self.new_type, causal=True)
def perform(self, matrix): result = matrix.matrix[self.key] return B.copy(matrix, new_value=result, causal=True)