Help about Accumulator

when i install the following query,occur error about @@avgdistance[i][j] += s.@embeddings[j] ,the avgaccum can’t update by add another accumlator
ArrayAccum<SumAccum>@cluster[1];
ArrayAccum@@avgdistance[1][1];
ArrayAccum<SumAccum>@embeddings[3];
FOREACH i IN RANGE[0,k-1] DO
tar = SELECT s
FROM source:s
WHERE s.@cluster[0] == i
ACCUM FOREACH j IN RANGE[0,2] DO
@@avgdistance[i][j] += s.@embeddings[j]
END;
END;

Its unclear what you are trying to do

  1. why use the ArrayAccum of size 1 ?
  2. why are you checking the @cluster accumulator in the WHERE clause?
  3. why are you assigning the values from @embeddings without having any data in it?

this is part of the code,I want get the Average of some vertex attributes to clustering,but the arry avgaccum can’t update by a arry sumaccum, the error log display no match function for call to ‘ArrayAccum::ArrayAccum(, const ArrayAccum&, const SumAccum&)’

ArrayAccum@@avgdistance[1][3];
ArrayAccum<SumAccum>@embeddings[3];
source ={electric.*};
source = select s
from source:s
accum s.@embedding[0]+=s.power,
      s.@embedding[0]+=s.start_time,
      s.@embedding[0]+=s.end_time;
FOREACH i IN RANGE[0,2] DO
tar = SELECT s
FROM source:s
where s.start_time==0
ACCUM FOREACH j IN RANGE[0,2] DO
@@avgdistance[i][j] += s.@embeddings[j]
END;
END;

Its not clear why the use of the ArrayAccum is necessary, but I still think this can be greatly simplified

In your example, the embeddings accumulator doesn’t seem to be doing anything, other than to set up your next portion of code to run in a loop, but that loop is not needed since this can all be achieved in a single pass - unless there is some other detail not shown in your code example - Look at my simplified version and see how this differs from what you are trying to do:

ArrayAccum<AvgAccum>  @@avgdistance[3];
source ={electric.*};
source = select s from source:s
   accum   @@avgdistance[0]+=s.power,
                  @@avgdistance[1]+=s.start_time,
                  @@avgdistance[2]+=s.end_time;

yes,this worked. Thank you!
But I still confuse why arry avgaccum can’t update by a arry sumaccum

I do that all the time, its quite useful to first sum and then average. Its possible that your use of the array was confusing matters. This simpler example works fine. The use of POST ACCUM is quite important in this example, and note that I am using V2 syntax

SumAccum<DOUBLE>   @totalsum;
AvgAccum  @@totalAvg;

S1 = SELECT s FROM sourcesample:s -(_>) - values:x
	             ACCUM  s.@totalsum += x.testAmount
	             POST-ACCUM @@totalAvg += s.@totalsum;
1 Like