HappenLee commented on code in PR #55184:
URL: https://github.com/apache/doris/pull/55184#discussion_r2297325340


##########
be/src/vec/functions/array/function_array_distance.h:
##########
@@ -35,82 +37,77 @@ class L1Distance {
 public:
     static constexpr auto name = "l1_distance";
     struct State {
-        double sum = 0;
+        float sum = 0;
     };
-    static void accumulate(State& state, double x, double y) { state.sum += 
fabs(x - y); }
-    static double finalize(const State& state) { return state.sum; }
+    static void accumulate(State& state, float x, float y) { state.sum += 
fabs(x - y); }
+    static float finalize(const State& state) { return state.sum; }
 };
 
 class L2Distance {
 public:
     static constexpr auto name = "l2_distance";
     struct State {
-        double sum = 0;
+        float sum = 0;
     };
-    static void accumulate(State& state, double x, double y) { state.sum += (x 
- y) * (x - y); }
-    static double finalize(const State& state) { return sqrt(state.sum); }
+    static void accumulate(State& state, float x, float y) { state.sum += (x - 
y) * (x - y); }
+    static float finalize(const State& state) { return sqrt(state.sum); }
 };
 
 class InnerProduct {
 public:
     static constexpr auto name = "inner_product";
     struct State {
-        double sum = 0;
+        float sum = 0;
     };
-    static void accumulate(State& state, double x, double y) { state.sum += x 
* y; }
-    static double finalize(const State& state) { return state.sum; }
+    static void accumulate(State& state, float x, float y) { state.sum += x * 
y; }
+    static float finalize(const State& state) { return state.sum; }
 };
 
 class CosineDistance {
 public:
     static constexpr auto name = "cosine_distance";
     struct State {
-        double dot_prod = 0;
-        double squared_x = 0;
-        double squared_y = 0;
+        float dot_prod = 0;
+        float squared_x = 0;
+        float squared_y = 0;
     };
-    static void accumulate(State& state, double x, double y) {
+    static void accumulate(State& state, float x, float y) {
         state.dot_prod += x * y;
         state.squared_x += x * x;
         state.squared_y += y * y;
     }
-    static double finalize(const State& state) {
+    static float finalize(const State& state) {
         return 1 - state.dot_prod / sqrt(state.squared_x * state.squared_y);
     }
 };
 
-class L2DistanceApproximate {
+class L2DistanceApproximate : public L2Distance {
 public:
     static constexpr auto name = "l2_distance_approximate";
-    struct State {
-        double sum = 0;
-    };
-    static void accumulate(State& state, double x, double y) { state.sum += (x 
- y) * (x - y); }
-    static double finalize(const State& state) { return sqrt(state.sum); }
 };
 
-class InnerProductApproximate {
+class InnerProductApproximate : public InnerProduct {
 public:
     static constexpr auto name = "inner_product_approximate";
-    struct State {
-        double sum = 0;
-    };
-    static void accumulate(State& state, double x, double y) { state.sum += x 
* y; }
-    static double finalize(const State& state) { return state.sum; }
 };
 
-template <typename DistanceImpl>
+template <typename DistanceImpl, PrimitiveType Type>
 class FunctionArrayDistance : public IFunction {
 public:
+    using DataType = PrimitiveTypeTraits<Type>::DataType;

Review Comment:
   the function seem only need return FLOAT, maybe we not need use template type



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to