From f29a8400d877cc3d960d21a9b4c58ca948891f01 Mon Sep 17 00:00:00 2001 From: Vitor Hideyoshi Date: Fri, 9 Dec 2022 01:32:35 -0300 Subject: [PATCH] Better Implementation of Gauss Method Check and Validates if the Linear System is valid and better implementation of the returned result column matrix. --- yoshi_seals/process/process.pyx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yoshi_seals/process/process.pyx b/yoshi_seals/process/process.pyx index 99a4fec..c8bcfdb 100644 --- a/yoshi_seals/process/process.pyx +++ b/yoshi_seals/process/process.pyx @@ -52,6 +52,8 @@ cpdef np.ndarray[np.float64_t, ndim=2] gauss(double[::,::] A, double[::,::] b): if not c_pointer: raise MemoryError() + if A.shape[0] < A.shape[1]: + raise ValueError("Invalid Matrix, this linear system is not solvable.") for i in range(A.shape[0]): @@ -78,7 +80,7 @@ cpdef np.ndarray[np.float64_t, ndim=2] gauss(double[::,::] A, double[::,::] b): sum_var += a[reversed_index][k]*x[k] x[reversed_index] = (a[reversed_index][A.shape[1]] - sum_var)/a[reversed_index][reversed_index] - return np.asarray(x).reshape(b.shape[0],b.shape[1]) + return np.asarray(x).reshape(A.shape[1],b.shape[1]) cpdef np.ndarray[np.float64_t, ndim=2] cholesky(double[:,:] A, double[:,:] b):