Skip to content
Snippets Groups Projects
Commit 0f1dc3a7 authored by Xiangrui Meng's avatar Xiangrui Meng Committed by Reynold Xin
Browse files

[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
parent 0266a0c8
No related branches found
No related tags found
No related merge requests found
......@@ -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]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment