You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by rx...@apache.org on 2014/06/11 09:22:44 UTC
git commit: [SPARK-2091][MLLIB] use numpy.dot instead of ndarray.dot
Repository: spark
Updated Branches:
refs/heads/master 0266a0c8a -> 0f1dc3a73
[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 <me...@databricks.com>
Closes #1035 from mengxr/numpy-1.4 and squashes the following commits:
7ad2f0c [Xiangrui Meng] use numpy.dot instead of ndarray.dot
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/0f1dc3a7
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/0f1dc3a7
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/0f1dc3a7
Branch: refs/heads/master
Commit: 0f1dc3a73d6687f0027a68eb9a4a13a7c7848205
Parents: 0266a0c
Author: Xiangrui Meng <me...@databricks.com>
Authored: Wed Jun 11 00:22:40 2014 -0700
Committer: Reynold Xin <rx...@apache.org>
Committed: Wed Jun 11 00:22:40 2014 -0700
----------------------------------------------------------------------
python/pyspark/mllib/_common.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/0f1dc3a7/python/pyspark/mllib/_common.py
----------------------------------------------------------------------
diff --git a/python/pyspark/mllib/_common.py b/python/pyspark/mllib/_common.py
index a411a5d..e609b60 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]