-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathelements_sum.gsql
41 lines (31 loc) · 1.09 KB
/
elements_sum.gsql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
CREATE FUNCTION gds.vector.elements_sum(list<double> list1) RETURNS(float) {
/*
First Author: Jue Yuan
First Commit Date: Nov 27, 2024
Recent Author: Jue Yuan
Recent Commit Date: Nov 27, 2024
Maturity:
alpha
Description:
Calculates the sum of all elements in a vector, represented as a list of double values.
This function is useful for aggregating vector components in mathematical and statistical operations.
Parameters:
list<double> list1:
The input vector as a list of double values.
Returns:
float:
The sum of all elements in the input vector.
Logic Overview:
Iterates through each element in the input list.
Accumulates the sum of all elements.
Returns the final sum as a floating-point value.
Use Case:
This function is valuable in various data processing tasks, such as computing vector norms,
validating data integrity, or performing aggregations in machine learning and statistical analysis.
*/
SumAccum<float> @@mySum;
FOREACH i IN list1 DO
@@mySum += i;
END;
RETURN @@mySum;
}