Skip to content

Commit

Permalink
MAINT: cluster: avoid copying when dtype is the same in vq
Browse files Browse the repository at this point in the history
  • Loading branch information
cairijun committed Jun 1, 2014
1 parent a59aa5c commit dd8a93f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions scipy/cluster/vq.py
Expand Up @@ -194,8 +194,20 @@ def vq(obs, code_book):
try:
from . import _vq
ct = common_type(obs, code_book)
c_obs = obs.astype(ct)
c_code_book = code_book.astype(ct)

# avoid copying when dtype is the same
# should be replaced with c_obs = astype(ct, copy=False)
# when we get to numpy 1.7.0
if obs.dtype != ct:
c_obs = obs.astype(ct)
else:
c_obs = obs

if code_book.dtype != ct:
c_code_book = code_book.astype(ct)
else:
c_code_book = code_book

if ct in (single, double):
results = _vq.vq(c_obs, c_code_book)
else:
Expand Down

0 comments on commit dd8a93f

Please sign in to comment.