@Override public void observe(VectorWritable v) { Vector x = v.get(); s0++; if (s1 == null) { s1 = x.clone(); } else { s1 = s1.plus(x); } if (s2 == null) { s2 = x.times(x); } else { s2 = s2.plus(x.times(x)); } }
public void reduce(VarLongWritable key, Iterable<VectorWritable> values, Context context) throws IOException, InterruptedException { Vector partial = null; for (VectorWritable vectorWritable : values) { partial = partial == null ? vectorWritable.get() : partial.plus(vectorWritable.get()); } context.write(key, new VectorWritable(partial)); }