Repository: spark Updated Branches: refs/heads/master 587c315b2 -> f9a82a884
[SPARK-9138] [MLLIB] fix Vectors.dense Vectors.dense() should accept numbers directly, like the one in Scala. We already use it in doctests, it worked by luck. cc mengxr jkbradley Author: Davies Liu <[email protected]> Closes #7476 from davies/fix_vectors_dense and squashes the following commits: e0fd292 [Davies Liu] fix Vectors.dense Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/f9a82a88 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/f9a82a88 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/f9a82a88 Branch: refs/heads/master Commit: f9a82a884e7cb2a466a33ab64912924ce7ee30c1 Parents: 587c315 Author: Davies Liu <[email protected]> Authored: Fri Jul 17 12:43:58 2015 -0700 Committer: Xiangrui Meng <[email protected]> Committed: Fri Jul 17 12:43:58 2015 -0700 ---------------------------------------------------------------------- python/pyspark/mllib/linalg.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/f9a82a88/python/pyspark/mllib/linalg.py ---------------------------------------------------------------------- diff --git a/python/pyspark/mllib/linalg.py b/python/pyspark/mllib/linalg.py index 040886f..529bd75 100644 --- a/python/pyspark/mllib/linalg.py +++ b/python/pyspark/mllib/linalg.py @@ -30,6 +30,7 @@ if sys.version >= '3': basestring = str xrange = range import copyreg as copy_reg + long = int else: from itertools import izip as zip import copy_reg @@ -770,14 +771,18 @@ class Vectors(object): return SparseVector(size, *args) @staticmethod - def dense(elements): + def dense(*elements): """ - Create a dense vector of 64-bit floats from a Python list. Always - returns a NumPy array. + Create a dense vector of 64-bit floats from a Python list or numbers. >>> Vectors.dense([1, 2, 3]) DenseVector([1.0, 2.0, 3.0]) + >>> Vectors.dense(1.0, 2.0) + DenseVector([1.0, 2.0]) """ + if len(elements) == 1 and not isinstance(elements[0], (float, int, long)): + # it's list, numpy.array or other iterable object. + elements = elements[0] return DenseVector(elements) @staticmethod --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
