Created
August 6, 2014 05:46
-
-
Save mitliagkas/a7654843efeb379763f8 to your computer and use it in GitHub Desktop.
PySpark Vector Accumulator Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taken almost verbatim from PySpark's doctest | |
from pyspark.accumulators import AccumulatorParam | |
class VectorAccumulatorParam(AccumulatorParam): | |
def zero(self, value): | |
return [0.0] * len(value) | |
def addInPlace(self, val1, val2): | |
for i in xrange(len(val1)): | |
val1[i] += val2[i] | |
return val1 | |
xnew = sc.accumulator([0.0]*p, VectorAccumulatorParam()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment