Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion python/pyspark/ml/linalg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ class DenseVector(Vector):
DenseVector([3.0, 2.0])
>>> u % 2
DenseVector([1.0, 0.0])
>>> -v
DenseVector([-1.0, -2.0])
"""
def __init__(self, ar):
if isinstance(ar, bytes):
Expand Down Expand Up @@ -436,14 +438,16 @@ def __hash__(self):
def __getattr__(self, item):
return getattr(self.array, item)

def __neg__(self):
return DenseVector(-self.array)

def _delegate(op):
def func(self, other):
if isinstance(other, DenseVector):
other = other.array
return DenseVector(getattr(self.array, op)(other))
return func

__neg__ = _delegate("__neg__")
__add__ = _delegate("__add__")
__sub__ = _delegate("__sub__")
__mul__ = _delegate("__mul__")
Expand Down
6 changes: 5 additions & 1 deletion python/pyspark/mllib/linalg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ class DenseVector(Vector):
DenseVector([3.0, 2.0])
>>> u % 2
DenseVector([1.0, 0.0])
>>> -v
DenseVector([-1.0, -2.0])
"""
def __init__(self, ar):
if isinstance(ar, bytes):
Expand Down Expand Up @@ -480,14 +482,16 @@ def __hash__(self):
def __getattr__(self, item):
return getattr(self.array, item)

def __neg__(self):
return DenseVector(-self.array)

def _delegate(op):
def func(self, other):
if isinstance(other, DenseVector):
other = other.array
return DenseVector(getattr(self.array, op)(other))
return func

__neg__ = _delegate("__neg__")
__add__ = _delegate("__add__")
__sub__ = _delegate("__sub__")
__mul__ = _delegate("__mul__")
Expand Down