aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorXiangrui Meng <meng@databricks.com>2014-06-11 00:22:40 -0700
committerReynold Xin <rxin@apache.org>2014-06-11 00:22:40 -0700
commit0f1dc3a73d6687f0027a68eb9a4a13a7c7848205 (patch)
tree898f336c24a99f1db1ceda52e1004f2225dcd2d1 /python
parent0266a0c8a70e0fbaeb0df63031f7a750ffc31a80 (diff)
downloadspark-0f1dc3a73d6687f0027a68eb9a4a13a7c7848205.tar.gz
spark-0f1dc3a73d6687f0027a68eb9a4a13a7c7848205.tar.bz2
spark-0f1dc3a73d6687f0027a68eb9a4a13a7c7848205.zip
[SPARK-2091][MLLIB] use numpy.dot instead of ndarray.dot
`ndarray.dot` is not available in numpy 1.4. This PR makes pyspark/mllib compatible with numpy 1.4. Author: Xiangrui Meng <meng@databricks.com> Closes #1035 from mengxr/numpy-1.4 and squashes the following commits: 7ad2f0c [Xiangrui Meng] use numpy.dot instead of ndarray.dot
Diffstat (limited to 'python')
-rw-r--r--python/pyspark/mllib/_common.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/python/pyspark/mllib/_common.py b/python/pyspark/mllib/_common.py
index a411a5d591..e609b60a0f 100644
--- a/python/pyspark/mllib/_common.py
+++ b/python/pyspark/mllib/_common.py
@@ -454,7 +454,7 @@ def _squared_distance(v1, v2):
v2 = _convert_vector(v2)
if type(v1) == ndarray and type(v2) == ndarray:
diff = v1 - v2
- return diff.dot(diff)
+ return numpy.dot(diff, diff)
elif type(v1) == ndarray:
return v2.squared_distance(v1)
else:
@@ -469,10 +469,12 @@ def _dot(vec, target):
calling numpy.dot of the two vectors, but for SciPy ones, we
have to transpose them because they're column vectors.
"""
- if type(vec) == ndarray or type(vec) == SparseVector:
+ if type(vec) == ndarray:
+ return numpy.dot(vec, target)
+ elif type(vec) == SparseVector:
return vec.dot(target)
elif type(vec) == list:
- return _convert_vector(vec).dot(target)
+ return numpy.dot(_convert_vector(vec), target)
else:
return vec.transpose().dot(target)[0]