Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use isinstance
  • Loading branch information
Nick Pentreath committed Jun 30, 2016
commit a1804213bd1cb9b26e2693826e44d548341b8942
8 changes: 4 additions & 4 deletions python/pyspark/mllib/linalg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,9 +909,9 @@ def fromML(vec):
:param vec: a :py:class:`pyspark.ml.linalg.Vector`
:return: a :py:class:`pyspark.mllib.linalg.Vector`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

versionadded

"""
if type(vec) == newlinalg.DenseVector:
if isinstance(vec, newlinalg.DenseVector):
return DenseVector(vec.array)
elif type(vec) == newlinalg.SparseVector:
elif isinstance(vec, newlinalg.SparseVector):
return SparseVector(vec.size, vec.indices, vec.values)
else:
raise TypeError("Unsupported vector type %s" % type(vec))
Expand Down Expand Up @@ -1389,9 +1389,9 @@ def fromML(mat):
:param vec: a :py:class:`pyspark.ml.linalg.Matrix`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vec -> mat

:return: a :py:class:`pyspark.mllib.linalg.Matrix`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

versionadded

"""
if type(mat) == newlinalg.DenseMatrix:
if isinstance(mat, newlinalg.DenseMatrix):
return DenseMatrix(mat.numRows, mat.numCols, mat.values, mat.isTransposed)
elif type(mat) == newlinalg.SparseMatrix:
elif isinstance(mat, newlinalg.SparseMatrix):
return SparseMatrix(mat.numRows, mat.numCols, mat.colPtrs, mat.rowIndices,
mat.values, mat.isTransposed)
else:
Expand Down