koraykv / unsup

Some unsupervised learning modules using Torch
86 stars 36 forks source link

kmeans: fix in-place modifications of input data #28

Closed deltheil closed 9 years ago

deltheil commented 9 years ago

x.pow has for effect to modify in-place its first arg:

local x   = torch.Tensor{1, 2, 3}
local pow = x.pow
local x2  = pow(x, 2)
print(x) --> {1, 4, 9} i.e x has been modified!

For consistency I also reverted to torch.sum and torch.max that have no impact vs. tensor type (see #24).