From caa3cbd2df8823bc9a53614517cf16c41833087a Mon Sep 17 00:00:00 2001 From: Jimmy Young Date: Wed, 2 Oct 2024 18:57:47 -0600 Subject: [PATCH] Refactored norm to centered for readability + Changed name of norm_a to centered_a + Changed name of norm_vectors to centered_vectors - Ensured that the function maintains its original functionality and correctness. - Verified that all tests pass successfully, confirming the correctness of the changes. --- src/ndmath/statistics.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ndmath/statistics.c b/src/ndmath/statistics.c index 3811e2c..d410c36 100644 --- a/src/ndmath/statistics.c +++ b/src/ndmath/statistics.c @@ -181,7 +181,7 @@ NDArray *NDArray_cov(NDArray *a, bool rowvar) int cols = NDArray_SHAPE(a)[0]; int rows = NDArray_SHAPE(a)[1]; - NDArray **norm_vectors = emalloc(sizeof(NDArray *) * cols); + NDArray **centered_vectors = emalloc(sizeof(NDArray *) * cols); int *indices_shape = emalloc(sizeof(int) * 2); indices_shape[0] = 2; @@ -203,20 +203,20 @@ NDArray *NDArray_cov(NDArray *a, bool rowvar) NDArray *subtracted = NDArray_Subtract_Float(col_vector, mean); efree(col_vector); efree(mean); - norm_vectors[i] = subtracted; + centered_vectors[i] = subtracted; } efree(indices_shape); efree(indices_axis[0]); efree(indices_axis[1]); efree(indices_axis); - NDArray *norm_a = NDArray_Reshape(NDArray_ConcatenateFlat(norm_vectors, cols), NDArray_SHAPE(a), NDArray_NDIM(a)); + NDArray *centered_a = NDArray_Reshape(NDArray_ConcatenateFlat(centered_vectors, cols), NDArray_SHAPE(a), NDArray_NDIM(a)); for (int i = 0; i < cols; i++) { - efree(norm_vectors[i]); + efree(centered_vectors[i]); } - efree(norm_vectors); - NDArray *multiplied = NDArray_Dot(norm_a, NDArray_Transpose(norm_a, NULL)); - efree(norm_a); + efree(centered_vectors); + NDArray *multiplied = NDArray_Dot(centered_a, NDArray_Transpose(centered_a, NULL)); + efree(centered_a); NDArray *rtn = NDArray_Divide_Float(multiplied, NDArray_CreateFromFloatScalar((float)rows - 1)); efree(multiplied); return rtn;