From db0f3c71043fed4a49e2760359b8ac1d2fb1123d Mon Sep 17 00:00:00 2001 From: Charles Dickens Date: Mon, 10 Jun 2024 08:37:41 -0700 Subject: [PATCH] Sum methods in MathUtils.java. --- .../java/org/linqs/psl/util/MathUtils.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/psl-core/src/main/java/org/linqs/psl/util/MathUtils.java b/psl-core/src/main/java/org/linqs/psl/util/MathUtils.java index 7a56de10c..2e02ad48d 100644 --- a/psl-core/src/main/java/org/linqs/psl/util/MathUtils.java +++ b/psl-core/src/main/java/org/linqs/psl/util/MathUtils.java @@ -221,6 +221,26 @@ public static void toMagnitude(float[] vector, double magnitude) { } } + /** + * Compute the sum of the provided vector. + */ + public static float sum(float[] vector) { + float sum = 0.0f; + for (float v : vector) { + sum += v; + } + return sum; + } + + + public static double sum(double[] vector) { + double sum = 0.0; + for (double v : vector) { + sum += v; + } + return sum; + } + /** * Compute the p-norm of the provided vector. */